summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h6
-rw-r--r--config.def.h.orig4
-rw-r--r--config.h8
-rwxr-xr-xdmenubin43016 -> 43080 bytes
-rw-r--r--dmenu-grid-4.9.diff107
-rw-r--r--dmenu.15
-rw-r--r--dmenu.1.orig3
-rw-r--r--dmenu.c27
-rw-r--r--dmenu.c.orig43
-rw-r--r--dmenu.obin36344 -> 36776 bytes
10 files changed, 180 insertions, 23 deletions
diff --git a/config.def.h b/config.def.h
index 28f5a89..2c02b26 100644
--- a/config.def.h
+++ b/config.def.h
@@ -2,8 +2,8 @@
/* Default settings; can be overriden by command line. */
static int topbar = 0; /* -b option; if 0, dmenu appears at bottom */
-static int centered = 0; /* -c option; centers dmenu on screen */
-static int min_width = 500; /* minimum width when centered */
+static int centered = 1; /* -c option; centers dmenu on screen */
+static int min_width = 400; /* minimum width when centered */
/* -fn option overrides fonts[0]; default X11 font or font set */
static const char *fonts[] = {
"Sauce Code Pro:size=11"
@@ -22,10 +22,10 @@ static const char *colors[SchemeLast][2] = {
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 12;
+static unsigned int columns = 2;
/* -h option; minimum height of a menu line */
static unsigned int lineheight = 24;
static unsigned int min_lineheight = 24;
-
/*
* Characters not considered part of a word while deleting words
* for example: " /?\"&[]"
diff --git a/config.def.h.orig b/config.def.h.orig
index bf9a338..f79f09d 100644
--- a/config.def.h.orig
+++ b/config.def.h.orig
@@ -2,6 +2,8 @@
/* Default settings; can be overriden by command line. */
static int topbar = 0; /* -b option; if 0, dmenu appears at bottom */
+static int centered = 1; /* -c option; centers dmenu on screen */
+static int min_width = 400; /* minimum width when centered */
/* -fn option overrides fonts[0]; default X11 font or font set */
static const char *fonts[] = {
"Sauce Code Pro:size=11"
@@ -19,7 +21,7 @@ static const char *colors[SchemeLast][2] = {
};
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
-static unsigned int lines = 3;
+static unsigned int lines = 12;
/* -h option; minimum height of a menu line */
static unsigned int lineheight = 24;
static unsigned int min_lineheight = 24;
diff --git a/config.h b/config.h
index 19700b2..2c02b26 100644
--- a/config.h
+++ b/config.h
@@ -2,8 +2,8 @@
/* Default settings; can be overriden by command line. */
static int topbar = 0; /* -b option; if 0, dmenu appears at bottom */
-static int centered = 0; /* -c option; centers dmenu on screen */
-static int min_width = 500; /* minimum width when centered */
+static int centered = 1; /* -c option; centers dmenu on screen */
+static int min_width = 400; /* minimum width when centered */
/* -fn option overrides fonts[0]; default X11 font or font set */
static const char *fonts[] = {
"Sauce Code Pro:size=11"
@@ -21,11 +21,11 @@ static const char *colors[SchemeLast][2] = {
};
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
-static unsigned int lines = 3;
+static unsigned int lines = 12;
+static unsigned int columns = 2;
/* -h option; minimum height of a menu line */
static unsigned int lineheight = 24;
static unsigned int min_lineheight = 24;
-
/*
* Characters not considered part of a word while deleting words
* for example: " /?\"&[]"
diff --git a/dmenu b/dmenu
index e01f982..b1a59d9 100755
--- a/dmenu
+++ b/dmenu
Binary files differ
diff --git a/dmenu-grid-4.9.diff b/dmenu-grid-4.9.diff
new file mode 100644
index 0000000..c27689b
--- /dev/null
+++ b/dmenu-grid-4.9.diff
@@ -0,0 +1,107 @@
+From 39ab9676914bd0d8105d0f96bbd7611a53077438 Mon Sep 17 00:00:00 2001
+From: Miles Alan <m@milesalan.com>
+Date: Sat, 4 Jul 2020 11:19:04 -0500
+Subject: [PATCH] Add -g option to display entries in the given number of grid
+ columns
+
+This option can be used in conjunction with -l to format dmenu's options in
+arbitrary size grids. For example, to create a 4 column by 6 line grid, you
+could use: dmenu -g 4 -l 6
+---
+ config.def.h | 3 ++-
+ dmenu.1 | 7 ++++++-
+ dmenu.c | 22 ++++++++++++++++------
+ 3 files changed, 24 insertions(+), 8 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 1edb647..96cf3c9 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -13,8 +13,9 @@ static const char *colors[SchemeLast][2] = {
+ [SchemeSel] = { "#eeeeee", "#005577" },
+ [SchemeOut] = { "#000000", "#00ffff" },
+ };
+-/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
++/* -l and -g options; controls number of lines and columns in grid if > 0 */
+ static unsigned int lines = 0;
++static unsigned int columns = 0;
+
+ /*
+ * Characters not considered part of a word while deleting words
+diff --git a/dmenu.1 b/dmenu.1
+index 323f93c..d0a734a 100644
+--- a/dmenu.1
++++ b/dmenu.1
+@@ -4,6 +4,8 @@ dmenu \- dynamic menu
+ .SH SYNOPSIS
+ .B dmenu
+ .RB [ \-bfiv ]
++.RB [ \-g
++.IR columns ]
+ .RB [ \-l
+ .IR lines ]
+ .RB [ \-m
+@@ -47,8 +49,11 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
+ .B \-i
+ dmenu matches menu items case insensitively.
+ .TP
++.BI \-g " columns"
++dmenu lists items in a grid with the given number of columns.
++.TP
+ .BI \-l " lines"
+-dmenu lists items vertically, with the given number of lines.
++dmenu lists items in a grid with the given number of lines.
+ .TP
+ .BI \-m " monitor"
+ dmenu is displayed on the monitor number supplied. Monitor numbers are starting
+diff --git a/dmenu.c b/dmenu.c
+index 6b8f51b..d79b6bb 100644
+--- a/dmenu.c
++++ b/dmenu.c
+@@ -77,7 +77,7 @@ calcoffsets(void)
+ int i, n;
+
+ if (lines > 0)
+- n = lines * bh;
++ n = lines * columns * bh;
+ else
+ n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
+ /* calculate which items will begin the next page and previous page */
+@@ -152,9 +152,15 @@ drawmenu(void)
+ }
+
+ if (lines > 0) {
+- /* draw vertical list */
+- for (item = curr; item != next; item = item->right)
+- drawitem(item, x, y += bh, mw - x);
++ /* draw grid */
++ int i = 0;
++ for (item = curr; item != next; item = item->right, i++)
++ drawitem(
++ item,
++ x + ((i / lines) * ((mw - x) / columns)),
++ y + (((i % lines) + 1) * bh),
++ (mw - x) / columns
++ );
+ } else if (matches) {
+ /* draw horizontal list */
+ x += inputw;
+@@ -708,9 +714,13 @@ main(int argc, char *argv[])
+ } else if (i + 1 == argc)
+ usage();
+ /* these options take one argument */
+- else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
++ else if (!strcmp(argv[i], "-g")) { /* number of columns in grid */
++ columns = atoi(argv[++i]);
++ if (lines == 0) lines = 1;
++ } else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */
+ lines = atoi(argv[++i]);
+- else if (!strcmp(argv[i], "-m"))
++ if (columns == 0) columns = 1;
++ } else if (!strcmp(argv[i], "-m"))
+ mon = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
+ prompt = argv[++i];
+--
+2.23.1
+
diff --git a/dmenu.1 b/dmenu.1
index 7591992..b16cc3f 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -4,6 +4,8 @@ dmenu \- dynamic menu
.SH SYNOPSIS
.B dmenu
.RB [ \-bfiv ]
+.RB [ \-g
+.IR columns ]
.RB [ \-l
.IR lines ]
.RB [ \-h
@@ -60,6 +62,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
.B \-i
dmenu matches menu items case insensitively.
.TP
+.BI \-g " columns"
+dmenu lists items in a grid with the given number of columns.
+.TP
.BI \-l " lines"
dmenu lists items vertically, with the given number of lines.
.TP
diff --git a/dmenu.1.orig b/dmenu.1.orig
index 0d7f343..7591992 100644
--- a/dmenu.1.orig
+++ b/dmenu.1.orig
@@ -50,6 +50,9 @@ which lists programs in the user's $PATH and runs the result in their $SHELL.
.B \-b
dmenu appears at the bottom of the screen.
.TP
+.B \-c
+dmenu appears centered on the screen.
+.TP
.B \-f
dmenu grabs the keyboard before reading stdin if not reading from a tty. This
is faster, but will lock up X until stdin reaches end\-of\-file.
diff --git a/dmenu.c b/dmenu.c
index 9f17c7d..69a5e07 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -84,7 +84,7 @@ calcoffsets(void)
int i, n;
if (lines > 0)
- n = lines * bh;
+ n = lines * columns * bh;
else
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
/* calculate which items will begin the next page and previous page */
@@ -212,9 +212,15 @@ drawmenu(void)
}
if (lines > 0) {
- /* draw vertical list */
- for (item = curr; item != next; item = item->right)
- drawitem(item, x, y += bh, mw - x);
+ /* draw grid */
+ int i = 0;
+ for (item = curr; item != next; item = item->right, i++)
+ drawitem(
+ item,
+ x + ((i / lines) * ((mw - x) / columns)),
+ y + (((i % lines) + 1) * bh),
+ (mw - x) / columns
+ );
} else if (matches) {
/* draw horizontal list */
x += inputw;
@@ -799,14 +805,19 @@ main(int argc, char *argv[])
} else if (i + 1 == argc)
usage();
/* these options take one argument */
- else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
+ else if (!strcmp(argv[i], "-g")) { /* number of columns in grid */
+ columns = atoi(argv[++i]);
+ if (lines == 0) lines = 1;
+ } else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */
lines = atoi(argv[++i]);
+ }
else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */
- lineheight = atoi(argv[++i]);
+ //lineheight = atoi(argv[++i]);
lineheight = MAX(lineheight, min_lineheight);
- }
- else if (!strcmp(argv[i], "-m"))
+ } else if (!strcmp(argv[i], "-m")) {
+ if (columns == 0) columns = 1;
mon = atoi(argv[++i]);
+ }
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
prompt = argv[++i];
else if (!strcmp(argv[i], "-fn")) /* font or font set */
diff --git a/dmenu.c.orig b/dmenu.c.orig
index 4bdbb71..9f17c7d 100644
--- a/dmenu.c.orig
+++ b/dmenu.c.orig
@@ -96,6 +96,15 @@ calcoffsets(void)
break;
}
+static int
+max_textw(void)
+{
+ int len = 0;
+ for (struct item *item = items; item && item->text; item++)
+ len = MAX(TEXTW(item->text), len);
+ return len;
+}
+
static void
cleanup(void)
{
@@ -663,6 +672,7 @@ setup(void)
bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */
lines = MAX(lines, 0);
mh = (lines + 1) * bh;
+ promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
#ifdef XINERAMA
i = 0;
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
@@ -689,9 +699,16 @@ setup(void)
if (INTERSECT(x, y, 1, 1, info[i]))
break;
- x = info[i].x_org;
- y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
- mw = info[i].width;
+ if (centered) {
+ mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width);
+ x = info[i].x_org + ((info[i].width - mw) / 2);
+ y = info[i].y_org + ((info[i].height - mh) / 2);
+ } else {
+ x = info[i].x_org;
+ y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
+ mw = info[i].width;
+ }
+
XFree(info);
} else
#endif
@@ -699,11 +716,17 @@ setup(void)
if (!XGetWindowAttributes(dpy, parentwin, &wa))
die("could not get embedding window attributes: 0x%lx",
parentwin);
- x = 0;
- y = topbar ? 0 : wa.height - mh;
- mw = wa.width;
+
+ if (centered) {
+ mw = MIN(MAX(max_textw() + promptw, min_width), wa.width);
+ x = (wa.width - mw) / 2;
+ y = (wa.height - mh) / 2;
+ } else {
+ x = 0;
+ y = topbar ? 0 : wa.height - mh;
+ mw = wa.width;
+ }
}
- promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
inputw = MIN(inputw, mw/3);
match();
@@ -764,6 +787,12 @@ main(int argc, char *argv[])
topbar = 0;
else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */
fast = 1;
+ else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */
+ centered = 1;
+ else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
+ fstrncmp = strncasecmp;
+ fstrstr = cistrstr;
+ }
else if (!strcmp(argv[i], "-s")) { /* case-sensitive item matching */
fstrncmp = strncmp;
fstrstr = strstr;
diff --git a/dmenu.o b/dmenu.o
index 00d636d..b71dea8 100644
--- a/dmenu.o
+++ b/dmenu.o
Binary files differ