wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit c8f0151586430f1e144f07e8a17c5722b75e18e5
parent 5fc1892c9fe1bc1cb3ddb80877a9086f161999ee
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Thu, 26 Jan 2006 15:16:04 +0200

proceeded with page.c


Diffstat:
cmd/wm/client.c | 9+++++++--
cmd/wm/layout.c | 137-------------------------------------------------------------------------------
cmd/wm/layout_float.c | 265-------------------------------------------------------------------------------
cmd/wm/page.c | 224+++++++++++++++++++++++++++++--------------------------------------------------
cmd/wm/wm.c | 2+-
5 files changed, 90 insertions(+), 547 deletions(-)

diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -137,6 +137,8 @@ focus_client(Client *c) Client *old = sel_client(); /* setup indexes */ + if(c->page != p) + focus_page(c->page); p->is_managed = c->managed; if(p->is_managed) { for(i = 0; (i < p->managedsz) && p->managed[i]; i++) { @@ -145,14 +147,17 @@ focus_client(Client *c) if((j < col->clientssz) && col->clients[j]) { p->sel_managed = i; col->sel = j; + p->file[P_SEL_MANAGED_CLIENT]->content = c->file[P_PREFIX]->content; break; } } } else { for(i = 0; (i < p->floatingsz) && p->floating[i] && (p->floating[i] != c); i++); - if((i < p->floatingsz) && p->floating[i]) + if((i < p->floatingsz) && p->floating[i]) { + p->file[P_SEL_FLOATING_CLIENT]->content = c->file[P_PREFIX]->content; p->sel_float = i; + } } if(old && (old != c)) { @@ -410,7 +415,7 @@ attach_client(Client *c) { Page *p; if(!pages) - focus_page(alloc_page()); + alloc_page(); p = pages[sel_page]; /* XXX: do we need */ resize_client(c, &c->rect, 0); diff --git a/cmd/wm/layout.c b/cmd/wm/layout.c @@ -1,137 +0,0 @@ -/* - * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> - * See LICENSE file for license details. - */ - -#include <assert.h> -#include <stdlib.h> -#include <string.h> - -#include "wm.h" - -static void handle_after_write_layout(IXPServer * s, File * file); - -Layout * -alloc_layout(Page * p, char *layout) -{ - char buf[MAX_BUF], *name; - Layout *l = (Layout *) cext_emallocz(sizeof(Layout)); - - l->page = p; - if(strncmp(layout, LAYOUT_FLOAT, strlen(LAYOUT_FLOAT) + 1)) - name = "managed"; - else - name = "float"; - snprintf(buf, MAX_BUF, "/%s/layout/%s", p->file[P_PREFIX]->name, name); - l->file[L_PREFIX] = ixp_create(ixps, buf); - snprintf(buf, MAX_BUF, "/%s/layout/%s/name", p->file[P_PREFIX]->name, name); - l->file[L_NAME] = wmii_create_ixpfile(ixps, buf, layout); - snprintf(buf, MAX_BUF, "/%s/layout/%s/frame", p->file[P_PREFIX]->name, name); - l->file[L_FRAME_PREFIX] = ixp_create(ixps, buf); - snprintf(buf, MAX_BUF, "/%s/layout/%s/frame/sel", - p->file[P_PREFIX]->name, name); - l->file[L_SEL_FRAME] = ixp_create(ixps, buf); - l->file[L_SEL_FRAME]->bind = 1; - snprintf(buf, MAX_BUF, "/%s/layout/%s/ctl", p->file[P_PREFIX]->name, name); - l->file[L_CTL] = ixp_create(ixps, buf); - l->file[L_CTL]->after_write = handle_after_write_layout; - l->def = match_layout_def(layout); - l->def->init(l, nil); - p->file[P_SEL_LAYOUT]->content = l->file[L_PREFIX]->content; - return l; -} - -void -destroy_layout(Layout *l) -{ - l->def->deinit(l); - ixp_remove_file(ixps, l->file[L_PREFIX]); - free(l); -} - -void -focus_layout(Layout *l) -{ - Page *p = l->page; - Client *c; - p->sel = l; - p->file[P_SEL_LAYOUT]->content = l->file[L_PREFIX]->content; - if((c = l->def->sel(l))) - l->def->focus(l, c, False); - else { - invoke_wm_event(def[WM_EVENT_CLIENT_UPDATE]); - XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); - } - invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]); -} - -void -unmap_layout(Layout *l) -{ - Frame *f; - if(!l->def) - return; - for(f = l->def->frames(l); f; f = f->next) - XMoveWindow(dpy, f->win, 2 * rect.width, 2 * rect.height); -} - -void -map_layout(Layout *l, Bool raise) -{ - Frame *f; - if(!l->def) - return; - for(f = l->def->frames(l); f; f = f->next) { - XMoveWindow(dpy, f->win, f->rect.x, f->rect.y); - if(raise) - XRaiseWindow(dpy, f->win); - } -} - -Layout * -sel_layout() -{ - return selpage ? selpage->sel : nil; -} - -void -attach_frame_to_layout(Layout *l, Frame * f) -{ - wmii_move_ixpfile(f->file[F_PREFIX], l->file[L_FRAME_PREFIX]); - l->file[L_SEL_FRAME]->content = f->file[F_PREFIX]->content; - f->layout = l; -} - -void -detach_frame_from_layout(Frame * f) -{ - f->layout->file[L_SEL_FRAME]->content = 0; - f->layout = 0; -} - -static void -handle_after_write_layout(IXPServer * s, File * file) -{ - Page *p; - for(p = pages; p; p = p->next) { - if(p->managed && (file == p->managed->file[L_CTL])) { - run_action(file, p->managed, - p->managed->def->actions(p->managed)); - return; - } else if(file == p->floating->file[L_CTL]) { - run_action(file, p->floating, - p->floating->def->actions(p->floating)); - return; - } - } -} - -LayoutDef * -match_layout_def(char *name) -{ - LayoutDef *l; - for(l = layouts; l; l = l->next) - if(!strncmp(name, l->name, strlen(l->name))) - return l; - return nil; -} diff --git a/cmd/wm/layout_float.c b/cmd/wm/layout_float.c @@ -1,265 +0,0 @@ -/* - * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> - * See LICENSE file for license details. - */ - -#include <stdlib.h> -#include <string.h> -#include <math.h> - -#include "wm.h" -#include "layoutdef.h" - -static void init_float(Layout *l, Client * clients); -static Client *deinit_float(Layout *l); -static void arrange_float(Layout *l); -static Bool attach_float(Layout *l, Client * c); -static void detach_float(Layout *l, Client * c, Bool unmap); -static void resize_float(Frame * f, XRectangle * new, XPoint * pt); -static void focus_float(Layout * l, Client * c, Bool raise); -static Frame *frames_float(Layout *l); -static Client *sel_float(Layout *l); -static Action *actions_float(Layout *l); - -static void select_frame(void *obj, char *arg); -static void max_frame(void *obj, char *arg); - -Action lfloat_acttbl[] = { - {"select", select_frame}, - {"max", max_frame}, - {0, 0} -}; - -typedef struct { - Frame *frames; - Frame *sel; - size_t nframes; -} Float; - -void -init_layout_float() -{ - LayoutDef *lp, *l = cext_emallocz(sizeof(LayoutDef)); - l->name = "float"; - l->init = init_float; - l->deinit = deinit_float; - l->arrange = arrange_float; - l->attach = attach_float; - l->detach = detach_float; - l->resize = resize_float; - l->focus = focus_float; - l->frames = frames_float; - l->sel = sel_float; - l->actions = actions_float; - - for(lp = layouts; lp && lp->next; lp = lp->next); - if(lp) - lp->next = l; - else - layouts = l; -} - -static void -arrange_float(Layout *l) -{ -} - -static void -init_float(Layout *l, Client * clients) -{ - Client *n, *c = clients; - Float *fl = cext_emallocz(sizeof(Float)); - l->aux = fl; - - while(c) { - n = c->next; - attach_float(l, c); - c = n; - } -} - -static void -attach_frame(Layout *l, Frame * new) -{ - Float *fl = l->aux; - Frame *f; - - for(f = fl->frames; f && f->next; f = f->next); - if(!f) - fl->frames = new; - else { - f->next = new; - new->prev = f; - } - attach_frame_to_layout(l, new); - fl->nframes++; -} - -static void -detach_frame(Layout *l, Frame * old) -{ - Float *fl = l->aux; - - if(old->prev) - old->prev->next = old->next; - else - fl->frames = old->next; - if(old->next) - old->next->prev = old->prev; - - if(fl->sel == old) - fl->sel = fl->frames; - - old->prev = old->next = nil; - detach_frame_from_layout(old); - fl->nframes--; -} - -static Client * -deinit_float(Layout *l) -{ - Float *fl = l->aux; - Client *res = nil, *c = nil, *cl; - Frame *f; - - while((f = fl->frames)) { - cl = f->client; - detach_client_from_frame(cl, False); - cl->prev = cl->next = 0; - if(!res) - res = c = cl; - else { - c->next = cl; - cl->prev = c; - c = cl; - } - detach_frame(l, f); - destroy_frame(f); - } - free(fl); - l->aux = nil; - return res; -} - -static Bool -attach_float(Layout *l, Client * c) -{ - Frame *f; - - /* check for tabbing? */ - if(c->rect.y < layout_rect.y) - c->rect.y = layout_rect.y; - if(c->rect.x < layout_rect.x) - c->rect.x = layout_rect.x; - - f = alloc_frame(&c->rect); - attach_frame_to_layout(l, f); - attach_frame(l, f); - attach_client_to_frame(f, c); - if(l->page == selpage) - XMapWindow(dpy, f->win); - focus_float(l, c, True); - return True; -} - -static void -detach_float(Layout *l, Client * c, Bool unmap) -{ - Frame *f = c->frame; - detach_client_from_frame(c, unmap); - detach_frame(l, f); - destroy_frame(f); -} - -static void -resize_float(Frame * f, XRectangle * new, XPoint * pt) -{ - f->rect = *new; -} - -static void -focus_float(Layout *l, Client *c, Bool raise) -{ - Float *fl = l->aux; - Client *old = sel_client(); - - c->frame->sel = c; - fl->sel = c->frame; - l->file[L_SEL_FRAME]->content = c->frame->file[F_PREFIX]->content; - - if(raise) { - XRaiseWindow(dpy, c->frame->win); - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, - c->rect.width / 2, c->rect.height / 2); - } - - focus_client(c, old); -} - -static Frame * -frames_float(Layout *l) -{ - Float *fl = l->aux; - return fl->frames; -} - -static void -max_frame(void *obj, char *arg) -{ - Layout *l = obj; - Float *fl = l->aux; - Frame *f = fl->sel; - - if(!f) - return; - if(f->maximized) { - resize_frame(f, &f->old, nil); - f->maximized = False; - } - else { - f->old = f->rect; - resize_frame(f, &rect, nil); - f->maximized = True; - } -} - -static void -select_frame(void *obj, char *arg) -{ - Layout *l = obj; - Float *fl = l->aux; - Frame *f = fl->sel; - - if(!f || !arg) - return; - if(!strncmp(arg, "prev", 5)) { - if(f->prev) - f = f->prev; - else - for(f = fl->frames; f && f->next; f = f->next); - } else if(!strncmp(arg, "next", 5)) { - if(f->next) - f = f->next; - else - f = fl->frames; - } else { - unsigned int i = 0, idx = blitz_strtonum(arg, 0, fl->nframes - 1); - for(f = fl->frames; f && i != idx; f = f->next) - i++; - } - if(f) - focus_float(l, f->sel, True); -} - -static Client * -sel_float(Layout *l) -{ - Float *fl = l->aux; - return fl->sel ? fl->sel->sel : nil; -} - -static Action * -actions_float(Layout *l) -{ - return lfloat_acttbl; -} diff --git a/cmd/wm/page.c b/cmd/wm/page.c @@ -57,113 +57,72 @@ alloc_page() { Page *p, *new = cext_emallocz(sizeof(Page)); char buf[MAX_BUF], buf2[16]; + static int id = 1; + size_t np; - snprintf(buf2, sizeof(buf2), "%d", pageid); - snprintf(buf, sizeof(buf), "/%d", pageid); + snprintf(buf2, sizeof(buf2), "%d", id); + snprintf(buf, sizeof(buf), "/%d", id); new->file[P_PREFIX] = ixp_create(ixps, buf); - snprintf(buf, sizeof(buf), "/%d/name", pageid); + snprintf(buf, sizeof(buf), "/%d/name", id); new->file[P_NAME] = wmii_create_ixpfile(ixps, buf, buf2); - snprintf(buf, sizeof(buf), "/%d/layout/", pageid); - new->file[P_LAYOUT_PREFIX] = ixp_create(ixps, buf); - snprintf(buf, sizeof(buf), "/%d/layout/sel", pageid); - new->file[P_SEL_LAYOUT] = ixp_create(ixps, buf); - new->file[P_SEL_LAYOUT]->bind = 1; /* mount point */ - snprintf(buf, MAX_BUF, "/%d/layoutname", pageid); - new->file[P_LAYOUT_NAME] = wmii_create_ixpfile(ixps, buf, def[WM_LAYOUT]->content); - new->file[P_LAYOUT_NAME]->after_write = handle_after_write_page; - snprintf(buf, sizeof(buf), "/%d/ctl", pageid); + snprintf(buf, sizeof(buf), "/%d/floating/", id); + new->file[P_FLOATING_PREFIX] = ixp_create(ixps, buf); + snprintf(buf, sizeof(buf), "/%d/managed/", id); + new->file[P_MANAGED_PREFIX] = ixp_create(ixps, buf); + snprintf(buf, sizeof(buf), "/%d/sel/", id); + new->file[P_SEL_PREFIX] = ixp_create(ixps, buf); + new->file[P_SEL_PREFIX]->bind = 1; /* mount point */ + snprintf(buf, sizeof(buf), "/%d/floating/sel", id); + new->file[P_SEL_FLOATING_CLIENT] = ixp_create(ixps, buf); + new->file[P_SEL_FLOATING_CLIENT]->bind = 1; + snprintf(buf, sizeof(buf), "/%d/managed/sel", id); + new->file[P_SEL_MANAGED_CLIENT] = ixp_create(ixps, buf); + new->file[P_SEL_MANAGED_CLIENT]->bind = 1; + snprintf(buf, sizeof(buf), "/%d/ctl", id); new->file[P_CTL] = ixp_create(ixps, buf); new->file[P_CTL]->after_write = handle_after_write_page; - new->floating = alloc_layout(new, LAYOUT_FLOAT); - new->sel = new->managed = alloc_layout(new, def[WM_LAYOUT]->content); - for(p = pages; p && p->next; p = p->next); - if(!p) { - pages = new; - new->index = 0; - } - else { - new->prev = p; - p->next = new; - new->index = p->index + 1; - } def[WM_SEL_PAGE]->content = new->file[P_PREFIX]->content; invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]); - pageid++; - npages++; + id++; + attach_page_to_array(p, pages, &pagessz); + for(np = 0; (np < pagessz) && pages[np]; np++); + focus_page(new); XChangeProperty(dpy, root, net_atoms[NET_NUMBER_OF_DESKTOPS], XA_CARDINAL, - 32, PropModeReplace, (unsigned char *) &npages, 1); + 32, PropModeReplace, (unsigned char *) &np, 1); return new; } void -destroy_page(Page * p) +destroy_page(Page *p) { - if(!p) - return; + unsigned int i; + size_t naqueue = 0; - Page *newselpage; - MapQueue *o, *n; + for(i = 0; (i < aqueuesz) && aqueue[i]; i++) + if(aqueue[i] == p) + naqueue++; + for(i = 0; i < naqueue; i++) + detach_page_from_array(p, aqueue); - while(attachqueue && (attachqueue->page == p)) { - n = attachqueue->next; - free(attachqueue); - attachqueue = n; - } - o = attachqueue; - n = nil; - if(attachqueue) - n = attachqueue->next; - while(n) { - if(n->page == p) { - o->next = n->next; - free(n); - n = o->next; - } else - n = n->next; - } + for(i = 0; (i < clientssz) && clients[i]; i++) + if(clients[i]->page == p) + detach_client(clients[i], False); + + for(i = 0; (i < pagessz) && pages[i] && (p != pages[i]); i++); + if(sel_page && (sel_page == i)) + sel_page--; - destroy_layout(p->floating); - destroy_layout(p->managed); def[WM_SEL_PAGE]->content = 0; ixp_remove_file(ixps, p->file[P_PREFIX]); - if(p == selpage) { - selpage = nil; - if(p->prev) - newselpage = p->prev; - else - newselpage = nil; - } - - if(p == pages) { - if(p->next) { - p->next->prev = nil; - pages = p->next; - pages->index = 0; - } else - pages = nil; - } else { - p->prev->next = p->next; - if(p->next) - p->next->prev = p->prev; - } - free(p); - /* update page indexes */ - for (p = pages; p && p->next; p = p->next) { - if (p->prev && p->prev->index + 1 != p->index) /* if page index difference is not one */ - --(p->index); - } - - npages--; + for(i = 0; (i < pagessz) && pages[i]; i++); XChangeProperty(dpy, root, net_atoms[NET_NUMBER_OF_DESKTOPS], XA_CARDINAL, - 32, PropModeReplace, (unsigned char *) &npages, 1); + 32, PropModeReplace, (unsigned char *) &i, 1); /* determine what to focus and do that */ - if(newselpage) - focus_page(newselpage); - else if(pages) - focus_page(pages); + if(pages[sel_page]) + focus_page(pages[sel_page]); else { invoke_wm_event(def[WM_EVENT_CLIENT_UPDATE]); invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]); @@ -172,26 +131,36 @@ destroy_page(Page * p) } void -focus_page(Page * p) +focus_page(Page *p) { - if(!p) - return; + unsigned int i, j; + Page *old = pages ? pages[sel_page] : nil; - if(p != selpage) { - if(selpage) { - unmap_layout(selpage->managed); - unmap_layout(selpage->floating); - } - map_layout(p->managed, False); - map_layout(p->floating, False); - } + if(!pages) + return; + + for(i = 0; (i < pagessz) && pages[i]; i++); + + if(i == sel_page) + return; - selpage = p; + sel_page = i; + for(j = 0; (j < clientssz) && clients[j]; j++) { + if(clients[j]->page == old) + XMoveWindow(dpy, clients[j]->frame.win, 2 * rect.width, 2 * rect.height); + else if(clients[j]->page == p) + XMoveWindow(dpy, clients[j]->frame.win, + clients[j]->frame.rect.x, clients[j]->frame.rect.y); + } def[WM_SEL_PAGE]->content = p->file[P_PREFIX]->content; + if(p->is_managed) + p->file[P_SEL_PREFIX]->content = p->file[P_MANAGED_PREFIX]->content; + else + p->file[P_SEL_PREFIX]->content = p->file[P_FLOATING_PREFIX]->content; + invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]); - focus_layout(p->sel); XChangeProperty(dpy, root, net_atoms[NET_CURRENT_DESKTOP], XA_CARDINAL, - 32, PropModeReplace, (unsigned char *) &(selpage->index), 1); + 32, PropModeReplace, (unsigned char *) &sel_page, 1); } XRectangle * @@ -226,38 +195,14 @@ rectangles(unsigned int *num) } static void -handle_after_write_page(IXPServer * s, File * file) +handle_after_write_page(IXPServer *s, File *file) { - Page *p; - for(p = pages; p; p = p->next) { - if(file == p->file[P_CTL]) { - run_action(file, p, page_acttbl); - return; - } - else if(file == p->file[P_LAYOUT_NAME]) { - LayoutDef *l = match_layout_def(file->content); - Client *clients = nil; + size_t i; - if(!strncmp(file->content, LAYOUT_FLOAT, strlen(LAYOUT_FLOAT))) - l = nil; - - if(p->managed->def) - clients = p->managed->def->deinit(p->managed); - p->managed->def = l; - if(l) { - p->managed->def->init(p->managed, clients); - focus_layout(p->managed); - } - else { - Client *n; - focus_layout(p->floating); - while(clients) { - n = clients->next; - p->floating->def->attach(p->floating, clients); - clients = n; - } - } - invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]); + for(i = 0; (i < pagessz) && pages[i]; i++) { + if(file == pages[i]->file[P_CTL]) { + run_action(file, pages[i], page_acttbl); + return; } } } @@ -265,16 +210,7 @@ handle_after_write_page(IXPServer * s, File * file) static void xexec(void *obj, char *arg) { - MapQueue *r; - - if(!attachqueue) - r = attachqueue = cext_emallocz(sizeof(MapQueue)); - else { - for(r = attachqueue; r && r->next; r = r->next); - r->next = cext_emallocz(sizeof(MapQueue)); - r = r->next; - } - r->page = obj; + attach_page_to_array(obj, aqueue, &aqueuesz); wmii_spawn(dpy, arg); } @@ -283,8 +219,12 @@ toggle_layout(void *obj, char *arg) { Page *p = obj; - if(!p->managed->def || (p->sel == p->managed)) - focus_layout(p->floating); - else - focus_layout(p->managed); + p->is_managed = !p->is_managed; + if(p->is_managed) { + Column *col = p->managed[p->sel_managed]; + if(col && col->clientssz && col->clients[col->sel]) + focus_client(col->clients[col->sel]); + } + else if(p->floating && p->floatingsz && p->floating[p->sel_float]) + focus_client(p->floating[p->sel_float]); } diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c @@ -450,7 +450,7 @@ xdestroy_page(void *obj, char *arg) static void new_page(void *obj, char *arg) { - focus_page(alloc_page()); + alloc_page(); } Client *