[dnd] Special-case St.Clickable

Currently manual dnd mode is used with St.Clickable to avoid messing
up its internal state with a pointer grab. To avoid code duplication,
move this special handling into dnd.

https://bugzilla.gnome.org/show_bug.cgi?id=610385
This commit is contained in:
Florian Müllner 2010-03-27 02:24:50 +01:00
parent c6f84cfa59
commit 04200a4281

View File

@ -2,6 +2,7 @@
const Clutter = imports.gi.Clutter;
const Gtk = imports.gi.Gtk;
const St = imports.gi.St;
const Lang = imports.lang;
const Signals = imports.signals;
const Tweener = imports.ui.tweener;
@ -61,13 +62,20 @@ _Draggable.prototype = {
},
_onButtonPress : function (actor, event) {
// FIXME: we should make sure it's button 1, but we can't currently
// check that from JavaScript
if (event.get_button() != 1)
return false;
if (Tweener.getTweenCount(actor))
return false;
this._buttonDown = true;
this._grabActor();
// special case St.Clickable: grabbing the pointer would mess up the
// internal state, so we start the drag manually on hover change
if (this.actor instanceof St.Clickable)
this.actor.connect('notify::hover',
Lang.bind(this, this._onClickableHoverChanged));
else
this._grabActor();
let [stageX, stageY] = event.get_coords();
this._dragStartX = stageX;
@ -76,6 +84,15 @@ _Draggable.prototype = {
return false;
},
_onClickableHoverChanged: function(button) {
if (button.hover || !button.held)
return;
button.fake_release();
this.startDrag(this._dragStartX, this._dragStartY,
global.get_current_time());
},
_grabActor: function() {
Clutter.grab_pointer(this.actor);
this._onEventId = this.actor.connect('event',