Move X11 error handler registration to before screen sets (#62)

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.
This commit is contained in:
tt2468 2024-03-27 13:38:33 -07:00 committed by GitHub
parent 8981051945
commit 00c7e6dfb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 1 deletions

View File

@ -50,6 +50,9 @@ func (manager *DesktopManagerCtx) Start() {
manager.logger.Panic().Str("display", manager.config.Display).Msg("unable to open display") 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() xorg.GetScreenConfigurations()
screenSize, err := xorg.ChangeScreenSize(manager.config.ScreenSize) screenSize, err := xorg.ChangeScreenSize(manager.config.ScreenSize)

View File

@ -14,6 +14,10 @@ static int XEventError(Display *display, XErrorEvent *event) {
return 1; return 1;
} }
void XSetupErrorHandler() {
XSetErrorHandler(XEventError);
}
void XEventLoop(char *name) { void XEventLoop(char *name) {
Display *display = XOpenDisplay(name); Display *display = XOpenDisplay(name);
Window root = DefaultRootWindow(display); Window root = DefaultRootWindow(display);
@ -33,7 +37,6 @@ void XEventLoop(char *name) {
XSelectInput(display, root, SubstructureNotifyMask); XSelectInput(display, root, SubstructureNotifyMask);
XSync(display, 0); XSync(display, 0);
XSetErrorHandler(XEventError);
while (goXEventActive()) { while (goXEventActive()) {
XEvent event; XEvent event;

View File

@ -23,6 +23,10 @@ func init() {
Emmiter = events.New() Emmiter = events.New()
} }
func SetupErrorHandler() {
C.XSetupErrorHandler()
}
func EventLoop(display string) { func EventLoop(display string) {
displayUnsafe := C.CString(display) displayUnsafe := C.CString(display)
defer C.free(unsafe.Pointer(displayUnsafe)) defer C.free(unsafe.Pointer(displayUnsafe))

View File

@ -17,6 +17,7 @@ extern void goXEventError(XErrorEvent *event, char *message);
extern int goXEventActive(); extern int goXEventActive();
static int XEventError(Display *display, XErrorEvent *event); static int XEventError(Display *display, XErrorEvent *event);
void XSetupErrorHandler();
void XEventLoop(char *display); void XEventLoop(char *display);
static void XWindowManagerStateEvent(Display *display, Window window, ulong action, ulong first, ulong second); static void XWindowManagerStateEvent(Display *display, Window window, ulong action, ulong first, ulong second);