Created
April 22, 2020 10:55
-
-
Save lbonn/89d064cde963cfbacabd77e0d3801398 to your computer and use it in GitHub Desktop.
Window switcher for sway ('rofi -show window' clone)
... and i rewrote this so it works with fuzzel, which involved (unfortunately) removing the fancy pango markup, but it should work with anything that supports dmenu now (as long as it also supports rofi's icon system):
https://gitlab.com/anarcat/scripts/-/blob/main/sway-window-menu
Sometimes app_ids are not enough in my experience, and sometimes app_ids don't translate to icons.
I updated @bellecp's script to accommodate this:
row=$(swaymsg -t get_tree | jq -r '
..
| objects
| select(.type == "workspace") as $ws
| ..
| objects
| select(has("app_id"))
| (if .focused == true then "*" else " " end) as $asterisk
| (
if .window_properties.class == "Spotify" then "spotify-client"
elif .window_properties.class == "LM Studio" then "lm-studio"
else .app_id // .window_properties.class // .name
end ) as $icon_name
| "[\($ws.name)] \($asterisk) <span weight=\"bold\">\(.app_id // .window_properties.class)</span> - \(.name) <!-- \(.id) -->\u0000icon\u001f\($icon_name)"
' |
sed 's/&/&/g' |
rofi -dmenu -show-icons -markup-rows -p "window")
if [ ! -z "$row" ]; then
winid=$(echo "$row" | sed 's/.*<!-- \([0-9]*\) -->.*/\1/')
swaymsg "[con_id=$winid] focus"
fi
There probably is a better way at detecting icons (rofi -show window) does a somewhat better job. I guess you might be able to map the app names to icons thorugh their .desktop files.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice. I made a few modifications in order to
rofi -show-icons
jq
to remove latency.The window id is encoded inside the strings passed to rofi hidden inside an html comment, for instace
<!-- 264 -->
, and retrieved later on using sed.