screenshot: Port to GrabHelper
Taking an area screenshot doesn't work currently when in "grab mode", for instance when the message tray or top bar menus are open. Fix this by using GrabHelper for selecting the area, so grabs are properly stacked for us. https://bugzilla.gnome.org/show_bug.cgi?id=709126
This commit is contained in:
parent
a244c1e987
commit
df08ae7996
@ -11,6 +11,7 @@ const Shell = imports.gi.Shell;
|
|||||||
const Signals = imports.signals;
|
const Signals = imports.signals;
|
||||||
const St = imports.gi.St;
|
const St = imports.gi.St;
|
||||||
|
|
||||||
|
const GrabHelper = imports.ui.grabHelper;
|
||||||
const Lightbox = imports.ui.lightbox;
|
const Lightbox = imports.ui.lightbox;
|
||||||
const Main = imports.ui.main;
|
const Main = imports.ui.main;
|
||||||
const Tweener = imports.ui.tweener;
|
const Tweener = imports.ui.tweener;
|
||||||
@ -139,6 +140,7 @@ const SelectArea = new Lang.Class({
|
|||||||
this._startY = -1;
|
this._startY = -1;
|
||||||
this._lastX = 0;
|
this._lastX = 0;
|
||||||
this._lastY = 0;
|
this._lastY = 0;
|
||||||
|
this._result = null;
|
||||||
|
|
||||||
this._initRubberbandColors();
|
this._initRubberbandColors();
|
||||||
|
|
||||||
@ -148,12 +150,12 @@ const SelectArea = new Lang.Class({
|
|||||||
y: 0 });
|
y: 0 });
|
||||||
Main.uiGroup.add_actor(this._group);
|
Main.uiGroup.add_actor(this._group);
|
||||||
|
|
||||||
|
this._grabHelper = new GrabHelper.GrabHelper(this._group);
|
||||||
|
|
||||||
this._group.connect('button-press-event',
|
this._group.connect('button-press-event',
|
||||||
Lang.bind(this, this._onButtonPress));
|
Lang.bind(this, this._onButtonPress));
|
||||||
this._group.connect('button-release-event',
|
this._group.connect('button-release-event',
|
||||||
Lang.bind(this, this._onButtonRelease));
|
Lang.bind(this, this._onButtonRelease));
|
||||||
this._group.connect('key-press-event',
|
|
||||||
Lang.bind(this, this._onKeyPress));
|
|
||||||
this._group.connect('motion-event',
|
this._group.connect('motion-event',
|
||||||
Lang.bind(this, this._onMotionEvent));
|
Lang.bind(this, this._onMotionEvent));
|
||||||
|
|
||||||
@ -169,10 +171,12 @@ const SelectArea = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
show: function() {
|
show: function() {
|
||||||
if (!Main.pushModal(this._group) || this._group.visible)
|
if (!this._grabHelper.grab({ actor: this._group,
|
||||||
|
onUngrab: Lang.bind(this, this._onUngrab) }))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
global.screen.set_cursor(Meta.Cursor.CROSSHAIR);
|
global.screen.set_cursor(Meta.Cursor.CROSSHAIR);
|
||||||
|
Main.uiGroup.set_child_above_sibling(this._group, null);
|
||||||
this._group.visible = true;
|
this._group.visible = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -202,13 +206,6 @@ const SelectArea = new Lang.Class({
|
|||||||
height: Math.abs(this._startY - this._lastY) };
|
height: Math.abs(this._startY - this._lastY) };
|
||||||
},
|
},
|
||||||
|
|
||||||
_onKeyPress: function(actor, event) {
|
|
||||||
if (event.get_key_symbol() == Clutter.Escape)
|
|
||||||
this._destroy(null, false);
|
|
||||||
|
|
||||||
return Clutter.EVENT_PROPAGATE;
|
|
||||||
},
|
|
||||||
|
|
||||||
_onMotionEvent: function(actor, event) {
|
_onMotionEvent: function(actor, event) {
|
||||||
if (this._startX == -1 || this._startY == -1)
|
if (this._startX == -1 || this._startY == -1)
|
||||||
return Clutter.EVENT_PROPAGATE;
|
return Clutter.EVENT_PROPAGATE;
|
||||||
@ -230,24 +227,28 @@ const SelectArea = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_onButtonRelease: function(actor, event) {
|
_onButtonRelease: function(actor, event) {
|
||||||
this._destroy(this._getGeometry(), true);
|
this._result = this._getGeometry();
|
||||||
return Clutter.EVENT_PROPAGATE;
|
|
||||||
},
|
|
||||||
|
|
||||||
_destroy: function(geometry, fade) {
|
|
||||||
Tweener.addTween(this._group,
|
Tweener.addTween(this._group,
|
||||||
{ opacity: 0,
|
{ opacity: 0,
|
||||||
time: fade ? 0.2 : 0,
|
time: 0.2,
|
||||||
transition: 'easeOutQuad',
|
transition: 'easeOutQuad',
|
||||||
onComplete: Lang.bind(this,
|
onComplete: Lang.bind(this,
|
||||||
function() {
|
function() {
|
||||||
Main.popModal(this._group);
|
this._grabHelper.ungrab();
|
||||||
this._group.destroy();
|
|
||||||
global.screen.set_cursor(Meta.Cursor.DEFAULT);
|
|
||||||
|
|
||||||
this.emit('finished', geometry);
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
},
|
||||||
|
|
||||||
|
_onUngrab: function() {
|
||||||
|
global.screen.set_cursor(Meta.Cursor.DEFAULT);
|
||||||
|
this.emit('finished', this._result);
|
||||||
|
|
||||||
|
GLib.idle_add(GLib.PRIORITY_DEFAULT, Lang.bind(this,
|
||||||
|
function() {
|
||||||
|
this._group.destroy();
|
||||||
|
return GLib.SOURCE_REMOVE;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Signals.addSignalMethods(SelectArea.prototype);
|
Signals.addSignalMethods(SelectArea.prototype);
|
||||||
|
Loading…
Reference in New Issue
Block a user