Abort drag-and-drop from a busy program
When the following happens:
- I start a drag-and-drop operation, starting from application ABC.
- Application ABC locks up (temporarily)
- I release the mouse button
then, until application ABC finishes processing, I have the following problems:
- Other programs cannot "grab" the mouse pointer
- The drag-and-drop cursor remains active
- I cannot click anything
- I cannot open the gnome-panel or GNOME menu
- I cannot press certain keys (including space, enter, arrow keys)
Obviously, I then cannot do other work while waiting for the application to finish.
A situation when this occurs is when I have ~500 firefox tabs open, when dragging tabs it sometimes freezes for half an hour or so.
A workaround is to use a terminal by pressing Ctrl-Alt-F1, log in, run killall ABC
to kill the offending application, and press Ctrl-Alt-F7 to get back to the graphical environment. But I would rather not have to kill ABC, instead letting it finish processing, while getting my mouse back.
So, is it possible to forcibly abort a drag-and-drop / un-grab the mouse pointer from a busy program, without killing the process?
In fact, it is possible to do this (at least with recent versions of X).
You can do this by pressing the XF86Ungrab key, introduced in this commit.
By default, this keysym is not bound to any physical key or key combination (it was disabled in 2012 after it was reported as a security hole, since it allows anyone to bypass lock screens by breaking their grabs). On some other setups it is bound to a shortcut that uses the number pad. Obviously, that won't work on laptops that lack a keypad.
But you can still activate the keysym using xdotool
:
setxkbmap -option grab:break_actions
xdotool key XF86Ungrab
This works with X.org version 2:1.11.4-0ubuntu10.8 on Ubuntu Precise.
In most operating systems or window systems you can abort a mouse drag handler by pressing the Escape button. And sometimes you can cancel the even by finding or using a "drag cancel" target like Mac os's top menu. For example in most Windows you will notice cursor changes to circle with line through it, like a classic No Smoking sign or No Diving type of sign in the real world ;)
In the case of OP, they are using GNOME / Firefox:
In Gnome, in most cases hitting escape key before letting go of mouse button will (should) cancel the drag/drop event. It is even part of their dev guidelines:
http://developer.gnome.org/hig-book/3.2/input-mouse.html.en#drag-drop-override
Allow all mouse operations to be cancelled before their completion. Pressing the Esc key should cancel any mouse operation in progress, such as dragging and dropping a file in a file manager, or drawing a shape in a drawing application.
and..
Allow the user to cancel a drag and drop operation by all of these methods:
- pressing Esc before releasing the mouse button dropping the object
- back on its original location performing a query drag and selecting
- Cancel on the pop-up menu (see Section 10.1.3.1.2 ― Query Drag)
- dropping the object on an invalid drop target.
I am sure it is the same in KDE from doing a few searches
On Mozilla dev's Drop Event
drop The drop event is fired on the element where the drop was occured at the end of the drag operation. A listener would be responsible for retrieving the data being dragged and inserting it at the drop location. This event will only fire if a drop is desired. It will not fire if the user cancelled the drag operation, for example by pressing the Escape key, or if the mouse button was released while the mouse was not over a valid drop target. For information about this, see Performing a Drop.
I never said this would work all the time in EVERY setup, for example I don't think this works on Ubuntu which is kind of lame. I remember the drag event abort working with the Escape key since in wondows since version 3.1.
In all MS Windows operating systems in almost all (properly coded) applications: - hitting the escape key before releasing the mouse button during a drag/drop mouse event will cancel/abort the handler function.
For example in Google Chrome on Windows7: - drag a tab off the toolbar as if you are going to detach it and before letting go, hit your keyboard Escape key. It should abort the drag and return your tab.