Merge lp:~unity-team/unity/unity.composition-char into lp:unity

Proposed by Jay Taoko
Status: Merged
Approved by: Didier Roche-Tolomelli
Approved revision: no longer in the source branch.
Merged at revision: 2054
Proposed branch: lp:~unity-team/unity/unity.composition-char
Merge into: lp:unity
Diff against target: 188 lines (+120/-8)
4 files modified
plugins/unityshell/src/IMTextEntry.cpp (+77/-8)
plugins/unityshell/src/IMTextEntry.h (+12/-0)
tests/autopilot/autopilot/emulators/X11.py (+1/-0)
tests/autopilot/autopilot/tests/test_dash.py (+30/-0)
To merge this branch: bzr merge lp:~unity-team/unity/unity.composition-char
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Needs Fixing
Neil J. Patel (community) Approve
Mirco Müller (community) Needs Fixing
Review via email: mp+95653@code.launchpad.net

Description of the change

UNBLOCK

* Use Gtk im for composition characters.

Fix bug #944674

To post a comment you must log in.
Revision history for this message
Mirco Müller (macslow) wrote :

In IMTextEntry::CheckValidClientWindow() you do...

76 + if (1/*focused_*/)
77 + {
78 + gtk_im_context_focus_in(im_context_);
79 + }

... please don't. Either use a proper conditional statement that can change at runtime or just drop completely.

In IMTextEntry::TryHandleEvent() you don't initialize ev...

89 + CheckValidClientWindow(event.x11_window);
90 +
91 + GdkEventKey ev;
92 + KeyEventToGdkEventKey(event, ev);

... and that's asking for trouble. Maybe not in that particular case (about to be filled by the next call). Just bzero() it. Always be explicit!

review: Needs Fixing
Revision history for this message
Jay Taoko (jaytaoko) wrote :

* ev is filled by the call to KeyEventToGdkEventKey. I think there is no need to bzero it.

Revision history for this message
Neil J. Patel (njpatel) wrote :

Code looks good, passes tests, excellent work!

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/385/console reported an error when processing this lp:~unity-team/unity/unity.composition-char branch.
Not merging it.

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

This breaks IBus support as well as any shortcut that uses the ctrl key, ie ctrl + a/x/c/v...

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/IMTextEntry.cpp'
2--- plugins/unityshell/src/IMTextEntry.cpp 2012-02-23 23:35:35 +0000
3+++ plugins/unityshell/src/IMTextEntry.cpp 2012-03-06 05:12:17 +0000
4@@ -35,8 +35,13 @@
5 NUX_IMPLEMENT_OBJECT_TYPE(IMTextEntry);
6
7 IMTextEntry::IMTextEntry()
8- : TextEntry("", NUX_TRACKER_LOCATION)
9+: TextEntry("", NUX_TRACKER_LOCATION)
10+, im_context_(0)
11+, client_window_(0)
12+, focused_(false)
13 {
14+ SetupSimpleIM();
15+
16 mouse_up.connect(sigc::mem_fun(this, &IMTextEntry::OnMouseButtonUp));
17 }
18
19@@ -44,12 +49,20 @@
20 unsigned int keysym,
21 const char* character)
22 {
23- bool need_to_filter_event = TryHandleSpecial(event_type, keysym, character);
24-
25- if (need_to_filter_event)
26- need_to_filter_event = TextEntry::InspectKeyEvent(event_type, keysym, character);
27-
28- return need_to_filter_event;
29+
30+ bool propagate_event = !(TryHandleEvent(event_type, keysym, character));
31+
32+ if (propagate_event)
33+ {
34+ propagate_event = TryHandleSpecial(event_type, keysym, character);
35+ }
36+
37+ if (propagate_event)
38+ {
39+ propagate_event = TextEntry::InspectKeyEvent(event_type, keysym, character);
40+ }
41+
42+ return propagate_event;
43 }
44
45 bool IMTextEntry::TryHandleSpecial(unsigned int eventType, unsigned int keysym, const char* character)
46@@ -138,7 +151,6 @@
47 SetText(new_text.c_str());
48 SetCursor(cursor + text.length());
49 QueueRefresh (true, true);
50- text_changed.emit(this);
51 }
52 }
53
54@@ -152,4 +164,61 @@
55 Paste(true);
56 }
57 }
58+
59+void IMTextEntry::KeyEventToGdkEventKey(Event& event, GdkEventKey& gdk_event)
60+{
61+ gdk_event.type = event.type == nux::NUX_KEYDOWN ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
62+ gdk_event.window = client_window_;
63+ gdk_event.send_event = FALSE;
64+ gdk_event.time = event.x11_timestamp;
65+ gdk_event.state = event.x11_key_state;
66+ gdk_event.keyval = event.x11_keysym;
67+
68+ gchar* txt = const_cast<gchar*>(event.GetText());
69+ gdk_event.length = strlen(txt);
70+ gdk_event.string = txt;
71+
72+ gdk_event.hardware_keycode = event.x11_keycode;
73+ gdk_event.group = 0;
74+ gdk_event.is_modifier = 0;
75+}
76+
77+bool IMTextEntry::TryHandleEvent(unsigned int eventType,
78+ unsigned int keysym,
79+ const char* character)
80+{
81+ nux::Event event = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent();
82+
83+ GdkEventKey ev;
84+ KeyEventToGdkEventKey(event, ev);
85+
86+ return gtk_im_context_filter_keypress(im_context_, &ev);
87+}
88+
89+void IMTextEntry::OnCommit(GtkIMContext* context, char* str)
90+{
91+ LOG_DEBUG(logger) << "Commit: " << str;
92+ DeleteSelection();
93+
94+ if (str)
95+ {
96+ std::string new_text = GetText();
97+ new_text.insert(cursor_, str);
98+
99+ int cursor = cursor_;
100+ SetText(new_text.c_str());
101+ SetCursor(cursor + strlen(str));
102+ QueueRefresh (true, true);
103+ text_changed.emit(this);
104+ }
105+}
106+
107+void IMTextEntry::SetupSimpleIM()
108+{
109+ LOG_DEBUG(logger) << "Using Simple IM.";
110+ im_context_ = static_cast<GtkIMContext*>(gtk_im_context_simple_new());
111+
112+ sig_manager_.Add(new Signal<void, GtkIMContext*, char*>(im_context_, "commit", sigc::mem_fun(this, &IMTextEntry::OnCommit)));
113+}
114+
115 }
116
117=== modified file 'plugins/unityshell/src/IMTextEntry.h'
118--- plugins/unityshell/src/IMTextEntry.h 2012-02-23 19:52:40 +0000
119+++ plugins/unityshell/src/IMTextEntry.h 2012-03-06 05:12:17 +0000
120@@ -49,6 +49,18 @@
121 void Paste(bool primary = false);
122
123 void OnMouseButtonUp(int x, int y, unsigned long bflags, unsigned long kflags);
124+
125+ void KeyEventToGdkEventKey(Event& event, GdkEventKey& gdk_event);
126+ bool TryHandleEvent(unsigned int eventType,
127+ unsigned int keysym,
128+ const char* character);
129+ void SetupSimpleIM();
130+ void OnCommit(GtkIMContext* context, char* str);
131+
132+ glib::Object<GtkIMContext> im_context_;
133+ GdkWindow* client_window_;
134+ glib::SignalManager sig_manager_;
135+ bool focused_;
136 };
137
138 }
139
140=== modified file 'tests/autopilot/autopilot/emulators/X11.py'
141--- tests/autopilot/autopilot/emulators/X11.py 2012-03-01 20:16:50 +0000
142+++ tests/autopilot/autopilot/emulators/X11.py 2012-03-06 05:12:17 +0000
143@@ -78,6 +78,7 @@
144 'Control' : 'Control_L',
145 'Ctrl' : 'Control_L',
146 'Alt' : 'Alt_L',
147+ 'AltR' : 'Alt_R',
148 'Super' : 'Super_L',
149 'Shift' : 'Shift_L',
150 'Enter' : 'Return',
151
152=== modified file 'tests/autopilot/autopilot/tests/test_dash.py'
153--- tests/autopilot/autopilot/tests/test_dash.py 2012-03-05 01:30:34 +0000
154+++ tests/autopilot/autopilot/tests/test_dash.py 2012-03-06 05:12:17 +0000
155@@ -389,3 +389,33 @@
156 searchbar = self.dash.get_searchbar()
157 self.assertEqual("hello world", searchbar.search_string)
158
159+class DashCompositionCharactersTests(AutopilotTestCase):
160+ """Tests that composition characters works."""
161+
162+ def setUp(self):
163+ super(DashCompositionCharactersTests, self).setUp()
164+ self.dash = Dash()
165+ self.addCleanup(self.dash.ensure_hidden)
166+
167+ def tearDown(self):
168+ super(DashCompositionCharactersTests, self).tearDown()
169+ self.dash.ensure_hidden()
170+
171+ def test_composition_characters(self):
172+ """Expanding or collapsing the filterbar must keave keyboard focus in the
173+ search bar.
174+ """
175+ self.dash.reveal_application_lens()
176+ filter_bar = self.dash.get_current_lens().get_filterbar()
177+ filter_bar.ensure_collapsed()
178+
179+ sleep(1)
180+ self.keyboard.press('Shift')
181+ self.keyboard.press_and_release('Multi_key')
182+ self.keyboard.press_and_release('6')
183+ self.keyboard.release('Shift')
184+ self.keyboard.type('o')
185+
186+ searchbar = self.dash.get_searchbar()
187+ self.assertEqual("ô", searchbar.search_string)
188+