Skip to content

Commit

Permalink
feat!: deprecate sync IM state back to capslock and remove X11 dep
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Feb 5, 2024
1 parent 8a85fcb commit 99fdb2b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 92 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ add_compile_definitions(
pkg_check_modules(GLIB2 REQUIRED IMPORTED_TARGET glib-2.0)
pkg_check_modules(GTK4 REQUIRED IMPORTED_TARGET gtk4)
pkg_check_modules(LIBADWAITA REQUIRED IMPORTED_TARGET libadwaita-1)
pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11)

find_program(GLIB_COMPILE_RESOURCES NAMES glib-compile-resources REQUIRED)

Expand Down
1 change: 0 additions & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Installation Instructions
gob >= 2.0.16
gtk >= 3
libchewing >= 0.5.1
libX11

1. Remove the old build cache:

Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ target_link_libraries(gui-core PUBLIC
PkgConfig::GLIB2
PkgConfig::GTK4
PkgConfig::LIBADWAITA
PkgConfig::X11
PkgConfig::IBUS
PkgConfig::CHEWING
)
Expand Down
23 changes: 0 additions & 23 deletions src/IBusChewingUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,6 @@ const char *key_sym_get_name(KSym k)
* Modifiers
*/

#define CAPS_LOCK_MASK 2
gboolean is_caps_led_on(Display * pDisplay)
{
XKeyboardState retState;

XGetKeyboardControl(pDisplay, &retState);
XFlush(pDisplay);
return (retState.led_mask & 1) ? TRUE : FALSE;
}

void set_caps_led(gboolean on, Display * pDisplay)
{
XKeyboardControl control;

control.led_mode = (on) ? LedModeOn : LedModeOff;
control.led = CAPS_LOCK_MASK;
guint flags = (on) ? CAPS_LOCK_MASK : 0;

XChangeKeyboardControl(pDisplay, KBLedMode, &control);
XkbLockModifiers(pDisplay, XkbUseCoreKbd, control.led, flags);
XFlush(pDisplay);
}

const gchar *modifier_get_string(guint modifier)
{
switch (modifier) {
Expand Down
6 changes: 0 additions & 6 deletions src/IBusChewingUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
# include <glib.h>
# include <ibus.h>
# include <chewing.h>
# include <X11/Xlib.h>
# include <X11/XKBlib.h>

# define ZHUYIN_BUFFER_SIZE 12

Expand Down Expand Up @@ -70,10 +68,6 @@ KSym key_sym_KP_to_normal(KSym k);

const char *key_sym_get_name(KSym k);

gboolean is_caps_led_on(Display * pDisplay);

void set_caps_led(gboolean on, Display * pDisplay);

const gchar *modifier_get_string(guint modifier);

const gchar *modifiers_to_string(guint modifier);
Expand Down
3 changes: 0 additions & 3 deletions src/ibus-chewing-engine-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include <stdio.h>
#define GETTEXT_PACKAGE "gtk30"
#include <glib/gi18n.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <ctype.h>
#include "IBusChewingUtil.h"
#include "IBusChewingProperties.h"
Expand Down Expand Up @@ -71,7 +69,6 @@ struct _IBusChewingEnginePrivate {
EngineFlag statusFlags;
IBusCapabilite capabilite;
ChewingInputStyle inputStyle;
Display * pDisplay;
};
void ibus_chewing_engine_use_setting (IBusChewingEngine * self);
void ibus_chewing_engine_restore_mode (IBusChewingEngine * self);
Expand Down
42 changes: 10 additions & 32 deletions src/ibus-chewing-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#define GETTEXT_PACKAGE "gtk30"
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <ctype.h>
#include "IBusChewingUtil.h"
#include "IBusChewingProperties.h"
Expand Down Expand Up @@ -144,7 +142,6 @@ static IBusEngineClass *parent_class = NULL;

#define is_password(self) ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_IS_PASSWORD)
#define ibus_chewing_engine_is_chinese_mode(self) ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit)
#define is_caps_lock(self) (is_caps_led_on(((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private(self))->pDisplay))

#define ibus_text_is_empty(iText) ((iText == NULL) || STRING_IS_EMPTY(iText->text))

Expand Down Expand Up @@ -194,7 +191,6 @@ ___finalize(GObject *obj_self)
if(self->AlnumSize) { g_object_unref ((gpointer) self->AlnumSize); self->AlnumSize = NULL; }
if(self->setup_prop) { g_object_unref ((gpointer) self->setup_prop); self->setup_prop = NULL; }
if(self->prop_list) { g_object_unref ((gpointer) self->prop_list); self->prop_list = NULL; }
if(selfp->pDisplay) { XCloseDisplay ((gpointer) selfp->pDisplay); selfp->pDisplay = NULL; }
if(G_OBJECT_CLASS(parent_class)->finalize) \
(* G_OBJECT_CLASS(parent_class)->finalize)(obj_self);
}
Expand Down Expand Up @@ -253,9 +249,6 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED)
g_object_ref_sink(ibus_prop_list_new())
;
self->keymap_us = ibus_keymap_get("us") ;
selfp->pDisplay =
XOpenDisplay(NULL)
;
{

/* initialize the object here */
Expand Down Expand Up @@ -300,11 +293,6 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED)

ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_INITIALIZED);

/* In case we cannot open X display */
if (selfp->pDisplay == NULL) {
IBUS_CHEWING_LOG(WARN, "init() XOpenDisplay return NULL");
}

IBUS_CHEWING_LOG(DEBUG, "init() Done");

}
Expand Down Expand Up @@ -440,17 +428,17 @@ ibus_chewing_engine_restore_mode (IBusChewingEngine * self)
{

IBUS_CHEWING_LOG(DEBUG, "restore_mode() statusFlags=%x", selfp->statusFlags);
if (selfp->pDisplay != NULL) {
/* Restore Led Mode only make sense if pDisplay is available */
GdkDisplay *display = gdk_display_get_default();
if (display != NULL) {
GdkSeat *seat = gdk_display_get_default_seat(display);
GdkDevice *keyboard = gdk_seat_get_keyboard(seat);
/* Restore Led Mode only make sense if display is available */
if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_IM)) {
IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_IM");
if (ibus_chewing_engine_is_chinese_mode(self) == is_caps_lock(self)) {
/* ChiEng mode does not agree each other */
set_caps_led(!ibus_chewing_engine_is_chinese_mode(self), selfp->pDisplay);
}
IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_IM (deprecated)");
} else if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_KEYBOARD)) {
IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_KEYBOARD");
chewing_set_ChiEngMode(self->icPreEdit->context, (is_caps_lock(self)) ? 0 : CHINESE_MODE);
gboolean caps_lock_on = gdk_device_get_caps_lock_state(keyboard);
chewing_set_ChiEngMode(self->icPreEdit->context, caps_lock_on ? 0 : CHINESE_MODE);
}
self_refresh_property(self, "InputMode");
}
Expand Down Expand Up @@ -1220,18 +1208,8 @@ void ibus_chewing_engine_property_activate(IBusEngine * engine,
/* Toggle Chinese <-> English */
ibus_chewing_pre_edit_toggle_chi_eng_mode(self->icPreEdit);
IBUS_CHEWING_LOG(INFO,
"property_activate chinese=%d caps_lock=%d",
ibus_chewing_engine_is_chinese_mode(self),
is_caps_lock(self));

if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_IM)
|| ibus_chewing_pre_edit_has_flag(self->icPreEdit,
FLAG_SYNC_FROM_KEYBOARD)) {
if (ibus_chewing_engine_is_chinese_mode(self) == is_caps_lock(self)) {
set_caps_led(!ibus_chewing_engine_is_chinese_mode(self),
selfp->pDisplay);
}
}
"property_activate chinese=%d",
ibus_chewing_engine_is_chinese_mode(self));
ibus_chewing_engine_refresh_property(self, prop_name);
} else if (STRING_EQUALS(prop_name, "AlnumSize")) {
/* Toggle Full <-> Half */
Expand Down
2 changes: 0 additions & 2 deletions src/ibus-chewing-engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#define GETTEXT_PACKAGE "gtk30"
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <ctype.h>
#include "IBusChewingUtil.h"
#include "IBusChewingProperties.h"
Expand Down
34 changes: 11 additions & 23 deletions src/setup/ibus-setup-chewing-window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,14 @@
<object class="AdwSwitchRow" id="plain_zhuyin">
<property name="active">True</property>
<property name="title" translatable="yes">Intelligent Phrasing</property>
<property name="subtitle" translatable="yes">Enable or disable automatic candidate
selection</property>
<property name="subtitle" translatable="yes">Enable or disable automatic candidate selection</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="show_systray">
<property name="title" translatable="yes">Show Systray Icon</property>
<property name="subtitle" translatable="yes">Whether to show the systray icon</property>
<property name="tooltip-text" translatable="yes">This feature is currently not
implemented.</property>
<property name="tooltip-text" translatable="yes">This feature is currently not implemented.</property>
<property name="sensitive">False</property>
</object>
</child>
Expand All @@ -82,16 +80,14 @@
<object class="AdwSwitchRow" id="auto_shift_cur">
<property name="active">True</property>
<property name="title" translatable="yes">Auto Move Cursor</property>
<property name="subtitle" translatable="yes">Automatically move the cursor to the
next character after selection</property>
<property name="subtitle" translatable="yes">Automatically move the cursor to the next character after selection</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="add_phrase_direction">
<property name="active">True</property>
<property name="title" translatable="yes">Add Phrase Before Cursor</property>
<property name="subtitle" translatable="yes">Use Ctrl + Numbers (2-9) to save new
phrase before or after the cursor</property>
<property name="subtitle" translatable="yes">Use Ctrl + Numbers (2-9) to save new phrase before or after the cursor</property>
</object>
</child>
<child>
Expand All @@ -104,15 +100,13 @@
<object class="AdwSwitchRow" id="easy_symbol_input">
<property name="active">True</property>
<property name="title" translatable="yes">Easy Symbol Input</property>
<property name="subtitle" translatable="yes">Press Shift + keys to input Chinese
punctuation symbols</property>
<property name="subtitle" translatable="yes">Press Shift + keys to input Chinese punctuation symbols</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="esc_clean_all_buf">
<property name="title" translatable="yes">Esc Clean All Buffer</property>
<property name="subtitle" translatable="yes">Escape key discards all uncommitted
texts</property>
<property name="subtitle" translatable="yes">Escape key discards all uncommitted texts</property>
</object>
</child>
<child>
Expand All @@ -126,8 +120,7 @@
</object>
</property>
<property name="title" translatable="yes">Maximum Chinese Characters</property>
<property name="subtitle" translatable="yes">Until how many characters should
trigger auto-commit</property>
<property name="subtitle" translatable="yes">Until how many characters should trigger auto-commit</property>
</object>
</child>
<child>
Expand All @@ -152,7 +145,6 @@
<items>
<item translatable="yes">Disable Syncing</item>
<item translatable="yes">Sync with Keyboard State</item>
<item translatable="yes">Sync with IM State</item>
</items>
</object>
</property>
Expand All @@ -171,17 +163,15 @@
</object>
</property>
<property name="title" translatable="yes">Default English Letter Case</property>
<property name="subtitle" translatable="yes">The letter case without pressing the
Shift key</property>
<property name="subtitle" translatable="yes">The letter case without pressing the Shift key</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Selecting</property>
<property name="description" translatable="yes">Configure the candidate selection
behavior</property>
<property name="description" translatable="yes">Configure the candidate selection behavior</property>
<child>
<object class="AdwSpinRow" id="cand_per_page">
<property name="adjustment">
Expand All @@ -205,8 +195,7 @@
<object class="AdwSwitchRow" id="phrase_choice_from_last">
<property name="active">True</property>
<property name="title" translatable="yes">Choose Phrases Backwards</property>
<property name="subtitle" translatable="yes">Open candidate list from the last
character of a phrase</property>
<property name="subtitle" translatable="yes">Open candidate list from the last character of a phrase</property>
</object>
</child>
<child>
Expand All @@ -219,8 +208,7 @@
<object class="AdwSwitchRow" id="vertical_lookup_table">
<property name="active">True</property>
<property name="title" translatable="yes">Use Vertical Candidate Panel</property>
<property name="subtitle" translatable="yes">Choose from vertical or horizontal
panel</property>
<property name="subtitle" translatable="yes">Choose from vertical or horizontal panel</property>
</object>
</child>
</object>
Expand Down

0 comments on commit 99fdb2b

Please sign in to comment.