Button passthrough when client is not focused 022d0760
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.
Markus Teich · 2017-01-07 17:21 1 file(s) · +11 −10
dwm.c +11 −10
446 446
			click = ClkWinTitle;
447 447
	} else if ((c = wintoclient(ev->window))) {
448 448
		focus(c);
449 +
		restack(selmon);
450 +
		XAllowEvents(dpy, ReplayPointer, CurrentTime);
449 451
		click = ClkClientWin;
450 452
	}
451 453
	for (i = 0; i < LENGTH(buttons); i++)
932 934
		unsigned int i, j;
933 935
		unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
934 936
		XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
935 -
		if (focused) {
936 -
			for (i = 0; i < LENGTH(buttons); i++)
937 -
				if (buttons[i].click == ClkClientWin)
938 -
					for (j = 0; j < LENGTH(modifiers); j++)
939 -
						XGrabButton(dpy, buttons[i].button,
940 -
						            buttons[i].mask | modifiers[j],
941 -
						            c->win, False, BUTTONMASK,
942 -
						            GrabModeAsync, GrabModeSync, None, None);
943 -
		} else
937 +
		if (!focused)
944 938
			XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
945 -
			            BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
939 +
			            BUTTONMASK, GrabModeSync, GrabModeSync, None, None);
940 +
		for (i = 0; i < LENGTH(buttons); i++)
941 +
			if (buttons[i].click == ClkClientWin)
942 +
				for (j = 0; j < LENGTH(modifiers); j++)
943 +
					XGrabButton(dpy, buttons[i].button,
944 +
					            buttons[i].mask | modifiers[j],
945 +
					            c->win, False, BUTTONMASK,
946 +
					            GrabModeAsync, GrabModeSync, None, None);
946 947
	}
947 948
}
948 949