diff --git a/main.c b/main.c index c2585d917e15044e4f6814cc6d797adf22ebf2c7..9bc3a4b4f7046bed7c7c1d74d41539febc0e9403 100644 --- a/main.c +++ b/main.c @@ -67,6 +67,7 @@ wm.running = 1; while(wm.running) { XNextEvent(wm.dpy, &wm.ev); + XLockDisplay(wm.dpy); switch (wm.ev.type) { case MapRequest: handle_map_request(); @@ -116,6 +117,7 @@ case ConfigureRequest: handle_configure_request(); break; } + XUnlockDisplay(wm.dpy); } deinit_window_manager(); diff --git a/manager.c b/manager.c index 58ee90ab6ea5761d1fa62ceb4f0f8bd7bc353785..f6b46f1d1695edce858f0c930a2e5f8b13f8cecb 100644 --- a/manager.c +++ b/manager.c @@ -586,7 +586,11 @@ changes.border_width = ev->border_width; changes.sibling = ev->above; changes.stack_mode = ev->detail; + XErrorHandler old = XSetErrorHandler(ignore_x_error); XConfigureWindow(wm.dpy, ev->window, ev->value_mask, &changes); + XSync(wm.dpy, False); + XSetErrorHandler(old); + log_message(stdout, LOG_DEBUG, "ConfigureRequest for 0x%lx (x=%d, y=%d, w=%d, h=%d)", ev->window, ev->x, ev->y, ev->width, ev->height); } @@ -594,6 +598,8 @@ // https://tronche.com/gui/x/xlib/events/structure-control/map.html void handle_map_request(void) { Window window = wm.ev.xmaprequest.window; if (window == wm.root) return; + + XErrorHandler old = XSetErrorHandler(ignore_x_error); // Move window under cursor position and clamps inside the screen bounds. XWindowAttributes check_attr; @@ -635,6 +641,10 @@ // Grab buttons for click-to-focus. grab_buttons(window); add_client(window); + + XSync(wm.dpy, False); + XSetErrorHandler(old); + log_message(stdout, LOG_DEBUG, "Window 0x%lx mapped and grabbed on desktop %d", window, wm.current_desktop); redraw_widgets(); update_client_list(); @@ -972,10 +982,10 @@ void handle_button_release(void) { if (wm.start.subwindow != None && (wm.start.state & MODKEY)) { XDefineCursor(wm.dpy, wm.start.subwindow, None); - // Restore default error handler - XSetErrorHandler(NULL); + // Restore window manager error handler + XSetErrorHandler(x_error_handler); - log_message(stdout, LOG_DEBUG, "Restored default cursor on window 0x%lx", wm.start.subwindow); + log_message(stdout, LOG_DEBUG, "Restored window manager cursor on window 0x%lx", wm.start.subwindow); wm.start.subwindow = None; } diff --git a/switcher.c b/switcher.c index 949bcef08e4b45418f4a211e1b5faa5a77b32f06..cde8c9073e24d5cc5dafdc1cc61a6bfd5c630d65 100644 --- a/switcher.c +++ b/switcher.c @@ -109,7 +109,7 @@ // Grab keyboard to catch Alt release (key release) // We grab it on the root window. XGrabKeyboard(wm.dpy, wm.root, True, GrabModeAsync, GrabModeAsync, CurrentTime); - // Count clients + // Count clients - allocate extra to handle new windows mapping during this process int count = 0; Client *c = wm.clients; while (c) { @@ -122,7 +122,7 @@ end_cycling(); return; } - wm.cycle_clients = malloc(sizeof(Window) * count); + wm.cycle_clients = malloc(sizeof(Window) * (count + 10)); wm.cycle_count = 0; wm.active_cycle_index = 0;