trigger a notification every time my keyboard is changed

alexΒ 29th April 2024 at 3:10pm

I cycle between three keyboards on my computer: english, portuguese, and now greek. There is no visual feedback as to what keyboard is currently active β€” and then I have to press some random keys to get information. I'd like a notification!


I found xkb-switch, which displays the current active layout.

Created a simple shell script,

#!/bin/bash

curr=$(xkb-switch)
echo $curr
if [ $curr == "us" ]; then
	dunstctl close-all && dunstify 'πŸ‡ΊπŸ‡Έ'
elif [ $curr == "pt" ]; then
	dunstctl close-all && dunstify 'πŸ‡΅πŸ‡Ή'
else
	dunstctl close-all && dunstify 'πŸ‡¬πŸ‡·'
fi

that closes previous notifications and displays a flag according to each current layout. With the use of xbindkeys, and a .xbindkeysrc file,

"dunstctl close-all"
alt + c

"keyboard-map-notif"
alt + z

"keyboard-map-notif"
alt + space

alt + space will show the current layout, z will trigger the change and display it β€” it works in tandem with my previous changing keyboard layouts configuration β€” and c will just clear notifications, while we're at it.