aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2025-06-16 16:09:59 +0200
committerPhilip Wittamore <philip@wittamore.com>2025-06-16 16:09:59 +0200
commit18a3bfdb765bfe9f72d8eb62bc7505e896a4e6f2 (patch)
tree1b3246df8b2fd8539e2149e7cedb06eb8d1b28b7
parent782a9e944b50ad1252cadb9491a761b8afdcf2f0 (diff)
downloaddmenu-18a3bfdb765bfe9f72d8eb62bc7505e896a4e6f2.tar.gz
dmenu-18a3bfdb765bfe9f72d8eb62bc7505e896a4e6f2.tar.bz2
dmenu-18a3bfdb765bfe9f72d8eb62bc7505e896a4e6f2.zip
update
-rw-r--r--README.md27
-rw-r--r--config.def.h2
-rw-r--r--config.h10
-rw-r--r--dmenu.124
-rw-r--r--dmenu.c33
-rw-r--r--patches/dmenu-xyw-5.2.diff99
6 files changed, 175 insertions, 20 deletions
diff --git a/README.md b/README.md
index 7b83f48..65b5438 100644
--- a/README.md
+++ b/README.md
@@ -3,17 +3,30 @@
- xresources
- center
- border
+- xyz
-The center patch adds the -c parameter for centering dmenu
-
-The border patch adds the -bw parameter followed by an integer (width in pixels)
+The center patch
+ adds the -c parameter for centering dmenu
+The border patch
+ adds the -bw parameter followed by an integer (width in pixels)
dmenu -bw 4 -c -l 4 -p "Power: "
-The xresources patch makes dmenu read the .Xresources file enabling<br>
-on the fly color matching with Pywal16
-### .Xressources or Pywal template
+The xyz patch:
+ The '-x' and '-y' options set the window position on the target monitor (0 if one is not supplied with '-m')
+ If option '-b' is used, the y offset is computed from the bottom
+ The '-x' and '-y' accept negative values
+ The '-z' option sets the window width
+
+ I've also modified the width calculation to accept a minimum width that is set in config.def.h
+ lines 835 and 835, and works with -c
+
+The xresources patch
+ makes dmenu read the .Xresources file enabling<br>
+ on the fly color matching with Pywal16
+
+ ### .Xressources or Pywal template
! dmenu
dmenu.background: {color1}
@@ -22,4 +35,4 @@ on the fly color matching with Pywal16
dmenu.selforeground: {color15}
dmenu.border: {color4}
-I've added border color to the xressources patch.
+ I've added border color to the xressources patch.
diff --git a/config.def.h b/config.def.h
index a287dd9..9a79dfc 100644
--- a/config.def.h
+++ b/config.def.h
@@ -5,10 +5,12 @@ static int topbar = 1; /* -b option; if 0, dmenu appears a
static int centered = 0; /* -c option; centers dmenu on screen */
static int min_width = 500; /* minimum width when centered */
static const float menu_height_ratio = 3.0f; /* This is the ratio used in the original calculation */
+
/* -fn option overrides fonts[0]; default X11 font or font set */
static char *fonts[] = {
"JetBrainsMono Nerd Font Mono:size=11"
};
+
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
static void *colors[SchemeLast][2] = {
/* fg bg */
diff --git a/config.h b/config.h
index 3a36d3e..9a79dfc 100644
--- a/config.h
+++ b/config.h
@@ -2,15 +2,17 @@
/* Default settings; can be overriden by command line. */
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
-static int centered = 1; /* -c option; centers dmenu on screen */
+static int centered = 0; /* -c option; centers dmenu on screen */
static int min_width = 500; /* minimum width when centered */
-static const float menu_height_ratio = 4.0f; /* This is the ratio used in the original calculation */
+static const float menu_height_ratio = 3.0f; /* This is the ratio used in the original calculation */
+
/* -fn option overrides fonts[0]; default X11 font or font set */
-static const char *fonts[] = {
+static char *fonts[] = {
"JetBrainsMono Nerd Font Mono:size=11"
};
+
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
-static const char *colors[SchemeLast][2] = {
+static void *colors[SchemeLast][2] = {
/* fg bg */
[SchemeNorm] = { "#bbbbbb", "#222222" },
[SchemeSel] = { "#eeeeee", "#005577" },
diff --git a/dmenu.1 b/dmenu.1
index c036baa..62bfc20 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -8,6 +8,12 @@ dmenu \- dynamic menu
.IR lines ]
.RB [ \-m
.IR monitor ]
+.RB [ \-x
+.IR xoffset ]
+.RB [ \-y
+.IR yoffset ]
+.RB [ \-z
+.IR width ]
.RB [ \-p
.IR prompt ]
.RB [ \-fn
@@ -57,6 +63,24 @@ dmenu lists items vertically, with the given number of lines.
dmenu is displayed on the monitor number supplied. Monitor numbers are starting
from 0.
.TP
+.BI \-x " xoffset"
+dmenu is placed at this offset measured from the left side of the monitor.
+Can be negative.
+If option
+.B \-m
+is present, the measurement will use the given monitor.
+.TP
+.BI \-y " yoffset"
+dmenu is placed at this offset measured from the top of the monitor. If the
+.B \-b
+option is used, the offset is measured from the bottom. Can be negative.
+If option
+.B \-m
+is present, the measurement will use the given monitor.
+.TP
+.BI \-z " width"
+sets the width of the dmenu window.
+.TP
.BI \-p " prompt"
defines the prompt to be displayed to the left of the input field.
.TP
diff --git a/dmenu.c b/dmenu.c
index 67ccc27..b0e3492 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -38,6 +38,9 @@ struct item {
static char text[BUFSIZ] = "";
static char *embed;
static int bh, mw, mh;
+static int dmx = 0; /* put dmenu at this x offset */
+static int dmy = 0; /* put dmenu at this y offset (measured from the bottom if topbar is 0) */
+static unsigned int dmw = 0; /* make dmenu this wide */
static int inputw = 0, promptw;
static int lrpad; /* sum of left and right padding */
static size_t cursor;
@@ -101,6 +104,7 @@ calcoffsets(void)
break;
}
+/*
static int
max_textw(void)
{
@@ -109,6 +113,8 @@ max_textw(void)
len = MAX(item->width, len);
return len;
}
+*/
+
static void
cleanup(void)
@@ -827,16 +833,17 @@ setup(void)
break;
if (centered) {
- mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width);
+ /* mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width); */
+ mw = MAX((dmw>0 ? dmw : info[i].width), min_width);
x = info[i].x_org + ((info[i].width - mw) / 2);
y = info[i].y_org + ((info[i].height - mh) / menu_height_ratio);
} else {
- x = info[i].x_org;
- y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
- mw = info[i].width;
+ x = info[i].x_org + dmx;
+ y = info[i].y_org + (topbar ? dmy : info[i].height - mh - dmy);
+ mw = (dmw>0 ? dmw : info[i].width);
}
-
XFree(info);
+
} else
#endif
{
@@ -845,13 +852,14 @@ setup(void)
parentwin);
if (centered) {
- mw = MIN(MAX(max_textw() + promptw, min_width), wa.width);
+ /* mw = MIN(MAX(max_textw() + promptw, min_width), wa.width); */
+ mw = MAX((dmw>0 ? dmw : wa.width), min_width);
x = (wa.width - mw) / 2;
y = (wa.height - mh) / 2;
} else {
- x = 0;
- y = topbar ? 0 : wa.height - mh;
- mw = wa.width;
+ x = dmx;
+ y = topbar ? dmy : wa.height - mh - dmy;
+ mw = (dmw>0 ? dmw : wa.width);
}
}
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
@@ -897,6 +905,7 @@ static void
usage(void)
{
die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+ " [-x xoffset] [-y yoffset] [-z width]\n"
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
}
@@ -960,6 +969,12 @@ main(int argc, char *argv[])
/* these options take one argument */
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
lines = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "-x")) /* window x offset */
+ dmx = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "-y")) /* window y offset (from bottom up if -b) */
+ dmy = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "-z")) /* make dmenu this wide */
+ dmw = atoi(argv[++i]);
else if (!strcmp(argv[i], "-m"))
mon = atoi(argv[++i]);
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
diff --git a/patches/dmenu-xyw-5.2.diff b/patches/dmenu-xyw-5.2.diff
new file mode 100644
index 0000000..312fb26
--- /dev/null
+++ b/patches/dmenu-xyw-5.2.diff
@@ -0,0 +1,99 @@
+--- a/dmenu.1 2022-10-04 10:36:58.000000000 -0700
++++ b/dmenu.1 2024-03-23 19:40:27.116453289 -0700
+@@ -8,6 +8,12 @@
+ .IR lines ]
+ .RB [ \-m
+ .IR monitor ]
++.RB [ \-x
++.IR xoffset ]
++.RB [ \-y
++.IR yoffset ]
++.RB [ \-z
++.IR width ]
+ .RB [ \-p
+ .IR prompt ]
+ .RB [ \-fn
+@@ -54,6 +60,24 @@
+ dmenu is displayed on the monitor number supplied. Monitor numbers are starting
+ from 0.
+ .TP
++.BI \-x " xoffset"
++dmenu is placed at this offset measured from the left side of the monitor.
++Can be negative.
++If option
++.B \-m
++is present, the measurement will use the given monitor.
++.TP
++.BI \-y " yoffset"
++dmenu is placed at this offset measured from the top of the monitor. If the
++.B \-b
++option is used, the offset is measured from the bottom. Can be negative.
++If option
++.B \-m
++is present, the measurement will use the given monitor.
++.TP
++.BI \-z " width"
++sets the width of the dmenu window.
++.TP
+ .BI \-p " prompt"
+ defines the prompt to be displayed to the left of the input field.
+ .TP
+--- a/dmenu.c 2022-10-04 10:36:58.000000000 -0700
++++ b/dmenu.c 2024-03-23 19:39:53.173081139 -0700
+@@ -37,6 +37,9 @@
+ static char text[BUFSIZ] = "";
+ static char *embed;
+ static int bh, mw, mh;
++static int dmx = 0; /* put dmenu at this x offset */
++static int dmy = 0; /* put dmenu at this y offset (measured from the bottom if topbar is 0) */
++static unsigned int dmw = 0; /* make dmenu this wide */
+ static int inputw = 0, promptw;
+ static int lrpad; /* sum of left and right padding */
+ static size_t cursor;
+@@ -658,9 +661,9 @@
+ if (INTERSECT(x, y, 1, 1, info[i]) != 0)
+ break;
+
+- x = info[i].x_org;
+- y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
+- mw = info[i].width;
++ x = info[i].x_org + dmx;
++ y = info[i].y_org + (topbar ? dmy : info[i].height - mh - dmy);
++ mw = (dmw>0 ? dmw : info[i].width);;
+ XFree(info);
+ } else
+ #endif
+@@ -668,9 +671,9 @@
+ 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;
++ x = dmx;
++ y = topbar ? dmy : wa.height - mh - dmy;
++ mw = (dmw>0 ? dmw : wa.width);
+ }
+ promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
+ inputw = mw / 3; /* input width: ~33% of monitor width */
+@@ -711,6 +714,7 @@
+ usage(void)
+ {
+ die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
++ " [-x xoffset] [-y yoffset] [-z width]\n"
+ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
+ }
+
+@@ -737,6 +741,12 @@
+ /* these options take one argument */
+ else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
+ lines = atoi(argv[++i]);
++ else if (!strcmp(argv[i], "-x")) /* window x offset */
++ dmx = atoi(argv[++i]);
++ else if (!strcmp(argv[i], "-y")) /* window y offset (from bottom up if -b) */
++ dmy = atoi(argv[++i]);
++ else if (!strcmp(argv[i], "-z")) /* make dmenu this wide */
++ dmw = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "-m"))
+ mon = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */