From: Michael D. Lowis Date: Wed, 7 Aug 2024 03:55:35 +0000 (-0400) Subject: Added logic to warp pointer andinit clients on startup X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=4eb5ca381c9ae5eb8e704f33375b203ae0cc2392;p=proto%2Fanvil.git Added logic to warp pointer andinit clients on startup --- diff --git a/anvil.c b/anvil.c index f438f5d..f3653de 100644 --- a/anvil.c +++ b/anvil.c @@ -237,6 +237,10 @@ static void InitFont(void) int nmiss; X.font = XCreateFontSet(X.disp, FONT_NAME, &miss, &nmiss, &def); if (!X.font) + { + X.font = XCreateFontSet(X.disp, "fixed", &miss, &nmiss, &def); + } + if (!X.font) { printf("anvil: fatal error: unable to create font set for title font\n"); exit(1); @@ -313,12 +317,12 @@ int main(void) XSync(X.disp, False); /* initialize all the things */ + Atoms_Init(); InitCursors(); InitFont(); Client_InitAll(); Keys_Init(); Monitors_Init(); - Atoms_Init(); /* setup window life-cycle management event handlers */ X.eventfns[MapRequest] = XMapRequest; diff --git a/anvil.h b/anvil.h index bcb2dfb..a020dd9 100644 --- a/anvil.h +++ b/anvil.h @@ -65,10 +65,11 @@ typedef struct { } XConf; enum { - F_WM_DELETE = (1 << 0), - F_DIALOG = (1 << 1), - F_FLOATING = (1 << 2), - F_SHADED = (1 << 3), + F_MAPPED_ONCE = (1 << 0), + F_WM_DELETE = (1 << 1), + F_DIALOG = (1 << 2), + F_FLOATING = (1 << 3), + F_SHADED = (1 << 4), }; typedef struct Node { diff --git a/client.c b/client.c index d5b403e..b4b7e01 100644 --- a/client.c +++ b/client.c @@ -32,9 +32,10 @@ Client* Client_Create(Window win) { Client* c = NULL; XWindowAttributes attr; + if (XGetWindowAttributes(X.disp, win, &attr) && !attr.override_redirect) { - /* we care about it, let's add it to withdrawn */ + /* we care about it, let's add it to the list */ c = Allocate(1, sizeof(Client)); c->win = win; c->x = attr.x; @@ -74,7 +75,6 @@ Client* Client_Create(Window win) } } Client_Place(c); - } return c; } @@ -87,6 +87,14 @@ void Client_Show(Client* c) c->y = mon->y + c->rel_y; Client_MoveResize(c); + /* set mouse to titlebar if mapping for first time */ + if (!(c->wm_flags & F_MAPPED_ONCE)) + { + Mouse_ToTitle(c); + c->wm_flags |= F_MAPPED_ONCE; + } + + /* update, map and redraw */ ReadProps(c); SetWMState(c, NormalState); XMapWindow(X.disp, c->frame); @@ -214,36 +222,25 @@ void Client_Place(Client* c) c->rel_y = c->y - Monitors[monitor].y; } - - - - void Client_InitAll(void) { -// /* TODO: Find all top-level windows and register them correctly -// -// * Find all root children with override_redirect set False -// * Add them to withdrawn list if WM_STATE = withdrawn -// * Add them as floating and unshaded if WM_STATE = Normal -// * Add them as floating ad shaded if WM_STATE = Iconic -// -// */ -// -// unsigned int nwins; -// Window d1, d2, *wins = NULL; -// XWindowAttributes attr; -// if (XQueryTree(X.disp, X.root, &d1, &d2, &wins, &nwins)) -// { -// for (unsigned int i = 0; i < nwins; i++) -// { -// if (XGetWindowAttributes(X.disp, wins[i], &attr) && (attr.override_redirect == False)) -// { -// Client* c = client_add(wins[i], &attr); -// c->flags |= F_FLOATING; -// } -// } -// xfree(wins); -// } + unsigned int nwins; + Window d1, d2, *wins = NULL; + XWindowAttributes attr; + if (XQueryTree(X.disp, X.root, &d1, &d2, &wins, &nwins)) + { + for (unsigned int i = 0; i < nwins; i++) + { + if (XGetWindowAttributes(X.disp, wins[i], &attr) && (attr.override_redirect == False) && (attr.map_state == IsViewable)) + { + Client* c = Client_Create(wins[i]); + c->wm_flags |= F_MAPPED_ONCE; + Client_Show(c); + } + } + xfree(wins); + Client_UpdateAll(); + } } void Client_UpdateAll(void) @@ -294,7 +291,6 @@ void Client_UpdateAll(void) // } //} - static void ReadProps(Client* c) { Atom *protos = NULL, actual_type, *wintype;