Merge lp:~jeremywootten/slingshot/fix-1659353-CJK-selection into lp:~elementary-pantheon/slingshot/trunk

Proposed by Jeremy Wootten
Status: Merged
Approved by: Leonardo Lemos
Approved revision: 734
Merged at revision: 735
Proposed branch: lp:~jeremywootten/slingshot/fix-1659353-CJK-selection
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 90 lines (+37/-10)
1 file modified
src/SlingshotView.vala (+37/-10)
To merge this branch: bzr merge lp:~jeremywootten/slingshot/fix-1659353-CJK-selection
Reviewer Review Type Date Requested Status
Leonardo Lemos (community) Approve
Review via email: mp+316822@code.launchpad.net

Commit message

Handle Input Methods Key Press Events properly

Description of the change

This branch reworks key press handling in SlingshotView so that input of CJK characters (using fcitx at least) is possible. Most key press events in the search bar are now handled after the default handler instead of before it, with the exception of those that cause the window to close or change modes.

To post a comment you must log in.
Revision history for this message
Leonardo Lemos (leonardolemos) :
review: Approve
Revision history for this message
Leonardo Lemos (leonardolemos) wrote :

Excellent work Jeremy ;)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/SlingshotView.vala'
--- src/SlingshotView.vala 2017-01-06 21:03:32 +0000
+++ src/SlingshotView.vala 2017-02-09 10:29:37 +0000
@@ -232,14 +232,17 @@
232 return false;232 return false;
233 });233 });
234234
235 event_box.key_press_event.connect (on_key_press);235 event_box.key_press_event.connect (on_event_box_key_press);
236 search_entry.key_press_event.connect (on_key_press);236 search_entry.key_press_event.connect (on_search_view_key_press);
237 search_entry.key_press_event.connect_after (on_key_press);
238
237 // Showing a menu reverts the effect of the grab_device function.239 // Showing a menu reverts the effect of the grab_device function.
238 search_entry.search_changed.connect (() => {240 search_entry.search_changed.connect (() => {
239 if (modality != Modality.SEARCH_VIEW)241 if (modality != Modality.SEARCH_VIEW)
240 set_modality (Modality.SEARCH_VIEW);242 set_modality (Modality.SEARCH_VIEW);
241 search.begin (search_entry.text);243 search.begin (search_entry.text);
242 });244 });
245
243 search_entry.grab_focus ();246 search_entry.grab_focus ();
244 search_entry.activate.connect (search_entry_activated);247 search_entry.activate.connect (search_entry_activated);
245248
@@ -343,19 +346,26 @@
343 }346 }
344 }347 }
345348
346 public bool on_key_press (Gdk.EventKey event) {349 /* These keys do not work if connect_after used; the rest of the key events
350 * are dealt with after the default handler in order that CJK input methods
351 * work properly */
352 public bool on_search_view_key_press (Gdk.EventKey event) {
347 var key = Gdk.keyval_name (event.keyval).replace ("KP_", "");353 var key = Gdk.keyval_name (event.keyval).replace ("KP_", "");
348354
349 if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0 &&
350 (key == "1" || key == "2")) {
351 change_view_mode (key);
352 return true;
353 }
354
355 switch (key) {355 switch (key) {
356 case "1":
357 case "2":
358 if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0) {
359 change_view_mode (key);
360 return true;
361 }
362
363 break;
364
356 case "F4":365 case "F4":
357 if ((event.state & Gdk.ModifierType.MOD1_MASK) != 0) {366 if ((event.state & Gdk.ModifierType.MOD1_MASK) != 0) {
358 close_indicator ();367 close_indicator ();
368 return true;
359 }369 }
360370
361 break;371 break;
@@ -369,6 +379,24 @@
369379
370 return true;380 return true;
371381
382 default:
383 break;
384 }
385
386 return false;
387 }
388
389 public bool on_event_box_key_press (Gdk.EventKey event) {
390 if (!on_search_view_key_press (event)) {
391 return on_key_press (event);
392 } else {
393 return true;
394 }
395 }
396
397 public bool on_key_press (Gdk.EventKey event) {
398 var key = Gdk.keyval_name (event.keyval).replace ("KP_", "");
399 switch (key) {
372 case "Enter": // "KP_Enter"400 case "Enter": // "KP_Enter"
373 case "Return":401 case "Return":
374 case "KP_Enter":402 case "KP_Enter":
@@ -557,7 +585,6 @@
557 }585 }
558586
559 return true;587 return true;
560
561 }588 }
562589
563 public override bool scroll_event (Gdk.EventScroll event) {590 public override bool scroll_event (Gdk.EventScroll event) {

Subscribers

People subscribed via source and target branches