Re: [hackers] [dwm] [PATCH 2/3] Button passthrough when client is not focused

From: Silvan Jegen <s.jegen_AT_gmail.com>
Date: Sat, 7 Jan 2017 21:26:04 +0100

Hi Markus

From what I understand, in case that the client does not have focus
already, with this patch we call XGrabButton twice compared to before the
patch. I assume that corresponds to the advertised functionality.

One more comment below.

On Sat, Jan 07, 2017 at 05:21:29PM +0100, Markus Teich wrote:
> Before this change it is not possible to press a button in a client on the first
> click if the client is not yet focused. The first click on the button would
> only focus the client and a second click on the button is needed to activate it.
> This situation can occur when moving the mouse over a client (therefore focusing
> it) and then moving the focus to another client with keyboard shortcuts.
>
> After this commit the behavior is fixed and button presses on unfocused clients
> are passed to the client correctly.
> ---
>
>
> Heyho,
>
> this patch is the same as submitted previously. I just added it to this patch
> series for a better overview of the pending patches.
>
> --Markus
>
>
> dwm.c | 21 +++++++++++----------
> 1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/dwm.c b/dwm.c
> index 3f80b63..9c01d1a 100644
> --- a/dwm.c
> +++ b/dwm.c
> _AT_@ -446,6 +446,8 @@ buttonpress(XEvent *e)
> click = ClkWinTitle;
> } else if ((c = wintoclient(ev->window))) {
> focus(c);
> + restack(selmon);
> + XAllowEvents(dpy, ReplayPointer, CurrentTime);
> click = ClkClientWin;
> }
> for (i = 0; i < LENGTH(buttons); i++)
> _AT_@ -932,17 +934,16 @@ grabbuttons(Client *c, int focused)
> unsigned int i, j;
> unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
> XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
> - if (focused) {
> - for (i = 0; i < LENGTH(buttons); i++)
> - if (buttons[i].click == ClkClientWin)
> - for (j = 0; j < LENGTH(modifiers); j++)
> - XGrabButton(dpy, buttons[i].button,
> - buttons[i].mask | modifiers[j],
> - c->win, False, BUTTONMASK,
> - GrabModeAsync, GrabModeSync, None, None);
> - } else
> + if (!focused)
> XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
> - BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
> + BUTTONMASK, GrabModeSync, GrabModeSync, None, None);

Here we pass "GrabModeSync" instead of "GrabModeAsync" as the "pointer
mode". According to https://tronche.com/gui/x/xlib/input/XGrabPointer.html
if the mode is "GrabModeSync",

"the state of the pointer, as seen by client applications, appears to
freeze, and the X server generates no further pointer events until
the grabbing client calls XAllowEvents() or until the pointer grab
is released."

Since we are calling XAllowEvents on buttonpress that should make sure
that only the focused client gets any pointer events, I assume?

I have been runnig with this patch for most of the day and haven't
encountered any issues.


Cheers,

Silvan


> + for (i = 0; i < LENGTH(buttons); i++)
> + if (buttons[i].click == ClkClientWin)
> + for (j = 0; j < LENGTH(modifiers); j++)
> + XGrabButton(dpy, buttons[i].button,
> + buttons[i].mask | modifiers[j],
> + c->win, False, BUTTONMASK,
> + GrabModeAsync, GrabModeSync, None, None);
> }
> }
>
> --
> 2.10.2
>
>
Received on Sat Jan 07 2017 - 21:26:04 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 10 2017 - 18:24:32 CET