Added code to the GTK+ Area to print the GdkKeymapKeys for a given key value. For GTK+/X11 it appears that we can just use the keyval field... that just leaves GTK+/Wayland (see previous commit). If the same applies, we'll need to see if I can feed artificial keycodes in and it'll still work as expected...

This commit is contained in:
Pietro Gagliardi 2014-03-21 17:05:53 -04:00
parent bf3a692b21
commit d14aed4f47
1 changed files with 22 additions and 0 deletions

View File

@ -161,6 +161,7 @@ var area_motion_notify_event_callback = C.GCallback(C.our_area_motion_notify_eve
func our_area_key_press_event_callback(widget *C.GtkWidget, event *C.GdkEvent, data C.gpointer) C.gboolean {
e := (*C.GdkEventKey)(unsafe.Pointer(event))
fmt.Printf("PRESS %#v\n", e)
pk(e.keyval, e.window)
return C.FALSE // TODO really false?
}
@ -170,7 +171,28 @@ var area_key_press_event_callback = C.GCallback(C.our_area_key_press_event_callb
func our_area_key_release_event_callback(widget *C.GtkWidget, event *C.GdkEvent, data C.gpointer) C.gboolean {
e := (*C.GdkEventKey)(unsafe.Pointer(event))
fmt.Printf("RELEASE %#v\n", e)
pk(e.keyval, e.window)
return C.FALSE // TODO really false?
}
var area_key_release_event_callback = C.GCallback(C.our_area_key_release_event_callback)
func pk(keyval C.guint, window *C.GdkWindow) {
var kk *C.GdkKeymapKey
var nk C.gint
km := C.gdk_keymap_get_for_display(C.gdk_window_get_display(window))
b := C.gdk_keymap_get_entries_for_keyval(km, keyval, &kk, &nk)
if b == C.FALSE {
fmt.Println("(no key equivalent)")
return
}
ok := kk
for i := C.gint(0); i < nk; i++ {
fmt.Println("equiv %d/%d: %#v\n", i + 1, nk, kk)
xkk := uintptr(unsafe.Pointer(kk))
xkk += unsafe.Sizeof(kk)
kk = (*C.GdkKeymapKey)(unsafe.Pointer(xkk))
}
C.g_free(C.gpointer(unsafe.Pointer(ok)))
}