Created
November 18, 2015 12:22
-
-
Save nfnty/21a2dca0c17d11c08c8f to your computer and use it in GitHub Desktop.
bspwm events screensaver toggling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 -u | |
''' Screensaver fullscreen toggling ''' | |
import subprocess | |
import json | |
def class_find(windows, name): | |
''' Find className ''' | |
for window in windows.values(): | |
if window['client']['className'] == name: | |
return True | |
return False | |
def main(): | |
''' Main ''' | |
windows = {} | |
process = subprocess.Popen(['/usr/bin/bspc', 'control', '--subscribe', 'window_state'], | |
stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) | |
for line in process.stdout: | |
line = json.loads(line) | |
if line['client']['state'] == 'fullscreen': | |
windows[line['client']['window']] = line | |
elif line['client']['window'] in windows: | |
del windows[line['client']['window']] | |
else: | |
continue | |
try: | |
subprocess.check_call(['/usr/bin/pgrep', 'i3lock']) | |
except subprocess.CalledProcessError: | |
pass | |
else: | |
continue | |
xset_output = subprocess.check_output(['/usr/bin/xset', 'q']).decode('UTF-8') | |
if 'DPMS is Enabled' in xset_output and windows: | |
if class_find(windows, 'Kodi'): | |
pass | |
else: | |
subprocess.check_call(['/usr/bin/xset', '-dpms']) | |
elif 'DPMS is Disabled' in xset_output: | |
if (windows and class_find(windows, 'Kodi')) or not windows: | |
subprocess.check_call(['/usr/bin/xset', '+dpms']) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The proper way to do this would be to build an initial world view based on the output of
query -T
and then update that world view in response towindow_{state,manage,unmanage}
events.