[wiki] [sites] [PATHC] dmenu - Add preselect patch || Mathieu Moneyron

From: <git_AT_suckless.org>
Date: Wed, 13 May 2020 18:17:21 +0200

commit 85081bd5fd334130215468354a7ee2347d0c36ee
Author: Mathieu Moneyron <mathieu.moneyron_AT_gmail.com>
Date: Wed May 13 18:13:57 2020 +0200

    [PATHC] dmenu - Add preselect patch

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
new file mode 100644
index 00000000..e0183575
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/preselect/dmenu-preselect-20200513-db6093f.diff
_AT_@ -0,0 +1,90 @@
+From 055e86dee88c5135b3d3a691942a915334d1b3a2 Mon Sep 17 00:00:00 2001
+From: Mathieu Moneyron <mathieu.moneyron_AT_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
+_AT_@ -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
+_AT_@ -22,6 +22,8 @@ dmenu \- dynamic menu
+ .IR color ]
+ .RB [ \-w
+ .IR windowid ]
++.RB [ \-n
++.IR number ]
+ .P
+ .BR dmenu_run " ..."
+ .SH DESCRIPTION
+_AT_@ -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
+_AT_@ -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) {
+_AT_@ -690,7 +701,7 @@ static void
+ usage(void)
+ {
+ fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]
"
+- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]
", stderr);
++ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid] [-n number]
", stderr);
+ exit(1);
+ }
+
+_AT_@ -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
new file mode 100644
index 00000000..0a80b728
Binary files /dev/null and b/tools.suckless.org/dmenu/patches/preselect/dmenu-preselect.png differ
diff --git a/tools.suckless.org/dmenu/patches/preselect/index.md b/tools.suckless.org/dmenu/patches/preselect/index.md
new file mode 100644
index 00000000..cb6ef83e
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/preselect/index.md
_AT_@ -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
item2
item3' | 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_AT_gmail.com>
Received on Wed May 13 2020 - 18:17:21 CEST

This archive was generated by hypermail 2.3.0 : Wed May 13 2020 - 18:24:49 CEST