linux - Inhibit screensaver with Python -
what's better cross-de way disable screensaver in linux? found something here it's gnome-screensaver. i'm wondering if there's way simulate keystroke or x.org api disable screensaver activation.
i have been looking while ago , ended using xdg-screensaver call via subprocess.
import subprocess def suspend_screensaver(): window_id = subprocess.popen('xwininfo -root | grep xwininfo | cut -d" " -f4', stdout=subprocess.pipe, shell=true).stdout.read().strip() #run xdg-screensaver on root window subprocess.call(['xdg-screensaver', 'suspend', window_id]) def resume_screensaver(window_id): subprocess.popen('xdg-screensaver resume ' + window_id, shell=true) this not ideal apparently there no other solution not involve messing around de-specific stuff dbus or gnome-screensaver-command.
i don't call xwininfo , wish there cleaner way far not find better. issue xwininfo approach uses id of root window instead of app window. using app window id instead of root window remove need resume_screensaver method since resume window destroyed.
and if want simulate keystrokes here naive bash script have been using time. require xdotool has installed separately.
#!/bin/bash while : sleep 200 nice -n 1 xdotool key shift echo . done update
after having used python solution above on year, found create zombie processes and/or many instances of xdg-screensaver, after digging around, found simpler alternative gnome-specific, works me in non-gnome de (xfce) since core gnome libraries required many gtk-based apps if don't have gnome desktop.
import subprocess def suspend_screensaver(): 'suspend linux screensaver' proc = subprocess.popen('gsettings set org.gnome.desktop.screensaver idle-activation-enabled false', shell=true) proc.wait() def resume_screensaver(): 'resume linux screensaver' proc = subprocess.popen('gsettings set org.gnome.desktop.screensaver idle-activation-enabled true', shell=true) proc.wait()
Comments
Post a Comment