I am trying to get the current state of keyboard modifiers through the gnome GDK or GTK library in order to implement the gnome accessibility shell extension that shows this state.
I know how to get its state using xlib, but there is no full binding for gns gjs.
The code below gets only the initial state. It does not update state.
#include <gdk/gdk.h>
int main (int argc, char **argv) {
gdk_init(&argc, &argv);
GdkDisplay * disp;
disp = gdk_display_open(NULL);
if (disp!=NULL) g_printf("display connected!\n");
GdkKeymap * kmap;
kmap = gdk_keymap_get_for_display(disp);
guint state;
state = gdk_keymap_get_modifier_state(kmap);
g_printf("mod state: %x\n", state);
while (1) {
g_usleep(1000000);
state = gdk_keymap_get_modifier_state(kmap);
g_printf("mod state: %x\n", state);
}
}
Here's an example of CAPS-locked output active, then inactive, but not changing:
$ ./gdk_mod
display found!
mod state: 2
mod state: 2
mod state: 2
mod state: 2
mod state: 2
^C
Currently used by Kubuntu 15.04.
What is wrong with my code?
source
share