diff --git a/qtile_config.py b/qtile_config.py index bcc20b2..358aaed 100644 --- a/qtile_config.py +++ b/qtile_config.py @@ -25,10 +25,13 @@ # SOFTWARE. import os +import subprocess +import re +import logging from libqtile.config import Key, Screen, Group, Drag, Click from libqtile.command import lazy -from libqtile import layout, bar, widget +from libqtile import layout, bar, widget, hook mod = "mod4" @@ -43,6 +46,10 @@ keys = [ [mod, "control"], "2", lazy.spawn("sh -c " + home + "/.screenlayout/office.sh"), ), + Key( + [mod, "control"], "3", + lazy.spawn("sh -c " + home + "/.screenlayout/home.sh"), + ), # Switch between windows in current stack pane Key( @@ -201,3 +208,28 @@ auto_fullscreen = True # We choose LG3D to maximize irony: it is a 3D non-reparenting WM written in # java that happens to be on java's whitelist. wmname = "LG3D" + + +def is_running(process): + s = subprocess.Popen(["ps", "axuw"], stdout=subprocess.PIPE) + if isinstance(process, list): + process = process[0] + + for x in s.stdout: + if re.search(process.encode(), x): + return True + return False + + +def execute_once(process): + if not is_running(process): + logging.getLogger('libqtile').warning('Starting ' + str(process)) + return subprocess.Popen(process, shell="/bin/bash") + else: + logging.getLogger('libqtile').warning(str(process) + ' already running. Not starting it') + + +@hook.subscribe.startup +def startup(): + execute_once('nm-applet') + execute_once('xautolock -detectsleep -time 15 -locker "i3lock -c 000000" & disown'.split())