Merge lp:~tombeckmann/granite/popover-focus-out into lp:~elementary-pantheon/granite/granite

Proposed by Tom Beckmann on 2012-08-17
Status: Merged
Merged at revision: 353
Proposed branch: lp:~tombeckmann/granite/popover-focus-out
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 78 lines (+51/-16)
1 file modified
lib/Widgets/PopOver.vala (+51/-16)
To merge this branch: bzr merge lp:~tombeckmann/granite/popover-focus-out
Reviewer Review Type Date Requested Status
Andrea Basso (community) 2012-08-17 Approve on 2012-08-17
Review via email: mp+120243@code.launchpad.net

Description of the change

This will solve all focus problems we had with popovers and slingshot in particular by doing a grab on the window like a GtkMenu does.

To post a comment you must log in.
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/Widgets/PopOver.vala'
--- lib/Widgets/PopOver.vala 2012-07-09 13:38:14 +0000
+++ lib/Widgets/PopOver.vala 2012-08-17 21:54:17 +0000
@@ -153,23 +153,58 @@
153 menu.get_style_context().add_class("popover_bg");153 menu.get_style_context().add_class("popover_bg");
154154
155 size_allocate.connect(on_size_allocate);155 size_allocate.connect(on_size_allocate);
156
157 focus_out_event.connect_after((f) =>
158 {
159 foreach(Gtk.Window window in Gtk.Window.list_toplevels())
160 {
161 if((window.type_hint == Gdk.WindowTypeHint.POPUP_MENU || window.type_hint == Gdk.WindowTypeHint.MENU) && window.visible && window != this)
162 {
163 return false;
164 }
165 }
166 hide ();
167
168 return false;
169 });
170
171 hide.connect( () => { response(Gtk.ResponseType.CANCEL); });
172 }156 }
157
158 public override void hide ()
159 {
160 var pointer = Gdk.Display.get_default ().get_device_manager ().get_client_pointer ();
161
162 Gtk.device_grab_remove (this, pointer);
163 pointer.ungrab (Gdk.CURRENT_TIME);
164
165 base.hide ();
166 }
167
168 public override bool map_event (Gdk.EventAny event)
169 {
170 var pointer = Gdk.Display.get_default ().get_device_manager ().get_client_pointer ();
171
172 var ret = pointer.grab (get_window (), Gdk.GrabOwnership.WINDOW, true, Gdk.EventMask.SMOOTH_SCROLL_MASK |
173 Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK |
174 Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK |
175 Gdk.EventMask.POINTER_MOTION_MASK,
176 null, Gdk.CURRENT_TIME);
177 Gtk.device_grab_add (this, pointer, true);
178
179 return false;
180 }
181
182 public override bool button_press_event (Gdk.EventButton event)
183 {
184 if (event_in_window (event))
185 return true;
186
187 return base.button_press_event (event);
188 }
189
190 public override bool button_release_event (Gdk.EventButton event)
191 {
192 if (event_in_window (event))
193 return true;
194
195 hide ();
196 return false;
197 }
198
199 bool event_in_window (Gdk.EventButton event)
200 {
201 int x, y, w, h;
202 get_position (out x, out y);
203 get_size (out w, out h);
204
205 return event.x_root >= x && event.x_root <= x + w &&
206 event.y_root >= y && event.y_root <= y + h;
207 }
173208
174 /* May be null if the screen is not composited */209 /* May be null if the screen is not composited */
175 protected Granite.Drawing.BufferSurface? main_buffer = null;210 protected Granite.Drawing.BufferSurface? main_buffer = null;

Subscribers

People subscribed via source and target branches