dnd: fix a case where ungrabEvents wasn't being called

If the drag actor is destroyed as part of a drag target accepting it,
we were not calling ungrabEvents, meaning the mouse/keyboard remained
grabbed until you clicked somewhere to cancel it.

This fixes that without trying to improve the extremely confusing
control flow...

https://bugzilla.gnome.org/show_bug.cgi?id=635278
This commit is contained in:
Dan Winship 2010-11-19 11:09:48 -05:00
parent b956c6f093
commit b7c1400eb3

View File

@ -100,6 +100,8 @@ _Draggable.prototype = {
this._buttonDown = false; // The mouse button has been pressed and has not yet been released. this._buttonDown = false; // The mouse button has been pressed and has not yet been released.
this._dragInProgress = false; // The drag has been started, and has not been dropped or cancelled yet. this._dragInProgress = false; // The drag has been started, and has not been dropped or cancelled yet.
this._animationInProgress = false; // The drag is over and the item is in the process of animating to its original position (snapping back or reverting). this._animationInProgress = false; // The drag is over and the item is in the process of animating to its original position (snapping back or reverting).
this._eventsGrabbed = false;
}, },
_onButtonPress : function (actor, event) { _onButtonPress : function (actor, event) {
@ -147,13 +149,19 @@ _Draggable.prototype = {
}, },
_grabEvents: function() { _grabEvents: function() {
Clutter.grab_pointer(_getEventHandlerActor()); if (!this._eventsGrabbed) {
Clutter.grab_keyboard(_getEventHandlerActor()); Clutter.grab_pointer(_getEventHandlerActor());
Clutter.grab_keyboard(_getEventHandlerActor());
this._eventsGrabbed = true;
}
}, },
_ungrabEvents: function() { _ungrabEvents: function() {
Clutter.ungrab_pointer(); if (this._eventsGrabbed) {
Clutter.ungrab_keyboard(); Clutter.ungrab_pointer();
Clutter.ungrab_keyboard();
this._eventsGrabbed = false;
}
}, },
_onEvent: function(actor, event) { _onEvent: function(actor, event) {
@ -476,6 +484,8 @@ _Draggable.prototype = {
if (this._actorDestroyed) { if (this._actorDestroyed) {
global.unset_cursor(); global.unset_cursor();
if (!this._buttonDown)
this._ungrabEvents();
this.emit('drag-end', eventTime, false); this.emit('drag-end', eventTime, false);
return; return;
} }