From e2395d12cfa14491c55bef07fa8c11bdf4ce9d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Tue, 5 Jul 2022 22:27:10 +0200 Subject: [PATCH] Add proper script to toggle workspace window --- i3/config.j2 | 22 +----------- i3/scripts/swap-from-workspace.sh | 59 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 21 deletions(-) create mode 100755 i3/scripts/swap-from-workspace.sh diff --git a/i3/config.j2 b/i3/config.j2 index 3edc4c9..4b13260 100644 --- a/i3/config.j2 +++ b/i3/config.j2 @@ -226,27 +226,7 @@ assign [class="^Wine$"] $workspace10 bindsym $mod+Shift+v exec --no-startup-id redshift-toggle - # bindsym $mod+$pim_toggle \ - # mark --add _source; \ - # focus output eDP-1; \ - # mark --add _origin; \ - # workspace $workspace10; \ - # mark --add _destination; \ - # [con_mark="^_destination$"] swap container with mark "_source"; \ - # [con_mark="^_source$"] focus; unmark _source; \ - # [con_mark="^_origin$"] focus; unmark _origin; \ - # [con_mark="^_destination$"] focus; unmark _destination; \ - - bindsym $mod+$pim_toggle \ - unmark _destination; \ - mark _source; \ - workspace $workspace10; \ - mark --add _destination; \ - [con_mark="^_destination$"] swap container with mark "_source"; \ - [con_mark="^_source$"] focus; \ - unmark _source; \ - [con_mark="^_destination$"] focus; \ - unmark _destination; + bindsym $mod+$pim_toggle exec --no-startup-id ~/.i3/scripts/swap-from-workspace.sh $workspace10 ################################################################################ ### MODES ###################################################################### diff --git a/i3/scripts/swap-from-workspace.sh b/i3/scripts/swap-from-workspace.sh new file mode 100755 index 0000000..7706be2 --- /dev/null +++ b/i3/scripts/swap-from-workspace.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +set -o nounset +set -o errexit +set -o pipefail +set -o xtrace + +cmds=() + +workspacescratch="${1}" + +i3msgworkspaces="$(i3-msg -t get_workspaces)" + +output_of_pim=$(printf '%s' "${i3msgworkspaces}" | jq -r 'map(select(.name == "'"${workspacescratch}"'")) | .[0].output') + +active_workspace_on_target_output=$(printf '%s' "${i3msgworkspaces}" | jq -r 'map(select(.output == "'"${output_of_pim}"'" and .visible)) | .[0].name') + +focused_workspace_name=$(printf '%s' "${i3msgworkspaces}" | jq -r 'map(select(.focused)) | .[0].name') +focused_workspace_output=$(printf '%s' "${i3msgworkspaces}" | jq -r 'map(select(.focused)) | .[0].output') + +if [[ "${focused_workspace_name}" == "${workspacescratch}" ]]; then + exit 0 +fi + +cmds+=('unmark _destination') +cmds+=('mark _source') + +if [[ "${active_workspace_on_target_output}" != "${workspacescratch}" ]] && [[ "${output_of_pim}" != "${focused_workspace_output}" ]]; then + need_output_reset=1 +else + need_output_reset=0 +fi + +if ((need_output_reset)); then + cmds+=('workspace "'"${active_workspace_on_target_output}"'"') + cmds+=("mark --add _origin") +fi + +cmds+=('workspace "'"${workspacescratch}"'"') +cmds+=('mark --add _destination') + +cmds+=('[con_mark="^_destination$"] swap container with mark "_source"') + +cmds+=('[con_mark="^_source$"] focus') +cmds+=('unmark _source') + +if ((need_output_reset)); then + cmds+=('[con_mark="^_origin$"] focus') + cmds+=('unmark _origin') +fi + +cmds+=('[con_mark="^_destination$"] focus') +cmds+=('unmark _destination') + +i3msgcmd="" +for cmd in "${cmds[@]}"; do + i3msgcmd="${i3msgcmd}${cmd};" +done +i3-msg "${i3msgcmd}"