Hi !
I use sway 1.0
Is it possible to see all openend windows (for all workspaces) with a shell command to use it in a rofi or dmenu and to switch to this opened windows and to this workspace -> like a window switcher ? (with rofi i use it this on xfce)
thanks
kind regards
kristoferus75
You can probably accomplish this with swaymsg -t get_tree and [...criteria...] focus. See the man pages for details.
bindsym $mod+g exec swaymsg \[con_id=$(swaymsg -t get_tree | jq -r '.nodes | .[] | .nodes | . [] | select(.nodes != null) | .nodes | .[] | select(.name != null) | "\(.id?) \(.name?)"' | rofi -dmenu -i | awk '{print $1}')] focus
Is my naive bindsym using jq.
Hi Emantor !
Thanks :-)
I have tested it and it shows only the tilled windows and not the floating windows and if im on an oher workspace it doesnt focus to that workspace to that windows !
Sorry i have no idea how to correct this !
Thanks
kind regards kristoferus75
Hi !
With this script it works now :
#!/bin/bash
# Get available windows
windows=$(swaymsg -t get_tree | jq -r '.nodes[1].nodes[].nodes[] | .. | (.id|tostring) + " " + .name?' | grep -e "[0-9]* ." )
# Select window with rofi
selected=$(echo "$windows" | rofi -dmenu -i | awk '{print $1}')
# Tell sway to focus said window
swaymsg [con_id="$selected"] focus
kind regards
kristoferus75
Edit: I realized jq wasn't installed there wasn't any error message. Installing jq fixed it. It now works.
Tweaked the above code to make it work with floating windows:
#!/bin/bash
# Get regular windows
regular_windows=$(swaymsg -t get_tree | jq -r '.nodes[1].nodes[].nodes[] | .. | (.id|tostring) + " " + .name?' | grep -e "[0-9]* ." )
# Get floating windows
floating_windows=$(swaymsg -t get_tree | jq '.nodes[1].nodes[].floating_nodes[] | (.id|tostring) + " " + .name?'| grep -e "[0-9]* ." | tr -d '"')
enter=$'\n'
if [[ $regular_windows && $floating_windows ]]; then
all_windows="$regular_windows$enter$floating_windows"
elif [[ $regular_windows ]]; then
all_windows=$regular_windows
else
all_windows=$floating_windows
fi
# Select window with rofi
selected=$(echo "$all_windows" | rofi -dmenu -i | awk '{print $1}')
# Tell sway to focus said window
swaymsg [con_id="$selected"] focus
I reimplemented the above snipped in python, removing the need to include the window id for wofi, dropping the jq dependency and improving startup time by ~40% on my laptop, running in power saving mode.
See here: https://github.com/tobiaspc/wofi-scripts
Most helpful comment
Hi !
With this script it works now :
kind regards
kristoferus75