Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

add option for dmenu like behaviour #405

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ bool cg_quit(arg_t _)
exit(EXIT_SUCCESS);
}

bool cg_switch_mode(arg_t _)
bool cg_switch_mode(arg_t ignore_d)
{
if (options->like_dmenu && !ignore_d) {
printf("%s\n", files[fileidx].name);
exit(EXIT_SUCCESS);
}

if (mode == MODE_IMAGE) {
if (tns.thumbs == NULL)
tns_init(&tns, files, &filecnt, &fileidx, &win);
Expand Down
3 changes: 2 additions & 1 deletion config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ static const int THUMB_SIZE = 3;
static const keymap_t keys[] = {
/* modifiers key function argument */
{ 0, XK_q, g_quit, None },
{ 0, XK_Return, g_switch_mode, None },
{ 0, XK_Return, g_switch_mode, 0 },
{ ControlMask, XK_Return, g_switch_mode, 1 },
{ 0, XK_f, g_toggle_fullscreen, None },
{ 0, XK_b, g_toggle_bar, None },
{ ControlMask, XK_x, g_prefix_external, None },
Expand Down
8 changes: 6 additions & 2 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const opt_t *options = (const opt_t*) &_options;

void print_usage(void)
{
printf("usage: sxiv [-abcfhiopqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] "
printf("usage: sxiv [-abcfhiodpqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] "
"[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] "
"FILES...\n");
}
Expand All @@ -51,6 +51,7 @@ void parse_options(int argc, char **argv)

_options.from_stdin = false;
_options.to_stdout = false;
_options.like_dmenu = false;
_options.recursive = false;
_options.startnum = 0;

Expand All @@ -72,7 +73,7 @@ void parse_options(int argc, char **argv)
_options.clean_cache = false;
_options.private_mode = false;

while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:opqrS:s:tvZz:")) != -1) {
while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:odpqrS:s:tvZz:")) != -1) {
switch (opt) {
case '?':
print_usage();
Expand Down Expand Up @@ -128,6 +129,9 @@ void parse_options(int argc, char **argv)
case 'o':
_options.to_stdout = true;
break;
case 'd':
_options.like_dmenu = true;
break;
case 'p':
_options.private_mode = true;
break;
Expand Down
1 change: 1 addition & 0 deletions sxiv.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ struct opt {
char **filenames;
bool from_stdin;
bool to_stdout;
bool like_dmenu;
bool recursive;
int filecnt;
int startnum;
Expand Down