-
Notifications
You must be signed in to change notification settings - Fork 76
/
x11.go
168 lines (143 loc) · 3.34 KB
/
x11.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Bamboo - A Vietnamese Input method editor
* Copyright (C) 2018 Luong Thanh Lam <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package main
/*
#cgo CFLAGS: -std=gnu99
#cgo LDFLAGS: -lX11 -lXtst -pthread
#include <stdlib.h>
extern void x11Copy(char*);
extern void x11Paste(int);
extern void clipboard_init();
extern void clipboard_exit();
extern void x11ClipboardReset();
extern void mouse_capture_init();
extern void mouse_capture_exit();
extern void mouse_capture_unlock();
extern void mouse_capture_start_or_unlock();
extern void mouse_recording_init();
extern void mouse_recording_exit();
extern void x11SendBackspace(int n, int timeout);
extern void x11SendShiftR();
extern void x11SendShiftLeft(int n, int r, int timeout);
extern void setXIgnoreErrorHandler();
extern char* x11GetFocusWindowClass();
extern void x11StartWindowInspector();
extern void x11StopWindowInspector();
*/
import "C"
import (
"sync"
"unsafe"
)
var (
mcapRunning bool
mcapMutex sync.RWMutex
)
func init() {
C.setXIgnoreErrorHandler()
}
//export mouse_move_handler
func mouse_move_handler() {
onMouseMove()
}
//export mouse_click_handler
func mouse_click_handler() {
onMouseClick()
}
var onMouseMove func()
var onMouseClick func()
func x11StartWindowInspector() {
C.x11StartWindowInspector()
}
func x11StopWindowInspector() {
C.x11StopWindowInspector()
}
func startMouseRecording() {
C.mouse_recording_init()
}
func stopMouseRecording() {
C.mouse_recording_exit()
}
func startMouseCapturing() {
mcapMutex.Lock()
defer mcapMutex.Unlock()
if !mcapRunning {
C.mouse_capture_init()
mcapRunning = true
}
}
func stopMouseCapturing() {
mcapMutex.RLock()
defer mcapMutex.RUnlock()
if mcapRunning {
C.mouse_capture_exit()
}
}
func mouseCaptureStartOrUnlock() {
mcapMutex.Lock()
defer mcapMutex.Unlock()
if !mcapRunning {
C.mouse_capture_start_or_unlock()
mcapRunning = true
}
}
func mouseCaptureUnlock() {
mcapMutex.RLock()
defer mcapMutex.RUnlock()
if mcapRunning {
C.mouse_capture_unlock()
}
}
func x11Copy(str string) {
cs := C.CString(str)
defer C.free(unsafe.Pointer(cs))
C.x11Copy(cs)
}
func x11ClipboardInit() {
C.clipboard_init()
}
func x11ClipboardExit() {
C.clipboard_exit()
}
func x11ClipboardReset() {
C.x11ClipboardReset()
}
func x11Paste(n int) {
C.x11Paste(C.int(n))
}
func x11SendShiftR() {
C.x11SendShiftR()
}
func x11SendShiftLeft(n int, shiftRightIsPressing bool, timeout int) {
var r = 0
if shiftRightIsPressing {
r = 1
}
C.x11SendShiftLeft(C.int(n), C.int(r), C.int(timeout))
}
func x11SendBackspace(n int, timeout int) {
C.x11SendBackspace(C.int(n), C.int(timeout))
}
func x11GetFocusWindowClass() string {
var wmClass = C.x11GetFocusWindowClass()
if wmClass != nil {
return C.GoString(wmClass)
}
return ""
}