/* 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) {
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);
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) {
}
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
static void xbtnpress(XConf* x, XEvent* e) {
printf("btn\n");
+ /*
+ *
+ */
}
static void xconfigrequest(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) {
}
}
-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);
(x->eventfns[e.type])(x, &e);
}
}
- (void)redrawfn;
}
void x11_event_loop(XConf* x, void (*redraw)(XConf* x)) {