Re: [hackers] [dmenu] detect active monitor using input focus || Connor Lane Smith

From: anonymous <p37sitdu_AT_lavabit.com>
Date: Wed, 28 Sep 2011 17:26:50 +0400

On Mon, Sep 19, 2011 at 07:16:50PM +0200, hg_AT_suckless.org wrote:
> changeset: 438:e340de0a8fd7
> tag: tip
> parent: 434:d007288ed923
> user: Connor Lane Smith <cls_AT_lubutu.com>
> date: Mon Sep 19 18:15:03 2011 +0100
> files: dmenu.c
> description:
> detect active monitor using input focus
>
>
> diff -r d007288ed923 -r e340de0a8fd7 dmenu.c
> --- a/dmenu.c Mon Sep 19 10:40:07 2011 +0100
> +++ b/dmenu.c Mon Sep 19 18:15:03 2011 +0100
> @@ -473,7 +473,7 @@
> setup(void) {
> int x, y, screen = DefaultScreen(dc->dpy);
> Window root = RootWindow(dc->dpy, screen);
> - XSetWindowAttributes wa;
> + XSetWindowAttributes swa;
> #ifdef XINERAMA
> int n;
> XineramaScreenInfo *info;
> @@ -494,9 +494,14 @@
> if((info = XineramaQueryScreens(dc->dpy, &n))) {
> int i, di;
> unsigned int du;
> - Window dw;
> + Window w, dw;
> + XWindowAttributes wa;
>
> - XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du);
> + XGetInputFocus(dc->dpy, &w, &di);
> + if(w != root && XGetWindowAttributes(dc->dpy, w, &wa))
> + XTranslateCoordinates(dc->dpy, root, root, wa.x, wa.y, &x, &y, &dw);
> + else
> + XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du);
> for(i = 0; i < n-1; i++)
> if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
> break;
> @@ -517,13 +522,13 @@
> match(False);
>
> /* menu window */
> - wa.override_redirect = True;
> - wa.background_pixmap = ParentRelative;
> - wa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
> + swa.override_redirect = True;
> + swa.background_pixmap = ParentRelative;
> + swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
> win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
> DefaultDepth(dc->dpy, screen), CopyFromParent,
> DefaultVisual(dc->dpy, screen),
> - CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
> + CWOverrideRedirect | CWBackPixmap | CWEventMask, &swa);
>
> XMapRaised(dc->dpy, win);
> resizedc(dc, mw, mh);
>
>

This patch is broken. Since revision 438 dmenu compiled with Xinerama
support has a bug. If you startx and try to start dmenu (Mod1+p), it
don't start. However if you change tag to 2 and back and then press
Mod1+p, it starts as usual.

With revision 437 or without -DXINERAMA, everything works.
Received on Wed Sep 28 2011 - 15:26:50 CEST

This archive was generated by hypermail 2.2.0 : Wed Sep 28 2011 - 16:00:08 CEST