Apply "Accepts focus" window rule to WM_TAKE_FOCUS messages as well

Currently the window rule is not 100% effective because the "take focus"
message is not guarded. So depending on the input model of the X11
window, kwin can still activate a window even if it has a window rule
to force no focus.

workspace()->setShouldGetFocus() should be guarded too to help the focus
stealing prevention logic.

Technically though, forcing XSetInputFocus() or WM_TAKE_FOCUS if the
client doesn't advertise supporting them is finiky. But on the other
hand, the window rules are an advanced feature, so its assumed that the
user knows what they do.
This commit is contained in:
Vlad Zahorodnii 2024-01-19 21:00:04 +02:00
parent bbb40a9a84
commit 3663e1ec13

View file

@ -2220,7 +2220,10 @@ QStringList X11Window::activities() const
*/
bool X11Window::takeFocus()
{
if (rules()->checkAcceptFocus(info->input())) {
const bool effectiveAcceptFocus = rules()->checkAcceptFocus(info->input());
const bool effectiveTakeFocus = rules()->checkAcceptFocus(info->supportsProtocol(NET::TakeFocusProtocol));
if (effectiveAcceptFocus) {
xcb_void_cookie_t cookie = xcb_set_input_focus_checked(kwinApp()->x11Connection(),
XCB_INPUT_FOCUS_POINTER_ROOT,
window(), XCB_TIME_CURRENT_TIME);
@ -2232,11 +2235,14 @@ bool X11Window::takeFocus()
} else {
demandAttention(false); // window cannot take input, at least withdraw urgency
}
if (info->supportsProtocol(NET::TakeFocusProtocol)) {
if (effectiveTakeFocus) {
kwinApp()->updateXTime();
sendClientMessage(window(), atoms->wm_protocols, atoms->wm_take_focus);
}
workspace()->setShouldGetFocus(this);
if (effectiveAcceptFocus || effectiveTakeFocus) {
workspace()->setShouldGetFocus(this);
}
return true;
}