grabHelper: Only connect to specific signals when actually taking a grab

When we enter the overview, we don't explicitly don't take a grab, so we
shouldn't connect to key-focus-changed and things like that, otherwise
random overview code will drop our grab for us.

This fixes escape in the overview not dropping when a notification is up.
This commit is contained in:
Jasper St. Pierre 2012-08-19 20:50:34 -04:00
parent c3ae4542b2
commit 3568e6d42d

View File

@ -46,6 +46,7 @@ const GrabHelper = new Lang.Class({
this._ignoreRelease = false; this._ignoreRelease = false;
this._modalCount = 0; this._modalCount = 0;
this._grabFocusCount = 0;
}, },
// addActor: // addActor:
@ -145,7 +146,7 @@ const GrabHelper = new Lang.Class({
if (this.isActorGrabbed(params.actor)) if (this.isActorGrabbed(params.actor))
return; return;
if (this._grabStack.length == 0) if (this._grabFocusCount == 0 && this._modalCount == 0)
this._fullGrab(hadFocus, params.modal, params.grabFocus); this._fullGrab(hadFocus, params.modal, params.grabFocus);
params.savedFocus = focus; params.savedFocus = focus;
@ -154,6 +155,9 @@ const GrabHelper = new Lang.Class({
if (params.modal) if (params.modal)
this._modalCount++; this._modalCount++;
if (params.grabFocus)
this._grabFocusCount++;
_navigateActor(newFocus, hadFocus); _navigateActor(newFocus, hadFocus);
}, },
@ -176,10 +180,12 @@ const GrabHelper = new Lang.Class({
} }
} }
this._capturedEventId = global.stage.connect('captured-event', Lang.bind(this, this._onCapturedEvent)); if (modal || grabFocus) {
this._eventId = global.stage.connect('event', Lang.bind(this, this._onEvent)); this._capturedEventId = global.stage.connect('captured-event', Lang.bind(this, this._onCapturedEvent));
this._keyFocusNotifyId = global.stage.connect('notify::key-focus', Lang.bind(this, this._onKeyFocusChanged)); this._eventId = global.stage.connect('event', Lang.bind(this, this._onEvent));
this._focusWindowChangedId = metaDisplay.connect('notify::focus-window', Lang.bind(this, this._focusWindowChanged)); this._keyFocusNotifyId = global.stage.connect('notify::key-focus', Lang.bind(this, this._onKeyFocusChanged));
this._focusWindowChangedId = metaDisplay.connect('notify::focus-window', Lang.bind(this, this._focusWindowChanged));
}
}, },
// ignoreRelease: // ignoreRelease:
@ -220,13 +226,15 @@ const GrabHelper = new Lang.Class({
if (poppedGrab.modal) if (poppedGrab.modal)
this._modalCount--; this._modalCount--;
if (poppedGrab.grabFocus)
this._grabFocusCount--;
} }
let focus = global.stage.key_focus; let focus = global.stage.key_focus;
let hadFocus = focus && this._isWithinGrabbedActor(focus); let hadFocus = focus && this._isWithinGrabbedActor(focus);
// If we took away the last grab, ungrab ourselves. if (this._grabFocusCount == 0 && this._modalCount == 0)
if (this._grabStack.length == 0)
this._fullUngrab(wasModal); this._fullUngrab(wasModal);
let poppedGrab = poppedGrabs[0]; let poppedGrab = poppedGrabs[0];
@ -234,15 +242,26 @@ const GrabHelper = new Lang.Class({
}, },
_fullUngrab: function(wasModal) { _fullUngrab: function(wasModal) {
global.stage.disconnect(this._capturedEventId); if (this._capturedEventId > 0) {
this._capturedEventId = 0; global.stage.disconnect(this._capturedEventId);
global.stage.disconnect(this._eventId); this._capturedEventId = 0;
this._eventId = 0; }
global.stage.disconnect(this._keyFocusNotifyId);
this._keyFocusNotifyId = 0; if (this._eventId > 0) {
let metaDisplay = global.screen.get_display(); global.stage.disconnect(this._eventId);
metaDisplay.disconnect(this._focusWindowChangedId); this._eventId = 0;
this._focusWindowChangedId = 0; }
if (this._keyFocusNotifyId > 0) {
global.stage.disconnect(this._keyFocusNotifyId);
this._keyFocusNotifyId = 0;
}
if (!this._focusWindowChanged > 0) {
let metaDisplay = global.screen.get_display();
metaDisplay.disconnect(this._focusWindowChangedId);
this._focusWindowChangedId = 0;
}
let prePopInputMode = global.stage_input_mode; let prePopInputMode = global.stage_input_mode;