Rofi Window Switcher With XFCE (updated, now with icons)
by Emile `iMil' Heitor - 2020-06-13
This bug forbids rofi window mode to give focus to a selected window when click to focus is disabled in XFCE. Using the same trick the first commenter used, I came up with this script which uses wmctrl to handle windows listing, selection and focus:
#!/bin/sh
clicktofocus="xfconf-query -c xfwm4 -p /general/click_to_focus -s "
$clicktofocus true
w=$(wmctrl -l|awk '{$1=$2=$3=""; sub(/^[ \t]+/, ""); print $0}' | \
rofi -dmenu -i -p "Window Switcher")
wmctrl -a "$w"
$clicktofocus false
Not the prettiest method but it emulates rofi -show window
pretty well.
Update
I wasn’t totally satisfied with the look of it, so I added a bit of graphics thanks to font awesome. I created the following mapping file (screenshot because fontawesome fonts probably won’t show up on your browser):
And modified the script like this:
#!/bin/bash
famap="${HOME}/etc/fa-map.txt"
title="Window Switcher"
font="Ubuntu Mono 12"
clicktofocus() {
xfconf-query -c xfwm4 -p /general/click_to_focus -s $1
}
listclean() {
awk '{$1=$2=$3=""; sub(/^[ \t]+/, ""); print $0}'
}
clicktofocus "true"
IFS=$'\n'
w=$(while read l
do
wid=${l%%\ *}
state=$(xprop -id $wid _NET_WM_STATE)
[ ! -z "$(echo \"$state\"|grep -i skip_pager)" ] && \
continue
l=$(echo $l|listclean)
while read i
do
name="${i%:*}"
icon=""
[ ! -z "$(echo \"$l\"|grep -i $name)" ] && \
icon="${i#*:\ }" && break
done < <(cat $famap)
echo -e "$icon\t$l"
done < <(wmctrl -l)| \
sort -u|rofi -dmenu -i -p "$title" -font "$font")
[ ! -z "${w}" ] && wmctrl -a "${w:2}"
clicktofocus "false"
And here’s the result: