aboutsummaryrefslogtreecommitdiff
path: root/sxhkd/terminal_bspwm.py
diff options
context:
space:
mode:
authorbozo.kopic <bozo.kopic@gmail.com>2020-07-16 04:29:34 +0200
committerbozo.kopic <bozo.kopic@gmail.com>2020-07-16 04:29:34 +0200
commitf61d921fd24c24da4258217510c809825cdbf8f8 (patch)
tree46d8e48963b8b2bced3b130ac5f9b54aa703a9aa /sxhkd/terminal_bspwm.py
parent5179366de4375c49e6906ca2b879a064ddb9639c (diff)
.
Diffstat (limited to 'sxhkd/terminal_bspwm.py')
-rw-r--r--sxhkd/terminal_bspwm.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/sxhkd/terminal_bspwm.py b/sxhkd/terminal_bspwm.py
new file mode 100644
index 0000000..eee7875
--- /dev/null
+++ b/sxhkd/terminal_bspwm.py
@@ -0,0 +1,46 @@
+import subprocess
+
+
+desktop_name = 'term'
+instance_name = 'tmux_term'
+
+
+def is_term_running():
+ p = subprocess.run(['xdo', 'id', '-n', instance_name])
+ return p.returncode == 0
+
+
+def run_term():
+ subprocess.Popen(['alacritty', '--class', instance_name,
+ '-e', 'tmux', 'new-session', '-A', '-s', 'default'])
+
+
+def get_focused_desktop():
+ p = subprocess.run(['bspc', 'query', '-D', '--names', '-d', 'focused'],
+ capture_output=True,
+ check=True)
+ return p.stdout.decode('utf-8').strip()
+
+
+def hide_term():
+ subprocess.run(['bspc', 'desktop', '-f', 'last.local'], check=True)
+
+
+def show_term():
+ subprocess.run(['bspc', 'desktop', 'term', '-m', 'focused'])
+ subprocess.run(['bspc', 'desktop', '-f', 'term'], check=True)
+
+
+def main():
+ if not is_term_running():
+ run_term()
+
+ focused_desktop = get_focused_desktop()
+ if focused_desktop == desktop_name:
+ hide_term()
+ else:
+ show_term()
+
+
+if __name__ == '__main__':
+ main()