Git Product home page Git Product logo

dragon's Introduction

dragon - simple drag-and-drop source/sink for X or Wayland

Many programs, particularly web applications, expect files to be dragged
into them now. If you don't habitually use a file manager that is a
problem. dragon is a lightweight drag-and-drop source for X where you
can run:
  dragon file.tar.gz
to get a window with just that file in it, ready to be dragged where you
need it.

What if you need to drag into something? Using:
  dragon --target
you get a window you can drag files and text into. Dropped items are
printed to standard output.

If you're only dealing with a single file, either source or sink, use
the --and-exit option to terminate as soon as one drag-and-drop
operation is complete.

If you want to keep the files you drag in around for a while, use:
  dragon --target --keep
and each file you drop becomes its own draggable button, which you can
drag elsewhere later.

Installing
----------
Just run `make` to compile dragon and get an executable you can run
immediately or put where you like.

To install, run `make install`, which will put it into ~/.local/bin by
default. If you want a different destination, run `make
PREFIX=/path/here install` instead. To choose a different executable
name, run `make NAME=dragon-drop install`, which will generate the
executable and man page to match the given name.

dragon requires GTK+ 3 and is distributed under the GNU GPL version 3.

dragon's People

Contributors

amarakon avatar andrembpontes avatar bgstack15 avatar eigengrau avatar fichtefoll avatar giof avatar mwh avatar n-r-k avatar sketch98 avatar toniz4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dragon's Issues

Doesn't work properly with "special" characters

I'm assuming this is a UTF-8 issue, but dragon doesn't work with all characters. For example,

touch a b a∩b
dragon *

a and b work as expected. However, you cannot drag a∩b. You can click on it to open the file, but dragging it results in no output.

In addition, the file itself doesn't have to have these characters in it for dragon to fail. It's sufficient for them to be in the path at all. i.e.

mkdir a∩b; cd a∩b
touch foo
dragon *

This will fail as above.

--and-exit does not work on Sway/Wayland

Hi there, starting dragon-drop from a wayland terminal breaks the --and-exit feature.
The popup still stays on screen, even if you drag the file somewhere.

Starting it from a terminal using X11, it works.

How can I ensure that dragon-drop is always started under X11?

Option to append more files

When dragon-drop is called multiple times, it opens up a new window every time.
It would be nice if it there was an option to just append the file list.

always prepends current working directory

I'm trying to use dragon with a file selector dialog such as yad or zenity.

Both give me the same error:
dragon -x "'$(yad 2>/dev/null --file)'"
dragon -x "'$(zenity --file-selection)'"

The file `/home/arif/'/home/arif/Downloads/remove-red.png'' does not exist.

(Using the funny quoting in an attempt not be disturbed by paths with spaces)

Scroll bar

When there are a lot of files, the window goes off screen, instead there should be a check to limit the size of the window (if possible), and there should be a scroll bar.

It's always possible to shrink the window, but then you can't access lower items, so a scrollbar is necessary.

[Feature Request] A more compact option for -a

What I would like to see is an additional flag that goes alongside -a that combines file objects into a much smaller single object that takes up less screen space and maybe lists how many files are in the selection and the total size of the selection or something.

Symlinks are dereferenced

When used with symlinks, dragon points to the target, rather than the symlink itself.

touch a
ln -s a b
dragon *

Observed behaviour: dragging either a or b results in the output of a.
Expected behaviour: dragging b should result in the output of b.

Tag commit as release

Hi, I'd like to package dragon for Void Linux since dragon is pretty useful in conjuction with terminal file manager I use
Void requires some version number for packaging. I'd be very grateful if you could create tag for lastest commit (v1 or something like that).

You can do this with

git tag v1
git push --tags

Cheers :)

Multi-select in open window to drag out

shift+click and control+click and control+a for selecting multiple items in the dragon window to drag OUT of the window

It works great for everything else, but say I wanted to drag like 10 files at once into something? If I select them all in ranger and then use dragon to pop up a window to drag them somewhere, I always have to then drag them somewhere 1 at a time.

Thoughts?

I might try to do this at some point myself but I would have to learn c first.....

It might be a good reason for me to learn some c though so I would welcome the challenge if people want this.

Or if someone who knows the project would be able to add this in an evening I would be extremely grateful

[SUGGESTION] Dragging plaintext only

I think there should be an option to interpret the input as the data itself, rather than converting it to file URIs. It's a bit asymmetrical that you can select and drag plaintext from a browser or some other graphical app into dragon, but not out of it.

Dragon can't handle combined flags

Bug

Currently dragon cannot handle combined flags in the arguments passed to it on the shell, for eg:

dragon-drag-and-drop -tk

Expected behaviour

dragon launches with -t and -k flags

Actual behaviour

dragon returns the following error

dragon-drag-and-drop: error: unknown option `-tk'.
Usage: dragon-drag-and-drop [OPTIONS] FILENAME

Potential fix

This can be fixed by using the standard getopt C library. I'd be happy to write PR for the same.

Can't drag from mtp mountpoint

When dragging from a gvfs-mtp mountpoint, dragon's behavior is different from thunar.

Thunar produce

file:///run/user/1000/gvfs/mtp:host=Android_OnePlus_a7de565f

Dragon produce

mtp:host=Android_OnePlus_a7de565f

Which can not be processed by chromium, so does all files in such mtp mountpoint.

name conflict

The name of this conflicts with the kde media player also called dragon.
I guess you could just try to work without one of the two, but that's not good practice.
I suggest changing the executable name to something like xdragon, that would also fit with xclip or xdotool since they are also small x utilities. Or you could just rename the project as a whole. Maybe the change would also enable it to get into the repos of some distros.

[QoL]: close on click

When I click on the window and it opens the file, I would expect the window to close as it would if the contents were dragged. (Probably would respect the --keep option)

Currently, it opens a new window which takes focus and I have to change the focus back to dragon-drop to close the source window.

Bash auto completions only show directory names

In Ubuntu 22.04 with i3wm after compiling and installing the binary in the default location I get completions only for directories, that is, if I press after dragon<Space> in the shell, only directories are auto completed.

I solved this issue by using a custom completion command for dragon:

complete -o default -o bashdefault dragon

Can this behavior be implemented by default?

[FEATURE REQUEST] More appearance customization

Currently, each file is displayed as a fairly large icon (or preview if available) alongside the full path.

image

Here are a few suggestions, that in my opinion would allow for better customization:

  1. --no-thumb don't show preview thumbnails, use file icons for all files
  2. --icon-size to go along with --thumb-size
  3. --font-size already requested in #30
  4. --verbatim-arguments show the file names exactly how they were passed on the CLI instead of normalizing to an absolute path (so dragon-drop foo will show foo, dragon-drop ../dir/foo will show ../dir/foo, etc)

Here's a mock up of dragon-drop --no-thumb --font-size 28 --verbatim-arguments bar baz download.jpeg foo:

Screenshot_20230125_161742_2

Add a option to help with --and-exit

Hi, I would like to add a new flag (can't find a good name for it) to supplement the --and-exit flag. Currently, if I have multiple files "served" by dragon with the -x option, then dragon doesn't wait till i drag all the files to respective apps. It closes on the first drag_end event.

I would like to add a -X or --individual-exit (name could be improved) that will:

  • Remove "dragged" entry on the drag_end event
  • Once there are no more entires, close dragon

I know the -a option exists but my workflow consists of me having to drag different files to different applications.

I have the code changes ready and can create a PR if the maintainers are interested. Please let me know if you have any questions

Thanks

segfault on drag+drop

I get a segfault when trying to drag+drop an (utf-8 encoded) text file.

If hat matters, on startup I get the following warnings:
(dragon:26094): Gtk-WARNING **: 18:06:12.639: Could not find the icon 'text-plain'. The 'hicolor' theme
was not found either, perhaps you need to install it.
You can get a copy from:
http://icon-theme.freedesktop.org/releases

(dragon:26094): Gtk-CRITICAL **: 18:06:12.639: gtk_icon_info_load_icon: assertion 'icon_info != NULL' failed

Dragon doesnt work on Sway

Hello. I switched to sway few weeks ago. Im in love with CLI-tools, that allow me to drag&drop from CLI, but im expiriencing troobles with that on Wayland. Drag window shows up, but i cant drop anything. Sometimes i can, sometimes - cant. Can u suggest some solution for me? Or, at least, tell me, how to debug it properly.

Also, your app gives me error:

(dragon:161804): Gdk-WARNING **: 14:59:50.047: Error writing selection data: Error writing to file descriptor: Broken pipe

If this error is related to my bug - how can i enable moving popups? Is that even possible?

Demonstration:

2024-04-07.14-57-31.mp4

Random freeze

Hi, thanks for this very useful program.
I've a problem since few months, sometimes when I drag a file the plus icon on the mouse doesn't appear and the whole GUI freeze, I have to kill dragon for get hand back on GUI.
I'am on arch linux with i3.
I'm sorry because I've no idea why it crashes sometimes, and sometimes not, with the same file...
I tried with dragon -v file but not learn anything, if you have ideas...
Thanks

support for utf-8 text

I tried to drag some utf-8(persian) text while running dragon with --target
but this was printed:

ÙÙØªÛ ÙÙÙز Ù
ردÙ
 Ù
ا تÙÙÛÙ
 ÙشدÙد ØÙÙ
عÙÛ ÙرÙØ·ÛÙ٠را ÙÙ
Û Ø¯Ø§ÙÙد ØÙباÛد تÙÙع داشت کرÙÙا ب٠اÛ٠زÙØ¯Û Ø§Ø² Ú©Ø´Ùر Ù
ا برÙدØبÛÙ Ù
رÛضÙØ§Û  Ù
٠اÙØ±Ø§Ø¯Û ÙستÙد ðÚ©Ù Û¶ÙرÙردÛ٠در

while the original text was:

وقتی هنوز مردم ما تفهیم نشدند ،ومعنی قرنطینه را نمی دانند ،نباید توقع داشت کرونا به این زودی از کشور ما برود،بین مریضهای  من افرادی هستند 🌀که ۶فروردین در

Option to auto-refresh file list

Consider this case in which the last ten files of a folder are listed: dragon-drop $(ls -tr | tail -n10)
I suggest adding an option that refreshes the list (e.g. removing files not existing anymore and adding new files from a folder automatically.
I know there is --stdin but I wasn't able to get this functionality using this.

Wayland?

Will this program support Wayland in the future, or is there a Wayland alternative?

MacOS alternative

Anyone aware of a tool that does what Dragon does on MacOS? I know this is off topic but I figure if anyone would know, it would be the people here.

Option to output filepath instead of URI

Amost every tool accepts standard filepaths as an argument or thorugh stdin, however dragon always outputs a file's URI in target mode. Currently I need to pipe dragon's output through a custom script to get the useful filepaths instead of the URIs and I can imagine this to be a common use case.

Path and thumbnail are not properly aligned

Hi, thanks for adding thumbnail support.

dragon

However as you can see, the path isn't properly centered/aligned with the thumbnails. Aligning it to center would be appreciated.

problem dropping files in arch linux

so I have no problem in draggin files out from my terminal into an other app, the problem is when I try to drop using
dragon --target --and-exit
because it just prints the name of the files but does nothing
I am currently in arch linux and I have tried compiling it from source, also tried using bouth of the packages in the AUR but I still have the same problem. any guesses?

Select all/select region?

Hi @mwh, first of all THANK YOU! I was lookgin for something like dragon for a long time... really really thanks.

Do you think it will be possilbe to have dragon support a select all or select region for files in window? I found most of the times I just need to attach 4/5 files to an email, for example, and I'd like to be able to select all from dragon window and drag them into the browser.

Dragged files not accepted by Discord

For some reason, Discord doesn't accept files dragged from dragon. However, it does accept file from Nautilus and Nautilus (and FireFox) also accepts files from dragon. Any clues as to what might be going on? Is Discord at fault?

To be clear, when dragging to a Discord client, the normal on-hover popup displays but when you release the mouse button, the popup just disappears and nothing happens. Not even an error message in the console.

Option to remove file from list

When opening multiple files, there might be the case that one file might not be of interest anymore (even without it being dragged at all).
I suggest to add an option to remove a file e.g. on right-click of the entry.

Allow to specify a font size

Would it be considered "in scope" to add an optional flag that sets the font size?

Allowing to specify a font name might be a bit of a stretch, but will certainly increase dragon's popularity amongst /r/unixporn.

Is resizing locked?

Is it possible to resize the dragon window?
Currently, it prints the complete path of the file as entry. It makes it cumbersome to place the window around. Is it possible to somehow resize the window to line-wrap the entries (so window size is grown vertically not horizontally)?
Excellent project BTW 💯 😃
image

Improvements - imho

VERSION "1.2.0"

  1. reduce the window size by using the label base-name.
  2. On start-up, in target mode, allow pre-configuration with files on command line.

Diff -e below:

560,561c

add_target_button();

for (int i=1; i<argc; i++) {
    if (argv[i][0] != '-' && argv[i][0] != '\0')
       add_filename_button(argv[i]);
}

gtk_widget_show_all(window);
gtk_main();

exit(0);

.
387,392d
155c
label = g_path_get_basename(label);

Automated screenshot + drop at mouse click location

Hi, thanks for dragon.
No issue here just a note: This is may be of use for someone else as well (just realized I got a few points at SO for it, so why not share):

Function: Hotkey to start script -> select area -> click into drop area. Done.

drag_into

It uses scrot to make a screenshot of a selected area, then dragon, to create a drag window top left, then xdotool to click and drag that to the point where you click.

Here the script

2.bin$ cat drag_into
#!/usr/bin/env bash
doc="$0 <filename|'shot'>

Drags a given file to where the mouse is using dragon. Click to drop it (anywere).
If filename is 'shot' then the file will be a shot of a an area to be selected
(i.e. ideal to be triggered by a hotkey).
"

cmd_shot="shot"
file=

exit_help () { echo -e "$doc"; exit 1; }

select_shot_area () {
    # create screen shot
    notify-send "Select area - we'll shoot it and drag to where the mouse is."
    cd "$HOME/Pictures/shots/" || exit 1
    rm -f "latest.png"
    scrot -s '%Y-%m-%d_$wx$h_scrot.png' -e 'ln -s $f latest.png'
    file="`readlink latest.png`"
}

main () {
    file="$1"
    test -z "$file" -o "$file" == "-h" && exit_help
    eval "$(xdotool getmouselocation --shell)" # into $X and $Y
    test "$file" == "$cmd_shot" && { select_shot_area || return 1; }
    killall dragon 2>/dev/null # No accidential drops of wrong items ...
    dragon --and-exit "$file" &
    while true; do
        xid="$(xdotool search --onlyvisible --class  dragon | head -n 2)"
        test -z "$xid" || break
        sleep 0.05
    done
    xdotool mousemove --sync -w "$xid" 1 1 mousedown 1 mousemove $X $Y
    notify-send "Click to drop $file..."
}

main "$@"

Bidirectional drag-and-drop

I have dragon on a keyboard shortcut in my terminal, and dragon --target on another shortcut. But I would rather have just one shortcut. Is it possible to have one command that supports drag-and-drop in both directions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.