]> git.mdlowis.com Git - proto/anvil.git/commitdiff
fixed up window resizing
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 5 Aug 2024 02:58:55 +0000 (22:58 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 5 Aug 2024 02:58:55 +0000 (22:58 -0400)
anvil.c
anvil.h
client.c
keys.c
mouse.c

diff --git a/anvil.c b/anvil.c
index 66cd393029e7aefc48c73853846e654f8ebfc399..ac5bc514acc9391f33bee7219986a2f5f98ee0a8 100644 (file)
--- a/anvil.c
+++ b/anvil.c
@@ -123,22 +123,18 @@ static void xconfigrequest(XEvent* e)
     wc.border_width = ev->border_width;
     wc.sibling = ev->above;
     wc.stack_mode = ev->detail;
-//    Location loc = {0};
-//    if (mons_find(ev->window, &loc))
-//    {
-//        /* only allow floating clients to resize on their own */
-//        if ((loc.client->win == ev->window) && !loc.column)
-//        {
-//            loc.client->w = wc.width + FRAME_WIDTH_SUM;
-//            loc.client->h = wc.height + FRAME_HEIGHT_SUM;
-//            client_adjust(loc.client);
-//            if (X.mode == M_RESIZE && Focused == loc.client)
-//            {
-//                mouse_tocorner(loc.client);
-//            }
-//        }
-//    }
-//    else
+    Client* c = Client_Find(ev->window);
+    if (c)
+    {
+        c->w = wc.width + FRAME_WIDTH_SUM;
+        c->h = wc.height + FRAME_HEIGHT_SUM;
+        Client_MoveResize(c);
+        if (X.mode == M_RESIZE /* && Focused == c */)
+        {
+            Mouse_ToCorner(c);
+        }
+    }
+    else
     {
         XConfigureWindow(X.disp, ev->window, ev->value_mask, &wc);
     }
@@ -149,33 +145,32 @@ static void xclientmsg(XEvent* e)
 {
     XClientMessageEvent* ev = &(e->xclient);
     printf("CLIENT_MSG(w: 0x%lx a: '%s')\n", ev->window, XGetAtomName(X.disp, ev->message_type));
-    if (ev->message_type == _NET_ACTIVE_WINDOW)
-    {
-//        mons_activate(ev->window);
-    }
+//    if (ev->message_type == _NET_ACTIVE_WINDOW)
+//    {
+////        mons_activate(ev->window);
+//    }
 }
 
 static void xpropnotify(XEvent* e)
 {
     XPropertyEvent* ev = &(e->xproperty);
     printf("PROP_NOTIFY(w: 0x%lx)\n", ev->window);
-//    Location loc = {0};
-//    if (mons_find(ev->window, &loc))
-//    {
-//        client_readprops(loc.client);
-//        client_draw(loc.client);
-//    }
+    Client* c = Client_Find(ev->window);
+    if (c)
+    {
+        Client_Update(c);
+    }
 }
 
 static void xenternotify(XEvent* e)
 {
     XCrossingEvent* ev = &(e->xcrossing);
-//    Location loc = {0};
     printf("ENTER(w: 0x%lx s: %d m: %d d: %d)\n", ev->window, ev->state, ev->mode, ev->detail);
-//    if (mons_find(ev->window, &loc))
-//    {
-//        client_focus(loc.client);
-//    }
+    Client* c = Client_Find(ev->window);
+    if (c)
+    {
+        Client_Focus(c);
+    }
 }
 
 static void xexpose(XEvent* e)
@@ -184,11 +179,11 @@ static void xexpose(XEvent* e)
     if (ev->count == 0)
     {
         printf("EXPOSE(w: 0x%lx)\n", ev->window);
-//        Location loc = {0};
-//        if (mons_find(ev->window, &loc))
-//        {
-//            client_draw(loc.client);
-//        }
+        Client* c = Client_Find(ev->window);
+        if (c)
+        {
+            Client_Update(c);
+        }
     }
 }
 
@@ -196,15 +191,13 @@ static void xmapnotify(XEvent* e)
 {
     XMapEvent* ev = &(e->xmap);
     printf("MAP(e: 0x%lx w: 0x%lx)\n", ev->event, ev->window);
-//    Location loc = {0};
-//    if (mons_find(ev->window, &loc))// && loc.client->win == ev->window)
-//    {
-//        client_draw(loc.client);
-//    }
+    Client* c = Client_Find(ev->window);
+    if (c)
+    {
+        Client_Update(c);
+    }
 }
 
-
-
 static void xkeypress(XEvent* e)
 {
     XKeyEvent* ev = &(e->xkey);
@@ -282,7 +275,6 @@ int main(void)
     atoms_init();
 
     /* setup window life-cycle management event handlers */
-//    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 50b773f7410e77568af46e281a6b88fe8872c26c..ad32035169f55d2c50a41318454ebace0b909621 100644 (file)
--- a/anvil.h
+++ b/anvil.h
@@ -158,6 +158,11 @@ void Client_Hide(Window win);
 void Client_MoveResize(Client* c);
 void Client_Move(Client* c, int xdiff, int ydiff);
 void Client_Resize(Client* c, int xdiff, int ydiff);
+void Client_Raise(Client* c);
+void Client_Lower(Client* c);
+void Client_Update(Client* c);
+void Client_Focus(Client* client);
+void Client_Close(Client* client);
 
 //Client* client_add(Window win, XWindowAttributes* attr);
 //void client_draw(Client* c);
index 43a203461e346fa912feb7ae9986ef8c14a70dbe..ac423718a948cf93f2d6b81ea24dd173072765fb 100644 (file)
--- a/client.c
+++ b/client.c
@@ -2,6 +2,7 @@
 
 static void ReadProps(Client* c);
 static void Redraw(Client* c);
+static void LayerWindows(void);
 
 void SetWMState(Client *c, int state)
 {
@@ -136,13 +137,24 @@ void Client_Hide(Window win)
 
 void Client_Destroy(Window win)
 {
-    (void)win;
+    Client* c = Client_Find(win);
+    if (c)
+    {
+        if (Focused == c)
+        {
+            Focused = NULL;
+        }
+        AllClients = list_del(AllClients, c);
+        xfree(c->name);
+        XDestroyWindow(X.disp, c->frame);
+        free(c);
+    }
 }
 
 void Client_MoveResize(Client* c)
 {
     int shaded = (c->flags & F_SHADED);
-    int floating = (c->flags & (F_DIALOG|F_FLOATING));
+    int floating = 1; //(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;
@@ -175,6 +187,51 @@ void Client_Resize(Client* c, int xdiff, int ydiff)
     Client_MoveResize(c);
 }
 
+void Client_Raise(Client* c)
+{
+    AllClients = list_del(AllClients, c);
+    c->next = AllClients;
+    AllClients = c;
+    LayerWindows();
+//    mons_layer(mon);
+
+}
+
+void Client_Lower(Client* c)
+{
+    (void)c;
+}
+
+void Client_Update(Client* c)
+{
+    ReadProps(c);
+    Redraw(c);
+}
+
+void Client_Focus(Client* client)
+{
+    Client* prev = Focused;
+    Focused = client;
+    XSetInputFocus(X.disp, client->win, RevertToPointerRoot, CurrentTime);
+    Redraw(client);
+    if (prev)
+    {
+        Redraw(prev);
+    }
+}
+
+void Client_Close(Client* client)
+{
+    if (client->flags & F_WM_DELETE)
+    {
+        sendmsg(client->win, WM_PROTOCOLS, WM_DELETE_WINDOW);
+    }
+    else
+    {
+        XKillClient(X.disp, client->win);
+    }
+}
+
 static void ReadProps(Client* c)
 {
     Atom *protos = NULL, actual_type, *wintype;
@@ -283,9 +340,46 @@ static void Redraw(Client* c)
     }
 
     /* tell the window to redraw itself */
-//    XClearArea(X.disp, c->win, 0, 0, 0, 0, True);
+\
 }
 
+void LayerWindows(void)
+{
+    int nwins = 0;
+    Window* wins = NULL;
+    Client* c;
+    LIST_FOR_EACH(c, AllClients)
+    {
+        wins = realloc(wins, ++nwins * sizeof(Window));
+        wins[nwins-1] = c->frame;
+    }
+//    /* add in the monocled windows first */
+//    LIST_FOR_EACH(col, mon->cspace->columns)
+//    {
+//        if (col->focused)
+//        {
+//            wins = realloc(wins, ++nwins * sizeof(Window));
+//            wins[nwins-1] = col->focused->frame;
+//        }
+//    }
+//    /* now lower all of the tiled windows */
+//    LIST_FOR_EACH(col, mon->cspace->columns)
+//    {
+//        LIST_FOR_EACH(c, col->clients)
+//        {
+//            if (col->focused != c)
+//            {
+//                wins = realloc(wins, ++nwins * sizeof(Window));
+//                wins[nwins-1] = c->frame;
+//            }
+//        }
+//    }
+    if (nwins)
+    {
+        XRestackWindows(X.disp, wins, nwins);
+    }
+    xfree(wins);
+}
 
 
 
@@ -365,37 +459,6 @@ void Client_InitAll(void)
 //    Client_MoveResize(c);
 //}
 //
-//void client_close(Client* c)
-//{
-//    if (c->flags & F_WM_DELETE)
-//    {
-//        sendmsg(c->win, WM_PROTOCOLS, WM_DELETE_WINDOW);
-//    }
-//    else
-//    {
-//        XKillClient(X.disp, c->win);
-//    }
-//}
-//
-//void client_focus(Client* c)
-//{
-//    Client* prev = Focused;
-//    Focused = c;
-//    XSetInputFocus(X.disp, c->win, RevertToPointerRoot, CurrentTime);
-//    Redraw(Focused);
-//    if (prev)
-//    {
-//        Redraw(prev);
-//    }
-//}
-//
-//void client_show(Client* c, int show)
-//{
-//    int (*mapfn)(Display*,Window) = (show ? XMapWindow : XUnmapWindow);
-//    mapfn(X.disp, c->frame);
-//    mapfn(X.disp, c->win);
-//}
-//
 //
 //void client_shade(Client* c)
 //{
diff --git a/keys.c b/keys.c
index 96fc186ac7080a944d1db27705acb5de2f5d575f..8fc45bf5377b0967a98dea0e57e5645491411913 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -52,7 +52,7 @@ static void killwin(Arg *arg)
     (void)arg;
     if (Focused)
     {
-//        client_close(Focused);
+        Client_Close(Focused);
     }
 }
 
diff --git a/mouse.c b/mouse.c
index baac4df2f892036f4a662e20e3ec32b01ff141cb..7b386721df4a97289f466b996d1f00cced81455d 100644 (file)
--- a/mouse.c
+++ b/mouse.c
@@ -49,11 +49,12 @@ static void lower_client(Client* client)
 {
     (void)client;
 //    mons_lower(loc->monitor, loc->client);
+    Client_Lower(client);
 }
 
 static void raise_client(Client* client)
 {
-    (void)client;
+    Client_Raise(client);
 //    mons_raise(loc->monitor, loc->client);
 }
 
@@ -104,37 +105,7 @@ static void ProcessMouseEvent(XButtonEvent* ev, Client* client, MouseAct* action
         }
     }
 }
-//
-//void mouse_down(XButtonEvent* ev, Location* loc)
-//{
-//    if (!loc->column)
-//    {
-//        process(ev, loc, Floating, sizeof(Floating)/sizeof(Floating[0]));
-//    }
-//    else
-//    {
-//        process(ev, loc, Stacked, sizeof(Stacked)/sizeof(Stacked[0]));
-//    }
-//}
-//
-//static void float_drag(XMotionEvent* ev, Location* loc)
-//{
-//}
-//
-//void mouse_up(XButtonEvent* ev, Location* loc)
-//{
-//    (void)ev;
-//    (void)loc;
-//}
-//
-//void mouse_drag(XMotionEvent* ev, Location* loc)
-//{
-//    if (!loc->column)
-//    {
-//        float_drag(ev, loc);
-//    }
-//}
-//
+
 //
 //void mouse_totitle(Client* c)
 //{