Tech News
← Back to articles

KDE Plasma prepares crackdown on focus-stealing window behavior under Wayland

read original related products more articles

When you purchase through links on our site, we may earn an affiliate commission. Here’s how it works

One of the most interesting things about Wayland is how it handles window focus, unlike X11, where focus stealing can be frustrating and even a security risk. Its main advantage is a mechanism that prevents focus stealing. The protocol that plays a role in this is known as "XDG Activation."

Here's how it works: Say you double-click a PDF file in your file manager. The file manager first asks the Wayland compositor for a special, single-use "activation token". This request is tied directly to your click, proving a human wanted this to happen.

The file manager then launches your PDF viewer and hands it the token. The PDF viewer, upon starting, shows this token to the compositor and asks to be activated. The compositor checks if the token is legit and, if so, gives the PDF viewer focus.

If the token is missing, old, or otherwise invalid, the compositor says no. The viewer window will not get focus, and instead, its icon in the taskbar will start flashing to grab your attention.

Flashing icon in the taskbar | Image: Kai-Uwe Broulik

Kai-Uwe Broulik, a KDE developer, recently wrote about the plan to "switch on KWin’s focus stealing on Wayland at a low level". This means KWin, the window manager for KDE Plasma, will begin enforcing this properly.

Under X11, new or dialog windows can only grab focus if their application was most recently active, a check often based on a timestamp called _NET_WM_USER_TIME . It was a flimsy system at best. For example, Kai cited how the prevention logic on X11 would sometimes stop the Adobe Flash Player fullscreen window from showing on top of a YouTube video. On X11, an application could just call XSetInputFocus on another app's window, and while KWin would try to undo it, focus did flicker for a moment.

Over on Wayland, things are much better with XDG Activation, but some apps still violate the protocol through improper usage. In situations like that, KWin would, by default, just focus any new window that opened. This is changing.

A new "Extreme" setting for "Focus Stealing Prevention" in the Window Management settings will force KWin to activate a window if and only if it requests activation with a valid token.

... continue reading