[wiki] [sites] [dmenu][patch] managed: Add patch, lets you turn dmenu into a managed window || Miles Alan

From: <git_AT_suckless.org>
Date: Sat, 04 Jul 2020 19:00:48 +0200

commit 5f3cde85330631d5740147a4d2a4fad7562cf859
Author: Miles Alan <m_AT_milesalan.com>
Date: Sat Jul 4 11:55:17 2020 -0500

    [dmenu][patch] managed: Add patch, lets you turn dmenu into a managed window

diff --git a/tools.suckless.org/dmenu/patches/managed/dmenu-managed-4.9.diff b/tools.suckless.org/dmenu/patches/managed/dmenu-managed-4.9.diff
new file mode 100644
index 00000000..f51f3bf2
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/managed/dmenu-managed-4.9.diff
_AT_@ -0,0 +1,95 @@
+From 5aee7d1488354322462e243416e27e026d73e0eb Mon Sep 17 00:00:00 2001
+From: Miles Alan <m_AT_milesalan.com>
+Date: Tue, 16 Jun 2020 21:40:30 -0500
+Subject: [PATCH] Add -wm flag to run dmenu as managed WM window (e.g. no
+ override_redirect)
+
+---
+ dmenu.1 | 4 ++++
+ dmenu.c | 20 +++++++++++++++++---
+ 2 files changed, 21 insertions(+), 3 deletions(-)
+
+diff --git a/dmenu.1 b/dmenu.1
+index 323f93c..89a9493 100644
+--- a/dmenu.1
++++ b/dmenu.1
+_AT_@ -22,6 +22,7 @@ dmenu \- dynamic menu
+ .IR color ]
+ .RB [ \-w
+ .IR windowid ]
++.RB [ \-wm ]
+ .P
+ .BR dmenu_run " ..."
+ .SH DESCRIPTION
+_AT_@ -80,6 +81,9 @@ prints version information to stdout, then exits.
+ .TP
+ .BI \-w " windowid"
+ embed into windowid.
++.TP
++.BI \-wm
++Display as a managed WM window (e.g. don't set overide_redirect flag)
+ .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 6b8f51b..4632eb4 100644
+--- a/dmenu.c
++++ b/dmenu.c
+_AT_@ -44,6 +44,7 @@ static struct item *items = NULL;
+ static struct item *matches, *matchend;
+ static struct item *prev, *curr, *next, *sel;
+ static int mon = -1, screen;
++static int managed = 0;
+
+ static Atom clip, utf8;
+ static Display *dpy;
+_AT_@ -198,7 +199,7 @@ grabkeyboard(void)
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 };
+ int i;
+
+- if (embed)
++ if (embed || managed)
+ return;
+ /* try to grab keyboard, we may have to wait for another process to ungrab */
+ for (i = 0; i < 1000; i++) {
+_AT_@ -651,7 +652,7 @@ setup(void)
+ match();
+
+ /* create menu window */
+- swa.override_redirect = True;
++ swa.override_redirect = managed ? False : True;
+ swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
+ swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
+ win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
+_AT_@ -665,7 +666,18 @@ setup(void)
+ XNClientWindow, win, XNFocusWindow, win, NULL);
+
+ XMapRaised(dpy, win);
+- XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
++
++ if (managed) {
++ XTextProperty prop;
++ char *windowtitle = prompt != NULL ? prompt : "dmenu";
++ Xutf8TextListToTextProperty(dpy, &windowtitle, 1, XUTF8StringStyle, &prop);
++ XSetWMName(dpy, win, &prop);
++ XSetTextProperty(dpy, win, &prop, XInternAtom(dpy, "_NET_WM_NAME", False));
++ XFree(prop.value);
++ } else {
++ XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
++ }
++
+ if (embed) {
+ XSelectInput(dpy, parentwin, FocusChangeMask);
+ if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) {
+_AT_@ -705,6 +717,8 @@ main(int argc, char *argv[])
+ else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
+ fstrncmp = strncasecmp;
+ fstrstr = cistrstr;
++ } else if (!strcmp(argv[i], "-wm")) { /* display as managed wm window */
++ managed = 1;
+ } else if (i + 1 == argc)
+ usage();
+ /* these options take one argument */
+--
+2.27.0
+
diff --git a/tools.suckless.org/dmenu/patches/managed/index.md b/tools.suckless.org/dmenu/patches/managed/index.md
new file mode 100644
index 00000000..1443063d
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/managed/index.md
_AT_@ -0,0 +1,15 @@
+managed
+=======
+Adds a `-wm` flag which sets override_redirect to false; thus letting your
+window manager manage the dmenu window.
+
+This may be helpful in contexts where you don't want to exclusively bind
+dmenu or want to treat dmenu more as a 'window' rather than as an overlay.
+
+Download
+--------
+* [dmenu-managed-4.9.diff](dmenu-managed-4.9.diff)
+
+Author
+------
+* Miles Alan <m_AT_milesalan.com>
Received on Sat Jul 04 2020 - 19:00:48 CEST

This archive was generated by hypermail 2.3.0 : Sat Jul 04 2020 - 19:12:44 CEST