hotkey
hotkey copied to clipboard
Linux hotkey can not be canceled correctly
Description
The Linux C code event loop only returns after the hotkey was pressed. The hotkey can not be canceled while waitHotkey
waits for a new hotkey. hk.Unregister()
can be successfully called, but the hotkey is only unregistered after it was triggered.
Steps to reproduce
- Register a simple hotkey on Linux
- Unregister the hotkey
Notes
hk := h.New([]h.Modifier{h.ModCtrl}, h.KeyM)
hk.Register()
go func() {
time.Sleep(time.Second * 1)
fmt.Println("Hotkey will be unregistered")
hk.Unregister()
fmt.Println("Hotkey unregistered")
hk.Register()
fmt.Println("Registered again")
}()
<-hk.Keydown()
This code blocks. I would expect the chan
to be closed and the program to exit.
https://github.com/golang-design/hotkey/blob/a5dde31e1341de42c328de537041eddd79995ff5/hotkey_linux.c#L64-L77
I would expect that the above loop checks, if the hotkey was unregistered. XNextEvent
also blocks until the next event, but that should be fine as long as a lot of events are triggered. Else something like XPending
could be used to check, if new events can be processed.
This is a bit tricky. Semantically, the hotkey is unregistered, not triggered. That's why the Keydown is not triggered and blocks forever.
Updated the example code. I tested a bit. The Unregister
itself also blocks.