From a7f6bcbf2930fda0547136491bf1a67c3b337224 Mon Sep 17 00:00:00 2001 From: "bozo.kopic" Date: Wed, 14 Oct 2020 23:57:21 +0200 Subject: . --- sway/config | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ sway/load_resources.sh | 6 ++++ sway/terminal.py | 54 +++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 sway/config create mode 100755 sway/load_resources.sh create mode 100644 sway/terminal.py (limited to 'sway') diff --git a/sway/config b/sway/config new file mode 100644 index 0000000..a042ab3 --- /dev/null +++ b/sway/config @@ -0,0 +1,86 @@ +set $primary eDP-1 +set $secondary DP-5 +output $primary pos 0 0 res 1920x1080 bg ~/.pictures/bg1.jpg stretch +output $secondary pos 1920 0 res 3840x2160 bg ~/.pictures/bg2.jpg stretch + +set $ws1 "1:1" +set $ws2 "2:2" +set $ws3 "3:3" +set $ws4 "4:4" +set $ws5 "5:a" +set $ws6 "6:s" +set $ws7 "7:d" +set $ws8 "8:f" +set $ws9 "9:term" +workspace $ws1 output $primary +workspace $ws2 output $primary +workspace $ws3 output $primary +workspace $ws4 output $primary +workspace $ws5 output $secondary +workspace $ws6 output $secondary +workspace $ws7 output $secondary +workspace $ws8 output $secondary + +set $mod Mod4 +font pango:Inter Medium 12 +floating_modifier $mod +default_border pixel 4 +#xwayland disable + +bindsym $mod+Return exec alacritty +bindsym $mod+space exec wofi --show drun --allow-images --allow-markup --gtk-dark +bindsym $mod+Tab layout toggle + +bindsym $mod+Shift+q kill +bindsym $mod+Shift+r restart +bindsym $mod+Shift+e exit +bindsym $mod+Shift+space floating toggle +bindsym $mod+Shift+Return fullscreen toggle + +bindsym $mod+h focus left +bindsym $mod+j focus down +bindsym $mod+k focus up +bindsym $mod+l focus right +bindsym $mod+Left focus left +bindsym $mod+Down focus down +bindsym $mod+Up focus up +bindsym $mod+Right focus right + +bindsym $mod+Shift+h move left +bindsym $mod+Shift+j move down +bindsym $mod+Shift+k move up +bindsym $mod+Shift+l move right +bindsym $mod+Shift+Left move left +bindsym $mod+Shift+Down move down +bindsym $mod+Shift+Up move up +bindsym $mod+Shift+Right move right + +bindsym $mod+1 workspace number $ws1 +bindsym $mod+2 workspace number $ws2 +bindsym $mod+3 workspace number $ws3 +bindsym $mod+4 workspace number $ws4 +bindsym $mod+a workspace number $ws5 +bindsym $mod+s workspace number $ws6 +bindsym $mod+d workspace number $ws7 +bindsym $mod+f workspace number $ws8 + +bindsym $mod+Shift+1 move container to workspace number $ws1 +bindsym $mod+Shift+2 move container to workspace number $ws2 +bindsym $mod+Shift+3 move container to workspace number $ws3 +bindsym $mod+Shift+4 move container to workspace number $ws4 +bindsym $mod+Shift+a move container to workspace number $ws5 +bindsym $mod+Shift+s move container to workspace number $ws6 +bindsym $mod+Shift+d move container to workspace number $ws7 +bindsym $mod+Shift+f move container to workspace number $ws8 + +bindsym F12 exec python ~/.config/sway/terminal.py +assign [app_id="^tmux_term$"] $ws9 + +bar { + swaybar_command waybar + position top + strip_workspace_numbers yes + tray_output $primary +} + +exec ~/.config/sway/load_resources.sh diff --git a/sway/load_resources.sh b/sway/load_resources.sh new file mode 100755 index 0000000..b1c07a2 --- /dev/null +++ b/sway/load_resources.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +xrdb -load ~/.Xresources +(swaymsg -p -t get_outputs | grep -q "Current mode: 3840x2160") && \ + echo "Xft.dpi: 120" | xrdb -override + diff --git a/sway/terminal.py b/sway/terminal.py new file mode 100644 index 0000000..3993dcd --- /dev/null +++ b/sway/terminal.py @@ -0,0 +1,54 @@ +import subprocess + +workspace_name = '9:term' +instance_name = 'tmux_term' + + +def is_term_running(): + p = subprocess.run(['swaymsg', '-t', 'get_tree'], + capture_output=True, + check=True) + return f'"app_id": "{instance_name}"' in p.stdout.decode('utf-8') + + +def run_term(): + subprocess.Popen(['alacritty', '--class', instance_name, + '-e', 'tmux', 'new-session', '-A', '-s', 'default']) + + +def get_focused(name): + p = subprocess.run(['swaymsg', '-p', '-t', f'get_{name}'], + capture_output=True, + check=True) + for line in p.stdout.decode('utf-8').strip().split('\n'): + if not line or line[0] == ' ': + continue + segments = line.split(' ') + if segments[-1] == '(focused)': + return segments[1] + + +def hide_term(): + subprocess.run(['swaymsg', 'workspace', 'back_and_forth'], check=True) + + +def show_term(): + output = get_focused('outputs') + subprocess.run(['swaymsg', 'workspace', workspace_name], check=True) + subprocess.run(['swaymsg', 'move', 'workspace', 'to', output], check=True) + subprocess.run(['swaymsg', 'workspace', workspace_name], check=True) + + +def main(): + if not is_term_running(): + run_term() + + focused_workspace = get_focused('workspaces') + if focused_workspace == workspace_name: + hide_term() + else: + show_term() + + +if __name__ == '__main__': + main() -- cgit v1.2.3-70-g09d2