messageTray: fix dwelling during mouse-down

If the user has the mouse down - for example when they are selecting
text and dragging - then the attempt to get a modal grab will fail.

grabHelper: allow the .grab() function to fail and do nothing in this
modal case if the grab fails.

messageTray: handle grab failure and don't pop up the tray. Change the
logic for tray dwelling so that we only try to pop up the tray once
while the pointer is in the dwell area - this avoids the possiility
that the tray will pop up once the user releases the mouse.

https://bugzilla.gnome.org/show_bug.cgi?id=682385
This commit is contained in:
Owen W. Taylor 2012-08-21 19:40:11 -04:00
parent 5d6f37017b
commit 3902e8bff0
2 changed files with 39 additions and 22 deletions

View File

@ -128,7 +128,9 @@ const GrabHelper = new Lang.Class({
// on the owner of the GrabHelper. As long as there is at least one
// { modal: true } actor on the grab stack, the grab will be kept.
// When the last { modal: true } actor is ungrabbed, then the modal
// will be dropped.
// will be dropped. A modal grab can fail if there is already a grab
// in effect from aother application; in this case the function returns
// false and nothing happens. Non-modal grabs can never fail.
//
// If @params contains { grabFocus: true }, then if you call grab()
// while the shell is outside the overview, it will set the stage
@ -151,10 +153,12 @@ const GrabHelper = new Lang.Class({
let newFocus = params.actor;
if (this.isActorGrabbed(params.actor))
return;
return true;
if (this._grabFocusCount == 0 && this._modalCount == 0)
this._fullGrab(hadFocus, params.modal, params.grabFocus);
if (this._grabFocusCount == 0 && this._modalCount == 0) {
if (!this._fullGrab(hadFocus, params.modal, params.grabFocus))
return false;
}
params.savedFocus = focus;
this._grabStack.push(params);
@ -166,19 +170,22 @@ const GrabHelper = new Lang.Class({
this._grabFocusCount++;
_navigateActor(newFocus, hadFocus);
return true;
},
_fullGrab: function(hadFocus, modal, grabFocus) {
let metaDisplay = global.screen.get_display();
if (modal) {
if (!Main.pushModal(this._owner))
return false;
}
this._grabbedFromKeynav = hadFocus;
this._preGrabInputMode = global.stage_input_mode;
this._prevFocusedWindow = null;
if (modal) {
Main.pushModal(this._owner);
}
if (grabFocus) {
this._prevFocusedWindow = metaDisplay.focus_window;
if (this._preGrabInputMode == Shell.StageInputMode.NONREACTIVE ||
@ -193,6 +200,8 @@ const GrabHelper = new Lang.Class({
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));
}
return true;
},
// ignoreRelease:

View File

@ -1489,19 +1489,24 @@ const MessageTray = new Lang.Class({
let pointerWatcher = PointerWatcher.getPointerWatcher();
pointerWatcher.addWatch(TRAY_DWELL_CHECK_INTERVAL, Lang.bind(this, this._checkTrayDwell));
this._trayDwellTimeoutId = 0;
this._trayDwelling = false;
},
_checkTrayDwell: function(x, y) {
if (y == global.screen_height - 1) {
// We only set up dwell timeout when the user is not hovering over the tray
// (!this.actor.hover). This avoids bringing up the message tray after the
// user clicks on a notification with the pointer on the bottom pixel
// of the monitor.
if (y == global.screen_height - 1 && !this.actor.hover) {
if (this._trayDwellTimeoutId == 0)
// of the monitor. The _trayDwelling variable is used so that we only try to
// fire off one tray dwell - if it fails (because, say, the user has the mouse down),
// we don't try again until the user moves the mouse up and down again.
if (!this._trayDwelling && !this.actor.hover && this._trayDwellTimeoutId == 0)
this._trayDwellTimeoutId = Mainloop.timeout_add(TRAY_DWELL_TIME,
Lang.bind(this, this._trayDwellTimeout));
this._trayDwelling = true;
} else {
this._cancelTrayDwell();
this._trayDwelling = false;
}
},
@ -1993,19 +1998,22 @@ const MessageTray = new Lang.Class({
},
_showTray: function() {
// Don't actually take a modal grab in the overview.
// Just add something to the grab stack that we can
// pop later.
if (!this._grabHelper.grab({ actor: this.actor,
modal: !this._overviewVisible,
onUngrab: Lang.bind(this, this._escapeTray) })) {
this._traySummoned = false;
return;
}
this._tween(this.actor, '_trayState', State.SHOWN,
{ y: -this.actor.height,
time: ANIMATION_TIME,
transition: 'easeOutQuad'
});
// Don't actually take a modal grab in the overview.
// Just add something to the grab stack that we can
// pop later.
this._grabHelper.grab({ actor: this.actor,
modal: !this._overviewVisible,
onUngrab: Lang.bind(this, this._escapeTray) });
// Don't move the windows up if we are in the overview,
// but show the tray in the ctrl+alt+tab list.
if (this._overviewVisible) {