Updated the GTK+ implementation and test programs to reflect the new KeyEvent setup.
This commit is contained in:
parent
4dd7eebc31
commit
07a877fa6e
20
area_unix.go
20
area_unix.go
|
@ -180,28 +180,22 @@ func doKeyEvent(widget *C.GtkWidget, event *C.GdkEvent, data C.gpointer, up bool
|
|||
var ke KeyEvent
|
||||
|
||||
e := (*C.GdkEventKey)(unsafe.Pointer(event))
|
||||
fmt.Println("$$", up, e.hardware_keycode)
|
||||
s := (*sysData)(unsafe.Pointer(data))
|
||||
keyval := e.keyval
|
||||
if extkey, ok := extkeys[keyval]; ok {
|
||||
ke.ExtKey = extkey
|
||||
} else if predef, ok := predefkeys[keyval]; ok {
|
||||
ke.ASCII = predef
|
||||
// } else if predef, ok := predefkeys[keyval]; ok {
|
||||
// ke.ASCII = predef
|
||||
} else if mod, ok := modonlykeys[keyval]; ok {
|
||||
// modifier keys don't seem to be set on their initial keypress; set them here
|
||||
ke.Modifiers |= mod
|
||||
} else {
|
||||
cp := C.gdk_keyval_to_unicode(keyval)
|
||||
// GDK keycodes in GDK 3.4 the ASCII plane map to their ASCII values
|
||||
// (proof: https://git.gnome.org/browse/gtk+/tree/gdk/gdkkeysyms.h?h=gtk-3-4)
|
||||
// this also handles the numeric keypad keys (proof: https://git.gnome.org/browse/gtk+/tree/gdk/gdkkeyuni.c?h=gtk-3-4#n846)
|
||||
// the cp < 0x20 will also handle the case where the key is totally unknown to us (gdk_keyval_to_unicode() returns 0) and the space key
|
||||
if cp < 0x20 || cp >= 0x7F {
|
||||
// TODO really stop here? or should we handle modifiers?
|
||||
} else if key, ok := scancodeMap[uintptr(e.hardware_keycode) - 8]; ok {
|
||||
// see events_notdarwin.go for details of the above map lookup
|
||||
ke.Key = key
|
||||
} else { // no match
|
||||
// TODO really stop here? [or should we handle modifiers?]
|
||||
return false // pretend unhandled
|
||||
}
|
||||
ke.ASCII = byte(cp)
|
||||
}
|
||||
state := translateModifiers(e.state, e.window)
|
||||
ke.Modifiers = makeModifiers(state, ke.Modifiers)
|
||||
ke.Up = up
|
||||
|
|
|
@ -49,10 +49,8 @@ func (a *keyboardArea) Key(e KeyEvent) (handled bool, repaint bool) {
|
|||
defer a.lock.Unlock()
|
||||
|
||||
switch {
|
||||
// case e.Key != 0:
|
||||
// markkey(a.kbd, keypoints[e.Key], e.Modifiers)
|
||||
case e.ASCII != 0:
|
||||
markkey(a.kbd, keypoints[e.ASCII], e.Modifiers)
|
||||
case e.Key != 0:
|
||||
markkey(a.kbd, keypoints[e.Key], e.Modifiers)
|
||||
case e.ExtKey != 0:
|
||||
markkey(a.kbd, extkeypoints[e.ExtKey], e.Modifiers)
|
||||
case e.Modifiers != 0:
|
||||
|
|
|
@ -136,7 +136,7 @@ func (a *areaHandler) Mouse(e MouseEvent) bool {
|
|||
return false
|
||||
}
|
||||
func (a *areaHandler) Key(e KeyEvent) (bool, bool) {
|
||||
fmt.Printf("%#v\n", e)
|
||||
fmt.Printf("%#v %q\n", e, e.Key)
|
||||
return false, false
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue