Skip to content

Commit

Permalink
PickWindow: emit WindowPickCancelled when press Escape
Browse files Browse the repository at this point in the history
  • Loading branch information
nlpsuge committed Mar 25, 2023
1 parent ecfe4f8 commit 4642487
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions utils/WindowPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var WindowPickerServiceProvider = class WindowPickerServiceProvider {
lookingGlass.open();
lookingGlass.hide();

const inspector = new LookingGlass.Inspector(Main.createLookingGlass());
const inspector = new MyInspector(Main.createLookingGlass());

// Release the global grab, so that we can move around freely (specially, free to use Ctrl+`
// to switch windows) and pick a window that is on another workspace.
Expand Down Expand Up @@ -96,6 +96,9 @@ var WindowPickerServiceProvider = class WindowPickerServiceProvider {
// Restore the global grab to prevent the error 'incorrect pop' thrown by LookingGlass.close/Main.popModal(this._grab)
lookingGlass._grab = Main.pushModal(lookingGlass, { actionMode: Shell.ActionMode.LOOKING_GLASS });
lookingGlass.close();
});

inspector.connect('WindowPickCancelled', () => {
this._dbus.emit_signal('WindowPickCancelled', null);
});
}
Expand All @@ -111,4 +114,22 @@ var WindowPickerServiceProvider = class WindowPickerServiceProvider {
destroy() {
this._dbus.unexport();
}
};
};

var MyInspector = GObject.registerClass({
Signals: {
'WindowPickCancelled': {}
}
}, class MyInspector extends LookingGlass.Inspector {
_init(lookingGlass) {
super._init(lookingGlass);
}

_onKeyPressEvent(actor, event) {
if (event.get_key_symbol() === Clutter.KEY_Escape) {
this.emit('WindowPickCancelled');
this._close();
}
return Clutter.EVENT_STOP;
}
});

0 comments on commit 4642487

Please sign in to comment.