From 64d540a026ca11f41efb4b4fee20f45300cc1d94 Mon Sep 17 00:00:00 2001 From: Adrian Chadd Date: Tue, 15 Mar 2022 21:37:31 -0700 Subject: [PATCH] [amiwm] Fix window size / position issues when asked to do something insane * ensure newly created windows are placed somewhere visible - ie, not off the screen. * ensure newly created window sizes aren't insanely large, which end up being unable to be moved or resized in amiwm. This has shown up with gtk apps (kicad, firefox) with their load/save dialog. For some reason they want to be almost 2x my desktop size, making them super hard to use. --- frame.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/frame.c b/frame.c index 9b9c003..47b9786 100644 --- a/frame.c +++ b/frame.c @@ -178,6 +178,7 @@ void reparent(Client *c) extern struct mcmd_keygrab *keygrabs; char **cargv = NULL; int cargc; + int size_changed = 0; if(XGetTransientForHint(dpy, c->window, &leader) && !XFindContext(dpy, leader, client_context, (XPointer *)&lc)) @@ -226,15 +227,58 @@ void reparent(Client *c) c->framewidth=8; c->frameheight=scr->bh+2; attr2.override_redirect=True; + + grav_map_win_to_frame(c, attr.x, attr.y, &c->x, &c->y); + + /* Note: this is half of framewidth */ + if ((c->x < 0) || (c->x > scr->width)) { + c->x = 0; + } + /* Note: this is the menu size, but no window framing */ + if ((c->y < scr->bh) || (c->y > scr->height)) { + c->y = scr->bh; + } + + /* + * Check to make sure we're not created larger than the + * available desktop size + */ + if (attr.width > (scr->width - c->framewidth)) { + attr.width = (scr->width - c->framewidth); + size_changed = 1; + } + if (attr.height > (scr->height - c->frameheight)) { + attr.height = (scr->height - c->frameheight); + size_changed = 1; + } + + c->pwidth = attr.width + c->framewidth; + c->pheight = attr.height + c->frameheight; + + /* + * Note: if we adjusted c->pwidth / c->pheight then + * we need to call XResizeWindow on c->window. + * + * Do it before we reparent it just to make things + * easy. + */ + if (size_changed == 1) { + XResizeWindow(dpy, c->window, c->pwidth-c->framewidth, + c->pheight-c->frameheight); + } + + /* Create the parent window that'll have our decoration */ c->parent=XCreateWindow(dpy, scr->back, c->x, c->y, - c->pwidth=attr.width+8, c->pheight=attr.height+2+scr->bh, + c->pwidth, c->pheight, 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect, &attr2); XSaveContext(dpy, c->parent, client_context, (XPointer)c); XSaveContext(dpy, c->parent, screen_context, (XPointer)c->scr); XSetWindowBackground(dpy, c->parent, scr->dri.dri_Pens[BACKGROUNDPEN]); XSetWindowBorderWidth(dpy, c->window, 0); + + /* Reparent time */ XReparentWindow(dpy, c->window, c->parent, 4, scr->bh); XSelectInput(dpy, c->window, EnterWindowMask | LeaveWindowMask | ColormapChangeMask | PropertyChangeMask |