@@ -12,6 +12,9 @@ public class Gala.InputMethod : Clutter.InputMethod {
1212 private IBus . Bus bus;
1313 private IBus . InputContext context;
1414
15+ private IBus . InputPurpose input_purpose;
16+ private IBus . InputHints input_hints;
17+
1518 public InputMethod (Meta .Display display ) {
1619 Object (display: display);
1720 }
@@ -34,9 +37,11 @@ public class Gala.InputMethod : Clutter.InputMethod {
3437 context = bus. create_input_context_async_finish (res);
3538 } catch (Error e) {
3639 warning (" Failed to create IBus input context: %s " , e. message);
40+ return ;
3741 }
3842
3943 context. commit_text. connect (on_commit_text);
44+ context. require_surrounding_text. connect (on_require_surrounding_text);
4045 context. delete_surrounding_text. connect (on_delete_surrounding_text);
4146 context. update_preedit_text_with_mode. connect (on_update_preedit_text_with_mode);
4247 context. show_preedit_text. connect (on_show_preedit_text);
@@ -48,6 +53,10 @@ public class Gala.InputMethod : Clutter.InputMethod {
4853 commit (text. text);
4954 }
5055
56+ private void on_require_surrounding_text () {
57+ request_surrounding ();
58+ }
59+
5160 private void on_delete_surrounding_text (int offset , uint length ) {
5261 delete_surrounding (offset, length);
5362 }
@@ -98,6 +107,7 @@ public class Gala.InputMethod : Clutter.InputMethod {
98107
99108 public override bool filter_key_event (Clutter .Event event ) {
100109 var state = (IBus . ModifierType ) event. get_state ();
110+ warning (" Filter key event" );
101111
102112 if (IBus . ModifierType . IGNORED_MASK in state) {
103113 return false ;
@@ -112,6 +122,7 @@ public class Gala.InputMethod : Clutter.InputMethod {
112122 (obj, res) = > {
113123 try {
114124 var handled = context. process_key_event_async_finish (res);
125+ warning (" Key event handled: %s " , handled ? " yes" : " no" );
115126 notify_key_event (event, handled);
116127 } catch (Error e) {
117128 warning (" Failed to process key event on IM: %s " , e. message);
@@ -121,4 +132,90 @@ public class Gala.InputMethod : Clutter.InputMethod {
121132
122133 return true ;
123134 }
135+
136+ public override void update_content_hints (Clutter .InputContentHintFlags hints ) {
137+ IBus . InputHints ibus_hints = 0 ;
138+
139+ if (COMPLETION in hints) {
140+ ibus_hints |= IBus . InputHints . WORD_COMPLETION ;
141+ }
142+
143+ if (SPELLCHECK in hints) {
144+ ibus_hints |= IBus . InputHints . SPELLCHECK ;
145+ }
146+
147+ if (AUTO_CAPITALIZATION in hints) {
148+ ibus_hints |= IBus . InputHints . UPPERCASE_SENTENCES ;
149+ }
150+
151+ if (LOWERCASE in hints) {
152+ ibus_hints |= IBus . InputHints . LOWERCASE ;
153+ }
154+
155+ if (UPPERCASE in hints) {
156+ ibus_hints |= IBus . InputHints . UPPERCASE_CHARS ;
157+ }
158+
159+ if (TITLECASE in hints) {
160+ ibus_hints |= IBus . InputHints . UPPERCASE_WORDS ;
161+ }
162+
163+ if (SENSITIVE_DATA in hints) {
164+ ibus_hints |= IBus . InputHints . PRIVATE ;
165+ }
166+
167+ if (HIDDEN_TEXT in hints) {
168+ // TODO: Probably needs a newer version
169+ // ibus_hints |= IBus.InputHints.HIDDEN_TEXT;
170+ }
171+
172+ input_hints = ibus_hints;
173+
174+ context. set_content_type (input_purpose, input_hints);
175+ }
176+
177+ public override void update_content_purpose (Clutter .InputContentPurpose purpose ) {
178+ IBus . InputPurpose ibus_purpose;
179+
180+ switch (purpose) {
181+ case NORMAL :
182+ ibus_purpose = FREE_FORM ;
183+ break ;
184+ case ALPHA :
185+ ibus_purpose = ALPHA ;
186+ break ;
187+ case DIGITS :
188+ ibus_purpose = DIGITS ;
189+ break ;
190+ case NUMBER :
191+ ibus_purpose = NUMBER ;
192+ break ;
193+ case PHONE :
194+ ibus_purpose = PHONE ;
195+ break ;
196+ case URL :
197+ ibus_purpose = URL ;
198+ break ;
199+ case EMAIL :
200+ ibus_purpose = EMAIL ;
201+ break ;
202+ case NAME :
203+ ibus_purpose = NAME ;
204+ break ;
205+ case PASSWORD :
206+ ibus_purpose = PASSWORD ;
207+ break ;
208+ case TERMINAL :
209+ ibus_purpose = TERMINAL ;
210+ break ;
211+ default:
212+ warning (" Unknown input purpose: %d " , purpose);
213+ ibus_purpose = FREE_FORM ;
214+ break ;
215+ }
216+
217+ input_purpose = ibus_purpose;
218+
219+ context. set_content_type(input_purpose, input_hints);
220+ }
124221}
0 commit comments