Added xcaffeine.py (self-written script) for keeping the screen awake when certain applications are open

This commit is contained in:
2022-06-26 01:55:13 -04:00
parent c589cfa80f
commit 7fb3a5ac98
3 changed files with 40 additions and 1 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ chmod -R 700 /home
# installing desktop environment and addons + utilities
if [ "$formfactor" -lt 4 ]; then
pacman -S pipewire pipewire-pulse pipewire-jack pipewire-alsa plasma-desktop lightdm-openrc lightdm-gtk-greeter kscreen kdeplasma-addons spectacle gwenview plasma-nm plasma-pa breeze-gtk kde-gtk-config kio-extras khotkeys kwalletmanager pcmanfm-qt yakuake ark kate micro bluedevil bluez --needed --noconfirm
pacman -S pipewire pipewire-pulse pipewire-jack pipewire-alsa libpulse plasma-desktop lightdm-openrc lightdm-gtk-greeter kscreen kdeplasma-addons spectacle gwenview plasma-nm plasma-pa breeze-gtk kde-gtk-config kio-extras khotkeys kwalletmanager pcmanfm-qt yakuake ark kate micro bluedevil bluez --needed --noconfirm
rc-update add lightdm
ln -s /usr/bin/micro /usr/bin/nano
fi
+7
View File
@@ -0,0 +1,7 @@
[Desktop Entry]
Exec=/usr/bin/xcaffeine.py
Icon=
Name=xcaffeine
Path=
Terminal=False
Type=Application
+32
View File
@@ -0,0 +1,32 @@
#!/bin/python3
# external modules
from os import setuid, system
from pwd import getpwnam
from subprocess import Popen, PIPE, STDOUT
from time import sleep
# depends on X11, libpulse (compatible w/Pipewire&PulseAudio)
# START USER CHANGEABLE VARIABLES
# list of pactl search terms
pactl_search = ['jellyfinmediaplayer', 'rpcs3']
# frequency to check for activity (in seconds)
timeout = 290
# FINISH USER CHANGEABLE VARIABLES
# ensure running as correct user
setuid(1000)
while True:
sleep(timeout)
for search_term in pactl_search:
command = f"pactl list | grep {search_term[:-1]}"
output = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
block = output.communicate()[0].strip() # blocks the program from proceeding until stdout is given
if block.decode('utf-8').__contains__(search_term):
print(f"Whitelisted content ({search_term}) is active, keeping screen alive...")
system('xset s off -dpms')
sleep(5)
system('xset s on +dpms')