Rofi Window Switcher With XFCE (updated, now with icons)

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:


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.


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):

font awesome mapping

And modified the script like this:


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"

w=$(while read l
	wid=${l%%\ *}
	state=$(xprop -id $wid _NET_WM_STATE) 
	[ ! -z "$(echo \"$state\"|grep -i skip_pager)" ] && \
	l=$(echo $l|listclean)
	while read i
		[ ! -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:

my own rofi window switcher