Bug 439483 - Ability to give fake focus to window [feature request]
Summary: Ability to give fake focus to window [feature request]
Status: RESOLVED INTENTIONAL
Alias: None
Product: frameworks-kwindowsystem
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.83.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-04 15:58 UTC by Andrew Shark
Modified: 2021-09-30 21:36 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Shark 2021-07-04 15:58:13 UTC
It would be good possibility for kwin to lie to the window that it has a focus.

There are applications that do some logic based on focus flag. For example, games may pause when minimized. There are cases when you want the window to believe that it has focus while in reality give the focus to another window. One example is when you want to switch to web browser to learn something, and be able to control unfocused game via gamepad. Other examples may be when game pauses when minimized, but do not allows you to skip credits. Or when the application do some "conveniences" such as hiding its dialog windows when not in focus, but you do not want that behavior.

For mode detailed explanation of examples please see this question: https://unix.stackexchange.com/questions/650156/trick-a-window-that-it-has-focus-in-kde

SOFTWARE/OS VERSIONS
Operating System: Arch Linux
KDE Plasma Version: 5.22.2
KDE Frameworks Version: 5.83.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION
In the window rules it could appear as option like "fake focus" or "always programatically focused".

Also it would be nice to specify input behavior when in fake focus. For example, disable keyboard input because it looks unnecessary for my examples (but who knows, someone may want it, to do simultaneous input to several windows), but enable gamepad input (to effectively force its input to game, despite game is unfocused).
Comment 1 David Edmundson 2021-07-04 17:09:00 UTC
I don't see how we can.
Xorg can only have one window as the focussed window.

Ultimately if you want a client app to have different behaviour, you're better of changing the client app.
Comment 2 David Edmundson 2021-07-04 17:13:13 UTC
Edit - I just remembered there is one solution that I use for debugging when I need a client to have focus.

Start Xephyr or a nested wayland. Spawn the app inside that.
Xephyr or our compositor might lose focus, but they tend not to forward it.

It's too niche to do at a kwin level though.
Comment 3 Andrew Shark 2021-07-04 17:21:20 UTC
Thank you for the answer, but could you please provide some info?

> Xorg can only have one window as the focussed window.

How does the requesting mechanism work? Does window asks X11 that it has focus or does it asks kwin for that info? If X11, then may it work with wayland?

> Ultimately if you want a client app to have different behaviour, you're better of changing the client app.

Of course, but the apps we speak about are not open source (games and davinci resolve video editor), so no way with this way.
Comment 4 David Edmundson 2021-07-04 21:48:16 UTC
On X11 kwin tells X who should have focus, clients look to X to be told who has focus.

> If X11, then may it work with wayland?

Arguably it could be done differently on wayland
Comment 5 Andrew Shark 2021-09-30 21:36:09 UTC
Actually, I needed such thing several times, additionally to the case described originally with the D:BH game. I just wanted to document that, probably, there may be other cases, so maybe this eventually could be considered to implement.

Here is my case. I have a video and I want to make its translated version. I want to transcript it first. I know there is a feature in google docs, that gives you speech to text function. I want to turn on the video and then swith the source for the audio stream from the output of video (like a virtual microphone).
In pavucontrol I could go to recording tab and change the from source. BUT the problem is that as long as I alt-tab from chromium window to pavucontrol window, microphone becomes deactivated in the google docs. So recording application (browser) disappears from pavucontrol.

If the feature was implemented, I could just keep a fake focus in browser, and alt-tab to pavucontrol, then change mic source.