Eric Bower
·
2026-09-08
1#!/usr/bin/env python3
2import json
3import subprocess
4import sys
5
6def handle_click(event):
7 key = event.get("key")
8 btn = event.get("button", 1)
9 if not key:
10 return
11
12 if key.startswith("ws_"):
13 ws_name = key[3:]
14 subprocess.run(["swaymsg", "workspace", ws_name], stderr=subprocess.DEVNULL)
15 elif key == "vol":
16 if btn == 1:
17 # Left click: open volume control GUI
18 subprocess.Popen(["pavucontrol"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
19 elif btn in (2):
20 # Middle/Right click: toggle mute
21 subprocess.run(["pamixer", "-t"], stderr=subprocess.DEVNULL)
22
23def main():
24 for line in sys.stdin:
25 line = line.strip()
26 if not line:
27 continue
28 try:
29 event = json.loads(line)
30 if event.get("event") == "click":
31 handle_click(event)
32 except Exception:
33 pass
34
35if __name__ == "__main__":
36 main()