/
keyboard.go
61 lines (49 loc) · 1.2 KB
/
keyboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"log"
"github.com/rajveermalviya/go-wayland/wayland/client"
"golang.org/x/sys/unix"
)
func (app *appState) attachKeyboard() {
keyboard, err := app.seat.GetKeyboard()
if err != nil {
log.Fatal("unable to register keyboard interface")
}
app.keyboard = keyboard
keyboard.SetKeyHandler(app.HandleKeyboardKey)
keyboard.SetKeymapHandler(app.HandleKeyboardKeymap)
logPrintln("keyboard interface registered")
}
func (app *appState) releaseKeyboard() {
if err := app.keyboard.Release(); err != nil {
logPrintln("unable to release keyboard interface")
}
app.keyboard = nil
logPrintln("keyboard interface released")
}
func (app *appState) HandleKeyboardKey(e client.KeyboardKeyEvent) {
// close on "esc"
if e.Key == 1 {
app.exit = true
}
}
func (app *appState) HandleKeyboardKeymap(e client.KeyboardKeymapEvent) {
defer unix.Close(e.Fd)
// flags := unix.MAP_SHARED
// if app.seatVersion >= 7 {
// flags = unix.MAP_PRIVATE
// }
// buf, err := unix.Mmap(
// e.Fd,
// 0,
// int(e.Size),
// unix.PROT_READ,
// flags,
// )
// if err != nil {
// log.Printf("failed to mmap keymap: %v\n", err)
// return
// }
// defer unix.Munmap(buf)
// fmt.Println(string(buf))
}