Skip to content

Commit

Permalink
Allow to set the size of thumbnails
Browse files Browse the repository at this point in the history
The command line arguments are compatible with dragon.
Note that for zsh completion of the size number, we use the "(single
unquoted space)" action, which is a dummy action (it doesn't make any
sense to autocomplete numbers).

This implements one part of #10
  • Loading branch information
vimpostor committed Oct 3, 2024
1 parent f2c8e02 commit d8e5827
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions assets/completions/bash-completion/completions/blobdrop
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _blobdrop() {
-p --persistent
-P --prefix
-R --remote
-s --thumb-size
-t --ontop
-x --auto-quit
"
Expand Down
1 change: 1 addition & 0 deletions assets/completions/fish/vendor_completions.d/blobdrop.fish
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ complete -c blobdrop -s '-k' -l 'keep' -d 'keep dropped files'
complete -c blobdrop -s '-p' -l 'persistent' -d 'disable autohiding during drag'
complete -c blobdrop -s '-P' -l 'prefix' -d 'remote prefix' -xa "(__fish_print_hostnames)"
complete -c blobdrop -s '-R' -l 'remote' -d 'enable ssh remote transparency'
complete -c blobdrop -s '-s' -l 'thumb-size' -d 'set thumbnail size' -x
complete -c blobdrop -s '-t' -l 'ontop' -d 'keep window on top'
complete -c blobdrop -s '-x' -l 'auto-quit' -d 'autoquit behaviour' -xa "never\t'do not autoquit' first\t'after first drag' all\t'after all items have been dragged'"
2 changes: 1 addition & 1 deletion assets/completions/zsh/site-functions/_blobdrop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#compdef blobdrop

_blobdrop() {
_arguments {-h,--help}'[show help]' {-v,--version}'[show version]' {-b,--frameless}'[show frameless window]' {-c,--cursor}'[spawn window at mouse cursor]' {-f,--frontend}'[selects frontend]:arg:((auto\:"automatic" gui\:"show window" immediate\:"drag immediately" notify\:"drag from notification" clipboard\:"copy to clipboard" stdout\:"print OSC8 link"))' {-i,--intercept}'[intercept another DnD]' {-k,--keep}'[keep dropped files]' {-p,--persistent}'[disable autohiding during drag]' {-P,--prefix}'[specify remote prefix]:arg:_hosts' {-R,--remote}'[enable ssh network transparency]' {-t,--ontop}'[keep window on top]' {-x,--auto-quit}'[autoquit behaviour]:num:((never\:"do not autoquit" first\:"after first drag" all\:"after all items have been dragged"))' '*: arg:_files'
_arguments {-h,--help}'[show help]' {-v,--version}'[show version]' {-b,--frameless}'[show frameless window]' {-c,--cursor}'[spawn window at mouse cursor]' {-f,--frontend}'[selects frontend]:arg:((auto\:"automatic" gui\:"show window" immediate\:"drag immediately" notify\:"drag from notification" clipboard\:"copy to clipboard" stdout\:"print OSC8 link"))' {-i,--intercept}'[intercept another DnD]' {-k,--keep}'[keep dropped files]' {-p,--persistent}'[disable autohiding during drag]' {-P,--prefix}'[specify remote prefix]:arg:_hosts' {-R,--remote}'[enable ssh network transparency]' {-s,--thumb-size}'[thumbnail size]:num: ' {-t,--ontop}'[keep window on top]' {-x,--auto-quit}'[autoquit behaviour]:arg:((never\:"do not autoquit" first\:"after first drag" all\:"after all items have been dragged"))' '*: arg:_files'
return 0
}

Expand Down
4 changes: 4 additions & 0 deletions doc/man/man1/blobdrop.1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ blobdrop \- Quickly drag and drop files from the terminal
[\-hvbcikpRt]
[\-f \fIOPT\fP]
[\-P \fIOPT\fP]
[\-s \fIOPT\fP]
[\-x \fIOPT\fP]
.I FILES

Expand Down Expand Up @@ -63,6 +64,9 @@ Enable ssh remote transparency. This sets the URI scheme to
.B sftp://
and the username, hostname and port based on heuristics, thus making it possible to drag and drop across a forwarded X11 session from a remote host. DnD requires trusted X11 forwarding (ssh -Y). In case of the heuristic failing, the \-\-prefix option can be used to manually set a value.
.TP
.B \-s, \-\-thumb\-size \fIOPT\fP
Sets the size of the thumbnail for listed images. The default size is 64.
.TP
.B \-t, \-\-ontop
Keep the window on top of other windows.
.TP
Expand Down
15 changes: 14 additions & 1 deletion src/getopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ bool parse(const QStringList &args) {
QCommandLineOption remote_opt(QStringList() << "R"
<< "remote",
"Enable ssh remote transparency.");
QCommandLineOption thumbnailsize_opt(QStringList() << "s"
<< "thumb-size",
"Set thumbnail size (default 64)",
"size");
QCommandLineOption ontop_opt(QStringList() << "t"
<< "ontop",
"Keep the window on top of other windows.");
Expand All @@ -59,7 +63,7 @@ bool parse(const QStringList &args) {
"The amount of drags after which the program should automatically close. Must be one of:" + QString::fromStdString(auto_quit_descr) + " (all is default)",
"behaviour");

p.addOptions({frameless_opt, cursor_opt, frontend_opt, intercept_opt, keep_opt, persistent_opt, prefix_opt, remote_opt, ontop_opt, auto_quit_opt});
p.addOptions({frameless_opt, cursor_opt, frontend_opt, intercept_opt, keep_opt, persistent_opt, prefix_opt, remote_opt, thumbnailsize_opt, ontop_opt, auto_quit_opt});
p.process(args);

if (p.isSet(auto_quit_opt)) {
Expand All @@ -72,6 +76,15 @@ bool parse(const QStringList &args) {
Settings::get()->auto_quit_behavior = static_cast<Settings::AutoQuitBehavior>(choice);
}
Settings::get()->remote = p.isSet(remote_opt);
if (p.isSet(thumbnailsize_opt)) {
const auto v = p.value(thumbnailsize_opt).toInt();
if (v) {
Settings::get()->thumbnail_size = v;
} else {
std::cerr << "Thumbnail size must be an integer." << std::endl;
return false;
}
}
if (p.isSet(prefix_opt)) {
if (!Settings::get()->remote) {
std::cerr << "This option has no effect if remote support is not enabled" << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions src/qml/PathView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ ListView {
visible: false
icon.name: "emblem-documents-symbolic"
icon.color: "transparent"
width: 64
height: 64
width: Settings.thumbnailSize
height: Settings.thumbnailSize
}
DragArea {
anchors.fill: parent
Expand All @@ -48,7 +48,7 @@ ListView {
}
}
delegate: Item {
height: 64
height: Settings.thumbnailSize
width: ListView.view.width
Pane {
id: pane
Expand Down
2 changes: 2 additions & 0 deletions src/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Settings : public QObject {
Q_PROPERTY(bool needsGui READ needs_gui NOTIFY hideGuiChanged)
Q_PROPERTY(bool spawnOnCursor MEMBER spawn_on_cursor CONSTANT)
Q_PROPERTY(bool intercept MEMBER intercept CONSTANT)
Q_PROPERTY(int thumbnailSize MEMBER thumbnail_size CONSTANT)
public:
enum class AutoQuitBehavior {
Never,
Expand Down Expand Up @@ -45,6 +46,7 @@ class Settings : public QObject {
bool suppress_always_on_bottom = false;
bool spawn_on_cursor = false;
bool intercept = false;
int thumbnail_size = 64;
bool remote = false;
signals:
void alwaysOnBottomChanged(bool alwaysOnBottom);
Expand Down

0 comments on commit d8e5827

Please sign in to comment.