Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Move X11 error handler registration to before screen sets (#62)
Browse files Browse the repository at this point in the history
If X11 throws an error during screen config get/set, the default error
handler at the time will be one which causes a program exit. This
splits the error handler registration in xevent into its own call,
allowing us to register our error handler earlier on. This results in
the safe error handling logic actually being called instead of a full
program exit.
  • Loading branch information
tt2468 authored Mar 27, 2024
1 parent 8981051 commit 00c7e6d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/desktop/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (manager *DesktopManagerCtx) Start() {
manager.logger.Panic().Str("display", manager.config.Display).Msg("unable to open display")
}

// X11 can throw errors below, and the default error handler exits
xevent.SetupErrorHandler()

xorg.GetScreenConfigurations()

screenSize, err := xorg.ChangeScreenSize(manager.config.ScreenSize)
Expand Down
5 changes: 4 additions & 1 deletion pkg/xevent/xevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ static int XEventError(Display *display, XErrorEvent *event) {
return 1;
}

void XSetupErrorHandler() {
XSetErrorHandler(XEventError);
}

void XEventLoop(char *name) {
Display *display = XOpenDisplay(name);
Window root = DefaultRootWindow(display);
Expand All @@ -33,7 +37,6 @@ void XEventLoop(char *name) {
XSelectInput(display, root, SubstructureNotifyMask);

XSync(display, 0);
XSetErrorHandler(XEventError);

while (goXEventActive()) {
XEvent event;
Expand Down
4 changes: 4 additions & 0 deletions pkg/xevent/xevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func init() {
Emmiter = events.New()
}

func SetupErrorHandler() {
C.XSetupErrorHandler()
}

func EventLoop(display string) {
displayUnsafe := C.CString(display)
defer C.free(unsafe.Pointer(displayUnsafe))
Expand Down
1 change: 1 addition & 0 deletions pkg/xevent/xevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern void goXEventError(XErrorEvent *event, char *message);
extern int goXEventActive();

static int XEventError(Display *display, XErrorEvent *event);
void XSetupErrorHandler();
void XEventLoop(char *display);

static void XWindowManagerStateEvent(Display *display, Window window, ulong action, ulong first, ulong second);
Expand Down

0 comments on commit 00c7e6d

Please sign in to comment.