From 65991cc0574049b2a8e1656014d8b1e960b968b1 Mon Sep 17 00:00:00 2001 From: Marina Zhurakhinskaya Date: Wed, 21 Jul 2010 01:26:25 -0400 Subject: [PATCH] Make Esc hide the tray when a notification has focus It's convenient to have Esc working for expanded new notifications that have focus and for summary notifications. https://bugzilla.gnome.org/show_bug.cgi?id=617224 --- js/ui/messageTray.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index cc97b12d1..a45d1f63b 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -87,6 +87,7 @@ Notification.prototype = { this._focusActorChangedId = 0; this._stageInputModeChangedId = 0; this._capturedEventId = 0; + this._keyPressId = 0; source.connect('clicked', Lang.bind(this, function() { @@ -405,6 +406,8 @@ Notification.prototype = { this._focusWindowChangedId = metaDisplay.connect('notify::focus-window', Lang.bind(this, this._focusWindowChanged)); this._stageInputModeChangedId = global.connect('notify::stage-input-mode', Lang.bind(this, this._stageInputModeChanged)); + + this._keyPressId = global.stage.connect('key-press-event', Lang.bind(this, this._onKeyPress)); } // We need to listen to this signal in the overview, as well as in the main view, to make the key bindings such as @@ -454,8 +457,29 @@ Notification.prototype = { _onCapturedEvent: function(actor, event) { let source = event.get_source(); - if (event.type() == Clutter.EventType.BUTTON_PRESS && !this.actor.contains(source)) - this.ungrabFocus(); + switch (event.type()) { + case Clutter.EventType.BUTTON_PRESS: + if (!this.actor.contains(source)) + this.ungrabFocus(); + break; + case Clutter.EventType.KEY_PRESS: + let symbol = event.get_key_symbol(); + if (symbol == Clutter.Escape) { + Main.messageTray.escapeTray(); + return true; + } + break; + } + + return false; + }, + + _onKeyPress: function(actor, event) { + let symbol = event.get_key_symbol(); + if (symbol == Clutter.Escape) { + Main.messageTray.escapeTray(); + return true; + } return false; }, @@ -485,6 +509,11 @@ Notification.prototype = { this._capturedEventId = 0; } + if (this._keyPressId > 0) { + global.stage.disconnect(this._keyPressId); + this._keyPressId = 0; + } + this._hasFocus = false; Main.messageTray.unlock(); @@ -1010,6 +1039,17 @@ MessageTray.prototype = { return false; }, + escapeTray: function() { + this.unlock(); + this._pointerInTray = false; + this._pointerInSummary = false; + if (this._notificationTimeoutId) { + Mainloop.source_remove(this._notificationTimeoutId); + this._notificationTimeoutId = 0; + } + this._updateState(); + }, + // All of the logic for what happens when occurs here; the various // event handlers merely update variables such as // 'this._pointerInTray', 'this._summaryState', etc, and