Re: GdkKeymap default for Display problem



Following this up:

Using Gtk 3.22.11 under Debian stable I get a different keymap than
the
one the application was launched with on calling 

gdk_keymap_get_for_display(gdk_display_get_default ())

This shows up when there are two keymaps available and I select the
alternative one for a terminal, launch the application and then use 

gdk_keymap_translate_keyboard_state ()

what happens is that it is *not* translated using the keymap that was
used to launch the application (and which shows up in GtkEntry etc
widgets). Instead it is translated using the "default" keymap for the
Desktop.
This lead me to look at the documentation and I see that there is
nothing to suggest you can access the GdkKeymap that the GtkWidgets
are
using - indeed there is nothing to suggest you can create a GdkKeymap
other than getting this "default for display" keymap.

Is there something I've missed here?

Richard Shann

I've created a minimal example of the problem:

//gcc -Wall KeyMap-test.c -o KeyMapTest `pkg-config --cflags --libs gtk+-3.0`
//Tested on debian stable and GTK3.22.18

#include<gtk/gtk.h>
static void callback (GtkWidget * widget, GdkEventKey * event)
{
   guint keyval;
   g_print ("key press event: keyval %d (%s)\n", event->keyval, gdk_keyval_name(event->keyval));
   gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), event->hardware_keycode,0,0, &keyval, 
NULL, NULL, NULL); 
   g_print ("After keymap translate keyval %d (%s)\n", keyval, gdk_keyval_name(keyval));
}
int main(int argc, char **argv)
 {
   gtk_init(&argc, &argv);

   GtkWidget *top_window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
   g_signal_connect (top_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
   g_signal_connect (G_OBJECT(top_window), "key-press-event", G_CALLBACK (callback), NULL);
   gtk_widget_show_all (top_window);

   gtk_main();

   return 0;  
 }

The output on setting a US keyboard in the terminal with a UK keyboard
as the desktop default and pressing the key code 51

rshann@debian:~$ ./KeyMapTest 
key press event: keyval 92 (backslash)
After keymap translate keyval 35 (numbersign)

The US key map is used for the GtkWindow widget to provide the keyval
92 but then the UK keymap is used for the call to
gdk_keymap_translate_keyboard_state() giving the keyval 35

Is this a bug in Gtk 3.22?

Richard






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]