mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-13 23:49:35 +08:00
[V3 Linux] Fix Keybind remit (#3797)
debounce linux keypress events remits if held past a certain value
This commit is contained in:
parent
77b8132591
commit
f16d1be955
@ -7,6 +7,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v3/internal/assetserver/webview"
|
"github.com/wailsapp/wails/v3/internal/assetserver/webview"
|
||||||
@ -1480,8 +1481,22 @@ func onUriList(extracted **C.char, data unsafe.Pointer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var debounceTimer *time.Timer
|
||||||
|
var isDebouncing bool = false
|
||||||
//export onKeyPressEvent
|
//export onKeyPressEvent
|
||||||
func onKeyPressEvent(widget *C.GtkWidget, event *C.GdkEventKey, userData C.uintptr_t) C.gboolean {
|
func onKeyPressEvent(_ *C.GtkWidget, event *C.GdkEventKey, userData C.uintptr_t) C.gboolean {
|
||||||
|
// Keypress re-emits if the key is pressed over a certain threshold so we need a debounce
|
||||||
|
if isDebouncing {
|
||||||
|
debounceTimer.Reset(50 * time.Millisecond)
|
||||||
|
return C.gboolean(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the debounce
|
||||||
|
isDebouncing = true
|
||||||
|
debounceTimer = time.AfterFunc(50*time.Millisecond, func() {
|
||||||
|
isDebouncing = false
|
||||||
|
})
|
||||||
|
|
||||||
windowID := uint(C.uint(userData))
|
windowID := uint(C.uint(userData))
|
||||||
if accelerator, ok := getKeyboardState(event); ok {
|
if accelerator, ok := getKeyboardState(event); ok {
|
||||||
windowKeyEvents <- &windowKeyEvent{
|
windowKeyEvents <- &windowKeyEvent{
|
||||||
|
Loading…
Reference in New Issue
Block a user