You probably don't want to reinvent the wheel so if you are creating something for public consumption then I'd recommend you just co-opt it. The script is a complete mess, so I empathize with anyone unfortunate enough to use it, but I haven't encountered any issues. The lockfiles should ensure there are no duplicate processes. The original state of DPMS is referenced in a separate lockfile. It stores the PID of the aforemention process along with window ID in a lockfile to reference upon suspend and resume. To track the window, it backgrounds xprop -id WINDOW_ID -spy to monitor the window for changes. Note that xdg-screensaver will only track the supplied window ID if xprop is available (it's part of x11-utils, so it should be). The xdg-screensaver resume command consists of xset +dpms (only if DPMS was originally enabled) then the DE-specific commands. If the window disappears, the resume command is run and xdg-screensaver exits. For the xdg-screensaver suspend command, it runs xset -dpms to disable DPMS, DE-specific commands, then watches the supplied window ID for it's duration. Xdg-screensaver detects the desktop environment (KDE, Gnome, XFCE, LXDE, xscreensaver, or gnome-screensaver) and acts accordingly. The many forks of lightsOn are ripe as well. If you're interested in implementing a truly cross-DE solution then I would strongly recommend examining the aforementioned xdg-screensaver/ caffeine-screensaver. Just a FYI that running xdg-screensaver suspend ROOT_WINDOW_ID will background a tracking process and leave it running indefinitely (until it is resumed). I haven't had any issues with xdg-screensaver zombie processes but I'm sure it could be remedied if I better knew the use-case or the conditions under which it was occurring. The first half of ccpizza's answer is great as it is cross-DE and very similar to caffeine's implementation. The caffeine project mostly consists of the following scripts: caffeine-screensaver caffeine caffeine-indicator caffeinateĬaffeine and caffeine-indicator are written in Python 3 whereas caffeine-screensaver is a rebranded xdg-screensaver written in shell script. In case you aren't familiar with it, I'd recommend checking out caffeine (Launchpad PPA ). I'll summarize some of what I've learned in the process. I wasn't happy with any of the solutions out there, so after playing around with some homebrew tools, I ended up modifying the caffeine project to suit my needs and have been using it happily ever since. You probably want to use the hackish xdg-screensaver shell script. To be clear, there aren't any particularly good cross-DE ways to do so in Linux, but at least there is potential. However the question also asked about doing so with Linux (presumably from the shell). TLDR there aren't any cross-DE ways to inhibit the screensaver with pure Python. Proc = subprocess.Popen('gsettings set idle-activation-enabled true', shell=True) Proc = subprocess.Popen('gsettings set idle-activation-enabled false', shell=True) #!/bin/bashĪfter having used the python solution above for over a year, it was found to occasionally create zombie processes and/or too many instances of xdg-screensaver, so after digging around, I found a simpler alternative which is Gnome-specific, but works for me even in a non-Gnome DE (XFCE) since the core Gnome libraries are required by many GTK-based apps even if you don't have a Gnome desktop. It does require xdotool which has to be installed separately. Using the app window id instead of the root window would remove the need for the resume_screensaver method since it would then resume as soon as the window is destroyed.Īnd if you want to simulate keystrokes here is a naive bash script I have been using for some time. Another issue with the xwininfo approach is that it uses the id of the root window instead of the app window. I don't really like the call to xwininfo and wish there was a cleaner way but so far could not find anything better. This is not ideal but apparently there is no other solution that would not involve messing around with DE-specific stuff like dbus or gnome-screensaver-command. Subprocess.Popen('xdg-screensaver resume ' + window_id, shell=True) Window_id = subprocess.Popen('xwininfo -root | grep xwininfo | cut -d" " -f4', stdout=subprocess.PIPE, shell=True).stdout.read().strip() I have been looking into this a while ago and finally ended up using xdg-screensaver which I call via subprocess.
0 Comments
Leave a Reply. |