Is it possible to have some indication of input language on keyboard cursor (or near it) or maybe change cursor color dependently on input language?
I think it would be a great addition for those who use more than one language to input.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
It certainly is possible, but the solution for that I came up with is very... ugly.
First of all, you would need to create you own cursor themes with your own colors. You can copy ones that you have in
/usr/share/icons (check for folders that contain
cursor.theme file) into your users
~/.icons folder, rename them by your choice and colorize. For the proof-of-concept I'll show you rest by just using cursor themes that should already be available in the system. Let's say "DMZ-White" and "DMZ-Black".
As for colorizing cursors, you can do it with GIMP and it's "colorize" function/filter, but you gotta apply it to all layers (different sizes) and then export those files with
.xmc extension and then strip that extension, so the names are like in the original, source theme.
Various desktop environments have different methods for storing current keyboard layout and for the one I'm working on (MATE) I wasn't even able to figure out a nice method, so I needed to use
xset -q which returns very meaningless "mask" that's different for each keyboard layout.
Try running this command after switching keyboard layouts:
xset -q | grep -A 0 'LED' | cut -c59-67
It should give you something like "00000002" for one layout and "00001002" for the other. You will need those values later on.
Now you gotta figure out how to change a cursor theme by a command at your environment.
Here's what works on MATE:
gsettings set org.mate.peripherals-mouse cursor-theme 'DMZ-Black'
... and this should probably work on GNOME:
gsettings set org.gnome.desktop.interface cursor-theme 'DMZ-Black'
If you don't know the proper names for your cursor themes, just switch them by GUI and check:
gsettings get org.mate.peripherals-mouse cursor-theme gsettings get org.gnome.desktop.interface cursor-theme
And now... the ugliest part - putting it all together and running a script on loop with given interval that will change a cursor according to a value from
xset. Here's a simple one that does that:
#!/bin/bash current=$(gsettings get org.mate.peripherals-mouse cursor-theme) echo "STARTING WITH: $current" while [ "true" ]; do xval=$(xset -q | grep -A 0 'LED' | cut -c59-67) if [ "$xval" == "00000002" ]; then if [ "$current" != "'DMZ-Black'" ]; then current="'DMZ-Black'" echo "CHANGING TO: $current" gsettings set org.mate.peripherals-mouse cursor-theme $current fi elif [ "$xval" == "00001002" ]; then if [ "$current" != "'DMZ-White'" ]; then current="'DMZ-White'" echo "CHANGING TO: $current" gsettings set org.mate.peripherals-mouse cursor-theme $current fi fi sleep 1 # one-second interval between each re-check done
Put this script in some file, apply
chmod +x to it (executable permission) and after configuring accordingly to your situation and testing in terminal (f.e.
bash /home/glaz/my-dynamic-cursor-script), you can add it to your auto-start and ~VIOLA~
Maybe not the nicest solution, but it does the job - at least for me :)
Oh... It also works when you are using that feature, that allows for a different input-layout for each window, so when you change focus to different window, cursor also updates. However it will not work over applications that are using their own, custom cursors - such cases would require that other idea you had: to follow a cursor in real-time and render some overlay next to it, but I don't think that it's as easy as this... it might require coding some specialized app/daemon that would perform just that.