justbuchanan / i3scripts

My scripts for enhancing i3wm
Other
162 stars 45 forks source link

Can autorename_workspaces.py be combined with monitor-assigned workspaces? #38

Open Kabouik opened 4 years ago

Kabouik commented 4 years ago

I am looking for a way to combine this script with monitor-assigned workspaces. Since workspaces names are changing all the time depending on open applications, I cannot use workspace 1 output MONITOR in my i3 config, and using workspace number 1 output MONITOR fails:

ERROR: CONFIG: Line  83: workspace number 7 output "HDMI2"
ERROR: CONFIG: Expected one of these tokens: 'output', 'gaps'

I tried using workspace 1 output MONITOR and enabling the script, but I ended up in what would be a nice panic mode, with an endless loop of my computer shifting workspaces across my three monitors. It was actually hard to edit my i3 config in that state and restart i3 to stop it!

For reference, here is my (WIP) i3 config file:

########################################
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
# i3 config file (v4)
# Please see https://i3wm.org/docs/userguide.html for a complete reference!
# This config file uses keycodes (bindsym) and was written for the QWERTY
# layout.
# To get a config file with the same key positions, but for your current
# layout, use the i3-config-wizard
########################################

########## GENERAL SETTINGS ##########
# Variables
set $mod Mod4
set $defaultmod $mod
set $up i
set $down k
set $left j
set $right l

# Mouse warping
mouse_warping none

# i3bar
bar {
    status_command    i3status
    position          top
    mode              hide
    modifier          none
    workspace_buttons yes
    tray_output       none

    font pango:DejaVu Sans Mono, Icons 12

    colors {
        background #333333
        statusline #ffffff

        focused_workspace  #ffffff #444444
        active_workspace   #888888 #232323
        inactive_workspace #888888 #222222
        urgent_workspace   #232323 #de935f        
    }
}

########## AUTOLAUNCH ##########
#exec --no-startup-id /usr/lib64/polkit-gnome/polkit-gnome-authentication-agent-1
# Compositor
exec --no-startup-id compton --config /home/mathieu/.config/compton.conf
# Network applet
exec --no-startup-id nm-applet
# Rename workspace (https://github.com/justbuchanan/i3scripts)
#exec_always ~/.config/i3/tools/i3scripts/autoname_workspaces.py &
# Wallpaper
exec --no-startup-id nitrogen --restore
# xkb layout
exec --no-startup-id setxkbmap -layout us -variant intl
# Monitor arrangement (automatic detection of current monitor setup thanks to autorandr configuratons)
# Create new configurations using autorandr -s LAYOUTNAME
# Then srandrd is a deamon that detect changes and apply the said configurations
exec --no-startup-id srandrd autorandr -c
# Execute ~/.xinputrc 
exec_always --no-startup-id source ~/.xinputrc
# Dotifications with dunst
exec_always --no-display dunst
# polybar
exec_always --no-startup-id ~/.config/polybar/launch_multimonitor.sh &
# Dim screen when entering a mode
exec_always --no-startup-id /home/mathieu/.config/i3/scripts/i3-mode-dim.sh

########## WORKSPACES ##########
workspace_auto_back_and_forth no
# Force workspaces on specific monitors (they can still be manually moved)
set $laptop_monitor "eDP1"
set $left_monitor "HDMI2"
set $right_monitor "DP1"
workspace number 1 output $left_monitor
workspace number 2 output $right_monitor
workspace number 3 output $laptop_monitor
workspace number 4 output $left_monitor
workspace number 5 output $right_monitor
workspace number 6 output $laptop_monitor
workspace number 7 output $left_monitor
workspace number 8 output $right_monitor
workspace number 9 output $laptop_monitor
workspace number 10 output $left_monitor
# Open applications on specific workspaces
# left monitor
assign [class="libreoffice"]            workspace 1
assign [class="Libreoffice"]            workspace 1
assign [class="mailspring"]             workspace 1
assign [class="Atom"]                   workspace 4
# right monitor
assign [class="Firefox"]                workspace 2
assign [class="discord"]                workspace 5
assign [class="Mattermost"]             workspace 5
assign [class="Hexchat"]                workspace 5
assign [class="gnome-mpv"]              workspace 8
assign [class="vlc"]                    workspace 8
assign [class="molotov"]                workspace 8
assign [class="com.github.tkashkin.gamehub"]  workspace 10
# laptop monitor
assign [class="Nemo"]                   workspace 3
assign [class="Nautilus"]               workspace 3
assign [class="Zotero"]                 workspace 6
assign [class="gnome-calendar"]         workspace 6
assign [class="mupdf"]                  workspace 6

# Change the default layout of specific workspaces
for_window [workspace=$ws1] layout tiled
for_window [workspace=$ws4] layout tiled
for_window [workspace=$ws5] layout tiled
for_window [workspace=$ws8] layout tabbed

########## KEYBINDINGS ##########
# Printscreen
# Save screenshot to ~/Pictures/Screenshots
bindsym Print exec scrot -q 75 ~/Pictures/Screenshots/ss-%Y-%m-%d_%H%M%S.png
# Save screenshot to ~/Pictures/Screenshots and upload to 0x0.st (requires 0x0 script)
bindsym Shift+Print --release exec "scrot -s ~/Pictures/Screenshots/ss-%Y-%m-%d_%H%M%S.png -e '0x0 -f $f'; exec notify-send -u low 'Saved to ~/Pictures/Screenshots and uploaded to 0x0.st'"
# Save screenshot to ~/Pictures/Screenshots and copy image to clipboard
bindsym Ctrl+Print --release exec "scrot -s ~/Pictures/Screenshots/ss-%Y-%m-%d_%H%M%S.png -e 'xclip -selection clipboard -t image/png -i $f'; exec notify-send -u low 'Saved to ~/Pictures/Screenshots and copied to clipboard'"

# Toggle i3-bar visibility
bindsym $mod+b bar mode toggle

# Move floating window with the mouse
floating_modifier $mod

# Start rofi
bindsym $mod+Tab exec "rofi -no-lazy-grab -show drun -theme themes/appsmenu.rasi"

# Start dmenu (a program launcher)
# bindsym $mod+d exec dmenu_run

# Start tilix
bindsym $mod+Return exec tilix

# Start tilix quake
bindsym Shift+Ctrl+space exec tilix --quake

# Start nautilus
bindsym $mod+n exec nautilus

# Start nautilus in floating mode
bindsym Shift+$mod+n exec nautilus --name floating

# Open link (containing a video) in the clipboard in a floating video player
# In Firefox: Ctrl+L -> Ctrl+C -> $mod+y (full combo to open the video of the active tab)
bindsym $mod+y exec mpv "$(xclip -selection c -out)"

# Kill focused window
bindsym $mod+Shift+q kill
bindsym $mod+BackSpace kill

# Change focus
bindsym $mod+$left focus left
bindsym $mod+$down focus down
bindsym $mod+$up focus up
bindsym $mod+$right focus right

bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

# Move focused window
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+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# Split in horizontal orientation
bindsym $mod+h split h

# Split in vertical orientation
bindsym $mod+v split v

# Enter fullscreen mode for the focused container
bindsym $mod+f fullscreen toggle

# Change container layout (stacked, tabbed, toggle split)
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split

# Toggle tiling/floating
bindsym $mod+Shift+space floating toggle

# Toggle sticky
bindsym $mod+Shift+s sticky toggle

# Change focus between tiling and floating windows
bindsym $mod+space focus mode_toggle

# Focus the parent container
bindsym $mod+a focus parent
focus_follows_mouse no

# Focus the child container
bindsym $mod+d focus child

# Move currently focused window to the scratchpad (minimise)
# and give it a mark to be able to recall it individually without
# cycling through all scratchpad windows (which would be the default behavior)
bindsym $mod+Ctrl+1 mark "scratch1", move scratchpad
bindsym $mod+mod1+1 [con_mark="scratch1"] scratchpad show
bindsym $mod+Ctrl+2 mark "scratch2", move scratchpad
bindsym $mod+mod1+2 [con_mark="scratch2"] scratchpad show
bindsym $mod+Ctrl+3 mark "scratch3", move scratchpad
bindsym $mod+mod1+3 [con_mark="scratch3"] scratchpad show
bindsym $mod+Ctrl+4 mark "scratch4", move scratchpad
bindsym $mod+mod1+4 [con_mark="scratch4"] scratchpad show
bindsym $mod+Ctrl+5 mark "scratch5", move scratchpad
bindsym $mod+mod1+5 [con_mark="scratch5"] scratchpad show
bindsym $mod+Ctrl+6 mark "scratch6", move scratchpad
bindsym $mod+mod1+6 [con_mark="scratch6"] scratchpad show
bindsym $mod+Ctrl+7 mark "scratch7", move scratchpad
bindsym $mod+mod1+7 [con_mark="scratch7"] scratchpad show
bindsym $mod+Ctrl+8 mark "scratch8", move scratchpad
bindsym $mod+mod1+8 [con_mark="scratch8"] scratchpad show
bindsym $mod+Ctrl+9 mark "scratch19", move scratchpad
bindsym $mod+mod1+9 [con_mark="scratch9"] scratchpad show
bindsym $mod+Ctrl+0 mark "scratch10", move scratchpad
bindsym $mod+mod1+0 [con_mark="scratch10"] scratchpad show

# Gaps control
bindsym $mod+Shift+g            gaps inner current plus $gaps_variation
bindsym $mod+Ctrl+g             gaps inner current minus $gaps_variation
bindsym $mod+g                  gaps inner current set $gaps_inner

# Switch to workspace
bindsym $mod+1 workspace number 1
bindsym $mod+2 workspace number 2
bindsym $mod+3 workspace number 3
bindsym $mod+4 workspace number 4
bindsym $mod+5 workspace number 5
bindsym $mod+6 workspace number 6
bindsym $mod+7 workspace number 7
bindsym $mod+8 workspace number 8
bindsym $mod+9 workspace number 9
bindsym $mod+0 workspace number 10

# Move focused container to workspace
bindsym $mod+Shift+1 move container to workspace number 1
bindsym $mod+Shift+2 move container to workspace number 2
bindsym $mod+Shift+3 move container to workspace number 3
bindsym $mod+Shift+4 move container to workspace number 4
bindsym $mod+Shift+5 move container to workspace number 5
bindsym $mod+Shift+6 move container to workspace number 6
bindsym $mod+Shift+7 move container to workspace number 7
bindsym $mod+Shift+8 move container to workspace number 8
bindsym $mod+Shift+9 move container to workspace number 9
bindsym $mod+Shift+0 move container to workspace number 10

# Move container
bindsym $mod+z move workspace to output $left_monitor
bindsym $mod+x move workspace to output $right_monitor
bindsym $mod+c move workspace to output $laptop_monitor

# Reload the configuration file
bindsym $mod+Shift+c reload

# Restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+r restart

# Exit i3 (logs you out of your X session)
bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"

# Display a qrcode for the current clipboard
bindsym $mod+F12 exec --no-startup-id xclip -selection c -out | qrencode -s 8 -o /tmp/qr_code.png && mupdf-x11 /tmp/qr_code.png && rm /tmp/qr_code.png

# Backlight
# Note: If light doesn't work, install xbacklight and 1) uncomment the two lines below.
# 2) Comment out the exec light lines.
#bindsym XF86MonBrightnessUp exec xbacklight -inc 10
#bindsym XF86MonBrightnessDown exec xbacklight -dec 10
bindsym XF86MonBrightnessUp exec light -A 10 # Increase Brightness
bindsym XF86MonBrightnessDown exec light -U 10 # Decrease Brightness

# Media Player
bindsym XF86AudioPlay exec playerctl play-pause
bindsym XF86AudioPause exec playerctl pause
bindsym XF86AudioPrev exec playerctl previous
bindsym XF86AudioNext exec playerctl next

# Sound
# Raise Volume
bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -D pulse sset Master 5%+ && paplay /usr/share/sounds/freedesktop/stereo/audio-volume-change.oga
# Lower Volume
bindsym XF86AudioLowerVolume exec --no-startup-id amixer -D pulse sset Master 5%- && paplay /usr/share/sounds/freedesktop/stereo/audio-volume-change.oga
bindsym XF86AudioMute exec --no-startup-id amixer -D pulse sset Master toggle-mute # Toggle muting

# Show help
bindsym $mod+F1 exec grep -A200 KEYBINDINGS ~/.config/i3/config | tee -a ${test} | yad --text-info --width=800 --height=1000 --name floating --no-buttons --close-on-unfocus --lang=markdown --title="i3wm keybindings"

# Fancy lock screen
bindsym Ctrl+Shift+l exec ~/.config/i3/tools/i3lock-fancy-rapid/i3lock-fancy-rapid 20 3 -f

# System shutdown mode, using ~/.config/i3/i3exit
set $system System [l]ock, log [o]ut, [s]uspend, [h]ibernate, [r]eboot, [Shift+s]hutdown
mode "$system" {
    # These bindings trigger as soon as you enter the $system mode
    # works only on systemctl based distributions
    bindsym l exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1, exec --no-startup-id ~/.config/i3/i3exit lock, mode "default"
    bindsym e exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1, exec --no-startup-id ~/.config/i3/i3exit logout, mode "default"
    bindsym s exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1, exec --no-startup-id ~/.config/i3/i3exit suspend, mode "default"
    bindsym h exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1, exec --no-startup-id ~/.config/i3/i3exit hibernate, mode "default"
    bindsym r exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1, exec --no-startup-id ~/.config/i3/i3exit reboot, mode "default"
    bindsym Shift+s exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1, exec --no-startup-id i3exit shutdown, mode "default"

    # back to normal: Enter or Escape
    bindsym Return mode "default", exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1
    bindsym Escape mode "default", exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1
}

bindsym $mod+Escape mode "$system", exec --no-startup-id xrandr --output $laptop_monitor --brightness 0.7, exec --no-startup-id xrandr --output $left_monitor --brightness 0.7, exec --no-startup-id xrandr --output $right_monitor --brightness 0.7

# Resize mode (you can also use the mouse for that)
# Tiled and floating windows can be resized using $mod+right click
mode "resize" {
        # These bindings trigger as soon as you enter the resize mode
        # Pressing left will shrink the window’s width.
        # Pressing right will grow the window’s width.
        # Pressing up will shrink the window’s height.
        # Pressing down will grow the window’s height.
        bindsym $left       resize shrink width 10 px or 10 ppt
        bindsym $down       resize grow height 10 px or 10 ppt
        bindsym $up         resize shrink height 10 px or 10 ppt
        bindsym $right      resize grow width 10 px or 10 ppt

        # same bindings, but for the arrow keys
        bindsym Left        resize shrink width 10 px or 10 ppt
        bindsym Down        resize grow height 10 px or 10 ppt
        bindsym Up          resize shrink height 10 px or 10 ppt
        bindsym Right       resize grow width 10 px or 10 ppt

        # back to normal: Enter or Escape or $mod+r
        bindsym Return mode "default", exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1
        bindsym Escape mode "default", exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1
        bindsym $mod+r mode "default", exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1
}

bindsym $mod+r mode "resize", exec --no-startup-id xrandr --output $laptop_monitor --brightness 0.7, exec --no-startup-id xrandr --output $left_monitor --brightness 0.7, exec --no-startup-id xrandr --output $right_monitor --brightness 0.7

# Display layout
set $displayLayout Display layout: [s]ingle, [t]riple (work), [h]orizontal dual (work), [v]ertical dual (work)
mode "$displayLayout" {
    bindsym s         exec --no-startup-id autorandr -l single, mode "default"
    bindsym t         exec --no-startup-id autorandr -l triple_work, mode "default"
    bindsym h         exec --no-startup-id autorandr -l dual_work_horizontal, mode "default"
    bindsym v         exec --no-startup-id autorandr -l dual_work_vertical, mode "default"
    bindsym d         exec --no-startup-id autorandr -l dual_work_diagonal, mode "default"
    bindsym Return    mode "default", exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1
    bindsym Escape    mode "default", exec --no-startup-id xrandr --output $laptop_monitor --brightness 1, exec --no-startup-id xrandr --output $left_monitor --brightness 1, exec --no-startup-id xrandr --output $right_monitor --brightness 1
}

bindsym $mod+Print    mode "$displayLayout", exec --no-startup-id xrandr --output $laptop_monitor --brightness 0.7, exec --no-startup-id xrandr --output $left_monitor --brightness 0.7, exec --no-startup-id xrandr --output $right_monitor --brightness 0.7

########## STYLING ##########
# class                 border  backgr. text    indicator child_border
client.focused          #404552 #404552 #fafafa #ff5757 #5294E2
client.focused_inactive #666666 #404552 #eeeeee #666666 #262626
client.unfocused        #404552 #484b52 #eeeeee #ff5757 #262626
client.urgent           #ff5757 #404552 #ffffff #555757 #EFEDEC
client.background       #404552

########## i3-gaps INTEGRATION ##########
for_window [class="^.*"] border pixel 2
for_window [window_role="pop-up"] floating enable
for_window [window_role="task_dialog"] floating enable
for_window [title="Preferences$"] floating enable

smart_borders no_gaps
smart_gaps on
gaps outer 0
set $gaps_inner 10
set $gaps_variation 4

# Font for window titles. Will also be used by the bar unless a different font is used in the bar.
font pango:RobotoMono 10

######### FLOATING #########
# Rules for floating windows
# Use the command `xprop WM_CLASS` to get a window's class
for_window [instance="floating"] floating enable
for_window [class="mpv"] floating enable, sticky toggle, resize set 730 308, exec --no-startup-id ~/.config/i3/scripts/window_relocate.sh "bottom" "right"
for_window [class="vlc"] floating enable
for_window [class="Peek"] floating enable
for_window [class="File-roller"] floating enable
for_window [window_role="pop-up"] floating enable
for_window [window_role="task_dialog"] floating enable