From 069aadd788d69d1ea6a0f4d44796fd46835f4e6a Mon Sep 17 00:00:00 2001 From: maudin Date: Thu, 24 Sep 2020 10:11:02 +0200 Subject: [PATCH] better workspace management --- .gitignore | 1 + bin/create_workspaces | 26 ++++++++++++++++++++++++++ bin/focus_workspace | 14 +++++++++----- bin/menu_workspace_switch | 2 +- config | 3 +++ 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100755 bin/create_workspaces diff --git a/.gitignore b/.gitignore index 16775c5..87e0137 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +env run/previous_* diff --git a/bin/create_workspaces b/bin/create_workspaces new file mode 100755 index 0000000..14467ee --- /dev/null +++ b/bin/create_workspaces @@ -0,0 +1,26 @@ +#! /bin/bash + +. ~/.config/i3/env + +usage() { + echo "usage: create_workspaces" +} + +if [ $# -ne 0 ]; then + usage; exit 1 +fi + +if [ -n "${SECONDARY_OUTPUT}" ]; then + for i in $(seq 11 19); do + i3-msg -q workspace number $i + i3-msg -q move workspace to output ${SECONDARY_OUTPUT} + done + i3-msg -q workspace number 11 +fi +if [ -n "${PRIMARY_OUTPUT}" ]; then + for i in $(seq 1 9); do + i3-msg -q workspace number $i + i3-msg -q move workspace to output ${SECONDARY_OUTPUT} + done +fi +i3-msg -q workspace number 1 diff --git a/bin/focus_workspace b/bin/focus_workspace index 82db1d9..b9d839a 100755 --- a/bin/focus_workspace +++ b/bin/focus_workspace @@ -1,5 +1,7 @@ #! /bin/bash +. ~/.config/i3/env + usage() { echo "usage: focus_workspace [previous|left|right|1-42]" } @@ -9,22 +11,24 @@ if [ $# -ne 1 ]; then fi CURRENT_OUTPUT=$(i3-msg -t get_workspaces | jq -r ".[] | select(.focused==true).output") +CURRENT_WORKSPACE=$(i3-msg -t get_workspaces | jq ".[] | select(.focused==true).num") + if [ $1 == "previous" ]; then NEXT_WORKSPACE=$(cat ~/.config/i3/run/previous_${CURRENT_OUTPUT}) elif [ "$1" == "left" ]; then NEXT_WORKSPACE=$(($(i3-msg -t get_workspaces | jq -r ".[] | select(.focused==true).num") - 1)) - [ ${NEXT_WORKSPACE} -lt 1 ] && NEXT_WORKSPACE=$(i3-msg -t get_workspaces | jq "[.[] | select(.output==\"${CURRENT_OUTPUT}\").num] | max") + [ ${CURRENT_OUTPUT} == "${PRIMARY_OUTPUT}" ] && [ ${NEXT_WORKSPACE} -lt 1 ] && NEXT_WORKSPACE=9 + [ ${CURRENT_OUTPUT} == "${SECONDARY_OUTPUT}" ] && [ ${NEXT_WORKSPACE} -lt 11 ] && NEXT_WORKSPACE=19 elif [ "$1" == "right" ]; then NEXT_WORKSPACE=$(($(i3-msg -t get_workspaces | jq -r ".[] | select(.focused==true).num") + 1)) - [ ${NEXT_WORKSPACE} -gt 42 ] && NEXT_WORKSPACE=$(i3-msg -t get_workspaces | jq "[.[] | select(.output==\"${CURRENT_OUTPUT}\").num] | min") + [ ${CURRENT_OUTPUT} == "${PRIMARY_OUTPUT}" ] && [ ${NEXT_WORKSPACE} -gt 9 ] && NEXT_WORKSPACE=1 + [ ${CURRENT_OUTPUT} == "${SECONDARY_OUTPUT}" ] && [ ${NEXT_WORKSPACE} -gt 19 ] && NEXT_WORKSPACE=11 elif [ $1 -gt 0 ] && [ $1 -lt 43 ]; then - CURRENT_OUTPUT=$(i3-msg -t get_workspaces | jq -r ".[] | select(.num==$1).output") - i3-msg -q "focus output ${CURRENT_OUTPUT}" NEXT_WORKSPACE=$1 + [ ${CURRENT_OUTPUT} == "${SECONDARY_OUTPUT}" ] && [ -z "${ROFI_INPUT}" ] && NEXT_WORKSPACE=$((10 + $1)) else usage; exit 1 fi -CURRENT_WORKSPACE=$(i3-msg -t get_workspaces | jq ".[] | select(.focused==true).num") i3-msg -q "workspace number ${NEXT_WORKSPACE}" # Update previous file in run/ diff --git a/bin/menu_workspace_switch b/bin/menu_workspace_switch index 60e9392..b2520d6 100755 --- a/bin/menu_workspace_switch +++ b/bin/menu_workspace_switch @@ -1,3 +1,3 @@ #!/bin/bash -~/.config/i3/bin/focus_workspace $(i3-msg -t get_workspaces | jq '.[]' | jq -r '.name' | rofi -dmenu -p "Select workspace:" | sed 's/:.*//') +ROFI_INPUT=1 ~/.config/i3/bin/focus_workspace $(i3-msg -t get_workspaces | jq '.[]' | jq -r '.name' | rofi -dmenu -p "Select workspace:" | sed 's/:.*//') diff --git a/config b/config index 34ac118..efae584 100644 --- a/config +++ b/config @@ -1,6 +1,8 @@ set $mod Mod4 floating_modifier $mod +exec --no-startup-id "~/.config/i3/bin/create_workspaces" + ########## # Visual # ########## @@ -80,6 +82,7 @@ bindsym $mod+Shift+9 move container to workspace number 9 # switch/move to output bindsym $mod+s focus output right bindsym $mod+Shift+s move container to output right + ####### # Bar # #######