From e3de00534fefcd771f55baa141e885126a489b7f Mon Sep 17 00:00:00 2001 From: Randall Date: Wed, 21 Sep 2022 20:28:35 -0400 Subject: [PATCH] Ported xcaffeine to bash, removed Python version --- README.md | 2 +- chrootInstall.sh | 4 ++-- install.sh | 2 +- programs/xcaffeine/xcaffeine.desktop | 2 +- programs/xcaffeine/xcaffeine.py | 32 ---------------------------- programs/xcaffeine/xcaffeine.sh | 23 ++++++++++++++++++++ 6 files changed, 28 insertions(+), 37 deletions(-) delete mode 100755 programs/xcaffeine/xcaffeine.py create mode 100755 programs/xcaffeine/xcaffeine.sh diff --git a/README.md b/README.md index b347315..19728d2 100755 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Some major/noteworthy differences from common configurations: - EXT4 fast_commit mode is enabled by default - makepkg is configured for better than stock performance - a custom .bashrc with useful power management aliases is included -- a custom script (xcaffeine.py) is included to keep the screen awake during the use of whitelisted applications +- a custom script (xcaffeine.sh) is included to keep the screen awake during the use of whitelisted applications - ...all of this and more on KDE Plasma X11 # Usage diff --git a/chrootInstall.sh b/chrootInstall.sh index 159607b..b10598f 100755 --- a/chrootInstall.sh +++ b/chrootInstall.sh @@ -115,12 +115,12 @@ if [ "$formfactor" -lt 4 ]; then pacman -S xorg pipewire pipewire-pulse pipewire-jack pipewire-alsa wireplumber 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-openrc --needed --noconfirm rc-update add lightdm curl https://raw.githubusercontent.com/rwinkhart/artix-install-script/main/programs/powerset/powerset.sh -o /usr/local/bin/powerset.sh - curl https://raw.githubusercontent.com/rwinkhart/artix-install-script/main/programs/xcaffeine/xcaffeine.py -o /usr/local/bin/xcaffeine.py + curl https://raw.githubusercontent.com/rwinkhart/artix-install-script/main/programs/xcaffeine/xcaffeine.sh -o /usr/local/bin/xcaffeine.sh mkdir -p /home/"$username"/.config/autostart/ curl https://raw.githubusercontent.com/rwinkhart/artix-install-script/main/programs/xcaffeine/xcaffeine.desktop -o /home/"$username"/.config/autostart/xcaffeine.desktop curl https://raw.githubusercontent.com/rwinkhart/artix-install-script/main/config-files/pipewire-start.sh -o /usr/local/bin/pipewire-start.sh curl https://raw.githubusercontent.com/rwinkhart/artix-install-script/main/config-files/pipewire.desktop -o /home/"$username"/.config/autostart/pipewire.desktop - chmod 755 /usr/local/bin/powerset.sh /usr/local/bin/xcaffeine.py /usr/local/bin/pipewire-start.sh + chmod 755 /usr/local/bin/powerset.sh /usr/local/bin/xcaffeine.sh /usr/local/bin/pipewire-start.sh chown -R root /usr/local/bin fi diff --git a/install.sh b/install.sh index cba08a4..e747fb3 100755 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ loadkeys us echo ---------------------------------------------------------------------------------------------- echo rwinkhart\'s artix install script -echo last updated september 20, 2022 +echo last updated september 21, 2022 echo ---------------------------------------------------------------------------------------------- echo You will be asked some questions before installation. echo -e "----------------------------------------------------------------------------------------------\n" diff --git a/programs/xcaffeine/xcaffeine.desktop b/programs/xcaffeine/xcaffeine.desktop index d402e57..d0fddc3 100755 --- a/programs/xcaffeine/xcaffeine.desktop +++ b/programs/xcaffeine/xcaffeine.desktop @@ -1,5 +1,5 @@ [Desktop Entry] - Exec=/usr/local/bin/xcaffeine.py + Exec=/usr/local/bin/xcaffeine.sh Icon= Name=xcaffeine Path= diff --git a/programs/xcaffeine/xcaffeine.py b/programs/xcaffeine/xcaffeine.py deleted file mode 100755 index 7d0a472..0000000 --- a/programs/xcaffeine/xcaffeine.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env 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') diff --git a/programs/xcaffeine/xcaffeine.sh b/programs/xcaffeine/xcaffeine.sh new file mode 100755 index 0000000..9fc5cc3 --- /dev/null +++ b/programs/xcaffeine/xcaffeine.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# 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 + +while [ True ]; do + sleep $timeout + for term in ${pactl_search[@]}; do + search_result=$(pactl list | grep $term) + if [ ! -z "$search_result" ]; then + echo "Whitelisted content ($term) is active, keeping screen alive..." + xset s off -dpms + sleep 5 + xset s on +dpms + fi + done +done