netbrain / zwift

Easily zwift on linux
The Unlicense
265 stars 28 forks source link

fix(screensaver): detect xscreensaver #148

Closed perrin4869 closed 4 months ago

perrin4869 commented 4 months ago

the ever evolving battle against screensavers (or in favor of screensavers, depending how you look at it) rages on. turns out that I was missing xscreensaver-command which is used by xdg-screensaver to detect and inhibit xscreensaver. this explains why I was still getting screensavers while zwift was open, whenever youtube would not be playing on my other screen. oops 😅 I think a few more environment variables might be needed to make available to detect other screensavers or power management schemes in gnome/kde, but I don't use those systems so I couldn't test them. I could try to add those based on the contents of xdg-screensaver though

perrin4869 commented 4 months ago

please note that xscreensaver-command -version will fail with an error if no xscreensaver daemon is running on the current xorg session, so just making it available in the container won't give a false positive

sHedC commented 4 months ago

That could get complex, we could rely on gamemoderun in the startup script?

https://github.com/FeralInteractive/gamemode

Maybe that would work as it is supposed to deal with that not sure about power I don't use power management on my desktop and laptop when plugged in its set to 4 hours (never cycled that long too boring).

Fedora install is just dnf install gamemode

???? Although I do wonder if it will do anyting as the script exits to would it stop or keep going with the docker?

perrin4869 commented 4 months ago

Hm... It's the first time I hear of this project! From skimming though, it doesn't sound like it handles screensaver inhibition?

sHedC commented 4 months ago

From skimming though, it doesn't sound like it handles screensaver inhibition?

It does, its part of what it is supposed to do its in the readme that it inhibits screen saver.

image

on a side note I think this is a fine submission from my point of view, nothing problematic I see with it. I will investigate gamemode as it should be possible to build it into the docker as there are games and flatpaks with it built in.

perrin4869 commented 4 months ago

Oh right sorry! Interesting, would need to evaluate exactly what it's doing to inhibit the screen. Since every screensaver has its own idiosyncrasies as to how to inhibit the screen, I'd be surprised if it covers as many cases as xdg-screensaver

netbrain commented 4 months ago

I'm on vacation, I'll look into it about a weeks time.

sHedC commented 4 months ago

@perrin4869 - I tried gamemode inside the docker worked for me not sure if you want to try:

In Dockerfile add game mode to line 45 RUN apt-get install -y wget curl sudo winbind libgl1 libvulkan1 procps gosu xdg-utils gamemode

In run_zwift.sh - comment out the xdg screen saver and add gamemoderun

[[ -n "${DBUS_SESSION_BUS_ADDRESS}" ]] && while true; do sleep 30; xdg-screensaver reset; done &

echo "Killing uneccesary applications"
pkill ZwiftLauncher
pkill ZwiftWindowsCra
pkill -f MicrosoftEdgeUpdate

/usr/games/gamemoderun wineserver -w

For me this enabled gamemode (I have a gnome extension to show when game mode is running. It stopped the screen saver which I set to 2 min.

perrin4869 commented 4 months ago

thanks! ok, just took a look at gamemode source code, the inhibiting is done here I haven't tried it yet, but I think this would work in my personal use-case (running the xscreensaver-systemd daemon). Also, note that this is also the method used by firefox when running youtube videos, for example. @sHedC what screensaver were you using? I think this would work also on recent versions of gnome and kde, but browsing through xdg-screensaver, it seems systems like mate and cinnamon and old versions of gnome and kde are not using the freedesktop dbus interface, for example. But it would be worth trying on those systems as well, cinnamon and mate may have added freedesktop support in the meantime to their screensavers? And then there are the other implications of running gamemode to consider? I'll try this later (or maybe tomorrow) for sure to confirm that it works, as of right now I think it would be fine replacing xdg-utils and with gamemode if support for those systems in question is not a priority

sHedC commented 4 months ago

I am using Gnome Fedora 40 and KDE fedora 40 usually test with both wayland and X as its an environment just for building and testing zwift. Also have a NixOS build with hyperland but don't really get that OS :)

I actualy only know about it because of steam never thought it inhibited screen saver but was using it for gaming.

sHedC commented 4 months ago

Gamemode changes to performance mode and changes some CPU scheduling if it can. It can't always do that it checks what it can do before it does.

But it is used by default in some games now such as tomb raider.

perrin4869 commented 4 months ago

ok, just confirmed gamemode does indeed work on my system, as expected. honestly, if it's good enough for firefox, I think it's good enough for us as well. I could update this PR to use gamemode, and remove xdg-utils and the whole heartbeat functionality I had there. It might break users on cinnamon or mint though, but couldn't confirm that without trying it

sHedC commented 4 months ago

Up to you if you want to update on this PR please do I will test it on some others, but basically game mode is used by Steam so I expect good support.

If not I can create a branch and do it there to test under a new issue/ PR :)

sHedC commented 4 months ago

Just as a note quick google and game mode seems to be working on a lot of distros and windows managers

sHedC commented 4 months ago

Closing in favour of #149 to use gamemode.