From 63cc84921657c2b7ff094e5ccc0d1f5987444de9 Mon Sep 17 00:00:00 2001 From: elbachir-one Date: Sun, 18 May 2025 20:47:19 +0100 Subject: Adding a Check for XGetWindowAttributes failure --- src/sxwm.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/sxwm.c b/src/sxwm.c index a2dfdcd..e7161d9 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -1527,30 +1527,39 @@ void toggle_floating(void) return; } - focused->floating = !focused->floating; if (focused->fullscreen) { focused->fullscreen = False; tile(); XSetWindowBorderWidth(dpy, focused->win, user_config.border_width); } + focused->floating = !focused->floating; + if (focused->floating) { XWindowAttributes wa; - XGetWindowAttributes(dpy, focused->win, &wa); - focused->x = wa.x; - focused->y = wa.y; - focused->w = wa.width; - focused->h = wa.height; - - XConfigureWindow( - dpy, focused->win, CWX | CWY | CWWidth | CWHeight, - &(XWindowChanges){.x = focused->x, .y = focused->y, .width = focused->w, .height = focused->h}); + if (XGetWindowAttributes(dpy, focused->win, &wa)) { + focused->x = wa.x; + focused->y = wa.y; + focused->w = wa.width; + focused->h = wa.height; + + XConfigureWindow( + dpy, focused->win, + CWX | CWY | CWWidth | CWHeight, + &(XWindowChanges){ + .x = focused->x, + .y = focused->y, + .width = focused->w, + .height = focused->h + } + ); + } } tile(); update_borders(); - /* floating windows are on top */ + /* Raise and refocus floating window */ if (focused->floating) { XRaiseWindow(dpy, focused->win); XSetInputFocus(dpy, focused->win, RevertToPointerRoot, CurrentTime); -- cgit v1.2.3