-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathextern.go
More file actions
46 lines (37 loc) · 885 Bytes
/
Copy pathextern.go
File metadata and controls
46 lines (37 loc) · 885 Bytes
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
//go:build !wayland && !(darwin && purego) && !(windows && purego) && !(linux && purego)
package hook
/*
// #include "event/hook_async.h"
*/
import "C"
import (
"log"
"runtime"
"time"
"encoding/json"
)
//export go_send
func go_send(s *C.char) {
str := []byte(C.GoString(s))
out := Event{}
err := json.Unmarshal(str, &out)
if err != nil {
log.Fatal("json.Unmarshal error is: ", err)
}
if out.Keychar != CharUndefined {
lck.Lock()
switch runtime.GOOS {
case "darwin":
rawToKeyDarwin[out.Rawcode] = string([]rune{out.Keychar})
case "windows":
raw2keyWin[out.Rawcode] = string([]rune{out.Keychar})
default:
raw2keyLinux[out.Rawcode] = string([]rune{out.Keychar})
}
lck.Unlock()
}
// todo bury this deep into the C lib so that the time is correct
out.When = time.Now() // at least it's consistent
// todo: maybe make non-bloking
ev <- out
}