Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[DND] Grab keyboard during dragging and abort drag on Escape #1315

Merged
merged 2 commits into from

2 participants

@autarkper
Collaborator

This grabs the keyboard focus while dragging an item and aborts the current drag if a press of Escape is detected. It is only partially successful but it doesn't seem to have any negative impact where it fails to grab the keyboard. It works fine in Expo. When dragging from the menu applet, it does not abort the current drag on Escape, but it has the beneficial effect of not closing the menu while the drag is still in progress, if Escape is pressed.

@glebihan glebihan merged commit a71deb3 into linuxmint:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 2 deletions.
  1. +16 −1 js/ui/dnd.js
  2. +2 −1  js/ui/popupMenu.js
View
17 js/ui/dnd.js
@@ -47,6 +47,10 @@ let eventHandlerActor = null;
let currentDraggable = null;
let dragMonitors = [];
+function isDragging() {
+ return currentDraggable != null;
+}
+
function _getEventHandlerActor() {
if (!eventHandlerActor) {
eventHandlerActor = new Clutter.Rectangle();
@@ -173,13 +177,19 @@ _Draggable.prototype = {
_grabEvents: function() {
if (!this._eventsGrabbed) {
- Clutter.grab_pointer(_getEventHandlerActor());
+ let eha = _getEventHandlerActor();
+ Clutter.grab_pointer(eha);
+ this.previousKeyFocusActor = global.stage.get_key_focus();
+ eha.grab_key_focus();
this._eventsGrabbed = true;
}
},
_ungrabEvents: function() {
if (this._eventsGrabbed) {
+ if (this.previousKeyFocusActor) {
+ this.previousKeyFocusActor.grab_key_focus();
+ }
Clutter.ungrab_pointer();
this._eventsGrabbed = false;
}
@@ -228,6 +238,11 @@ _Draggable.prototype = {
this._firstLeaveActor = event.get_source();
} else if (event.type() == Clutter.EventType.ENTER) {
this._lastEnterActor = event.get_source();
+ } else if (event.type() == Clutter.EventType.KEY_PRESS) {
+ if (event.get_key_symbol() === Clutter.Escape) {
+ this._cancelDrag(event.get_time());
+ }
+ return true; // swallow all keyboard input during drag
}
return false;
View
3  js/ui/popupMenu.js
@@ -9,6 +9,7 @@ const Signals = imports.signals;
const St = imports.gi.St;
const BoxPointer = imports.ui.boxpointer;
+const DND = imports.ui.dnd;
const Main = imports.ui.main;
const Params = imports.misc.params;
const Tweener = imports.ui.tweener;
@@ -1922,7 +1923,7 @@ else
},
_onKeyFocusChanged: function() {
- if (!this.grabbed || !this._activeMenu)
+ if (!this.grabbed || !this._activeMenu || DND.isDragging())
return;
let focus = global.stage.key_focus;
Something went wrong with that request. Please try again.