MessageTray: pass keyboard events to tray icons

Synthetize XKeyEvents for clicks emulated by StButton using Return or
Space.

https://bugzilla.gnome.org/show_bug.cgi?id=687425
This commit is contained in:
Giovanni Campagna 2012-11-02 16:09:04 +01:00
parent 42c1285ead
commit 59ecd610b1
4 changed files with 45 additions and 26 deletions

View File

@ -637,11 +637,7 @@ const KeyboardSource = new Lang.Class({
this.keepTrayOnSummaryClick = true;
},
handleSummaryClick: function() {
let event = Clutter.get_current_event();
if (event.type() != Clutter.EventType.BUTTON_RELEASE)
return false;
handleSummaryClick: function(button) {
this.open();
return true;
},

View File

@ -1831,7 +1831,7 @@ const MessageTray = new Lang.Class({
},
_onSummaryItemClicked: function(summaryItem, button) {
if (summaryItem.source.handleSummaryClick()) {
if (summaryItem.source.handleSummaryClick(button)) {
if (summaryItem.source.keepTrayOnSummaryClick)
this._setClickedSummaryItem(null);
else

View File

@ -565,19 +565,17 @@ const Source = new Lang.Class({
this.notify(notification);
},
handleSummaryClick: function() {
handleSummaryClick: function(button) {
if (!this.trayIcon)
return false;
let event = Clutter.get_current_event();
if (event.type() != Clutter.EventType.BUTTON_RELEASE)
return false;
// Left clicks are passed through only where there aren't unacknowledged
// notifications, so it possible to open them in summary mode; right
// clicks are always forwarded, as the right click menu is not useful for
// tray icons
if (event.get_button() == 1 &&
if (button == 1 &&
this.notifications.length > 0)
return false;

View File

@ -180,6 +180,7 @@ void
shell_tray_icon_click (ShellTrayIcon *icon,
ClutterEvent *event)
{
XKeyEvent xkevent;
XButtonEvent xbevent;
XCrossingEvent xcevent;
GdkWindow *remote_window;
@ -187,8 +188,10 @@ shell_tray_icon_click (ShellTrayIcon *icon,
int x_root, y_root;
Display *xdisplay;
Window xwindow, xrootwindow;
ClutterEventType event_type = clutter_event_type (event);
g_return_if_fail (clutter_event_type (event) == CLUTTER_BUTTON_RELEASE);
g_return_if_fail (event_type == CLUTTER_BUTTON_RELEASE ||
event_type == CLUTTER_KEY_RELEASE);
gdk_error_trap_push ();
@ -215,22 +218,44 @@ shell_tray_icon_click (ShellTrayIcon *icon,
XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xcevent);
/* Now do the click */
xbevent.type = ButtonPress;
xbevent.window = xwindow;
xbevent.root = xrootwindow;
xbevent.subwindow = None;
xbevent.time = xcevent.time;
xbevent.x = xcevent.x;
xbevent.y = xcevent.y;
xbevent.x_root = xcevent.x_root;
xbevent.y_root = xcevent.y_root;
xbevent.state = clutter_event_get_state (event);
xbevent.button = clutter_event_get_button (event);
xbevent.same_screen = True;
XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xbevent);
if (event_type == CLUTTER_BUTTON_RELEASE)
{
xbevent.window = xwindow;
xbevent.root = xrootwindow;
xbevent.subwindow = None;
xbevent.time = xcevent.time;
xbevent.x = xcevent.x;
xbevent.y = xcevent.y;
xbevent.x_root = xcevent.x_root;
xbevent.y_root = xcevent.y_root;
xbevent.state = clutter_event_get_state (event);
xbevent.same_screen = True;
xbevent.type = ButtonPress;
xbevent.button = clutter_event_get_button (event);
XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xbevent);
xbevent.type = ButtonRelease;
XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xbevent);
xbevent.type = ButtonRelease;
XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xbevent);
}
else
{
xkevent.window = xwindow;
xkevent.root = xrootwindow;
xkevent.subwindow = None;
xkevent.time = xcevent.time;
xkevent.x = xcevent.x;
xkevent.y = xcevent.y;
xkevent.x_root = xcevent.x_root;
xkevent.y_root = xcevent.y_root;
xkevent.state = clutter_event_get_state (event);
xkevent.same_screen = True;
xkevent.type = KeyPress;
xkevent.keycode = clutter_event_get_key_code (event);
XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xkevent);
xkevent.type = KeyRelease;
XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xkevent);
}
/* And move the pointer back out */
xcevent.type = LeaveNotify;