Skip to content

Linux hotkey can not be canceled correctly #15

@data-niklas

Description

@data-niklas

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

  1. Register a simple hotkey on Linux
  2. 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.

hotkey/hotkey_linux.c

Lines 64 to 77 in a5dde31

while(1) {
XNextEvent(d, &ev);
switch(ev.type) {
case KeyPress:
hotkeyDown(hkhandle);
continue;
case KeyRelease:
hotkeyUp(hkhandle);
XUngrabKey(d, keycode, mod, DefaultRootWindow(d));
XCloseDisplay(d);
return 0;
}
}
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions