]> git.mdlowis.com Git - proto/anvil.git/commitdiff
got floating windows mostly working with WM_STATE. Redraws are not happining in an...
authorMike Lowis <mike.lowis@gentex.com>
Thu, 1 Aug 2024 15:45:46 +0000 (11:45 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Thu, 1 Aug 2024 15:45:46 +0000 (11:45 -0400)
anvil.c
anvil.h
client.c

diff --git a/anvil.c b/anvil.c
index c976eaed186366f7230e02471f8635592f36844b..236433bc0c6dc8cac94b3e8b1aedf78b3d6f88f5 100644 (file)
--- a/anvil.c
+++ b/anvil.c
@@ -5,37 +5,29 @@
 
     X11 Client Window State Management:
 
-    CreateNotify    ->Withdrawn:
-                        Create window detached from any workspace (withdrawn list).
-                        Place window in withdrawn list.
-
-    MapRequest      ->Normal:
-                        Read the window properties
-                        Reparent the window to a frame if applicable
-                        Move window to current workspace tiled or floating
-                        Send expose event to window
+    MapRequest      ->Normal/Withdrawn:
+                        If window already tracked
+                            Show the window and frame
+                            Send expose event to window
+                        else
+                            Create new client struct
+                            Read the window properties
+                            Reparent the window to a frame if applicable
+                            Move window to current workspace tiled or floating
+                            Send expose event to window
 
     UnmapNotify     ->Withdrawn/Iconified:
                         if shaded -> Iconified
-                            Keep window where it is, show only titlebar
+                            Iconified: Keep window where it is, show only titlebar
                         else if unloaded
-                            Keep window where it is but unmapped
+                            Withdrawn: Keep window where it is but unmapped
                         else
-                            Remove window from workspace.
-                            Place window in withdrawn list.
+                            Withdrawn: Remove window from workspace.
 
     DestroyNotify   ->Destroyed
                         Window is destroyed. Free all resources.
 
 */
-static void xcreatenotify(XEvent* e)
-{
-    XCreateWindowEvent* ev = &(e->xcreatewindow);
-    printf("CREATE(w: 0x%lx)\n", ev->window);
-
-    /* add the new window in the withdrawn state */
-    Client_Create(ev->window);
-}
 
 static void xmaprequest(XEvent* e)
 {
@@ -321,7 +313,7 @@ int main(void)
     atoms_init();
 
     /* setup window life-cycle management event handlers */
-    X.eventfns[CreateNotify] = xcreatenotify;
+//    X.eventfns[CreateNotify] = xcreatenotify;
     X.eventfns[MapRequest] = xmaprequest;
     X.eventfns[UnmapNotify] = xunmapnotify;
     X.eventfns[DestroyNotify] = xdestroynotify;
diff --git a/anvil.h b/anvil.h
index 147a61477a0b776e5178116686872cd42d051971..c63df7426f5e40df2e9e889ed5c136ebc7db8e8a 100644 (file)
--- a/anvil.h
+++ b/anvil.h
@@ -78,7 +78,7 @@ typedef struct Client {
     struct Client* next;
     char* name;
     Window frame, win;
-    int flags, x, y, w, h;
+    int state, flags, x, y, w, h;
     long hint_flags, wm_flags;
     XWMHints hints;
     XSizeHints size_hints;
index 6b7e8e96067be9f4a266f1337688fbbafcf4ec99..87882e0a6f202f05f683a10a68b058e450c9ef53 100644 (file)
--- a/client.c
+++ b/client.c
@@ -7,6 +7,7 @@ static void Redraw(Client* c);
 void SetWMState(Client *c, int state)
 {
     CARD32 data[2] = {state, None};
+    c->state = state;
     XChangeProperty(X.disp, c->win, WM_STATE, WM_STATE, 32, PropModeReplace, (unsigned char *)data, 2);
 }
 
@@ -32,14 +33,14 @@ void SetWMState(Client *c, int state)
 //    return state;
 //}
 
-void Client_Create(Window win)
+static Client* Create(Window win)
 {
-    (void)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 */
-        Client* c = ecalloc(1, sizeof(Client));
+        c = ecalloc(1, sizeof(Client));
         c->win = win;
         c->x = attr.x;
         c->y = attr.y;
@@ -63,36 +64,31 @@ void Client_Create(Window win)
         XReparentWindow(X.disp, c->win, c->frame, BORDER_WIDTH, MIN_HEIGHT);
         SetWMState(c, WithdrawnState);
 
-//        /* set the state now based on attributes and hints */
-//        if (attr.map_state == IsUnmapped)
-//        {
-//            SetWMState(c, WithdrawnState);
-//        }
-//        else
-//        {
-//            SetWMState(c, NormalState);
-//            XWMHints* hints = XGetWMHints(X.disp, c->win);
-//            if (hints)
-//            {
-//                if (hints->flags & StateHint)
-//                {
-//                    SetWMState(c, hints->initial_state);
-//                }
-//                XFree(hints);
-//            }
-//        }
+        /* set the state now based on attributes and hints */
+        if (attr.map_state != IsViewable)
+        {
+            SetWMState(c, NormalState);
+            XWMHints* hints = XGetWMHints(X.disp, c->win);
+            if (hints)
+            {
+                if (hints->flags & StateHint)
+                {
+                    SetWMState(c, hints->initial_state);
+                }
+                XFree(hints);
+            }
+        }
     }
-}
-
-void Client_Destroy(Window win)
-{
-    (void)win;
+    return c;
 }
 
 void Client_Show(Window win)
 {
+    /* find or create the client structure */
     Client* c = FindClient(win);
-    printf("%p %p\n", Withdrawn, c);
+    if (!c) { c = Create(win); }
+
+    /* if we have a calid client, show it */
     if (c)
     {
         ReadProps(c);
@@ -126,6 +122,34 @@ void Client_Hide(Window win)
 
 }
 
+void Client_Destroy(Window win)
+{
+    (void)win;
+}
+
+void Client_MoveResize(Client* c)
+{
+    int shaded = (c->flags & F_SHADED);
+    int floating = (c->flags & (F_DIALOG|F_FLOATING));
+    int minheight = (shaded || !floating ? MIN_HEIGHT : 3*MIN_HEIGHT);
+    if (c->w < minheight) c->w = minheight;
+    if (c->h < minheight) c->h = minheight;
+    printf("XMoveResize(0x%lx, %d, %d, %d, %d)\n", c->frame, c->x, c->y, c->w, c->h);
+    XMoveResizeWindow(X.disp, c->frame, c->x, c->y, c->w, (shaded ? minheight : c->h));
+    if ( !(c->flags & F_SHADED) )
+    {
+        int child_w = c->w - FRAME_WIDTH_SUM;
+        int child_h = c->h - FRAME_HEIGHT_SUM;
+        if (child_w < 1) c->w = 1;
+        if (child_h < 1) c->h = 1;
+        printf("XResize(0x%lx, %d, %d)\n", c->win, c->w, c->h);
+        XResizeWindow(X.disp, c->win, child_w, child_h);
+    }
+//    mons_place(c);
+    Redraw(c);
+}
+
+
 static void ReadProps(Client* c)
 {
     Atom *protos = NULL, actual_type, *wintype;
@@ -313,27 +337,6 @@ Client* client_add(Window win, XWindowAttributes* attr)
 }
 
 
-void client_adjust(Client* c)
-{
-    int shaded = (c->flags & F_SHADED);
-    int floating = (c->flags & (F_DIALOG|F_FLOATING));
-    int minheight = (shaded || !floating ? MIN_HEIGHT : 3*MIN_HEIGHT);
-    if (c->w < minheight) c->w = minheight;
-    if (c->h < minheight) c->h = minheight;
-printf("XMoveResize(0x%lx, %d, %d, %d, %d)\n", c->frame, c->x, c->y, c->w, c->h);
-    XMoveResizeWindow(X.disp, c->frame, c->x, c->y, c->w, (shaded ? minheight : c->h));
-    if ( !(c->flags & F_SHADED) )
-    {
-        int child_w = c->w - FRAME_WIDTH_SUM;
-        int child_h = c->h - FRAME_HEIGHT_SUM;
-        if (child_w < 1) c->w = 1;
-        if (child_h < 1) c->h = 1;
-printf("XResize(0x%lx, %d, %d)\n", c->win, c->w, c->h);
-        XResizeWindow(X.disp, c->win, child_w, child_h);
-    }
-    mons_place(c);
-//    Redraw(c);
-}
 
 void client_move(Client* c, int xdiff, int ydiff)
 {