add sxhkd mode support to statusbar.py

This commit is contained in:
stupidcomputer 2024-05-13 18:44:23 -05:00
parent 9053b258c0
commit 921c36dc0f
4 changed files with 22 additions and 3 deletions

View File

@ -1,3 +1,3 @@
# start the wm
sxhkd &
mode sxhkdrc
bspwm

View File

@ -50,5 +50,6 @@ super + {_,shift + } {1-9,0}
super + {t,f,s}
bspc node -t {tiled,floating,fullscreen}
# x230t specific -- activate the tablet menu
XF86RotateWindows
tabletmenu

View File

@ -38,6 +38,22 @@ def generate_desktop_string(monitor_array):
return ' '.join(output)
def filemodfactory(filename: str, modname: str):
def filemod(queue, _):
orig = 0
while True:
new = os.path.getmtime(filename)
if(new > orig):
with open(filename, 'r') as f:
queue.put({
"module": modname,
"data": f.read().rstrip()
})
orig = new
time.sleep(0.1)
return filemod
def bspwm(queue, monitor):
client = socket.socket(
socket.AF_UNIX,
@ -90,11 +106,12 @@ def filecheckerfactory(filename: str, modname: str, timeout=60):
battery = filecheckerfactory("/sys/class/power_supply/BAT0/capacity", "bat")
batterystatus = filecheckerfactory("/sys/class/power_supply/BAT0/status", "batstat")
sxhkdmode = filemodfactory("/home/usr/.cache/sxhkd_mode", "sxhkdmode")
def render(modules) -> str:
columns, _ = os.get_terminal_size(0)
left = "{} | {}".format(modules["clock"], modules["bspwm"])
left = "{} | {}({})".format(modules["clock"], modules["bspwm"], modules["sxhkdmode"])
right = "{}({})".format(modules["bat"], modules["batstat"])
padding = " " * (columns - len(left) - len(right) - 0)
@ -146,7 +163,7 @@ def main():
))
return
queue = Queue()
modules = [bspwm, clock, battery, batterystatus]
modules = [bspwm, clock, battery, batterystatus, sxhkdmode]
[Process(target=module, args=(queue, argv[1])).start() for module in modules]
module_outputs = defaultdict(lambda: "")

View File

@ -4,6 +4,7 @@ if [ -n "$1" ]; then
pkill sxhkd
sxhkd -c ~/.config/sxhkd/$1 & disown
[ -f "~/.config/sxhkd/$1.sh" ] && ~/.config/sxhkd/$1.sh
echo "$1" > ~/.cache/sxhkd_mode
exit
fi