You are not logged in.

#1 2020-12-18 21:17:18

From: Tel Aviv-Jaffa, Israel
Registered: 2012-08-08
Posts: 102

Hooking into GNOME keyboard layout changes

I have this weird idea for a hardware project, I'm a bilingual user that requires constant usage of two keyboard layouts which I switch between often.
However, the active keyboard layout widget on the GNOME top bar is way too subtle, especially on a large screen where it requires lots of eye movement to focus on.

My thought is to build a simple hardware device, say Arduino-based (but really any board will work here) that will light an RGB LED somewhere around my screen with a different color according to the active keyboard layout.
The hardware part is a no-brainer, but what I'm missing is how to write a script/process that can hook into GNOME keyboard layout changes and send out a signal over serial port to the hardware board to toggle the LED color.

Any ideas on how to do that? As a fallback, if there's no hook/callback I can use, I can periodically poll or make an API call, but would rather have a more performant solution.

The best I got so far is this:

$ gsettings get org.gnome.desktop.input-sources sources
[('xkb', 'us'), ('xkb', 'il')]

but even that doesn't really show me the active layout.

Last edited by yuvadm (2020-12-18 21:22:07)


#2 2020-12-19 14:16:02

Registered: 2020-12-13
Posts: 9

Re: Hooking into GNOME keyboard layout changes

If works properly, "org.gnome.desktop.input-sources.mru-sources" (most-recently-used sources) looks like what you want, and can be monitored by

$ gsettings monitor org.gnome.desktop.input-sources mru-sources

. But it's not reliable as far as I see; sometimes updation stops probably because of IBus status flag. Instead, polling

$ gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval 'imports.ui.status.keyboard.getInputSourceManager()'

directly might be better though it's dirty.


#3 2024-04-23 15:49:01

From: China
Registered: 2020-02-01
Posts: 57

Re: Hooking into GNOME keyboard layout changes

After gnome 41, `org.gnome.Shell.Eval` cannot work in default safe mode. You can:

- Use to enable unsafe mode
- Use to get input method directly

An adherent of hacker culture and open source.


Board footer

Powered by FluxBB