From bc5ef8dd70268880e00de4990cda3de647237e36 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Thu, 21 Nov 2024 10:02:37 +0100 Subject: [PATCH] sway: Fix dropdown terminals not being brought into focus when toggled --- .config/sway/config | 4 ++-- .local/bin/swayvm-toggle-scratchpad | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100755 .local/bin/swayvm-toggle-scratchpad diff --git a/.config/sway/config b/.config/sway/config index 28ad21a..478947d 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -120,8 +120,8 @@ bar { ### Key bindings # Dropdown terminals - bindsym $mod+u [app_id="dropdown1"] scratchpad show - bindsym $mod+Shift+u [app_id="dropdown2"] scratchpad show + bindsym $mod+u exec ~/.local/bin/swayvm-toggle-scratchpad dropdown1 + bindsym $mod+Shift+u exec ~/.local/bin/swayvm-toggle-scratchpad dropdown2 # Browser bindsym $mod+Shift+t exec firefox diff --git a/.local/bin/swayvm-toggle-scratchpad b/.local/bin/swayvm-toggle-scratchpad new file mode 100755 index 0000000..db396b8 --- /dev/null +++ b/.local/bin/swayvm-toggle-scratchpad @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +target=$1 +data=$(swaymsg -t get_tree | jq ".. | select(.type?) | select(.app_id==\"$target\" or .window_properties.class==\"$target\")") +id=$(echo "$data" | jq ".id") +is_visible=$(echo "$data" | jq ".visible") + +if [[ "$is_visible" == "true" ]]; then + swaymsg "[con_id=$id] scratchpad show" + exit +fi + +swaymsg "[con_id=$id] scratchpad show" && swaymsg "[con_id=$id] focus"