]> git.mdlowis.com Git - projs/tide.git/commitdiff
added rudimentary layout logic.
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 10 Jun 2019 02:35:14 +0000 (22:35 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 10 Jun 2019 02:35:14 +0000 (22:35 -0400)
inc/x11.h
src/anvil.c
src/lib/x11.c
src/tframe.c
src/tide.c

index dadf8958ea4484fd26426bdaaf9b708bb1307894..35276462d04278f228d2ad4d7ae79d02616402e3 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -134,7 +134,7 @@ void x11_resize(XConf* x, XEvent* e);
 
 void x11_mkwin(XConf* x, int width, int height, int evmask);
 void x11_mkdialog(XConf* x, int width, int height, int evmask);
-void x11_process_events(XConf* x, void (*redrawfn)(XConf*));
+void x11_process_events(XConf* x);
 void x11_event_loop(XConf* x, void (*redraw)(XConf* x));
 int x11_getptr(XConf* x, int* ptrx, int* ptry);
 uint32_t x11_getkey(XConf* x, XEvent* e);
index cc7cc9e9e941ba8b6f75de2df6677221032b8133..d399df0ebccebaac3e787bdf790de20fc6a185da 100644 (file)
@@ -45,12 +45,11 @@ void* xfree(void* p) {
 
 /* Client Handling
  *****************************************************************************/
-
-
 void client_config(XConf* xs, Client* c, int x, int y, int w, int h) {
     c->x = x, c->y = y, c->w = w, c->h = h;
-    XMoveResizeWindow(xs->display, c->frame, x, y, c->w-2, xs->font->height);
-    XMoveResizeWindow(xs->display, c->win,   x, y + xs->font->height, c->w - 2, c->h - xs->font->height - 2);
+    int height = xs->font->height + 3;
+    XMoveResizeWindow(xs->display, c->frame, x, y, c->w-2, height);
+    XMoveResizeWindow(xs->display, c->win,   x, y + height, c->w - 2, c->h - height - 2);
 }
 
 void client_raise(XConf* x, Client* c) {
@@ -61,8 +60,6 @@ void client_raise(XConf* x, Client* c) {
 void client_add(XConf* x, Window win) {
     Client* c = calloc(1, sizeof(Client));
     c->win = win;
-    c->next = Clients;
-    Clients = c;
     XGrabServer(x->display);
     XFetchName(x->display, win, &c->name);
 
@@ -86,11 +83,23 @@ void client_add(XConf* x, Window win) {
         EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
 
     /* position the window and frame */
+    Client* biggy = Clients;
+    for (Client* curr = Clients; curr; curr = curr->next)
+        if (curr->h > biggy->h) biggy = curr;
+    if (biggy) {
+        c->h = (biggy->h - (biggy->h / 2));
+        biggy->h /= 2;
+        c->y = biggy->y + biggy->h;
+        client_config(x, biggy, biggy->x, biggy->y, biggy->w, biggy->h);
+    }
     client_config(x, c, c->x, c->y, c->w, c->h);
     client_raise(x, c);
 
     XSync(x->display, False);
     XUngrabServer(x->display);
+
+    c->next = Clients;
+    Clients = c;
 }
 
 Client* client_del(XConf* x, Client* curr, Client* c) {
@@ -121,7 +130,10 @@ Client* client_find(Window win) {
 }
 
 void client_redraw(XConf* x, Client* c) {
-    (void)x, (void)c;
+    XftColor clr;
+    xftcolor(x, &clr, -1);
+    XftDrawStringUtf8(c->xft, &clr, x->font, 0, x->font->ascent, (const FcChar8*)c->name, strlen(c->name));
+    XftColorFree(x->display, x->visual, x->colormap, &clr);
 }
 
 /* X11 Event Handling
@@ -132,6 +144,9 @@ void client_redraw(XConf* x, Client* c) {
 
 static void xbtnpress(XConf* x, XEvent* e) {
     printf("btn\n");
+    /*
+        *
+    */
 }
 
 static void xconfigrequest(XConf* x, XEvent* e) {
@@ -171,11 +186,25 @@ static void xunmapnotify(XConf* x, XEvent* e) {
 
 static void xdestroynotify(XConf* x, XEvent* e) {
     printf("destroy\n");
-    /*
-        This is where we cleanup windows we care about. destroy them and their frames.
-    */
+    /* This is where we cleanup windows we care about. destroy them and their frames. */
     Client* c = client_find(e->xdestroywindow.window);
-    if (c) Clients = client_del(x, Clients, c);
+    if (c) {
+        //int y = c->y, h = c->h;
+        Client* next = c->next;
+        printf("c: %p next: %p\n", (void*)c, (void*)next);
+//        if (next) {
+//            next->y = y, next->h += h;
+//            client_config(x, next, next->x, next->y, next->w, next->h);
+//            client_raise(x, next);
+//        }
+
+        for (Client* n = Clients; n; n = n->next) {
+            printf("%p ", (void*)n);
+        }
+        puts("");
+
+        Clients = client_del(x, Clients, c);
+    }
 }
 
 static void xclientmsg(XConf* x, XEvent* e) {
index 052d08e7116490ae59b4106d73922df8618a47dc..d2334a54682337d264f690430cbf228e95ab44a5 100644 (file)
@@ -84,14 +84,12 @@ static void update_state(XConf* x, XEvent* e) {
     }
 }
 
-void x11_process_events(XConf* x, void (*redrawfn)(XConf*)) {
+void x11_process_events(XConf* x) {
     int nevents;
     /* reap zombie background processes */
     for (int status; waitpid(-1, &status, WNOHANG) > 0;);
     /* process the entire event queue */
-
-    while (XEventsQueued(x->display, QueuedAfterFlush))
-    {
+    while (XEventsQueued(x->display, QueuedAfterFlush)) {
         XGetMotionEvents(x->display, x->self, CurrentTime, CurrentTime, &nevents);
         for (XEvent e; XPending(x->display);) {
             XNextEvent(x->display, &e);
@@ -100,7 +98,6 @@ void x11_process_events(XConf* x, void (*redrawfn)(XConf*)) {
                 (x->eventfns[e.type])(x, &e);
         }
     }
-    (void)redrawfn;
 }
 
 void x11_event_loop(XConf* x, void (*redraw)(XConf* x)) {
index 7979304c395534b3af7c1d4584089199d8342d25..4b388db99b37b31173bd182550542861f1f7393f 100644 (file)
@@ -198,7 +198,7 @@ static void xredraw(XConf* x) {
 }
 
 static void xupdate(Job* job) {
-    x11_process_events(&X, xredraw);
+    x11_process_events(&X);
     if (!job) xredraw(&X);
 }
 
index 3201cec9ea10cfa609aa76461f98b17ee94ded13..f9ff77023a283f36aba2323eff448eeb7ad684ce 100644 (file)
@@ -212,7 +212,7 @@ static void xredraw(XConf* x) {
 
 static void xupdate(Job* job) {
     /* redraw if we have changes or if we have input from a job */
-    x11_process_events(&X, xredraw);
+    x11_process_events(&X);
     if (!job) xredraw(&X);
 }