gamescope icon indicating copy to clipboard operation
gamescope copied to clipboard

Input holding: Implement libinput evdev device holding on SDL and Wayland backends.

Open davidawesome02-backup opened this issue 1 year ago • 10 comments

Added command line options to allow users to disable default window input processing, and enable mouse and keyboard processing via evdev paths. When using disabled mouse on window, and using passed through mouse, gamescope mouse compositing is enabled, to allow users to see the mouse pointer.

Intended to allow client isolation, and what is essentially a continuation of multiseating in a subcompositor rather than as a standalone compositor. Doing this separation and device holding in a subcompositor allows for actions including single GPU and monitor gaming with multiple people.

As stated in my original issue #1771 , this would essentially be a continuation and introduction into the wayland space of a process that was able to be used previously in the xephyr project, back when it had a evdev / libinput backend.

These changes currently only work on the X11 backend (SDL) and Wayland backend, with the libinput changes allowing VR to specify devices to hold, although this is untested and seems to be unhelpful in that area.

These changes may also help in the development of split screen gaming on linux in a more complete fashion, in projects similar to and including partydeck

Feel free to ask for any changes that may be required to merge, this is my first contribution to this project, or really any outside of personal ones, so let me know if any changes are required.

--libinput-hold-dev is used by passing --libinput-hold-dev /dev/input/by-id/USB-...,/dev/input/by-id/... or in multiple arguments, while the options --backend-disable-keyboard and --backend-disable-mouse are passed with no arguments, and simply disable the backend's keyboard and mouse processors.

davidawesome02-backup avatar Jun 25 '25 19:06 davidawesome02-backup

The software cursor seems to not render in certain instances. PrismLauncher for Minecraft does show a cursor in the launcher, but not in-game. Left 4 Dead 2 does properly display the cursor. Will have to test with more games/applications, but my initial guess is that it may have something to do with the game's rendering API? (Minecraft is OpenGL while L4D2 was run in Vulkan with -gamepadui)

wunnr avatar Jun 26 '25 05:06 wunnr

Also, when starting through terminal, if you specify --libinput-hold-dev with the specific keyboard that hit Enter to run the command, the Enter key gets stuck until the gamescope window that is holding it is closed; this causes the terminal to spam the Enter command. This may be fixed by putting a small delay before grabbing keyboards?

wunnr avatar Jun 26 '25 05:06 wunnr

Also, when starting through terminal, if you specify --libinput-hold-dev with the specific keyboard that hit Enter to run the command, the Enter key gets stuck until the gamescope window that is holding it is closed; this causes the terminal to spam the Enter command. This may be fixed by putting a small delay before grabbing keyboards?

Gamescope is generally assumed to be used from an automated sense, and adding a timeout would be difficult, as there is no way to know when the person releases the enter key, and thus is safe to grab. We could do some checks before we bind to it, but it may be over complicated for no real reason. Do you have any other ideas for it, because I don't think a timeout would work well for this part of the program, if we are doing cmdline testing for this, you can use a sleep 1s; gamescope or similar to avoid the issue, but I am not sure how to resolve it in a decent way without undue delay in the starting of gamescope.

davidawesome02-backup avatar Jun 26 '25 15:06 davidawesome02-backup

Sorry, just realized when changing some typos I forgot to add the submodules to my gitignore. I force-pushed a change that removed the glm update that vscode did automatically (did it during push for some reason, so I didn't catch it).

davidawesome02-backup avatar Jul 05 '25 15:07 davidawesome02-backup

Tested in games: Chivalry 2, Magicka 2, Terraria, Helldivers 2 Caused no issues and worked exactly as david described it would

Edit: Holding a mouse in prismlauncher doesn't show any cursor but it does work upon specifying --backend-disable-mouse Then it works perfectly as described

Edit 2: I tested some more: Battlebit Remastered, Darkwood, Garry's Mod with and without holding mouse/keyboard and --backend-disable-mouse and all the games I listed work without issue

xamionex avatar Jul 22 '25 23:07 xamionex

Tested with just minecraft(prismlauncher), works great, ~however, if gamescope is started with --expose-wayland, mouse jumps between middle, top middle, top left and middle left of the window, flickering the window slightly, and when right/left clicked, gamescope segfaults. The keyboard just doesn't work, segfaults when pressed. The reason for using that option is to get rid of flickering, as per this comment in #495. Just in case this information is useful for reproduction, I'm on NixOS 25.05, gamescope 3.16.17, Wayland Plasma 6.3.6, Kernel 6.12.48, Nvidia 580.65 proprietary~ Edit: strikethrough text not related to this PR

Wlnfr avatar Sep 25 '25 09:09 Wlnfr

Tested with just minecraft(prismlauncher), works great, however, if gamescope is started with --expose-wayland, mouse jumps between middle, top middle, top left and middle left of the window, flickering the window slightly, and when right/left clicked, gamescope segfaults. The keyboard just doesn't work, segfaults when pressed. The reason for using that option is to get rid of flickering, as per this comment in #495. Just in case this information is useful for reproduction, I'm on NixOS 25.05, gamescope 3.16.17, Wayland Plasma 6.3.6, Kernel 6.12.48, Nvidia 580.65 proprietary

I believe this to be unrelated to input holding as it happens with gamescope without it

xamionex avatar Sep 25 '25 09:09 xamionex

I believe this to be unrelated to input holding as it happens with gamescope without it

Okay, sorry, it seems I have done too little testing with --expose-wayland before reporting here,as I was able to segfault it without input holding

Wlnfr avatar Sep 25 '25 10:09 Wlnfr

Hey, happy to see more comments on this!

While it is not ready for merging currently in my testing branch, I have a few new changes I was wondering if I should add to this branch, mainly that being of toggling keyboard / mouse grab when a key is pressed. Currently, keyboard grabbing is done instantly on running gamescope (with this patch), but I was thinking of following the (somewhat) convention of the Win/Super+G Grab keybind to grab / ungrab devices.

Now, I am asking because I see it implemented in the SDL backend (just telling SDL to grab it) and being entirely faked in the WAYLAND backend, just changing the window title to (grabbed) without actually doing anything? (<a href="https://github.com/ValveSoftware/gamescope/blob/6bda0eec5cfc6111907e2a69e329a0b409ec4c6d/src/Backends/WaylandBackend.cpp#L1201C1-L1207C6" rel="nofollow" target="_blank" >source</a>)</p> <p>Also, to allow this to work, and to allow expansion, or possible implementation of other keybinds, I used a <code>static std::bitset<KEY_MAX+1> held_keys;</code> inside the backend... dose anyone know a better way, or is this how you guys would want it to be implemented?</p> <p>Code I changed to add this, and another feature to my testing branch; would not be committed as is, just showing as to get opinions on these types changes: https://github.com/davidawesome02-backup/gamescope/commit/a9bd04ccf4e37915ab0e20023e66558a98b22ce1</p> <p>@wunnr Would you be interested in this? I implemented it in my version of your project, and if I push this into this version up here, the default would change, requiring <code>--grab</code> to be issued along side the <code>--libinput-hold-dev</code> to instantly grab the device, unless anyone here believes that <code>--libinput-hold-dev</code> should imply <code>--grab</code>, and thus require a <code>--no-grab</code> option, but I think this is overly complex.</p> </p> <div class="body-meta"> <div class="owner-info float-right"> <img class="owner-avatar" src="https://avatars.githubusercontent.com/u/138835606?v=4" alt="davidawesome02-backup avatar" width="48" height="48" title="Published by a pub.dev verified publisher"/> <span class="w3-opacity w3-small"> Sep 26 '25 05:09 </span> <a class="owner-name" href="http://gitmemories.com/davidawesome02-backup"> davidawesome02-backup </a> </div> </div> <div class="clear-both"></div> </div> <div class="issue-body"> <p> <blockquote> <p>Replying to https://github.com/ValveSoftware/gamescope/pull/1897#issuecomment-3336856813</p> </blockquote> <p>Unfortunately, I can't help you with the code, but I do believe <code>Win/Super+G</code> keybind will be nice to have. About <code>--grab</code> option, while I personally believe it should be implied, I would be fine with having to include it manually. And as long as it's documented(in <code>--help</code>) that it should be included as an option to automatically grab input devices, I don't see it being a problem. The <code>--no-grab</code> option, however, feels unnecessary for me, if <code>--libinput-hold-dev</code> would imply <code>--grab</code>.</p> </p> <div class="body-meta"> <div class="owner-info float-right"> <img class="owner-avatar" src="https://avatars.githubusercontent.com/u/8050905?v=4" alt="Wlnfr avatar" width="48" height="48" title="Published by a pub.dev verified publisher"/> <span class="w3-opacity w3-small"> Sep 26 '25 17:09 </span> <a class="owner-name" href="http://gitmemories.com/Wlnfr"> Wlnfr </a> </div> </div> <div class="clear-both"></div> </div> </section> </div> </div> </div> <aside class="detail-info-box"> <h3 class="title pkg-infobox-metadata">Labels</h3> <script type="text/javascript"> atOptions = { 'key' : '6ca19c2b16e3f20a28885886ef99a68e', 'format' : 'iframe', 'height' : 250, 'width' : 300, 'params' : {} }; </script> <script type="text/javascript" src="https://www.highperformanceformat.com/6ca19c2b16e3f20a28885886ef99a68e/invoke.js" ></script> <h3 class="title">Owner</h3> <div class="owner-info flex-items-center d-flex"> <img class="owner-avatar" src="https://avatars.githubusercontent.com/u/138835606?v=4" alt="davidawesome02-backup avatar" width="48" height="48" title="Published by a pub.dev verified publisher"/> <a class="owner-name" href="http://gitmemories.com/davidawesome02-backup"> davidawesome02-backup </a> </div> <hr class="color1"> <h3>Other Repo Issues</h3> <div class="packages"> </div> <div style="clear: both"></div> </aside> </div> </div> </main> <footer class="site-footer"> <span>© 2022 Git Memory </span> <a class="link sep" href="http://gitmemories.com/privacy-policy">Policy</a> <a class="link sep" href="http://gitmemories.com/terms">Terms </a> <a class="link sep" href="http://gitmemories.com/contact">Contact </a> <a class="link sep" href="https://exchangetuts.com">Exchangetuts </a> <a class="link sep" href="https://onltools.com/">Onltools </a> <a class="link sep" href="https://serveraide.com/">Serveraide </a> </footer> <script src="http://gitmemories.com/js/app.js?id=a1337f444c840fae34ad"></script> </body> </html>