Skip to content

Commit

Permalink
[V3 Linux] Fix Keybind remit (#3797)
Browse files Browse the repository at this point in the history
debounce linux keypress events  remits if held past a certain value
  • Loading branch information
atterpac authored Oct 1, 2024
1 parent 77b8132 commit f16d1be
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion v3/pkg/application/linux_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"
"strings"
"sync"
"time"
"unsafe"

"github.com/wailsapp/wails/v3/internal/assetserver/webview"
Expand Down Expand Up @@ -1480,8 +1481,22 @@ func onUriList(extracted **C.char, data unsafe.Pointer) {
}
}

var debounceTimer *time.Timer
var isDebouncing bool = false
//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))
if accelerator, ok := getKeyboardState(event); ok {
windowKeyEvents <- &windowKeyEvent{
Expand Down

0 comments on commit f16d1be

Please sign in to comment.