messageTray: forward clicks on trayicon SummaryItems to the icon

If the user clicks on the title of a trayicon's SummaryItem, forward
that click to the trayicon. Also adjust
gnome_shell_plugin_xevent_filter() so that if the trayicon takes a
grab as a result of this, we don't hide the message tray.

https://bugzilla.gnome.org/show_bug.cgi?id=630842
This commit is contained in:
Dan Winship
2011-01-13 15:04:37 -05:00
parent a40daa3c22
commit 7f17fcfafc
5 changed files with 132 additions and 25 deletions

View File

@@ -874,6 +874,14 @@ Source.prototype = {
this.emit('destroy');
},
// A subclass can redefine this to "steal" clicks from the
// summaryitem; Use Clutter.get_current_event() to get the
// details, return true to prevent the default handling from
// ocurring.
handleSummaryClick: function() {
return false;
},
//// Protected methods ////
// The subclass must call this at least once to set the summary icon.
@@ -903,6 +911,7 @@ SummaryItem.prototype = {
this.source = source;
this.actor = new St.Button({ style_class: 'summary-source-button',
reactive: true,
button_mask: St.ButtonMask.ONE | St.ButtonMask.TWO | St.ButtonMask.THREE,
track_hover: true });
this._sourceBox = new St.BoxLayout({ style_class: 'summary-source' });
@@ -1165,9 +1174,9 @@ MessageTray.prototype = {
this._onSummaryItemHoverChanged(summaryItem);
}));
summaryItem.actor.connect('button-press-event', Lang.bind(this,
function (actor, event) {
this._onSummaryItemClicked(summaryItem, event);
summaryItem.actor.connect('clicked', Lang.bind(this,
function (actor, button) {
this._onSummaryItemClicked(summaryItem, button);
}));
source.connect('destroy', Lang.bind(this, this._onSourceDestroy));
@@ -1404,13 +1413,14 @@ MessageTray.prototype = {
this._expandedSummaryItem.setEllipsization(Pango.EllipsizeMode.END);
},
_onSummaryItemClicked: function(summaryItem, event) {
let clickedButton = event.get_button();
if (!this._clickedSummaryItem ||
this._clickedSummaryItem != summaryItem ||
this._clickedSummaryItemMouseButton != clickedButton) {
_onSummaryItemClicked: function(summaryItem, button) {
if (summaryItem.source.handleSummaryClick())
this._unsetClickedSummaryItem();
else if (!this._clickedSummaryItem ||
this._clickedSummaryItem != summaryItem ||
this._clickedSummaryItemMouseButton != button) {
this._clickedSummaryItem = summaryItem;
this._clickedSummaryItemMouseButton = clickedButton;
this._clickedSummaryItemMouseButton = button;
} else {
this._unsetClickedSummaryItem();
}

View File

@@ -1,5 +1,6 @@
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
const Clutter = imports.gi.Clutter;
const DBus = imports.dbus;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
@@ -441,7 +442,7 @@ Source.prototype = {
this.title = this.app.get_name();
else
this.useNotificationIcon = true;
this._isTrayIcon = false;
this._trayIcon = null;
},
notify: function(notification, icon) {
@@ -452,6 +453,18 @@ Source.prototype = {
MessageTray.Source.prototype.notify.call(this, notification);
},
handleSummaryClick: function() {
if (!this._trayIcon)
return false;
let event = Clutter.get_current_event();
if (event.type() != Clutter.EventType.BUTTON_RELEASE)
return false;
this._trayIcon.click(event);
return true;
},
_setApp: function() {
if (this.app)
return;
@@ -466,7 +479,7 @@ Source.prototype = {
// Only override the icon if we were previously using
// notification-based icons (ie, not a trayicon) or if it was unset before
if (!this._isTrayIcon) {
if (!this._trayIcon) {
this.useNotificationIcon = false;
this._setSummaryIcon(this.app.create_icon_texture (this.ICON_SIZE));
}
@@ -475,7 +488,7 @@ Source.prototype = {
setTrayIcon: function(icon) {
this._setSummaryIcon(icon);
this.useNotificationIcon = false;
this._isTrayIcon = true;
this._trayIcon = icon;
},
open: function(notification) {
@@ -483,7 +496,7 @@ Source.prototype = {
},
_notificationRemoved: function() {
if (!this._isTrayIcon)
if (!this._trayIcon)
this.destroy();
},