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

Proposed by Jeremy Wootten on 2017-02-09
Status: Merged
Approved by: Leonardo Lemos on 2017-02-09
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) 2017-02-09 Approve on 2017-02-09
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.
review: Approve
Leonardo Lemos (leonardolemos) wrote :

Excellent work Jeremy ;)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/SlingshotView.vala'
2--- src/SlingshotView.vala 2017-01-06 21:03:32 +0000
3+++ src/SlingshotView.vala 2017-02-09 10:29:37 +0000
4@@ -232,14 +232,17 @@
5 return false;
6 });
7
8- event_box.key_press_event.connect (on_key_press);
9- search_entry.key_press_event.connect (on_key_press);
10+ event_box.key_press_event.connect (on_event_box_key_press);
11+ search_entry.key_press_event.connect (on_search_view_key_press);
12+ search_entry.key_press_event.connect_after (on_key_press);
13+
14 // Showing a menu reverts the effect of the grab_device function.
15 search_entry.search_changed.connect (() => {
16 if (modality != Modality.SEARCH_VIEW)
17 set_modality (Modality.SEARCH_VIEW);
18 search.begin (search_entry.text);
19 });
20+
21 search_entry.grab_focus ();
22 search_entry.activate.connect (search_entry_activated);
23
24@@ -343,19 +346,26 @@
25 }
26 }
27
28- public bool on_key_press (Gdk.EventKey event) {
29+ /* These keys do not work if connect_after used; the rest of the key events
30+ * are dealt with after the default handler in order that CJK input methods
31+ * work properly */
32+ public bool on_search_view_key_press (Gdk.EventKey event) {
33 var key = Gdk.keyval_name (event.keyval).replace ("KP_", "");
34
35- if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0 &&
36- (key == "1" || key == "2")) {
37- change_view_mode (key);
38- return true;
39- }
40-
41 switch (key) {
42+ case "1":
43+ case "2":
44+ if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0) {
45+ change_view_mode (key);
46+ return true;
47+ }
48+
49+ break;
50+
51 case "F4":
52 if ((event.state & Gdk.ModifierType.MOD1_MASK) != 0) {
53 close_indicator ();
54+ return true;
55 }
56
57 break;
58@@ -369,6 +379,24 @@
59
60 return true;
61
62+ default:
63+ break;
64+ }
65+
66+ return false;
67+ }
68+
69+ public bool on_event_box_key_press (Gdk.EventKey event) {
70+ if (!on_search_view_key_press (event)) {
71+ return on_key_press (event);
72+ } else {
73+ return true;
74+ }
75+ }
76+
77+ public bool on_key_press (Gdk.EventKey event) {
78+ var key = Gdk.keyval_name (event.keyval).replace ("KP_", "");
79+ switch (key) {
80 case "Enter": // "KP_Enter"
81 case "Return":
82 case "KP_Enter":
83@@ -557,7 +585,6 @@
84 }
85
86 return true;
87-
88 }
89
90 public override bool scroll_event (Gdk.EventScroll event) {

Subscribers

People subscribed via source and target branches