Skip to content

Commit

Permalink
revert: global err channel
Browse files Browse the repository at this point in the history
  • Loading branch information
ventsislav-georgiev committed Jan 5, 2022
1 parent 725f57c commit cf377d3
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 37 deletions.
16 changes: 1 addition & 15 deletions examples/multiple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func main() { mainthread.Init(fn) }
func fn() {
wg := sync.WaitGroup{}
wg.Add(3)
wg.Add(2)
go func() {
defer wg.Done()

Expand All @@ -32,20 +32,6 @@ func fn() {
log.Println(err)
}
}()
go func() {
defer wg.Done()

err := listenHotkey(hotkey.KeyA, hotkey.ModCtrl, hotkey.ModShift)
if err != nil {
log.Println(err)
}
}()

go func() {
<-hotkey.Err()
log.Println("some key binding has failed")
wg.Done()
}()

wg.Wait()
}
Expand Down
14 changes: 0 additions & 14 deletions hotkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,6 @@ import (
"runtime"
)

var (
errIn chan<- Event
errOut <-chan Event
)

// Err returns a channel that receives a signal when an unexpected error has occured.
// On Linux systems using X11 this indicates a failed XGrabKey.
// Not used for Windows and Darwin
func Err() <-chan Event { return errOut }

func init() {
errIn, errOut = newEventChan()
}

// Event represents a hotkey event
type Event struct{}

Expand Down
3 changes: 0 additions & 3 deletions hotkey_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>

extern void err();
extern void hotkeyDown(uintptr_t hkhandle);
extern void hotkeyUp(uintptr_t hkhandle);

static int xErrHandler(Display* d, XErrorEvent* pErr)
{
if( pErr->request_code == 33 ){ // X_GrabKey
if( pErr->error_code == BadAccess ){
err();
return 0;
}
} else {
Expand Down Expand Up @@ -61,7 +59,6 @@ int waitHotkey(uintptr_t hkhandle, unsigned int mod, int key) {
}
int keycode = XKeysymToKeycode(d, key);
XGrabKey(d, keycode, mod, DefaultRootWindow(d), False, GrabModeAsync, GrabModeAsync);

XSelectInput(d, DefaultRootWindow(d), KeyPressMask);
XEvent ev;
while(1) {
Expand Down
5 changes: 0 additions & 5 deletions hotkey_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ func init() {
}
}

//export err
func err() {
errIn <- Event{}
}

type platformHotkey struct {
mu sync.Mutex
registered bool
Expand Down

0 comments on commit cf377d3

Please sign in to comment.