mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Linux Keybinds
- Adds getKeyboardState into linux_cgo to parse keypress event and transfer it into an accelerator for the handleKeyEvent using GDK keycodes
This commit is contained in:
parent
d65f1b1647
commit
f122db2e7b
3 changed files with 202 additions and 8 deletions
|
|
@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
click by @5aaee9 in [#2991](https://github.com/wailsapp/wails/pull/2991)
|
||||
- [darwin] add getPrimaryScreen/getScreens to impl by @tmclane in
|
||||
[#2618](https://github.com/wailsapp/wails/pull/2618)
|
||||
- [linux] add onKeyPress logic to convert linux keypress into an accelerator @[Atterpac](https://github.com/Atterpac) in[#3022](https://github.com/wailsapp/wails/pull/3022])
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
|||
165
v3/pkg/application/keys_linux.go
Normal file
165
v3/pkg/application/keys_linux.go
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
//go:build linux
|
||||
|
||||
package application
|
||||
|
||||
var VirtualKeyCodes = map[uint]string{
|
||||
0xff08: "backspace",
|
||||
0xff09: "tab",
|
||||
0xff0a: "linefeed",
|
||||
0xff0b: "clear",
|
||||
0xff0d: "return",
|
||||
0xff13: "pause",
|
||||
0xff14: "scrolllock",
|
||||
0xff15: "sysreq",
|
||||
0xff1b: "escape",
|
||||
0xffff: "delete",
|
||||
0xff50: "home",
|
||||
0xff51: "left",
|
||||
|
||||
0xffe1: "lshift",
|
||||
0xffe2: "rshift",
|
||||
0xffe3: "lcontrol",
|
||||
0xffe4: "rcontrol",
|
||||
0xffeb: "lmeta",
|
||||
0xffec: "rmeta",
|
||||
0xffed: "lalt",
|
||||
0xffee: "ralt",
|
||||
// Multi-Lang
|
||||
0xff21: "kanji",
|
||||
0xff22: "muhenkan",
|
||||
0xff24: "henkan",
|
||||
0xff25: "hiragana",
|
||||
0xff26: "katakana",
|
||||
0xff27: "hiragana/katakana",
|
||||
0xff28: "zenkaku",
|
||||
0xff29: "hankaku",
|
||||
0xff2a: "zenkaku/hankaku",
|
||||
0xff2b: "touroku",
|
||||
0xff2c: "massyo",
|
||||
0xff2d: "kana lock",
|
||||
0xff2e: "kana shift",
|
||||
0xff2f: "eisu shift",
|
||||
0xff30: "eisu toggle",
|
||||
0xff37: "kanji bangou",
|
||||
|
||||
// Directions
|
||||
0xff52: "up",
|
||||
0xff53: "right",
|
||||
0xff54: "down",
|
||||
0xff55: "pageup",
|
||||
0xff56: "pagedown",
|
||||
0xff57: "end",
|
||||
0xff58: "begin",
|
||||
|
||||
|
||||
// Alphabet
|
||||
0x41: "a",
|
||||
0x42: "b",
|
||||
0x43: "c",
|
||||
0x44: "d",
|
||||
0x45: "e",
|
||||
0x46: "f",
|
||||
0x47: "g",
|
||||
0x48: "h",
|
||||
0x49: "i",
|
||||
0x4a: "j",
|
||||
0x4b: "k",
|
||||
0x4c: "l",
|
||||
0x4d: "m",
|
||||
0x4e: "n",
|
||||
0x4f: "o",
|
||||
0x50: "p",
|
||||
0x51: "q",
|
||||
0x52: "r",
|
||||
0x53: "s",
|
||||
0x54: "t",
|
||||
0x55: "u",
|
||||
0x56: "v",
|
||||
0x57: "w",
|
||||
0x58: "x",
|
||||
0x59: "y",
|
||||
0x5a: "z",
|
||||
|
||||
0x5b: "lbracket",
|
||||
0x5c: "backslash",
|
||||
0x5d: "rbracket",
|
||||
0x5e: "caret",
|
||||
0x5f: "underscore",
|
||||
0x60: "grave",
|
||||
// Capital Alphabet
|
||||
0x61: "a",
|
||||
0x62: "b",
|
||||
0x63: "c",
|
||||
0x64: "d",
|
||||
0x65: "e",
|
||||
0x66: "f",
|
||||
0x67: "g",
|
||||
0x68: "h",
|
||||
0x69: "i",
|
||||
0x6a: "j",
|
||||
0x6b: "k",
|
||||
0x6c: "l",
|
||||
0x6d: "m",
|
||||
0x6e: "n",
|
||||
0x6f: "o",
|
||||
0x70: "p",
|
||||
0x71: "q",
|
||||
0x72: "r",
|
||||
0x73: "s",
|
||||
0x74: "t",
|
||||
0x75: "u",
|
||||
0x76: "v",
|
||||
0x77: "w",
|
||||
0x78: "x",
|
||||
0x79: "y",
|
||||
0x7a: "z",
|
||||
0x7b: "lbrace",
|
||||
0x7c: "pipe",
|
||||
0x7d: "rbrace",
|
||||
0x7e: "tilde",
|
||||
0xa1: "exclam",
|
||||
0xa2: "cent",
|
||||
0xa3: "sterling",
|
||||
0xa4: "currency",
|
||||
0xa5: "yen",
|
||||
0xa6: "brokenbar",
|
||||
0xa7: "section",
|
||||
0xa8: "diaeresis",
|
||||
0xa9: "copyright",
|
||||
0xaa: "ordfeminine",
|
||||
0xab: "guillemotleft",
|
||||
0xad: "hyphen",
|
||||
0xae: "registered",
|
||||
0xaf: "macron",
|
||||
0xb0: "degree",
|
||||
0xb1: "plusminus",
|
||||
0xb2: "twosuperior",
|
||||
|
||||
// Function Keys
|
||||
0xffbe: "f1",
|
||||
0xffbf: "f2",
|
||||
0xffc0: "f3",
|
||||
0xffc1: "f4",
|
||||
0xffc2: "f5",
|
||||
0xffc3: "f6",
|
||||
0xffc4: "f7",
|
||||
0xffc5: "f8",
|
||||
0xffc6: "f9",
|
||||
0xffc7: "f10",
|
||||
0xffc8: "f11",
|
||||
0xffc9: "f12",
|
||||
0xffca: "f13",
|
||||
0xffcb: "f14",
|
||||
0xffcc: "f15",
|
||||
0xffcd: "f16",
|
||||
0xffce: "f17",
|
||||
0xffcf: "f18",
|
||||
0xffd0: "f19",
|
||||
0xffd1: "f20",
|
||||
0xffd2: "f21",
|
||||
0xffd3: "f22",
|
||||
0xffd4: "f23",
|
||||
0xffd5: "f24",
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1035,17 +1035,45 @@ func onDragNDrop(target unsafe.Pointer, context *C.GdkDragContext, x C.gint, y C
|
|||
|
||||
//export onKeyPressEvent
|
||||
func onKeyPressEvent(widget *C.GtkWidget, event *C.GdkEventKey, userData unsafe.Pointer) C.gboolean {
|
||||
// windowId := uint(*((*C.uint)(userData)))
|
||||
// fmt.Println("onKeyPressEvent", windowId)
|
||||
/*
|
||||
windowKeyEvents <- &windowKeyEvent{
|
||||
windowId: windowID,
|
||||
acceleratorString: C.GoString(acceleratorString),
|
||||
}
|
||||
*/
|
||||
windowID := uint(*((*C.uint)(userData)))
|
||||
accelerator, ok := getKeyboardState(event)
|
||||
if !ok {
|
||||
return C.gboolean(0)
|
||||
}
|
||||
windowKeyEvents <- &windowKeyEvent{
|
||||
windowId: windowID,
|
||||
acceleratorString: accelerator,
|
||||
}
|
||||
return C.gboolean(0)
|
||||
}
|
||||
|
||||
func getKeyboardState(event *C.GdkEventKey) (string, bool) {
|
||||
modifiers := uint(event.state) & C.GDK_MODIFIER_MASK
|
||||
keyCode := uint(event.keyval)
|
||||
|
||||
var acc accelerator
|
||||
// Check Accelerators
|
||||
if modifiers&(C.GDK_SHIFT_MASK) != 0 {
|
||||
acc.Modifiers = append(acc.Modifiers, ShiftKey)
|
||||
}
|
||||
if modifiers&(C.GDK_CONTROL_MASK) != 0 {
|
||||
acc.Modifiers = append(acc.Modifiers, ControlKey)
|
||||
}
|
||||
if modifiers&(C.GDK_MOD1_MASK) != 0 {
|
||||
acc.Modifiers = append(acc.Modifiers, OptionOrAltKey)
|
||||
}
|
||||
if modifiers&(C.GDK_SUPER_MASK) != 0 {
|
||||
acc.Modifiers = append(acc.Modifiers, SuperKey)
|
||||
}
|
||||
keyString, ok := VirtualKeyCodes[keyCode]
|
||||
if !ok {
|
||||
fmt.Println("Error Could not find key code: ", keyCode)
|
||||
return "", false
|
||||
}
|
||||
acc.Key = keyString
|
||||
return acc.String(), true
|
||||
}
|
||||
|
||||
//export onProcessRequest
|
||||
func onProcessRequest(request unsafe.Pointer, data unsafe.Pointer) {
|
||||
windowId := uint(*((*C.uint)(data)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue