]> git.mdlowis.com Git - proto/anvil.git/commitdiff
start responding to client messages master
authorMike Lowis <mike.lowis@gentex.com>
Thu, 15 Aug 2024 20:13:47 +0000 (16:13 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Thu, 15 Aug 2024 20:13:47 +0000 (16:13 -0400)
client.c

index e31c32845d828ca97ce103937ec8dad98c7ec105..78afc3d560097186c6c7abc01b857328e7aa5378 100644 (file)
--- a/client.c
+++ b/client.c
@@ -5,6 +5,10 @@
 #define LIST_FOR_EACH(val,list) \
     for (val = list; (val != NULL); val = val->next)
 
+static int UpdateStateFlag(Client* c, int op, Atom prop);
+static void UpdateHiddenState(Client* c, int op);
+static void UpdateFullscreenState(Client* c, int op);
+
 static void ReadProps(Client* c);
 static void Redraw(Client* c);
 static void LayerWindows(void);
@@ -81,37 +85,40 @@ Client* Client_Create(Window win)
 
 void Client_Show(Client* c)
 {
-    /* position it with relative coords */
-    Monitor* mon = &Monitors[Workspaces[c->wspace].monitor];
-    c->x = mon->x + c->rel_x;
-    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))
-    {
-        int mon = Monitors_GetActiveMonitor();
-        c->wspace = Monitors[mon].wspace;
-        c->x = Monitors[mon].midx - c->w/2;
-        c->y = Monitors[mon].midy - c->h/2;
-        Client_MoveResize(c);
-        Mouse_ToTitle(c);
-        c->wm_flags |= F_MAPPED_ONCE;
-    }
-
-    /* update, map and redraw */
-    ReadProps(c);
-    SetWMState(c, NormalState);
-    XMapWindow(X.disp, c->frame);
-    XMapWindow(X.disp, c->win);
-    Redraw(c);
+//    /* position it with relative coords */
+//    Monitor* mon = &Monitors[Workspaces[c->wspace].monitor];
+//    c->x = mon->x + c->rel_x;
+//    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))
+//    {
+//        int mon = Monitors_GetActiveMonitor();
+//        c->wspace = Monitors[mon].wspace;
+//        c->x = Monitors[mon].midx - c->w/2;
+//        c->y = Monitors[mon].midy - c->h/2;
+//        Client_MoveResize(c);
+//        Mouse_ToTitle(c);
+//        c->wm_flags |= F_MAPPED_ONCE;
+//    }
+//
+//    /* update, map and redraw */
+//    ReadProps(c);
+//    SetWMState(c, NormalState);
+//    XMapWindow(X.disp, c->frame);
+//    XMapWindow(X.disp, c->win);
+//    Redraw(c);
+
+    UpdateHiddenState(c, CLR_FLAG);
 }
 
 void Client_Hide(Client* c)
 {
-    SetWMState(c, HiddenState);
-    XUnmapWindow(X.disp, c->frame);
-    XUnmapWindow(X.disp, c->win);
+//    SetWMState(c, HiddenState);
+//    XUnmapWindow(X.disp, c->frame);
+//    XUnmapWindow(X.disp, c->win);
+    UpdateHiddenState(c, SET_FLAG);
 }
 
 void Client_Destroy(Client* c)
@@ -278,50 +285,93 @@ void Client_UpdateAll(void)
     }
 }
 
-void Client_UpdateWindowState(Client* c, int op, Atom prop)
+static int UpdateStateFlag(Client* c, int op, Atom prop)
 {
-    (void)c, (void)op;
-    if (prop == _NET_WM_STATE_HIDDEN)
+    int setting = 0;
+    int id = EWMH_GetFlagId(WindowState, nelem(WindowState), prop);
+    assert(id >= 0);
+    if (op == 2)
     {
-//        UpdateHiddenState(c, op);
+        setting = ((c->wm_state & (1 << id)) == 0);
     }
-    else if (prop == _NET_WM_STATE_FULLSCREEN)
+
+    if (setting)
     {
-//        UpdateFullscreenState(c, op);
+        c->wm_state |= (1 << id);
+    }
+    else
+    {
+        c->wm_state &= ~(1 << id);
     }
 
-
-
-
-//    int id = EWMH_GetFlagId(WindowState, nelem(WindowState), prop);
-//    if (id >= 0)
-//    {
-//        int clearing = 0;
-//        if (op == 2)
-//        {
-//            clearing = ((c->wm_state & (1 << id)) != 0);
-//        }
-//
-//        if (clearing)
-//        {
-//            c->wm_state &= ~(1 << id);
-//        }
-//        else
-//        {
-//            c->wm_state |= (1 << id);
-//        }
-//    }
+    return setting;
 }
 
+static void UpdateHiddenState(Client* c, int op)
+{
+    if (UpdateStateFlag(c, op, _NET_WM_STATE_HIDDEN))
+    {
+        SetWMState(c, HiddenState);
+        XUnmapWindow(X.disp, c->frame);
+        XUnmapWindow(X.disp, c->win);
+    }
+    else
+    {
+        /* position it with relative coords */
+        Monitor* mon = &Monitors[Workspaces[c->wspace].monitor];
+        c->x = mon->x + c->rel_x;
+        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))
+        {
+            int mon = Monitors_GetActiveMonitor();
+            c->wspace = Monitors[mon].wspace;
+            c->x = Monitors[mon].midx - c->w/2;
+            c->y = Monitors[mon].midy - c->h/2;
+            Client_MoveResize(c);
+            Mouse_ToTitle(c);
+            c->wm_flags |= F_MAPPED_ONCE;
+        }
 
+        /* update, map and redraw */
+        ReadProps(c);
+        SetWMState(c, NormalState);
+        XMapWindow(X.disp, c->frame);
+        XMapWindow(X.disp, c->win);
+        Redraw(c);
+    }
+}
 
+static void UpdateFullscreenState(Client* c, int op)
+{
+    if (UpdateStateFlag(c, op, _NET_WM_STATE_FULLSCREEN))
+    {
+        // mark it as fullscreen on workspace
+        // unmap or shrink frame
+        // move/resize to full workspace
+    }
+    else
+    {
+        // mark it as fullscreen on workspace
+        // map or grow frame
+        // move/resize to original location
+    }
+}
 
-
-
-
-
-
+void Client_UpdateWindowState(Client* c, int op, Atom prop)
+{
+    (void)c, (void)op;
+    if (prop == _NET_WM_STATE_HIDDEN)
+    {
+        UpdateHiddenState(c, op);
+    }
+    else if (prop == _NET_WM_STATE_FULLSCREEN)
+    {
+        UpdateFullscreenState(c, op);
+    }
+}
 
 //void client_shade(Client* c)
 //{