Skip to content

Commit 561cd64

Browse files
committed
refactor: simplify utility functions
1 parent 362fdae commit 561cd64

20 files changed

+146
-527
lines changed

po/POTFILES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ src/ibus-chewing-lookup-table.c
88
src/ibus-chewing-preedit.c
99
src/ibus-chewing-util.c
1010
src/main.c
11-
src/maker-dialog-util.c

src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
add_library(common STATIC
22
ibus-chewing-lookup-table.c
3-
maker-dialog-util.c
43

54
ibus-chewing-lookup-table.h
6-
maker-dialog-util.h
75
ibus-chewing-engine.h
86
)
97
target_link_libraries(common PUBLIC

src/ibus-chewing-engine.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
* USA.
2121
*/
2222
#include "ibus-chewing-engine.h"
23-
#include "ibus-chewing-preedit.h"
23+
#include "ibus-chewing-engine-private.h"
2424
#include "ibus-chewing-lookup-table.h"
25+
#include "ibus-chewing-preedit.h"
2526
#include "ibus-chewing-util.h"
26-
#include "maker-dialog-util.h"
27-
#include "ibus-chewing-engine-private.h"
2827
#include <chewing.h>
2928
#include <glib.h>
3029
#include <glib/gi18n.h>
@@ -569,7 +568,7 @@ void ibus_chewing_engine_refresh_property(IBusChewingEngine *self,
569568
#ifndef UNIT_TEST
570569
IBUS_CHEWING_LOG(DEBUG, "refresh_property(%s) status=%x", prop_name, self->statusFlags);
571570

572-
if (STRING_EQUALS(prop_name, "InputMode")) {
571+
if (g_strcmp0(prop_name, "InputMode") == 0) {
573572

574573
ibus_property_set_label(self->InputMode,
575574
ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit)
@@ -585,7 +584,7 @@ void ibus_chewing_engine_refresh_property(IBusChewingEngine *self,
585584

586585
ibus_engine_update_property(IBUS_ENGINE(self), self->InputMode);
587586

588-
} else if (STRING_EQUALS(prop_name, "AlnumSize")) {
587+
} else if (g_strcmp0(prop_name, "AlnumSize") == 0) {
589588

590589
ibus_property_set_label(self->AlnumSize, chewing_get_ShapeMode(self->icPreEdit->context)
591590
? self->AlnumSize_label_full
@@ -601,7 +600,7 @@ void ibus_chewing_engine_refresh_property(IBusChewingEngine *self,
601600
if (self->statusFlags & ENGINE_FLAG_PROPERTIES_REGISTERED)
602601
ibus_engine_update_property(IBUS_ENGINE(self), self->AlnumSize);
603602

604-
} else if (STRING_EQUALS(prop_name, "setup_prop")) {
603+
} else if (g_strcmp0(prop_name, "setup_prop") == 0) {
605604
#if IBUS_CHECK_VERSION(1, 5, 0)
606605
ibus_property_set_symbol(self->setup_prop, self->setup_prop_symbol);
607606
#endif
@@ -650,11 +649,11 @@ static IBusProperty *ibus_chewing_engine_get_ibus_property_by_name(IBusChewingEn
650649
g_return_val_if_fail(self != NULL, (IBusProperty *)0);
651650
g_return_val_if_fail(IBUS_IS_CHEWING_ENGINE(self), (IBusProperty *)0);
652651
{
653-
if (STRING_EQUALS(prop_name, "InputMode")) {
652+
if (g_strcmp0(prop_name, "InputMode") == 0) {
654653
return self->InputMode;
655-
} else if (STRING_EQUALS(prop_name, "AlnumSize")) {
654+
} else if (g_strcmp0(prop_name, "AlnumSize") == 0) {
656655
return self->AlnumSize;
657-
} else if (STRING_EQUALS(prop_name, "setup_prop")) {
656+
} else if (g_strcmp0(prop_name, "setup_prop") == 0) {
658657
return self->setup_prop;
659658
}
660659
IBUS_CHEWING_LOG(MSG, "get_ibus_property_by_name(%s): NULL is returned", prop_name);
@@ -848,8 +847,8 @@ static void parent_update_pre_edit_text_with_mode([[maybe_unused]] IBusEngine *i
848847
IBusText *iText, guint cursor_pos,
849848
gboolean visible, IBusPreeditFocusMode mode) {
850849
#ifdef UNIT_TEST
851-
printf("# * parent_update_pre_edit_text_with_mode(-, %s, %u, %x, %x)\n", iText->text, cursor_pos,
852-
visible, mode);
850+
printf("# * parent_update_pre_edit_text_with_mode(-, %s, %u, %x, %x)\n", iText->text,
851+
cursor_pos, visible, mode);
853852
#else
854853
ibus_engine_update_preedit_text_with_mode(iEngine, iText, cursor_pos, visible, mode);
855854
#endif
@@ -858,7 +857,8 @@ static void parent_update_pre_edit_text_with_mode([[maybe_unused]] IBusEngine *i
858857
static void parent_update_auxiliary_text([[maybe_unused]] IBusEngine *iEngine, IBusText *iText,
859858
gboolean visible) {
860859
#ifdef UNIT_TEST
861-
printf("# * parent_update_auxiliary_text(-, %s, %x)\n", (iText) ? iText->text : "NULL", visible);
860+
printf("# * parent_update_auxiliary_text(-, %s, %x)\n", (iText) ? iText->text : "NULL",
861+
visible);
862862
#else
863863
if (!visible || ibus_text_is_empty(iText)) {
864864
ibus_engine_hide_auxiliary_text(iEngine);
@@ -1017,7 +1017,7 @@ void commit_text(IBusChewingEngine *self) {
10171017
gboolean ibus_chewing_engine_process_key_event(IBusEngine *engine, KSym keySym, guint keycode,
10181018
KeyModifiers unmaskedMod) {
10191019
IBUS_CHEWING_LOG(MSG, "******** process_key_event(-,%x(%s),%x,%x) %s", keySym,
1020-
key_sym_get_name(keySym), keycode, unmaskedMod,
1020+
ibus_keyval_name(keySym), keycode, unmaskedMod,
10211021
modifiers_to_string(unmaskedMod));
10221022

10231023
IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine);
@@ -1081,17 +1081,17 @@ void ibus_chewing_engine_property_activate(IBusEngine *engine, const gchar *prop
10811081
IBUS_CHEWING_LOG(INFO, "property_activate(-, %s, %u)", prop_name, prop_state);
10821082
IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine);
10831083

1084-
if (STRING_EQUALS(prop_name, "InputMode")) {
1084+
if (g_strcmp0(prop_name, "InputMode") == 0) {
10851085
/* Toggle Chinese <-> English */
10861086
ibus_chewing_pre_edit_toggle_chi_eng_mode(self->icPreEdit);
10871087
IBUS_CHEWING_LOG(INFO, "property_activate chinese=%d", is_chinese_mode(self));
10881088
ibus_chewing_engine_refresh_property(self, prop_name);
1089-
} else if (STRING_EQUALS(prop_name, "AlnumSize")) {
1089+
} else if (g_strcmp0(prop_name, "AlnumSize") == 0) {
10901090
/* Toggle Full <-> Half */
10911091
ibus_chewing_pre_edit_toggle_full_half_mode(self->icPreEdit);
10921092
IBUS_CHEWING_LOG(INFO, "property_activate fullwidth=%d", is_fullwidth_mode(self));
10931093
ibus_chewing_engine_refresh_property(self, prop_name);
1094-
} else if (STRING_EQUALS(prop_name, "setup_prop")) {
1094+
} else if (g_strcmp0(prop_name, "setup_prop") == 0) {
10951095
/* open preferences window */
10961096
char *argv[] = {QUOTE_ME(LIBEXEC_DIR) "/ibus-setup-chewing", NULL};
10971097
g_spawn_async(NULL, argv, NULL, G_SPAWN_DEFAULT, NULL, NULL, NULL, NULL);
@@ -1103,16 +1103,16 @@ void ibus_chewing_engine_property_activate(IBusEngine *engine, const gchar *prop
11031103

11041104
char ibus_chewing_engine_get_default_english_case(IBusChewingEngine *self) {
11051105
char *prop = self->prop_default_english_case;
1106-
return STRING_EQUALS(prop, "lowercase") ? 'l' : STRING_EQUALS(prop, "uppercase") ? 'u' : 'n';
1106+
return g_strcmp0(prop, "lowercase") == 0 ? 'l' : g_strcmp0(prop, "uppercase") == 0 ? 'u' : 'n';
11071107
}
11081108

11091109
char ibus_chewing_engine_get_chinese_english_toggle_key(IBusChewingEngine *self) {
11101110
char *prop = self->prop_chi_eng_mode_toggle;
1111-
return STRING_EQUALS(prop, "caps_lock") ? 'c'
1112-
: STRING_EQUALS(prop, "shift") ? 's'
1113-
: STRING_EQUALS(prop, "shift_l") ? 'l'
1114-
: STRING_EQUALS(prop, "shift_r") ? 'r'
1115-
: 'n';
1111+
return g_strcmp0(prop, "caps_lock") == 0 ? 'c'
1112+
: g_strcmp0(prop, "shift") == 0 ? 's'
1113+
: g_strcmp0(prop, "shift_l") == 0 ? 'l'
1114+
: g_strcmp0(prop, "shift_r") == 0 ? 'r'
1115+
: 'n';
11161116
return 'n';
11171117
}
11181118

src/ibus-chewing-lookup-table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "ibus-chewing-lookup-table.h"
22
#include "ibus-chewing-util.h"
3-
#include "maker-dialog-util.h"
3+
#include <ctype.h>
44

55
IBusLookupTable *ibus_chewing_lookup_table_new(ChewingContext *context) {
66
guint size = 10;

src/ibus-chewing-lookup-table.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@
3838

3939
IBusLookupTable *ibus_chewing_lookup_table_new(ChewingContext *context);
4040

41-
void ibus_chewing_lookup_table_resize(IBusLookupTable *iTable,
42-
ChewingContext *context);
41+
void ibus_chewing_lookup_table_resize(IBusLookupTable *iTable, ChewingContext *context);
4342

44-
guint ibus_chewing_lookup_table_update(IBusLookupTable *iTable,
45-
ChewingContext *context);
43+
guint ibus_chewing_lookup_table_update(IBusLookupTable *iTable, ChewingContext *context);
4644

4745
#endif /* _IBUS_CHEWING_LOOKUP_TABLE_H_ */

src/ibus-chewing-preedit-private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
#define handle_log(funcName) \
7878
IBUS_CHEWING_LOG(INFO, "* self_handle_%s(-,%x(%s),%x(%s))", funcName, kSym, \
79-
key_sym_get_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod));
79+
ibus_keyval_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod));
8080

8181
KSym self_key_sym_fix(IBusChewingPreEdit *self, KSym kSym, KeyModifiers unmaskedMod);
8282

src/ibus-chewing-preedit.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
#include "ibus-chewing-engine.h"
21
#include "ibus-chewing-preedit.h"
2+
#include "ibus-chewing-engine.h"
33
#include "ibus-chewing-lookup-table.h"
4-
#include "ibus-chewing-util.h"
5-
#include "maker-dialog-util.h"
64
#include "ibus-chewing-preedit-private.h"
5+
#include "ibus-chewing-util.h"
6+
#include "ibus.h"
77
#include <chewing.h>
8+
#include <ctype.h>
89
#include <glib.h>
910

1011
/**************************************
@@ -258,7 +259,7 @@ EventResponse self_handle_key_sym_default(IBusChewingPreEdit *self, KSym kSym,
258259
KSym fixedKSym = self_key_sym_fix(self, kSym, unmaskedMod);
259260

260261
IBUS_CHEWING_LOG(DEBUG, "* self_handle_key_sym_default(): new kSym %x(%s), %x(%s)", fixedKSym,
261-
key_sym_get_name(fixedKSym), unmaskedMod, modifiers_to_string(unmaskedMod));
262+
ibus_keyval_name(fixedKSym), unmaskedMod, modifiers_to_string(unmaskedMod));
262263
gint ret = chewing_handle_Default(self->context, fixedKSym);
263264

264265
/* Handle quick commit */
@@ -770,7 +771,7 @@ gboolean is_shift_toggle(KSym keyLast, KSym kSym, KeyModifiers unmaskedMod) {
770771
gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit *self, KSym kSym,
771772
KeyModifiers unmaskedMod) {
772773
IBUS_CHEWING_LOG(INFO, "***** ibus_chewing_pre_edit_process_key(-,%x(%s),%x(%s))", kSym,
773-
key_sym_get_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod));
774+
ibus_keyval_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod));
774775
process_key_debug("Before response");
775776

776777
/* Find corresponding rule */

src/ibus-chewing-preedit.h

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ guint ibus_chewing_pre_edit_word_length(IBusChewingPreEdit *self);
9999

100100
guint ibus_chewing_pre_edit_word_limit(IBusChewingPreEdit *self);
101101

102-
#define ibus_chewing_pre_edit_is_empty(self) \
103-
(ibus_chewing_pre_edit_length(self) == 0)
102+
#define ibus_chewing_pre_edit_is_empty(self) (ibus_chewing_pre_edit_length(self) == 0)
104103

105-
#define ibus_chewing_pre_edit_is_full(self) \
104+
#define ibus_chewing_pre_edit_is_full(self) \
106105
(self->wordLen >= ibus_chewing_pre_edit_word_limit(self))
107106

108107
#define ibus_chewing_pre_edit_is_outgoing_empty(self) (self->outgoing->len == 0)
@@ -129,8 +128,7 @@ gchar *ibus_chewing_pre_edit_get_outgoing(IBusChewingPreEdit *self);
129128

130129
#define ibus_chewing_pre_edit_has_flag(self, f) mkdg_has_flag(self->flags, f)
131130
#define ibus_chewing_pre_edit_set_flag(self, f) mkdg_set_flag(self->flags, f)
132-
#define ibus_chewing_pre_edit_clear_flag(self, f) \
133-
mkdg_clear_flag(self->flags, f)
131+
#define ibus_chewing_pre_edit_clear_flag(self, f) mkdg_clear_flag(self->flags, f)
134132

135133
void ibus_chewing_pre_edit_force_commit(IBusChewingPreEdit *self);
136134
void ibus_chewing_pre_edit_clear(IBusChewingPreEdit *self);
@@ -141,17 +139,13 @@ void ibus_chewing_pre_edit_clear_outgoing(IBusChewingPreEdit *self);
141139
gboolean ibus_chewing_pre_edit_get_chi_eng_mode(IBusChewingPreEdit *self);
142140
gboolean ibus_chewing_pre_edit_get_full_half_mode(IBusChewingPreEdit *self);
143141

144-
void ibus_chewing_pre_edit_set_chi_eng_mode(IBusChewingPreEdit *self,
145-
gboolean chineseMode);
146-
void ibus_chewing_pre_edit_set_full_half_mode(IBusChewingPreEdit *self,
147-
gboolean fullShapeMode);
142+
void ibus_chewing_pre_edit_set_chi_eng_mode(IBusChewingPreEdit *self, gboolean chineseMode);
143+
void ibus_chewing_pre_edit_set_full_half_mode(IBusChewingPreEdit *self, gboolean fullShapeMode);
148144

149-
#define ibus_chewing_pre_edit_toggle_chi_eng_mode(self) \
150-
ibus_chewing_pre_edit_set_chi_eng_mode( \
151-
self, !ibus_chewing_pre_edit_get_chi_eng_mode(self))
152-
#define ibus_chewing_pre_edit_toggle_full_half_mode(self) \
153-
ibus_chewing_pre_edit_set_full_half_mode( \
154-
self, !ibus_chewing_pre_edit_get_full_half_mode(self))
145+
#define ibus_chewing_pre_edit_toggle_chi_eng_mode(self) \
146+
ibus_chewing_pre_edit_set_chi_eng_mode(self, !ibus_chewing_pre_edit_get_chi_eng_mode(self))
147+
#define ibus_chewing_pre_edit_toggle_full_half_mode(self) \
148+
ibus_chewing_pre_edit_set_full_half_mode(self, !ibus_chewing_pre_edit_get_full_half_mode(self))
155149

156150
gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit *self, KSym kSym,
157151
KeyModifiers unmaskedMod);
@@ -161,8 +155,7 @@ gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit *self, KSym kSym,
161155
*
162156
* Convert keycode to key_sym.
163157
*/
164-
KSym ibus_chewing_pre_edit_key_code_to_key_sym(IBusChewingPreEdit *self,
165-
KSym keySym, guint keyCode,
158+
KSym ibus_chewing_pre_edit_key_code_to_key_sym(IBusChewingPreEdit *self, KSym keySym, guint keyCode,
166159
KeyModifiers unmaskedMod);
167160

168161
/**
@@ -175,9 +168,9 @@ gchar *ibus_chewing_pre_edit_get_bopomofo_string(IBusChewingPreEdit *self);
175168

176169
typedef enum {
177170
EVENT_RESPONSE_PROCESS = 0, /* Event process by IM */
178-
EVENT_RESPONSE_ABSORB, /* Event throw away by IM (e.g. Release event) */
179-
EVENT_RESPONSE_IGNORE, /* Event that should be passed to application, but
180-
not process by IM */
171+
EVENT_RESPONSE_ABSORB, /* Event throw away by IM (e.g. Release event) */
172+
EVENT_RESPONSE_IGNORE, /* Event that should be passed to application, but
173+
not process by IM */
181174
EVENT_RESPONSE_UNDECIDED,
182175
} EventResponse;
183176

0 commit comments

Comments
 (0)