sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 85081bd5fd334130215468354a7ee2347d0c36ee
parent bca263a670b207ed7d85aedbc3f9410e4f65d705
Author: Mathieu Moneyron <mathieu.moneyron@gmail.com>
Date:   Wed, 13 May 2020 18:13:57 +0200

[PATHC] dmenu - Add preselect patch

Diffstat:
Atools.suckless.org/dmenu/patches/preselect/dmenu-preselect-20200513-db6093f.diff | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/dmenu/patches/preselect/dmenu-preselect.png | 0
Atools.suckless.org/dmenu/patches/preselect/index.md | 22++++++++++++++++++++++
3 files changed, 112 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/dmenu/patches/preselect/dmenu-preselect-20200513-db6093f.diff b/tools.suckless.org/dmenu/patches/preselect/dmenu-preselect-20200513-db6093f.diff @@ -0,0 +1,90 @@ +From 055e86dee88c5135b3d3a691942a915334d1b3a2 Mon Sep 17 00:00:00 2001 +From: Mathieu Moneyron <mathieu.moneyron@gmail.com> +Date: Wed, 13 May 2020 17:28:37 +0200 +Subject: [PATCH] Added option to preselect an item by providing a number + +--- + config.def.h | 3 +++ + dmenu.1 | 5 +++++ + dmenu.c | 15 ++++++++++++++- + 3 files changed, 22 insertions(+), 1 deletion(-) + +diff --git a/config.def.h b/config.def.h +index 1edb647..95bee59 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -21,3 +21,6 @@ static unsigned int lines = 0; + * for example: " /?\"&[]" + */ + static const char worddelimiters[] = " "; ++ ++/* -n option; preselected item starting from 0 */ ++static unsigned int preselected = 0; +diff --git a/dmenu.1 b/dmenu.1 +index 323f93c..6e1ee7f 100644 +--- a/dmenu.1 ++++ b/dmenu.1 +@@ -22,6 +22,8 @@ dmenu \- dynamic menu + .IR color ] + .RB [ \-w + .IR windowid ] ++.RB [ \-n ++.IR number ] + .P + .BR dmenu_run " ..." + .SH DESCRIPTION +@@ -80,6 +82,9 @@ prints version information to stdout, then exits. + .TP + .BI \-w " windowid" + embed into windowid. ++.TP ++.BI \-n " number" ++preseslected item starting from 0. + .SH USAGE + dmenu is completely controlled by the keyboard. Items are selected using the + arrow keys, page up, page down, home, and end. +diff --git a/dmenu.c b/dmenu.c +index 65f25ce..0a02609 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -551,8 +551,19 @@ static void + run(void) + { + XEvent ev; ++ int i; + + while (!XNextEvent(dpy, &ev)) { ++ if (preselected) { ++ for (i = 0; i < preselected; i++) { ++ if (sel && sel->right && (sel = sel->right) == next) { ++ curr = next; ++ calcoffsets(); ++ } ++ } ++ drawmenu(); ++ preselected = 0; ++ } + if (XFilterEvent(&ev, win)) + continue; + switch(ev.type) { +@@ -690,7 +701,7 @@ static void + usage(void) + { + fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" +- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); ++ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid] [-n number]\n", stderr); + exit(1); + } + +@@ -733,6 +744,8 @@ main(int argc, char *argv[]) + colors[SchemeSel][ColFg] = argv[++i]; + else if (!strcmp(argv[i], "-w")) /* embedding window id */ + embed = argv[++i]; ++ else if (!strcmp(argv[i], "-n")) /* preselected item */ ++ preselected = atoi(argv[++i]); + else + usage(); + +-- +2.26.2 + diff --git a/tools.suckless.org/dmenu/patches/preselect/dmenu-preselect.png b/tools.suckless.org/dmenu/patches/preselect/dmenu-preselect.png Binary files differ. diff --git a/tools.suckless.org/dmenu/patches/preselect/index.md b/tools.suckless.org/dmenu/patches/preselect/index.md @@ -0,0 +1,22 @@ +preselect +====== + +Description +----------- +This patch adds an option to preselect an item by providing a number. This number +is the item order in the input list starting from 0. A use case is for selecting +media controls like in the following screenshot. + +Create menu with the second item preselected: + + echo -c 'item1\nitem2\nitem3' | dmenu -n 1 + +![dmenu preselect screenshot](dmenu-preselect.png) + +Download +-------- +* [dmenu-preselect-20200513-db6093f](dmenu-preselect-20200513-db6093f.diff) (13.05.2020) + +Authors +------- +* Mathieu Moneyron <mathieu.moneyron@gmail.com>