Created
March 14, 2020 23:49
-
-
Save t184256/42b335f9a48e5995ee523ec41114f574 to your computer and use it in GitHub Desktop.
A script to move my terminal window to/from my tablet when I leave/reenter the workspace, tmux + sway/i3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env nix-shell | |
#!nix-shell -i python -p "python3.withPackages(ps: with ps; [ i3ipc ])" | |
# A script I've thrown together | |
# to use my tablet as a somewhat usable extra screen. | |
# The core idea is to ssh (mosh) to my work laptop, | |
# attach to a tmux session creating a new group (`tmux new-session -t tablet`) | |
# and then create a tmux binding to exchange windows between tablet and laptop | |
# (`bind Tab swap-window -t tablet`). | |
# But the best part is automatically moving the active tmux window | |
# to the tablet when I change workspaces so that I keep seeing it | |
# and swapping it back when I change back. | |
import i3ipc | |
import os | |
TERMINAL_WORKSPACE_NUM = 3 | |
ipc = i3ipc.Connection() | |
prev_workspace = ipc.get_tree().find_focused().workspace().num | |
def on_workspace_focus(ipc, event): | |
global prev_workspace | |
new_workspace = event.current.num | |
if TERMINAL_WORKSPACE_NUM in (prev_workspace, new_workspace): | |
os.system('tmux swap-window -t tablet &') | |
prev_workspace = new_workspace | |
ipc.on("workspace::focus", on_workspace_focus) | |
ipc.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment