ShellTrayIcon: forward key presses too

StWidget::popup-menu is emitted when Menu/<Shift>F10 is pressed,
not released (for consistency with Gtk+), so we need to forward
that. Note that for key press we don't emit the matching key
release, because the app will take a grab and get the event directly
from X when the key is physicall released.

https://bugzilla.gnome.org/show_bug.cgi?id=721267
This commit is contained in:
Giovanni Campagna 2014-01-04 18:14:25 +01:00
parent 24cd13935a
commit 7d13cf1587

View File

@ -172,8 +172,9 @@ shell_tray_icon_new (ShellEmbeddedWindow *window)
* @event: the #ClutterEvent triggering the fake click * @event: the #ClutterEvent triggering the fake click
* *
* Fakes a press and release on @icon. @event must be a * Fakes a press and release on @icon. @event must be a
* %CLUTTER_BUTTON_RELEASE event. Its relevant details will be passed * %CLUTTER_BUTTON_RELEASE, %CLUTTER_KEY_PRESS or %CLUTTER_KEY_RELEASE event.
* on to the icon, but its coordinates will be ignored; the click is * Its relevant details will be passed on to the icon, but its
* coordinates will be ignored; the click is
* always made on the center of @icon. * always made on the center of @icon.
*/ */
void void
@ -191,6 +192,7 @@ shell_tray_icon_click (ShellTrayIcon *icon,
ClutterEventType event_type = clutter_event_type (event); ClutterEventType event_type = clutter_event_type (event);
g_return_if_fail (event_type == CLUTTER_BUTTON_RELEASE || g_return_if_fail (event_type == CLUTTER_BUTTON_RELEASE ||
event_type == CLUTTER_KEY_PRESS ||
event_type == CLUTTER_KEY_RELEASE); event_type == CLUTTER_KEY_RELEASE);
gdk_error_trap_push (); gdk_error_trap_push ();
@ -249,12 +251,24 @@ shell_tray_icon_click (ShellTrayIcon *icon,
xkevent.y_root = xcevent.y_root; xkevent.y_root = xcevent.y_root;
xkevent.state = clutter_event_get_state (event); xkevent.state = clutter_event_get_state (event);
xkevent.same_screen = True; xkevent.same_screen = True;
xkevent.type = KeyPress;
xkevent.keycode = clutter_event_get_key_code (event); xkevent.keycode = clutter_event_get_key_code (event);
xkevent.type = KeyPress;
XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xkevent); XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xkevent);
xkevent.type = KeyRelease; if (event_type == CLUTTER_KEY_RELEASE)
XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xkevent); {
/* If the application takes a grab on KeyPress, we don't
* want to send it a KeyRelease. There's no good way of
* knowing whether a tray icon will take a grab, so just
* assume it does, and don't send the KeyRelease. That might
* make the tracking for key events messed up if it doesn't take
* a grab, but the tray icon won't get key focus in normal cases,
* so let's hope this isn't too damaging...
*/
xkevent.type = KeyRelease;
XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xkevent);
}
} }
/* And move the pointer back out */ /* And move the pointer back out */