dmenu-managed-4.9.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dmenu-managed-4.9.diff (2917B)
       ---
            1 From 5aee7d1488354322462e243416e27e026d73e0eb Mon Sep 17 00:00:00 2001
            2 From: Miles Alan <m@milesalan.com>
            3 Date: Tue, 16 Jun 2020 21:40:30 -0500
            4 Subject: [PATCH] Add -wm flag to run dmenu as managed WM window (e.g. no
            5  override_redirect)
            6 
            7 ---
            8  dmenu.1 |  4 ++++
            9  dmenu.c | 20 +++++++++++++++++---
           10  2 files changed, 21 insertions(+), 3 deletions(-)
           11 
           12 diff --git a/dmenu.1 b/dmenu.1
           13 index 323f93c..89a9493 100644
           14 --- a/dmenu.1
           15 +++ b/dmenu.1
           16 @@ -22,6 +22,7 @@ dmenu \- dynamic menu
           17  .IR color ]
           18  .RB [ \-w
           19  .IR windowid ]
           20 +.RB [ \-wm ]
           21  .P
           22  .BR dmenu_run " ..."
           23  .SH DESCRIPTION
           24 @@ -80,6 +81,9 @@ prints version information to stdout, then exits.
           25  .TP
           26  .BI \-w " windowid"
           27  embed into windowid.
           28 +.TP
           29 +.BI \-wm
           30 +Display as a managed WM window (e.g. don't set overide_redirect flag)
           31  .SH USAGE
           32  dmenu is completely controlled by the keyboard.  Items are selected using the
           33  arrow keys, page up, page down, home, and end.
           34 diff --git a/dmenu.c b/dmenu.c
           35 index 6b8f51b..4632eb4 100644
           36 --- a/dmenu.c
           37 +++ b/dmenu.c
           38 @@ -44,6 +44,7 @@ static struct item *items = NULL;
           39  static struct item *matches, *matchend;
           40  static struct item *prev, *curr, *next, *sel;
           41  static int mon = -1, screen;
           42 +static int managed = 0;
           43  
           44  static Atom clip, utf8;
           45  static Display *dpy;
           46 @@ -198,7 +199,7 @@ grabkeyboard(void)
           47          struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000  };
           48          int i;
           49  
           50 -        if (embed)
           51 +        if (embed || managed)
           52                  return;
           53          /* try to grab keyboard, we may have to wait for another process to ungrab */
           54          for (i = 0; i < 1000; i++) {
           55 @@ -651,7 +652,7 @@ setup(void)
           56          match();
           57  
           58          /* create menu window */
           59 -        swa.override_redirect = True;
           60 +        swa.override_redirect = managed ? False : True;
           61          swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
           62          swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
           63          win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
           64 @@ -665,7 +666,18 @@ setup(void)
           65                          XNClientWindow, win, XNFocusWindow, win, NULL);
           66  
           67          XMapRaised(dpy, win);
           68 -        XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
           69 +
           70 +        if (managed) {
           71 +                XTextProperty prop;
           72 +                char *windowtitle = prompt != NULL ? prompt : "dmenu";
           73 +                Xutf8TextListToTextProperty(dpy, &windowtitle, 1, XUTF8StringStyle, &prop);
           74 +                XSetWMName(dpy, win, &prop);
           75 +                XSetTextProperty(dpy, win, &prop, XInternAtom(dpy, "_NET_WM_NAME", False));
           76 +                XFree(prop.value);
           77 +        } else {
           78 +                XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
           79 +        }
           80 +
           81          if (embed) {
           82                  XSelectInput(dpy, parentwin, FocusChangeMask);
           83                  if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) {
           84 @@ -705,6 +717,8 @@ main(int argc, char *argv[])
           85                  else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
           86                          fstrncmp = strncasecmp;
           87                          fstrstr = cistrstr;
           88 +                } else if (!strcmp(argv[i], "-wm")) { /* display as managed wm window */
           89 +                        managed = 1;
           90                  } else if (i + 1 == argc)
           91                          usage();
           92                  /* these options take one argument */
           93 -- 
           94 2.27.0
           95