X11 – How to Drag a File into a Window Without a File Manager

drag and dropfile-managerx11

(I'm on Arch Linux, using i3 as my wm and xterm as my terminal emulator, though I don't know if any of that is relevant.)

Occasionally, a website asks me to drag a file with my mouse from my desktop into the internet browser's window. Almost always, there is an alternative, but recently I found something I want to do that requires the drag and drop. Unfortunately, I don't have a file manager. I navigate my computer's file system solely through bash.

Is there a way I can fake the drag and drop action? Can I tell my browser "I just dropped this file onto you" without actually doing it?

Worst case scenario, I can download a graphical file manager exclusively to drop files into my web browser, but I'd like to avoid that solution.

Best Answer

I had exactly the same problem a few months back and ultimately just wrote a tool to do it for me. When I saw this and found someone else had the same itch I cleaned it up so that someone other than me could actually get it running, and finished off my to-do list. The code is up now: https://github.com/mwh/dragon

To get it, run

git clone https://github.com/mwh/dragon.git
cd dragon
make

That will give you a standalone dragon executable - you can move it wherever you want. make install will put it in $HOME/.local/bin.

Either way, you can then:

dragon *.jpg

to get a simple window with draggable buttons for each of those files:

Screenshot of dragon showing a few files

You can drag any of those into a browser, a file manager, an editor, or anywhere else that speaks the standard drag-and-drop protocol.

If you want to go the other way, and drag things in to it, use --target — they'll be printed to standard output, or available to drag out again with if you use --keep as well.


To build you'll need a C compiler and the GTK+ 3 development headers - if you're on Arch you'll get those just by installing GTK+, but on other distributions you may have to apt-get install build-essentials libgtk3-dev or yum install gtk3-devel or similar first. Other than that it's entirely self-contained, with no constituent libraries or anything, and you can just put the executable where you want.

My use case is mostly one-off drags of only a few files (usually just one), without particularly caring how they show up, so if that doesn't line up with what you want then Dragbox (which I didn't see until recently) might still be better for you. Just yesterday I added the support for using it as a drag target as well, so that part hasn't had much use on my end. Other than that, though, I've been using this successfully for a while now. There are other modes and options described in the readme file.

Related Question