3

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.

  • I think you could change the system's mouse cursor theme (which still can be overridden by applications), but it's probably not possible to configure how the text entry cursor should look on system level, because that is application-specific. – Byte Commander Jan 13 '18 at 20:07
  • @ByteCommander Maybe there is a way to locate keyboard cursor? In that case, it is possible to show something near to the cursor. – GLaz Jan 13 '18 at 20:59
3

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.

| improve this answer | |
  • But that changes only the mouse cursor, not the text cursor, right? I understood the question to be about text cursors... – Byte Commander Jan 14 '18 at 12:27
  • You can change whatever cursor you want... when you colorize text cursor in the theme it will change the text cursor. You just need to have file named "text" in you theme, so in case of "DMZ"-themes, you can just ln -s xterm text and colorize the "xterm" one. Unless of course your app uses it's own, custom cursor... – GreggD Jan 14 '18 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.