CheckKeys() mutex on shared map.
This commit is contained in:
parent
8a9f465d0b
commit
1fd53cfb74
1 changed files with 15 additions and 10 deletions
|
|
@ -25,6 +25,9 @@ var debounce_key = make(map[uint64]time.Time)
|
||||||
var mu = sync.Mutex{}
|
var mu = sync.Mutex{}
|
||||||
|
|
||||||
func GetScreenConfigurations() {
|
func GetScreenConfigurations() {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
|
||||||
C.XGetScreenConfigurations()
|
C.XGetScreenConfigurations()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,38 +124,40 @@ func KeyUp(code uint64) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResetKeys() {
|
func ResetKeys() {
|
||||||
for code := range debounce_button {
|
mu.Lock()
|
||||||
//nolint
|
defer mu.Unlock()
|
||||||
ButtonUp(code)
|
|
||||||
|
|
||||||
|
for code := range debounce_button {
|
||||||
|
C.XButton(C.uint(code), C.int(0))
|
||||||
delete(debounce_button, code)
|
delete(debounce_button, code)
|
||||||
}
|
}
|
||||||
for code := range debounce_key {
|
|
||||||
//nolint
|
|
||||||
KeyUp(code)
|
|
||||||
|
|
||||||
|
for code := range debounce_key {
|
||||||
|
C.XKey(C.ulong(code), C.int(0))
|
||||||
delete(debounce_key, code)
|
delete(debounce_key, code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckKeys(duration time.Duration) {
|
func CheckKeys(duration time.Duration) {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
for code, start := range debounce_button {
|
for code, start := range debounce_button {
|
||||||
if t.Sub(start) < duration {
|
if t.Sub(start) < duration {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//nolint
|
|
||||||
ButtonUp(code)
|
|
||||||
|
|
||||||
|
C.XButton(C.uint(code), C.int(0))
|
||||||
delete(debounce_button, code)
|
delete(debounce_button, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
for code, start := range debounce_key {
|
for code, start := range debounce_key {
|
||||||
if t.Sub(start) < duration {
|
if t.Sub(start) < duration {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//nolint
|
|
||||||
KeyUp(code)
|
|
||||||
|
|
||||||
|
C.XKey(C.ulong(code), C.int(0))
|
||||||
delete(debounce_key, code)
|
delete(debounce_key, code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue