pop-os / cosmic-comp

Compositor for the COSMIC desktop environment
GNU General Public License v3.0
476 stars 85 forks source link

Set clipboard/primary focus in `refresh_focus` #533

Closed ids1024 closed 4 months ago

ids1024 commented 4 months ago

This should fix https://github.com/pop-os/cosmic-comp/issues/494, and make clipboard and primary focus consistently correct.

Changing the active element of a stack needs to change the clipboard focus, but it wasn't being changed since the KeyboardFocusTarget was unchanged. The CosmicStack methods that change the active stack element also have no obvious way to change the keyboard focus. So we can set this in refresh_focus, which should be correct.

If the new focus WlSurface is None, this clears the focus instead of leaving it as the previous code did. I believe that is desirable.

Requires https://github.com/Smithay/smithay/pull/1442 to avoid repeated offers, instead of only when focus changed.

(Perhaps this could better be solved by having a WlSurface variant of KeyboardFocusTarget, like pointer focus, or some mechanism for a stack of focus, which could help other things. But it's also unclear exactly how that would work with the code for setting the active stack element, among other questions.)

ids1024 commented 4 months ago

Added a commit changing how same_client_as works for stacks, which should be necessary to prevent a background window in a stack from setting the clipboard.

Not sure if anything else uses same_client_as that might for some reason need the previous behavior, but I wouldn't expect it.