aboutsummaryrefslogtreecommitdiff
path: root/sxhkd
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
parent5179366de4375c49e6906ca2b879a064ddb9639c (diff)
.
Diffstat (limited to 'sxhkd')
-rw-r--r--sxhkd/sxhkdrc.bspwm54
-rw-r--r--sxhkd/sxhkdrc.i3 (renamed from sxhkd/sxhkdrc)34
-rw-r--r--sxhkd/terminal_bspwm.py46
-rw-r--r--sxhkd/terminal_i3.py58
4 files changed, 167 insertions, 25 deletions
diff --git a/sxhkd/sxhkdrc.bspwm b/sxhkd/sxhkdrc.bspwm
new file mode 100644
index 0000000..aaeb018
--- /dev/null
+++ b/sxhkd/sxhkdrc.bspwm
@@ -0,0 +1,54 @@
+F12
+ python ~/.config/sxhkd/terminal_bspwm.py
+
+mod4 + Return
+ alacritty
+mod4 + space
+ rofi -show drun
+#mod4 + backslash
+# i3-msg "split h"
+#mod4 + minus
+# i3-msg "split v"
+#mod4 + Tab
+# i3-msg "layout toggle split"
+#mod4 + p
+# i3-msg "focus parent"
+#mod4 + r
+# i3-msg "mode resize"
+
+
+mod4 + {1, 2, 3, 4, a, s, d, f}
+ bspc desktop -f {1, 2, 3, 4, a, s, d, f}
+
+mod4 + shift + {1, 2, 3, 4, a, s, d, f}
+ bspc node -d {1, 2, 3, 4, a, s, d, f}
+
+
+mod4 + shift + r
+ bspc wm -r
+mod4 + shift + e
+ bspc quit
+mod4 + shift + q
+ bspc node -c
+mod4 + shift + space
+ bspc node -t ~floating
+mod4 + shift + Return
+ bspc node -t ~fullscreen
+
+mod4 + {h, Left}
+ bspc node -f west
+mod4 + {j, Down}
+ bspc node -f south
+mod4 + {k, Up}
+ bspc node -f north
+mod4 + {l, Right}
+ bspc node -f east
+
+mod4 + shift + {h, Left}
+ bspc node -s west
+mod4 + shift + {j, Down}
+ bspc node -s west
+mod4 + shift + {k, Up}
+ bspc node -s west
+mod4 + shift + {l, Right}
+ bspc node -s west
diff --git a/sxhkd/sxhkdrc b/sxhkd/sxhkdrc.i3
index fa91ced..ec9af48 100644
--- a/sxhkd/sxhkdrc
+++ b/sxhkd/sxhkdrc.i3
@@ -1,5 +1,5 @@
F12
- python ~/.dotfiles/terminal.py
+ python ~/.config/sxhkd/terminal_i3.py
mod4 + Return
alacritty
@@ -27,36 +27,20 @@ mod4 + shift + space
mod4 + shift + Return
i3-msg "fullscreen toggle"
-mod4 + h
+mod4 + {h, Left}
i3-msg "focus left"
-mod4 + Left
- i3-msg "focus left"
-mod4 + j
- i3-msg "focus down"
-mod4 + Down
+mod4 + {j, Down}
i3-msg "focus down"
-mod4 + k
+mod4 + {k, Up}
i3-msg "focus up"
-mod4 + Up
- i3-msg "focus up"
-mod4 + l
- i3-msg "focus right"
-mod4 + Right
+mod4 + {l, Right}
i3-msg "focus right"
-mod4 + shift + h
+mod4 + shift + {h, Left}
i3-msg "move left"
-mod4 + shift + Left
- i3-msg "move left"
-mod4 + shift + j
- i3-msg "move down"
-mod4 + shift + Down
+mod4 + shift + {j, Down}
i3-msg "move down"
-mod4 + shift + k
+mod4 + shift + {k, Up}
i3-msg "move up"
-mod4 + shift + Up
- i3-msg "move up"
-mod4 + shift + l
- i3-msg "move right"
-mod4 + shift + Right
+mod4 + shift + {l, Right}
i3-msg "move right"
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()
diff --git a/sxhkd/terminal_i3.py b/sxhkd/terminal_i3.py
new file mode 100644
index 0000000..c53ff53
--- /dev/null
+++ b/sxhkd/terminal_i3.py
@@ -0,0 +1,58 @@
+import json
+import subprocess
+
+
+def send_msg(msg_type, msg):
+ p = subprocess.run(['i3-msg', '-t', msg_type, msg],
+ capture_output=True,
+ check=True)
+ return json.loads(p.stdout.decode('utf-8'))
+
+
+def is_term_running():
+
+ def node_exists(node):
+ if node.get('window_properties', {}).get('instance') == 'scratchpad_term':
+ return True
+ return any(node_exists(i) for i in node.get('nodes', []))
+
+ tree = send_msg('get_tree', '')
+ return node_exists(tree)
+
+
+def run_term():
+ subprocess.Popen([
+ 'alacritty', '--class', 'scratchpad_term',
+ '-e', 'tmux', 'new-session', '-A', '-s', 'default'])
+
+
+def get_focused_workspace():
+ workspaces = send_msg('get_workspaces', '')
+ for workspace in workspaces:
+ if workspace['focused']:
+ return workspace['name']
+
+
+def get_focused_output(focused_workspace):
+ outputs = send_msg('get_outputs', '')
+ for out in outputs:
+ if out['current_workspace'] == focused_workspace:
+ return out['name']
+
+
+def main():
+ focused_workspace = get_focused_workspace()
+ if focused_workspace == '9:term':
+ send_msg('command', 'workspace back_and_forth')
+ else:
+ focused_output = get_focused_output(focused_workspace)
+ if not is_term_running():
+ run_term()
+ send_msg('command', '[instance="scratchpad_term"] '
+ 'move container to workspace "9:term"')
+ send_msg('command', 'workspace "9:term"')
+ send_msg('command', f'move workspace to output {focused_output}')
+
+
+if __name__ == '__main__':
+ main()