0

Is it possible to make a window believe that it has a focus while it has not?

My use case description: I am playing a game named Detroit Become Human. I am playing with gamepad. The game is actually an interactive movie. It has a very complicated flowcharts. I want to see other scenes that I missed after my original walkthrough. I am reading the walkthrough guide in a browser and switching to game very often and want to see flowchart in a game. Because the flowcharts are very complicated, I need to keep lots of tabs in browser, constantly scroll pages up and down trying to read descriptions for some nodes. And I get really annoyed that I constantly need to refocus a game itself to be able to control it (even with gamepad) and press alt+tab to release mouse from the game. Also, the game makes me rewatching lots of scenes that I already have seen and I want to do some other readings while such scenes are playing. Also, there are scenes with minor interactions, but still I need to focus a game window for them.

I wanted to make it easier. I want the game to be controllable by gamepad while its window not in focus. I thought that I need to capture a gamepad input and redirect it to inactive window. And that thing was what I wanted originally to ask. However, I have noticed, that chromium while not in focus is still able to see the gamepad input by using this web site: https://gamepad-tester.com/. This means (as I think) that all windows have access to the gamepad input.

Now I think that the problem is the game itself. I think it checks if it is in focus, and if not, it do not interprets the input.

I want the game to always interpret gamepad, even when missing focus. Is that possible?

My system details:
Arch Linux.
Game launched via steam.
Tried with Steam Input and without it.
KDE Plasma.
Logitech F710 Gamepad in XInput mode.
The game launched in borderless window mode, also tried fullscreen and windowed.

Additional info.
This trick may be useful not only for games (which often pauses when not in focus), but also for applications. For example, DaVinci Resolve hides a window with effects parameters. I am watching a tutorial video on youtube in browser. When I focus a browser, I cannot see my parameters window to compare it with such on a youtube. Tricking the DaVinci Resolve that it has focus (while still disabling keyboard input for it) may solve this.

1

4 Answers 4

1

This isn't the solution you were looking for, but a way around it is to change the setting for mouse focus in System Settings->Workspace->Window Management->Window Behavior->Focus->Window Activation policy:Focus follows mouse (mouse precedence). This lets the window under your mouse be focused automatically, which I find ridiculously convenient just in general.

1
  • Thanks for this suggestion as a general, but in this case it is not helping. The game captures the cursor when hover over its window (to release you need alt-tab), so you even cannot "easify" switching by just moving mouse. And cannot workaround capturing of mouse by creating a window rule to restrict focusing, because the input will not work. The goal was to avoid this "focusing and releasing" actions, but unfortunately, not achieving it. And inpossible to control via gamepad while game not in focus.
    – Ashark
    May 19, 2021 at 22:26
1

As far as I know it is not possible to have multiple focus. You could try one of these solutions:

  • play the game inside a VM and see it remotely

  • play the game inside a vncserver and see it remotely (if it can run on a non-accelerated x11)

4
  • Virtual machine is an obvious solution, but it is not always appropriate. For this game, a good gpu is required, so need gpu passthrough (so need at least two gpus). So I need to maintain a separate installation of the os (and steam account with game installed, etc). While I could passthrough the usb hub with gamepad wireless receiver, I got the inconveniences of switching between monitor sources, which is worse than just alt-tab. Also, having a separate laptop for browsing guides is also an obvious solution.
    – Ashark
    May 19, 2021 at 22:04
  • If it were my installation I'd try an overlay of the KDE functions that tells the program if it has the focus for example, or a modification of the source for that. But that's a hard sell, so I went for the basics. But yes, if you go down to the source and are ready to rebuild or compile something, then there are more options. May 20, 2021 at 0:15
  • I would like to. But I have currently no idea from where to start.
    – Ashark
    May 20, 2021 at 19:52
  • Another idea that I thought of is launching a separate X server via xephyr. It is a separate X server, that is presented as one window. But I do not know what about performance of games in this scenario. Probably, gpu is only possible to be used by one of the X servers. However, even if it is possible to passthrough "gpu power" to the nested X server, then I do not know if some thing like "kvmfr looking glass" for the linux will be needed.
    – Ashark
    May 20, 2021 at 20:00
0

I have another idea to half workaround this. Need to write a script/application that listens to gamepad input events (as said in the question, looks like all applications can listen to it simultaneously) and focuses the window with the game at receiving any event.

This will at least simplify switching to game. But still will need to alt-tab if want to work with keyboard input in other windows.

0

Another idea which could be the only solution in the long run. As David Edmundson said in #439483 bug report, the nested wayland could be used. It seems it supports gpu acceleration. The keyboard input still seems to be at one window, but this is not a problem for me. And the gamepad input should work: the compositor window is unfocused but gamepad could be listened by all windows, then the game in focus (inside compositor window) gets the input and moves character.

The remaining problem for me is how to actually start the game in the nested wayland. Some links that I may start of are:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.