Skip to content

Commit a109ce9

Browse files
committed
screenshot.js: Improve button event handling, listen to stage
events during rubber-banding. After pushModal, our _group actor isn't guaranteed to get all events, so we listen to 'captured-event' on the stage to make sure we don't miss a button release (or extra press).
1 parent fbafd39 commit a109ce9

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

js/ui/screenshot.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ class SelectArea {
168168
this.left_mask = null;
169169
this.right_mask = null;
170170

171+
this.active = false;
172+
this.stage_event_id = 0;
173+
171174
this._initRubberbandColors();
172175

173176
this._group = new St.Widget(
@@ -322,6 +325,10 @@ class SelectArea {
322325
}
323326

324327
_onButtonPress(actor, event) {
328+
if (this.active) {
329+
return Clutter.EVENT_STOP;
330+
}
331+
325332
[this._startX, this._startY] = event.get_coords();
326333
this._startX = Math.floor(this._startX);
327334
this._startY = Math.floor(this._startY);
@@ -334,7 +341,18 @@ class SelectArea {
334341
this._lastX = this._startX;
335342
this._lastY = this._startY;
336343

337-
return Clutter.EVENT_PROPAGATE;
344+
this.active = true;
345+
346+
this.stage_event_id = global.stage.connect("captured-event", (actor, event) => {
347+
if (Main.modalCount === 0)
348+
return false;
349+
350+
if (event.type() === Clutter.EventType.BUTTON_RELEASE) {
351+
return this._onButtonRelease(actor, event);
352+
}
353+
354+
return Clutter.EVENT_PROPAGATE;
355+
});
338356
}
339357

340358
_onButtonRelease(actor, event) {
@@ -351,6 +369,13 @@ class SelectArea {
351369
}
352370

353371
_ungrab() {
372+
this.active = false;
373+
374+
if (this.stage_event_id > 0) {
375+
global.stage.disconnect(this.stage_event_id);
376+
this.stage_event_id = 0;
377+
}
378+
354379
Main.popModal(this._group);
355380
global.unset_cursor();
356381
this.emit('finished', this._result);

0 commit comments

Comments
 (0)