grabHelper: Allow pressing escape on grab focus grabs

We didn't install the captured event handler on grab focus grabs,
leading to the case where we didn't ungrab correctly.

https://bugzilla.gnome.org/show_bug.cgi?id=690897
This commit is contained in:
Jasper St. Pierre 2012-12-30 12:32:41 -05:00
parent bd383888de
commit 52ca15b514

View File

@ -183,6 +183,9 @@ const GrabHelper = new Lang.Class({
else if (hadFocus || params.grabFocus) else if (hadFocus || params.grabFocus)
_navigateActor(newFocus); _navigateActor(newFocus);
if ((params.grabFocus || params.modal) && !this._capturedEventId)
this._capturedEventId = global.stage.connect('captured-event', Lang.bind(this, this._onCapturedEvent));
this._grabStack.push(params); this._grabStack.push(params);
return true; return true;
}, },
@ -192,8 +195,6 @@ const GrabHelper = new Lang.Class({
if (firstGrab) { if (firstGrab) {
if (!Main.pushModal(this._owner, this._modalParams)) if (!Main.pushModal(this._owner, this._modalParams))
return false; return false;
this._capturedEventId = global.stage.connect('captured-event', Lang.bind(this, this._onCapturedEvent));
} }
this._modalCount++; this._modalCount++;
@ -205,11 +206,6 @@ const GrabHelper = new Lang.Class({
if (this._modalCount > 0) if (this._modalCount > 0)
return; return;
if (this._capturedEventId > 0) {
global.stage.disconnect(this._capturedEventId);
this._capturedEventId = 0;
}
Main.popModal(this._owner); Main.popModal(this._owner);
global.sync_pointer(); global.sync_pointer();
}, },
@ -308,6 +304,11 @@ const GrabHelper = new Lang.Class({
this._releaseFocusGrab(); this._releaseFocusGrab();
} }
if (!this.grabbed && this._capturedEventId > 0) {
global.stage.disconnect(this._capturedEventId);
this._capturedEventId = 0;
}
if (hadFocus) { if (hadFocus) {
let poppedGrab = poppedGrabs[0]; let poppedGrab = poppedGrabs[0];
_navigateActor(poppedGrab.savedFocus); _navigateActor(poppedGrab.savedFocus);
@ -316,6 +317,13 @@ const GrabHelper = new Lang.Class({
_onCapturedEvent: function(actor, event) { _onCapturedEvent: function(actor, event) {
let type = event.type(); let type = event.type();
if (type == Clutter.EventType.KEY_PRESS &&
event.get_key_symbol() == Clutter.KEY_Escape) {
this.ungrab({ isUser: true });
return true;
}
let press = type == Clutter.EventType.BUTTON_PRESS; let press = type == Clutter.EventType.BUTTON_PRESS;
let release = type == Clutter.EventType.BUTTON_RELEASE; let release = type == Clutter.EventType.BUTTON_RELEASE;
let button = press || release; let button = press || release;
@ -328,12 +336,6 @@ const GrabHelper = new Lang.Class({
if (!button && this._modalCount == 0) if (!button && this._modalCount == 0)
return false; return false;
if (type == Clutter.EventType.KEY_PRESS &&
event.get_key_symbol() == Clutter.KEY_Escape) {
this.ungrab({ isUser: true });
return true;
}
if (this._isWithinGrabbedActor(event.get_source())) if (this._isWithinGrabbedActor(event.get_source()))
return false; return false;