]> git.mdlowis.com Git - proto/anvil.git/commitdiff
Added logic to warp pointer andinit clients on startup
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 7 Aug 2024 03:55:35 +0000 (23:55 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 7 Aug 2024 03:55:35 +0000 (23:55 -0400)
anvil.c
anvil.h
client.c

diff --git a/anvil.c b/anvil.c
index f438f5d4516f6f8d0df38ee101a465562067b406..f3653de0b4a9e6b42e165007fec5c7a5e4f83bcd 100644 (file)
--- 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 bcb2dfb4d558680dc7abe510daeef0ccf99d5e59..a020dd9a6f8cc855449ee1bee67483464e72cbd0 100644 (file)
--- 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 {
index d5b403e32aec07cd1ccf2b5cc2ee5bc9c17e713a..b4b7e01ecfb8c3e968019725c779e49929fbf224 100644 (file)
--- 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;