wmii

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

commit 7a8fe69742620a1b2bae362185d1f544ffb147b5
parent c09888f7a1b35954518996a9d6dd002d51789822
Author: garbeam <garbeam@localhost.localdomain>
Date:   Mon,  5 Dec 2005 00:45:59 +0200

several changes, adding alloc_area


Diffstat:
cmd/wm/area.c | 60++++++++++++++++++++++++++++++++++++++----------------------
cmd/wm/client.c | 143++++++++++++++++++++++++++++++++++++-------------------------------------------
cmd/wm/core.c | 298+++++++++++++++++++++++++++++++++++++++++--------------------------------------
cmd/wm/event.c | 107+++++++++++++++++++++++++++++++++++--------------------------------------------
cmd/wm/frame.c | 276+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
cmd/wm/layout_column.c | 206++++++++++++++++++++++++++++++++++++++++----------------------------------------
cmd/wm/mouse.c | 154++++++++++++++++++++++++++++++++++++++++---------------------------------------
cmd/wm/page.c | 195++++++++++++++++++++++++++++++++++++++-----------------------------------------
cmd/wm/wm.c | 175++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
cmd/wm/wm.h | 274++++++++++++++++++++++++++++++++++++++++---------------------------------------
cmd/wmibar.c | 226++++++++++++++++++++++++++++++++++++++-----------------------------------------
cmd/wmibar2.c | 163++++++++++++++++++++++++++++++++++++-------------------------------------------
cmd/wmifs.c | 175++++++++++++++++++++++++++++++++++++-------------------------------------------
cmd/wmikeys.c | 216++++++++++++++++++++++++++++++++++++++-----------------------------------------
cmd/wmimenu.c | 316+++++++++++++++++++++++++++++++++++++++++++------------------------------------
cmd/wmiplumb.c | 43++++++++++++++++++++-----------------------
cmd/wmir.c | 75++++++++++++++++++++++++++++++++++++---------------------------------------
cmd/wmir2.c | 117+++++++++++++++++++++++++++++++++++++-------------------------------------------
cmd/wmiwarp.c | 18++++++++----------
libcext/array.c | 41+++++++++++++++++------------------------
libcext/cext.h | 28++++++++++++++--------------
libcext/emalloc.c | 7+++----
libcext/estrdup.c | 5++---
libcext/strlcat.c | 7+++----
libcext/strlcpy.c | 9++++-----
libcext/strtonum.c | 27+++++++++++----------------
libcext/tokenize.c | 9++++-----
libixp/client.c | 110++++++++++++++++++++++++++++++++++++-------------------------------------------
libixp/ixp.h | 196+++++++++++++++++++++++++++++++++++++++----------------------------------------
libixp/message.c | 97++++++++++++++++++++++++++++++++++---------------------------------------------
libixp/ramfs.c | 84+++++++++++++++++++++++++++++++++++--------------------------------------------
libixp/server.c | 153+++++++++++++++++++++++++++++++++++--------------------------------------------
libixp2/client.c | 53++++++++++++++++++++++-------------------------------
libixp2/convert.c | 64+++++++++++++++++++++++-----------------------------------------
libixp2/ixp.h | 228+++++++++++++++++++++++++++++++++++++++----------------------------------------
libixp2/message.c | 40++++++++++++++++++----------------------
libixp2/server.c | 77+++++++++++++++++++++++++++++++++--------------------------------------------
libixp2/socket.c | 35++++++++++++++++-------------------
libixp2/transport.c | 21+++++++++------------
liblitz/blitz.h | 57++++++++++++++++++++++++++++-----------------------------
liblitz/draw.c | 47+++++++++++++++++++----------------------------
liblitz/geometry.c | 55++++++++++++++++++++++++++-----------------------------
liblitz/kb.c | 10++++------
liblitz/mouse.c | 10++++------
liblitz/util.c | 11+++++------
libwmii/ixputil.c | 31+++++++++++++------------------
libwmii/spawn.c | 3+--
libwmii/util.c | 5++---
libwmii/wm.c | 32+++++++++++++++-----------------
libwmii/wmii.h | 28++++++++++++++--------------
50 files changed, 2344 insertions(+), 2473 deletions(-)

diff --git a/cmd/wm/area.c b/cmd/wm/area.c @@ -11,64 +11,80 @@ #include <cext.h> -/*static Area zero_area = {0};*/ +static Area zero_area = {0}; -void -free_area(Area* a) +Area *alloc_area(Page *p, XRectangle * r) +{ + char buf[MAX_BUF]; + Area *a = (Area *) emalloc(sizeof(Area)); + + *a = zero_area; + a->rect = *r; + a->page = p; + snprintf(buf, MAX_BUF, "/%s/area/%d", p->files[P_PREFIX]->name, count_items((void **) p->areas)); + a->files[A_PREFIX] = ixp_create(ixps, buf); + snprintf(buf, MAX_BUF, "/%s/area/%d/frame/sel", p->files[P_PREFIX]->name, count_items((void **) p->areas)); + a->files[A_SEL_FRAME] = ixp_create(ixps, buf); + snprintf(buf, MAX_BUF, "/%s/area/%d/ctl", p->files[P_PREFIX]->name, count_items((void **) p->areas)); + a->files[A_CTL] = ixp_create(ixps, buf); + snprintf(buf, MAX_BUF, "/%s/area/%d/geometry", p->files[P_PREFIX]->name, count_items((void **) p->areas)); + a->files[A_GEOMETRY] = ixp_create(ixps, buf); + snprintf(buf, MAX_BUF, "/%s/area/%d/layout", p->files[P_PREFIX]->name, count_items((void **) p->areas)); + a->files[A_LAYOUT] = ixp_create(ixps, buf); + p->areas = + (Area **) attach_item_end((void **) p->areas, a, sizeof(Area *)); + p->sel = index_item((void **) p->areas, a); + return a; +} + +void free_area(Area * a) { ixp_remove_file(ixps, a->files[A_PREFIX]); free(a); } -void -destroy_area(Area *a) +void destroy_area(Area * a) { unsigned int i; a->layout->deinit(a); - for(i = 0; a->frames && a->frames[i]; i++); - destroy_frame(a->frames[i]); + for (i = 0; a->frames && a->frames[i]; i++); + destroy_frame(a->frames[i]); free(a->frames); free_area(a); } -void -focus_area(Area *a, int raise, int up, int down) +void focus_area(Area * a, int raise, int up, int down) { - Page *p = a->page; + Page *p = a->page; if (!p) return; if (down && a->frames) focus_frame(a->frames[a->sel], raise, 0, down); - p->sel = index_item((void **)p->areas, a); + p->sel = index_item((void **) p->areas, a); p->files[P_SEL_AREA]->content = a->files[A_PREFIX]->content; if (up) focus_page(p, raise, 0); } -void -attach_frame_to_area(Area *a, Frame * f) -{ +void attach_frame_to_area(Area * a, Frame * f) +{ } -void -detach_frame_from_area(Frame * f, int ignore_focus_and_destroy) +void detach_frame_from_area(Frame * f, int ignore_focus_and_destroy) { } -void -draw_area(Area *a) +void draw_area(Area * a) { } -void -hide_area(Area *a) +void hide_area(Area * a) { } -void -show_area(Area *a) +void show_area(Area * a) { } diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -12,16 +12,15 @@ #include <cext.h> -static Client zero_client = {0}; +static Client zero_client = { 0 }; -Client * -alloc_client(Window w) +Client *alloc_client(Window w) { - static int id = 0; - char buf[MAX_BUF]; - char buf2[MAX_BUF]; - XClassHint ch; - Client *c = (Client *) emalloc(sizeof(Client)); + static int id = 0; + char buf[MAX_BUF]; + char buf2[MAX_BUF]; + XClassHint ch; + Client *c = (Client *) emalloc(sizeof(Client)); *c = zero_client; c->win = w; @@ -42,24 +41,24 @@ alloc_client(Window w) c->files[C_INSTANCE] = ixp_create(ixps, buf); } id++; - clients = (Client **) attach_item_end((void **) clients, c, sizeof(Client *)); + clients = + (Client **) attach_item_end((void **) clients, c, + sizeof(Client *)); XSelectInput(dpy, c->win, CLIENT_MASK); return c; } -void -set_client_state(Client * c, int state) +void set_client_state(Client * c, int state) { - long data[2]; + long data[2]; data[0] = (long) state; data[1] = (long) None; XChangeProperty(dpy, c->win, wm_state, wm_state, 32, - PropModeReplace, (unsigned char *) data, 2); + PropModeReplace, (unsigned char *) data, 2); } -void -show_client(Client * c) +void show_client(Client * c) { XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask); XMapWindow(dpy, c->win); @@ -69,8 +68,7 @@ show_client(Client * c) grab_client(c, Mod1Mask, Button3); } -void -hide_client(Client * c) +void hide_client(Client * c) { ungrab_client(c, AnyModifier, AnyButton); XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask); @@ -79,34 +77,31 @@ hide_client(Client * c) set_client_state(c, WithdrawnState); } -void -reparent_client(Client * c, Window w, int x, int y) +void reparent_client(Client * c, Window w, int x, int y) { XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask); XReparentWindow(dpy, c->win, w, x, y); XSelectInput(dpy, c->win, CLIENT_MASK); } -void -grab_client(Client * c, unsigned long mod, unsigned int button) +void grab_client(Client * c, unsigned long mod, unsigned int button) { XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask); XGrabButton(dpy, button, mod, c->win, False, - ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None); + ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None); if ((mod != AnyModifier) && num_lock_mask) { XGrabButton(dpy, button, mod | num_lock_mask, c->win, - False, ButtonPressMask, GrabModeAsync, GrabModeAsync, - None, None); + False, ButtonPressMask, GrabModeAsync, GrabModeAsync, + None, None); XGrabButton(dpy, button, mod | num_lock_mask | LockMask, - c->win, False, ButtonPressMask, GrabModeAsync, - GrabModeAsync, None, None); + c->win, False, ButtonPressMask, GrabModeAsync, + GrabModeAsync, None, None); } XSelectInput(dpy, c->win, CLIENT_MASK); XSync(dpy, False); } -void -ungrab_client(Client * c, unsigned long mod, unsigned int button) +void ungrab_client(Client * c, unsigned long mod, unsigned int button) { XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask); XUngrabButton(dpy, button, mod, c->win); @@ -118,8 +113,7 @@ ungrab_client(Client * c, unsigned long mod, unsigned int button) XSync(dpy, False); } -void -configure_client(Client * c) +void configure_client(Client * c) { XConfigureEvent e; e.type = ConfigureNotify; @@ -143,8 +137,7 @@ configure_client(Client * c) XSync(dpy, False); } -void -close_client(Client * c) +void close_client(Client * c) { if (c->proto & PROTO_DEL) send_message(dpy, c->win, wm_protocols, wm_delete); @@ -152,10 +145,9 @@ close_client(Client * c) XKillClient(dpy, c->win); } -void -_init_client(Client * c, XWindowAttributes * wa) +void _init_client(Client * c, XWindowAttributes * wa) { - long msize; + long msize; c->rect.x = wa->x; c->rect.y = wa->y; c->border = wa->border_width; @@ -167,20 +159,19 @@ _init_client(Client * c, XWindowAttributes * wa) XGetTransientForHint(dpy, c->win, &c->trans); /* size hints */ if (!XGetWMNormalHints(dpy, c->win, &c->size, &msize) - || !c->size.flags) + || !c->size.flags) c->size.flags = PSize; XAddToSaveSet(dpy, c->win); } -void -handle_client_property(Client * c, XPropertyEvent * e) +void handle_client_property(Client * c, XPropertyEvent * e) { - char buf[1024]; - long msize; + char buf[1024]; + long msize; buf[0] = '\0'; if (e->state == PropertyDelete) - return; /* ignore */ + return; /* ignore */ if (e->atom == wm_protocols) { /* update */ @@ -205,18 +196,17 @@ handle_client_property(Client * c, XPropertyEvent * e) break; case XA_WM_NORMAL_HINTS: if (!XGetWMNormalHints(dpy, c->win, &c->size, &msize) - || !c->size.flags) { + || !c->size.flags) { c->size.flags = PSize; } break; } } -void -free_client(Client * c) +void free_client(Client * c) { clients = - (Client **) detach_item((void **) clients, c, sizeof(Client *)); + (Client **) detach_item((void **) clients, c, sizeof(Client *)); ixp_remove_file(ixps, c->files[C_PREFIX]); if (ixps->errstr) fprintf(stderr, "wmiiwm: free_client(): %s\n", ixps->errstr); @@ -224,13 +214,12 @@ free_client(Client * c) } /* speed reasoned function for client property change */ -void -draw_client(Client * c) +void draw_client(Client * c) { - Frame *f = c->frame; - unsigned int tabh = tab_height(f); - int i, size; - int tw; + Frame *f = c->frame; + unsigned int tabh = tab_height(f); + int i, size; + int tw; if (!tabh) return; @@ -241,19 +230,19 @@ draw_client(Client * c) for (i = 0; f->clients[i] && f->clients[i] != c; i++); if (!f->clients[i + 1]) - draw_tab(f, c->files[C_NAME]->content, i * tw, 0, f->rect.width - (i * tw), tabh, - ISSELFRAME(f) && f->clients[f->sel] == c); + draw_tab(f, c->files[C_NAME]->content, i * tw, 0, + f->rect.width - (i * tw), tabh, ISSELFRAME(f) + && f->clients[f->sel] == c); else draw_tab(f, c->files[C_NAME]->content, i * tw, 0, tw, tabh, - ISSELFRAME(f) && f->clients[f->sel] == c); + ISSELFRAME(f) && f->clients[f->sel] == c); } -void -draw_clients(Frame * f) +void draw_clients(Frame * f) { - unsigned int tabh = tab_height(f); - int i, size = count_items((void **) f->clients); - int tw = f->rect.width; + unsigned int tabh = tab_height(f); + int i, size = count_items((void **) f->clients); + int tw = f->rect.width; if (!tabh || !size) return; @@ -261,36 +250,35 @@ draw_clients(Frame * f) tw /= size; for (i = 0; f->clients[i]; i++) { if (!f->clients[i + 1]) { - int xoff = i * tw; + int xoff = i * tw; draw_tab(f, f->clients[i]->files[C_NAME]->content, - xoff, 0, f->rect.width - xoff, tabh, ISSELFRAME(f) - && f->clients[f->sel] == f->clients[i]); + xoff, 0, f->rect.width - xoff, tabh, ISSELFRAME(f) + && f->clients[f->sel] == f->clients[i]); break; } else draw_tab(f, f->clients[i]->files[C_NAME]->content, - i * tw, 0, tw, tabh, ISSELFRAME(f) - && f->clients[f->sel] == f->clients[i]); + i * tw, 0, tw, tabh, ISSELFRAME(f) + && f->clients[f->sel] == f->clients[i]); } XSync(dpy, False); } -int -manage_class_instance(Client * c) +int manage_class_instance(Client * c) { - char buf[MAX_BUF]; - File *f; - char *class = (char *) c->files[C_CLASS]->content; - char *inst = (char *) c->files[C_INSTANCE]->content; + char buf[MAX_BUF]; + File *f; + char *class = (char *) c->files[C_CLASS]->content; + char *inst = (char *) c->files[C_INSTANCE]->content; if (!c->files[C_CLASS]->content || !c->files[C_INSTANCE]->content) return 1; snprintf(buf, sizeof(buf), "/default/client/%s:%s/manage", - class ? class : "", inst ? inst : ""); + class ? class : "", inst ? inst : ""); f = ixp_walk(ixps, buf); if (!f) { snprintf(buf, sizeof(buf), "/default/client/%s:%s/manage", - class ? class : "", "*"); + class ? class : "", "*"); f = ixp_walk(ixps, buf); } if (f && f->content) @@ -298,11 +286,10 @@ manage_class_instance(Client * c) return 1; } -void -gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert) +void gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert) { - int dx = 0, dy = 0; - int gravity = NorthWestGravity; + int dx = 0, dy = 0; + int gravity = NorthWestGravity; if (c->size.flags & PWinGravity) { gravity = c->size.win_gravity; @@ -325,7 +312,7 @@ gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert) case SouthWestGravity: dy = -c->rect.height; break; - default: /* don't care */ + default: /* don't care */ break; } @@ -347,7 +334,7 @@ gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert) case SouthEastGravity: dx = -(c->rect.width + bw); break; - default: /* don't care */ + default: /* don't care */ break; } diff --git a/cmd/wm/core.c b/cmd/wm/core.c @@ -12,18 +12,18 @@ #include "wm.h" -static void new_page(void *obj, char *cmd); -static void _select_page(void *obj, char *cmd); -static void _destroy_page(void *obj, char *cmd); -static void quit(void *obj, char *cmd); -static void _attach_client(void *obj, char *cmd); -static void _detach_client(void *obj, char *cmd); -static void _close_client(void *obj, char *cmd); -static void pager(void *obj, char *cmd); -static void icons(void *obj, char *cmd); +static void new_page(void *obj, char *cmd); +static void _select_page(void *obj, char *cmd); +static void _destroy_page(void *obj, char *cmd); +static void quit(void *obj, char *cmd); +static void _attach_client(void *obj, char *cmd); +static void _detach_client(void *obj, char *cmd); +static void _close_client(void *obj, char *cmd); +static void pager(void *obj, char *cmd); +static void icons(void *obj, char *cmd); /* action table for /ctl namespace */ -Action core_acttbl[] = { +Action core_acttbl[] = { {"new", new_page}, {"destroy", _destroy_page}, {"select", _select_page}, @@ -36,11 +36,10 @@ Action core_acttbl[] = { {0, 0} }; -void -run_action(File * f, void *obj, Action * acttbl) +void run_action(File * f, void *obj, Action * acttbl) { - int i; - size_t len; + int i; + size_t len; if (!f->content) return; @@ -56,25 +55,22 @@ run_action(File * f, void *obj, Action * acttbl) } } fprintf(stderr, "wmiiwm: unknown action '%s'\n" - " or invalid ctl device\n", (char *) f->content); + " or invalid ctl device\n", (char *) f->content); } -static void -quit(void *obj, char *cmd) +static void quit(void *obj, char *cmd) { ixps->runlevel = SHUTDOWN; } -void -invoke_core_event(File * f) +void invoke_core_event(File * f) { if (!f->content) return; spawn(dpy, f->content); } -void -focus_page(Page * p, int raise, int down) +void focus_page(Page * p, int raise, int down) { if (!pages) return; @@ -89,28 +85,26 @@ focus_page(Page * p, int raise, int down) focus_area(p->areas[p->sel], raise, 0, down); } -unsigned int -tab_height(Frame *f) +unsigned int tab_height(Frame * f) { if (_strtonum(f->files[F_TAB]->content, 0, 1)) return font->ascent + font->descent + 4; return 0; } -unsigned int -border_width(Frame *f) +unsigned int border_width(Frame * f) { - if(_strtonum(f->files[F_BORDER]->content, 0, 1)) + if (_strtonum(f->files[F_BORDER]->content, 0, 1)) return BORDER_WIDTH; return 0; } static void scale_rect(XRectangle * from_dim, XRectangle * to_dim, - XRectangle * src, XRectangle * tgt) + XRectangle * src, XRectangle * tgt) { - double wfact = (double) to_dim->width / (double) from_dim->width; - double hfact = (double) to_dim->height / (double) from_dim->height; + double wfact = (double) to_dim->width / (double) from_dim->width; + double hfact = (double) to_dim->height / (double) from_dim->height; tgt->x = to_dim->x + (src->x * wfact); tgt->y = to_dim->y + (src->y * hfact); @@ -123,59 +117,86 @@ scale_rect(XRectangle * from_dim, XRectangle * to_dim, tgt->height = 1; } -static void -draw_pager_page(Page * p, Draw * d) +static void draw_pager_page(Page * p, Draw * d) { - unsigned int i, j; - XRectangle r = d->rect; + unsigned int i, j; + XRectangle r = d->rect; char name[4]; if (p == pages[sel]) { - d->bg = blitz_loadcolor(dpy, screen_num, defaults[WM_SEL_BG_COLOR]->content); - d->fg = blitz_loadcolor(dpy, screen_num, defaults[WM_SEL_FG_COLOR]->content); - d->border = blitz_loadcolor(dpy, screen_num, defaults[WM_SEL_BORDER_COLOR]->content); + d->bg = + blitz_loadcolor(dpy, screen_num, + defaults[WM_SEL_BG_COLOR]->content); + d->fg = + blitz_loadcolor(dpy, screen_num, + defaults[WM_SEL_FG_COLOR]->content); + d->border = + blitz_loadcolor(dpy, screen_num, + defaults[WM_SEL_BORDER_COLOR]->content); d->font = font; } else { - d->bg = blitz_loadcolor(dpy, screen_num, defaults[WM_NORM_BG_COLOR]->content); - d->fg = blitz_loadcolor(dpy, screen_num, defaults[WM_NORM_FG_COLOR]->content); - d->border = blitz_loadcolor(dpy, screen_num, defaults[WM_NORM_BORDER_COLOR]->content); + d->bg = + blitz_loadcolor(dpy, screen_num, + defaults[WM_NORM_BG_COLOR]->content); + d->fg = + blitz_loadcolor(dpy, screen_num, + defaults[WM_NORM_FG_COLOR]->content); + d->border = + blitz_loadcolor(dpy, screen_num, + defaults[WM_NORM_BORDER_COLOR]->content); d->font = font; } - snprintf(name, sizeof(name), "%d", index_item((void **)pages, p)); + snprintf(name, sizeof(name), "%d", index_item((void **) pages, p)); d->data = name; blitz_drawlabel(dpy, d); XSync(dpy, False); for (i = 0; p->areas[i]; i++) { - for(j = 0; p->areas[i]->frames[j]; j++) { + for (j = 0; p->areas[i]->frames[j]; j++) { if (i == p->sel && j == p->areas[i]->sel) { - d->bg = blitz_loadcolor(dpy, screen_num, defaults[WM_SEL_BG_COLOR]->content); - d->fg = blitz_loadcolor(dpy, screen_num, defaults[WM_SEL_FG_COLOR]->content); - d->border = blitz_loadcolor(dpy, screen_num, defaults[WM_SEL_BORDER_COLOR]->content); + d->bg = + blitz_loadcolor(dpy, screen_num, + defaults[WM_SEL_BG_COLOR]->content); + d->fg = + blitz_loadcolor(dpy, screen_num, + defaults[WM_SEL_FG_COLOR]->content); + d->border = + blitz_loadcolor(dpy, screen_num, + defaults[WM_SEL_BORDER_COLOR]-> + content); d->font = font; } else { - d->bg = blitz_loadcolor(dpy, screen_num, defaults[WM_NORM_BG_COLOR]->content); - d->fg = blitz_loadcolor(dpy, screen_num, defaults[WM_NORM_FG_COLOR]->content); - d->border = blitz_loadcolor(dpy, screen_num, defaults[WM_NORM_BORDER_COLOR]->content); + d->bg = + blitz_loadcolor(dpy, screen_num, + defaults[WM_NORM_BG_COLOR]->content); + d->fg = + blitz_loadcolor(dpy, screen_num, + defaults[WM_NORM_FG_COLOR]->content); + d->border = + blitz_loadcolor(dpy, screen_num, + defaults[WM_NORM_BORDER_COLOR]-> + content); d->font = font; } - d->data = p->areas[i]->frames[j]->clients[p->areas[i]->frames[j]->sel]->files[C_NAME]->content; + d->data = + p->areas[i]->frames[j]->clients[p->areas[i]->frames[j]-> + sel]->files[C_NAME]-> + content; scale_rect(&rect, &r, &p->areas[i]->rect, &d->rect); blitz_drawlabel(dpy, d); - XSync(dpy, False); /* do not clear upwards */ + XSync(dpy, False); /* do not clear upwards */ } } } -static void -draw_pager() +static void draw_pager() { - unsigned int ic, ir, tw, th, rows, cols, size; - int i = 0; - int dx; - Draw d = {0}; + unsigned int ic, ir, tw, th, rows, cols, size; + int i = 0; + int dx; + Draw d = { 0 }; blitz_getbasegeometry((void **) pages, &size, &cols, &rows); - dx = (cols - 1) * GAP; /* GAPpx space */ + dx = (cols - 1) * GAP; /* GAPpx space */ tw = (rect.width - dx) / cols; th = ((double) tw / rect.width) * rect.height; d.drawable = transient; @@ -197,18 +218,17 @@ draw_pager() } } -static Page * -xy_to_pager_page(int x, int y) +static Page *xy_to_pager_page(int x, int y) { - unsigned int ic, ir, tw, th, rows, cols, size; - int i = 0; - int dx; - XRectangle r; + unsigned int ic, ir, tw, th, rows, cols, size; + int i = 0; + int dx; + XRectangle r; if (!pages) return 0; blitz_getbasegeometry((void **) pages, &size, &cols, &rows); - dx = (cols - 1) * GAP; /* GAPpx space */ + dx = (cols - 1) * GAP; /* GAPpx space */ tw = (rect.width - dx) / cols; th = ((double) tw / rect.width) * rect.height; @@ -231,10 +251,9 @@ xy_to_pager_page(int x, int y) return 0; } -static int -handle_kpress(XKeyEvent * e) +static int handle_kpress(XKeyEvent * e) { - KeySym ksym = XKeycodeToKeysym(dpy, e->keycode, 0); + KeySym ksym = XKeycodeToKeysym(dpy, e->keycode, 0); if (ksym >= XK_1 && ksym <= XK_9) return ksym - XK_1; @@ -246,11 +265,10 @@ handle_kpress(XKeyEvent * e) return -1; } -static void -pager(void *obj, char *cmd) +static void pager(void *obj, char *cmd) { - XEvent ev; - int i; + XEvent ev; + int i; if (!pages) return; @@ -258,11 +276,14 @@ pager(void *obj, char *cmd) XClearWindow(dpy, transient); XMapRaised(dpy, transient); draw_pager(); - while (XGrabKeyboard(dpy, transient, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess) + while (XGrabKeyboard + (dpy, transient, True, GrabModeAsync, GrabModeAsync, + CurrentTime) != GrabSuccess) usleep(1000); for (;;) { - while (!XCheckWindowEvent(dpy, transient, ButtonPressMask | KeyPressMask, &ev)) { + while (!XCheckWindowEvent + (dpy, transient, ButtonPressMask | KeyPressMask, &ev)) { usleep(20000); continue; } @@ -279,7 +300,7 @@ pager(void *obj, char *cmd) case ButtonPress: XUnmapWindow(dpy, transient); if (ev.xbutton.button == Button1) { - Page *p = xy_to_pager_page(ev.xbutton.x, ev.xbutton.y); + Page *p = xy_to_pager_page(ev.xbutton.x, ev.xbutton.y); if (p) focus_page(p, 0, 1); } @@ -289,17 +310,16 @@ pager(void *obj, char *cmd) } } -static void -draw_icons() +static void draw_icons() { - unsigned int i, ic, ir, tw, th, rows, cols, size; - int dx, dy; + unsigned int i, ic, ir, tw, th, rows, cols, size; + int dx, dy; if (!detached) return; blitz_getbasegeometry((void **) detached, &size, &cols, &rows); - dx = (cols - 1) * GAP; /* GAPpx space */ - dy = (rows - 1) * GAP; /* GAPpx space */ + dx = (cols - 1) * GAP; /* GAPpx space */ + dy = (rows - 1) * GAP; /* GAPpx space */ tw = (rect.width - dx) / cols; th = (rect.height - dy) / rows; @@ -308,8 +328,8 @@ draw_icons() i = 0; for (ir = 0; ir < rows; ir++) { for (ic = 0; ic < cols; ic++) { - Client *c = detached[i++]; - XRectangle cr; + Client *c = detached[i++]; + XRectangle cr; if (!c) return; cr.x = ic * tw + (ic * GAP); @@ -317,7 +337,7 @@ draw_icons() cr.width = tw; cr.height = th; XMoveResizeWindow(dpy, c->win, cr.x, cr.y, cr.width, - cr.height); + cr.height); configure_client(c); show_client(c); XRaiseWindow(dpy, c->win); @@ -328,12 +348,11 @@ draw_icons() } -static void -icons(void *obj, char *cmd) +static void icons(void *obj, char *cmd) { - XEvent ev; - int i, n; - Client *c; + XEvent ev; + int i, n; + Client *c; if (!detached) return; @@ -341,7 +360,9 @@ icons(void *obj, char *cmd) XClearWindow(dpy, transient); XMapRaised(dpy, transient); draw_icons(); - while (XGrabKeyboard(dpy, transient, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess) + while (XGrabKeyboard + (dpy, transient, True, GrabModeAsync, GrabModeAsync, + CurrentTime) != GrabSuccess) usleep(1000); for (;;) { @@ -357,8 +378,9 @@ icons(void *obj, char *cmd) hide_client(detached[i]); if (n - 1 < i) { c = detached[n]; - detached = (Client **) detach_item((void **) detached, c, - sizeof(Client *)); + detached = + (Client **) detach_item((void **) detached, c, + sizeof(Client *)); attach_client(c); } } else { @@ -376,7 +398,7 @@ icons(void *obj, char *cmd) if ((c = win_to_client(ev.xbutton.window))) { detached = (Client **) detach_item((void **) detached, c, - sizeof(Client *)); + sizeof(Client *)); attach_client(c); } XUngrabKeyboard(dpy, CurrentTime); @@ -387,30 +409,27 @@ icons(void *obj, char *cmd) } } -static void -_close_client(void *obj, char *cmd) +static void _close_client(void *obj, char *cmd) { Frame *f = pages ? SELFRAME(pages[sel]) : 0; - if (f->clients[f->sel]) + if (f->clients[f->sel]) close_client(f->clients[f->sel]); } -static void -_attach_client(void *obj, char *cmd) +static void _attach_client(void *obj, char *cmd) { if (detached) { - Client *c = detached[0]; + Client *c = detached[0]; detached = (Client **) detach_item((void **) detached, c, - sizeof(Client *)); + sizeof(Client *)); attach_client(c); } } -static void -_detach_client(void *obj, char *cmd) +static void _detach_client(void *obj, char *cmd) { - Frame *f; + Frame *f; if (!pages) return; f = SELFRAME(pages[sel]); @@ -419,8 +438,7 @@ _detach_client(void *obj, char *cmd) detach_client_from_frame(f->clients[f->sel], 0, 0); } -static void -_select_page(void *obj, char *cmd) +static void _select_page(void *obj, char *cmd) { if (!pages || !cmd) return; @@ -429,45 +447,42 @@ _select_page(void *obj, char *cmd) else if (!strncmp(cmd, "next", 5)) sel = index_next_item((void **) pages, pages[sel]); else - sel = _strtonum(cmd, 0, count_items((void **)pages)); + sel = _strtonum(cmd, 0, count_items((void **) pages)); focus_page(pages[sel], 0, 1); } -void -destroy_page(Page * p) +void destroy_page(Page * p) { - unsigned int i; + unsigned int i; for (i = 0; p->areas[i]; i++) destroy_area(p->areas[i]); free_page(p); if (pages) { show_page(pages[sel]); - defaults[WM_SEL_PAGE]->content = pages[sel]->files[P_PREFIX]->content; + defaults[WM_SEL_PAGE]->content = + pages[sel]->files[P_PREFIX]->content; focus_page(pages[sel], 0, 1); invoke_core_event(defaults[WM_EVENT_PAGE_UPDATE]); } } -static void -_destroy_page(void *obj, char *cmd) +static void _destroy_page(void *obj, char *cmd) { if (!pages) return; destroy_page(pages[sel]); } -static void -new_page(void *obj, char *cmd) +static void new_page(void *obj, char *cmd) { if (pages) hide_page(pages[sel]); alloc_page("0"); } -Client * -win_to_client(Window w) +Client *win_to_client(Window w) { - int i; + int i; for (i = 0; clients && clients[i]; i++) if (clients[i]->win == w) @@ -475,22 +490,21 @@ win_to_client(Window w) return 0; } -void -scan_wins() +void scan_wins() { - int i; - unsigned int num; - Window *wins; + int i; + unsigned int num; + Window *wins; XWindowAttributes wa; - Window d1, d2; - Client *c; + Window d1, d2; + Client *c; if (XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { for (i = 0; i < num; i++) { if (!XGetWindowAttributes(dpy, wins[i], &wa)) continue; if (wa.override_redirect - || XGetTransientForHint(dpy, wins[i], &d1)) + || XGetTransientForHint(dpy, wins[i], &d1)) continue; if (wa.map_state == IsViewable) { c = alloc_client(wins[i]); @@ -503,10 +517,9 @@ scan_wins() XFree(wins); } -void * -get_func(void *acttbl[][2], int rows, char *fname) +void *get_func(void *acttbl[][2], int rows, char *fname) { - int i; + int i; for (i = 0; i < rows; i++) { if (!strncmp((char *) acttbl[i][0], fname, MAX_BUF)) { return acttbl[i][1]; @@ -515,16 +528,15 @@ get_func(void *acttbl[][2], int rows, char *fname) return 0; } -int -win_proto(Window w) +int win_proto(Window w) { - Atom *protocols; - long res; - int protos = 0; - int i; + Atom *protocols; + long res; + int protos = 0; + int i; res = property(dpy, w, wm_protocols, XA_ATOM, - 20L, ((unsigned char **) &protocols)); + 20L, ((unsigned char **) &protocols)); if (res <= 0) { return protos; } @@ -537,16 +549,15 @@ win_proto(Window w) return protos; } -int -win_state(Window w) +int win_state(Window w) { /* state hints */ - XWMHints *hints = XGetWMHints(dpy, w); - int res; + XWMHints *hints = XGetWMHints(dpy, w); + int res; - long *prop = 0; + long *prop = 0; if (property(dpy, w, wm_state, wm_state, - 2L, ((unsigned char **) &prop)) > 0) { + 2L, ((unsigned char **) &prop)) > 0) { res = (int) *prop; free((long *) prop); } else { @@ -559,18 +570,17 @@ win_state(Window w) return res; } -void -handle_after_write(IXPServer * s, File * f) +void handle_after_write(IXPServer * s, File * f) { if (f == defaults[WM_CTL]) run_action(f, 0, core_acttbl); else if (f == defaults[WM_TRANS_COLOR]) { - unsigned long col[1]; + unsigned long col[1]; col[0] = xorcolor.pixel; XFreeColors(dpy, DefaultColormap(dpy, screen_num), col, 1, 0); XAllocNamedColor(dpy, DefaultColormap(dpy, screen_num), - defaults[WM_TRANS_COLOR]->content, - &xorcolor, &xorcolor); + defaults[WM_TRANS_COLOR]->content, + &xorcolor, &xorcolor); XSetForeground(dpy, xorgc, xorcolor.pixel); } check_event(0); diff --git a/cmd/wm/event.c b/cmd/wm/event.c @@ -11,25 +11,24 @@ #include "wm.h" /* local functions */ -static void handle_buttonpress(XEvent * e); -static void handle_configurerequest(XEvent * e); -static void handle_destroynotify(XEvent * e); -static void handle_expose(XEvent * e); -static void handle_maprequest(XEvent * e); -static void handle_motionnotify(XEvent * e); -static void handle_propertynotify(XEvent * e); -static void handle_unmapnotify(XEvent * e); -static void handle_enternotify(XEvent * e); -static void update_ignore_enternotify_hack(XEvent * e); +static void handle_buttonpress(XEvent * e); +static void handle_configurerequest(XEvent * e); +static void handle_destroynotify(XEvent * e); +static void handle_expose(XEvent * e); +static void handle_maprequest(XEvent * e); +static void handle_motionnotify(XEvent * e); +static void handle_propertynotify(XEvent * e); +static void handle_unmapnotify(XEvent * e); +static void handle_enternotify(XEvent * e); +static void update_ignore_enternotify_hack(XEvent * e); static unsigned int ignore_enternotify_hack = 0; -void (*handler[LASTEvent]) (XEvent *); +void (*handler[LASTEvent]) (XEvent *); -void -init_event_hander() +void init_event_hander() { - int i; + int i; /* init event handler */ for (i = 0; i < LASTEvent; i++) { handler[i] = 0; @@ -48,10 +47,9 @@ init_event_hander() handler[UnmapNotify] = handle_unmapnotify; } -void -check_event(Connection * c) +void check_event(Connection * c) { - XEvent ev; + XEvent ev; while (XPending(dpy)) { XNextEvent(dpy, &ev); /* main evet loop */ @@ -62,12 +60,11 @@ check_event(Connection * c) } } -static void -handle_buttonpress(XEvent * e) +static void handle_buttonpress(XEvent * e) { - Client *c; + Client *c; XButtonPressedEvent *ev = &e->xbutton; - Frame *f = win_to_frame(ev->window); + Frame *f = win_to_frame(ev->window); if (f) { handle_frame_buttonpress(ev, f); return; @@ -88,7 +85,7 @@ handle_buttonpress(XEvent * e) break; case Button3: { - Align align = xy_to_align(&c->rect, ev->x, ev->y); + Align align = xy_to_align(&c->rect, ev->x, ev->y); if (align == CENTER) mouse_move(c->frame); else @@ -103,14 +100,13 @@ handle_buttonpress(XEvent * e) } } -static void -handle_configurerequest(XEvent * e) +static void handle_configurerequest(XEvent * e) { XConfigureRequestEvent *ev = &e->xconfigurerequest; - XWindowChanges wc; - Client *c; - unsigned int bw = 0, tabh = 0; - Frame *f = 0; + XWindowChanges wc; + Client *c; + unsigned int bw = 0, tabh = 0; + Frame *f = 0; update_ignore_enternotify_hack(e); /* fprintf(stderr, "%s", "configure request\n"); */ @@ -150,7 +146,8 @@ handle_configurerequest(XEvent * e) f->rect.x = wc.x = c->rect.x - bw; f->rect.y = wc.y = c->rect.y - (tabh ? tabh : bw); f->rect.width = wc.width = c->rect.width + 2 * bw; - f->rect.height = wc.height = c->rect.height + bw + (tabh ? tabh : bw); + f->rect.height = wc.height = + c->rect.height + bw + (tabh ? tabh : bw); wc.border_width = 1; wc.sibling = None; wc.stack_mode = ev->detail; @@ -174,7 +171,7 @@ handle_configurerequest(XEvent * e) ev->value_mask &= ~CWStackMode; ev->value_mask |= CWBorderWidth; XConfigureWindow(dpy, e->xconfigurerequest.window, ev->value_mask, - &wc); + &wc); XSync(dpy, False); /* @@ -182,11 +179,10 @@ handle_configurerequest(XEvent * e) */ } -static void -handle_destroynotify(XEvent * e) +static void handle_destroynotify(XEvent * e) { XDestroyWindowEvent *ev = &e->xdestroywindow; - Client *c = win_to_client(ev->window); + Client *c = win_to_client(ev->window); /* fprintf(stderr, "destroy: client 0x%x\n", (int)ev->window); */ if (!c) return; @@ -194,14 +190,13 @@ handle_destroynotify(XEvent * e) detach_client_from_frame(c, 0, 1); else if (detached && (index_item((void **) detached, c) >= 0)) detached = (Client **) detach_item((void **) detached, c, - sizeof(Client *)); + sizeof(Client *)); free_client(c); } -static void -handle_expose(XEvent * e) +static void handle_expose(XEvent * e) { - static Frame *f; + static Frame *f; if (e->xexpose.count == 0) { f = win_to_frame(e->xbutton.window); if (f) @@ -209,12 +204,11 @@ handle_expose(XEvent * e) } } -static void -handle_maprequest(XEvent * e) +static void handle_maprequest(XEvent * e) { XMapRequestEvent *ev = &e->xmaprequest; static XWindowAttributes wa; - static Client *c; + static Client *c; /* fprintf(stderr, "map: window 0x%x\n", (int)ev->window); */ if (!XGetWindowAttributes(dpy, ev->window, &wa)) @@ -231,13 +225,12 @@ handle_maprequest(XEvent * e) } } -static void -handle_motionnotify(XEvent * e) +static void handle_motionnotify(XEvent * e) { - Frame *f = win_to_frame(e->xmotion.window); - Cursor cursor; + Frame *f = win_to_frame(e->xmotion.window); + Cursor cursor; if (f) { - Frame *old = SELFRAME(pages[sel]); + Frame *old = SELFRAME(pages[sel]); if (old != f) { focus_frame(f, 0, 0, 1); draw_frame(old); @@ -245,7 +238,7 @@ handle_motionnotify(XEvent * e) } else if (f->clients) { /* multihead assumption */ XSetInputFocus(dpy, f->clients[f->sel]->win, - RevertToPointerRoot, CurrentTime); + RevertToPointerRoot, CurrentTime); XSync(dpy, False); } cursor = cursor_for_motion(f, e->xmotion.x, e->xmotion.y); @@ -256,11 +249,10 @@ handle_motionnotify(XEvent * e) } } -static void -handle_propertynotify(XEvent * e) +static void handle_propertynotify(XEvent * e) { XPropertyEvent *ev = &e->xproperty; - Client *c = win_to_client(ev->window); + Client *c = win_to_client(ev->window); if (c) { handle_client_property(c, ev); @@ -268,11 +260,10 @@ handle_propertynotify(XEvent * e) } } -static void -handle_unmapnotify(XEvent * e) +static void handle_unmapnotify(XEvent * e) { - XUnmapEvent *ev = &e->xunmap; - Client *c; + XUnmapEvent *ev = &e->xunmap; + Client *c; update_ignore_enternotify_hack(e); if (ev->event == root) @@ -290,11 +281,10 @@ handle_unmapnotify(XEvent * e) } } -static void -handle_enternotify(XEvent * e) +static void handle_enternotify(XEvent * e) { XCrossingEvent *ev = &e->xcrossing; - Client *c; + Client *c; if (ev->mode != NotifyNormal) return; @@ -305,7 +295,7 @@ handle_enternotify(XEvent * e) c = win_to_client(ev->window); if (c && c->frame && (ev->serial != ignore_enternotify_hack)) { - Frame *old = SELFRAME(pages[sel]); + Frame *old = SELFRAME(pages[sel]); XUndefineCursor(dpy, c->frame->win); if (old != c->frame) { focus_frame(c->frame, 0, 0, 1); @@ -319,8 +309,7 @@ handle_enternotify(XEvent * e) } } -static void -update_ignore_enternotify_hack(XEvent * e) +static void update_ignore_enternotify_hack(XEvent * e) { ignore_enternotify_hack = e->xany.serial; XSync(dpy, False); diff --git a/cmd/wm/frame.c b/cmd/wm/frame.c @@ -12,26 +12,25 @@ #include <cext.h> -static Frame zero_frame = {0}; +static Frame zero_frame = { 0 }; -static void mouse(); -static void select_client(void *obj, char *cmd); -static void handle_after_write_frame(IXPServer * s, File * f); -static void handle_before_read_frame(IXPServer * s, File * f); +static void mouse(); +static void select_client(void *obj, char *cmd); +static void handle_after_write_frame(IXPServer * s, File * f); +static void handle_before_read_frame(IXPServer * s, File * f); /* action table for /frame/?/ namespace */ -Action frame_acttbl[] = { +Action frame_acttbl[] = { {"select", select_client}, {0, 0} }; -Frame * -alloc_frame(XRectangle * r, int add_frame_border, int floating) +Frame *alloc_frame(XRectangle * r, int add_frame_border, int floating) { XSetWindowAttributes wa; - static int id = 0; - char buf[MAX_BUF]; - Frame *f = (Frame *) emalloc(sizeof(Frame)); + static int id = 0; + char buf[MAX_BUF]; + Frame *f = (Frame *) emalloc(sizeof(Frame)); *f = zero_frame; f->rect = *r; @@ -52,36 +51,58 @@ alloc_frame(XRectangle * r, int add_frame_border, int floating) f->files[F_SIZE]->before_read = handle_before_read_frame; f->files[F_SIZE]->after_write = handle_after_write_frame; snprintf(buf, MAX_BUF, "/detached/frame/%d/border", id); - f->files[F_BORDER] = wmii_create_ixpfile(ixps, buf, defaults[WM_BORDER]->content); + f->files[F_BORDER] = + wmii_create_ixpfile(ixps, buf, defaults[WM_BORDER]->content); f->files[F_BORDER]->after_write = handle_after_write_frame; snprintf(buf, MAX_BUF, "/detached/frame/%d/tab", id); - f->files[F_TAB] = wmii_create_ixpfile(ixps, buf, defaults[WM_TAB]->content); + f->files[F_TAB] = + wmii_create_ixpfile(ixps, buf, defaults[WM_TAB]->content); f->files[F_TAB]->after_write = handle_after_write_frame; snprintf(buf, MAX_BUF, "/detached/frame/%d/handleinc", id); - f->files[F_HANDLE_INC] = wmii_create_ixpfile(ixps, buf, defaults[WM_HANDLE_INC]->content); + f->files[F_HANDLE_INC] = + wmii_create_ixpfile(ixps, buf, defaults[WM_HANDLE_INC]->content); f->files[F_HANDLE_INC]->after_write = handle_after_write_frame; snprintf(buf, MAX_BUF, "/detached/frame/%d/locked", id); - f->files[F_LOCKED] = wmii_create_ixpfile(ixps, buf, defaults[WM_LOCKED]->content); + f->files[F_LOCKED] = + wmii_create_ixpfile(ixps, buf, defaults[WM_LOCKED]->content); snprintf(buf, MAX_BUF, "/detached/frame/%d/selstyle/bgcolor", id); - f->files[F_SEL_BG_COLOR] = wmii_create_ixpfile(ixps, buf, defaults[WM_SEL_BG_COLOR]->content); + f->files[F_SEL_BG_COLOR] = + wmii_create_ixpfile(ixps, buf, defaults[WM_SEL_BG_COLOR]->content); snprintf(buf, MAX_BUF, "/detached/frame/%d/selstyle/fgcolor", id); - f->files[F_SEL_FG_COLOR] = wmii_create_ixpfile(ixps, buf, defaults[WM_SEL_FG_COLOR]->content); + f->files[F_SEL_FG_COLOR] = + wmii_create_ixpfile(ixps, buf, defaults[WM_SEL_FG_COLOR]->content); snprintf(buf, MAX_BUF, "/detached/frame/%d/selstyle/bordercolor", id); - f->files[F_SEL_BORDER_COLOR] = wmii_create_ixpfile(ixps, buf, defaults[WM_SEL_BORDER_COLOR]->content); + f->files[F_SEL_BORDER_COLOR] = + wmii_create_ixpfile(ixps, buf, + defaults[WM_SEL_BORDER_COLOR]->content); snprintf(buf, MAX_BUF, "/detached/frame/%d/normstyle/bgcolor", id); - f->files[F_NORM_BG_COLOR] = wmii_create_ixpfile(ixps, buf, defaults[WM_NORM_BG_COLOR]->content); + f->files[F_NORM_BG_COLOR] = + wmii_create_ixpfile(ixps, buf, + defaults[WM_NORM_BG_COLOR]->content); snprintf(buf, MAX_BUF, "/detached/frame/%d/normstyle/fgcolor", id); - f->files[F_NORM_FG_COLOR] = wmii_create_ixpfile(ixps, buf, defaults[WM_NORM_FG_COLOR]->content); + f->files[F_NORM_FG_COLOR] = + wmii_create_ixpfile(ixps, buf, + defaults[WM_NORM_FG_COLOR]->content); snprintf(buf, MAX_BUF, "/detached/frame/%d/normstyle/bordercolor", id); - f->files[F_NORM_BORDER_COLOR] = wmii_create_ixpfile(ixps, buf, defaults[WM_NORM_BORDER_COLOR]->content); + f->files[F_NORM_BORDER_COLOR] = + wmii_create_ixpfile(ixps, buf, + defaults[WM_NORM_BORDER_COLOR]->content); snprintf(buf, MAX_BUF, "/detached/frame/%d/event/b2press", id); - f->files[F_EVENT_B2PRESS] = wmii_create_ixpfile(ixps, buf, defaults[WM_EVENT_B2PRESS]->content); + f->files[F_EVENT_B2PRESS] = + wmii_create_ixpfile(ixps, buf, + defaults[WM_EVENT_B2PRESS]->content); snprintf(buf, MAX_BUF, "/detached/frame/%d/event/b3press", id); - f->files[F_EVENT_B3PRESS] = wmii_create_ixpfile(ixps, buf, defaults[WM_EVENT_B3PRESS]->content); + f->files[F_EVENT_B3PRESS] = + wmii_create_ixpfile(ixps, buf, + defaults[WM_EVENT_B3PRESS]->content); snprintf(buf, MAX_BUF, "/detached/frame/%d/event/b4press", id); - f->files[F_EVENT_B4PRESS] = wmii_create_ixpfile(ixps, buf, defaults[WM_EVENT_B4PRESS]->content); + f->files[F_EVENT_B4PRESS] = + wmii_create_ixpfile(ixps, buf, + defaults[WM_EVENT_B4PRESS]->content); snprintf(buf, MAX_BUF, "/detached/frame/%d/event/b5press", id); - f->files[F_EVENT_B5PRESS] = wmii_create_ixpfile(ixps, buf, defaults[WM_EVENT_B5PRESS]->content); + f->files[F_EVENT_B5PRESS] = + wmii_create_ixpfile(ixps, buf, + defaults[WM_EVENT_B5PRESS]->content); id++; wa.override_redirect = 1; @@ -91,17 +112,17 @@ alloc_frame(XRectangle * r, int add_frame_border, int floating) | SubstructureNotifyMask; if (add_frame_border) { - int bw = border_width(f); - int th = tab_height(f); + int bw = border_width(f); + int th = tab_height(f); f->rect.width += 2 * bw; f->rect.height += bw + (th ? th : bw); } f->win = - XCreateWindow(dpy, root, f->rect.x, f->rect.y, f->rect.width, f->rect.height, 0, - DefaultDepth(dpy, screen_num), CopyFromParent, - DefaultVisual(dpy, screen_num), - CWOverrideRedirect | CWBackPixmap | CWEventMask, - &wa); + XCreateWindow(dpy, root, f->rect.x, f->rect.y, f->rect.width, + f->rect.height, 0, DefaultDepth(dpy, screen_num), + CopyFromParent, DefaultVisual(dpy, screen_num), + CWOverrideRedirect | CWBackPixmap | CWEventMask, + &wa); XDefineCursor(dpy, f->win, f->cursor); f->gc = XCreateGC(dpy, f->win, 0, 0); @@ -111,24 +132,22 @@ alloc_frame(XRectangle * r, int add_frame_border, int floating) return f; } -void -focus_frame(Frame * f, int raise, int up, int down) +void focus_frame(Frame * f, int raise, int up, int down) { Area *a = f->area; if (down && f->clients) focus_client(f->clients[f->sel], raise, 0); - a->sel = index_item((void **)a->frames, f); + a->sel = index_item((void **) a->frames, f); a->files[A_SEL_FRAME]->content = f->files[F_PREFIX]->content; - if (raise && a->page->sel == 0) /* only floating windows are raised */ + if (raise && a->page->sel == 0) /* only floating windows are raised */ XRaiseWindow(dpy, f->win); if (up) focus_area(a, raise, up, 0); } -Frame * -win_to_frame(Window w) +Frame *win_to_frame(Window w) { - int i; + int i; for (i = 0; frames && frames[i]; i++) if (frames[i]->win == w) @@ -136,8 +155,7 @@ win_to_frame(Window w) return 0; } -void -destroy_frame(Frame * f) +void destroy_frame(Frame * f) { frames = (Frame **) detach_item((void **) frames, f, sizeof(Frame *)); XFreeGC(dpy, f->gc); @@ -148,10 +166,9 @@ destroy_frame(Frame * f) free(f); } -void -focus_client(Client * c, int raise, int up) +void focus_client(Client * c, int raise, int up) { - Frame *f = 0; + Frame *f = 0; /* focus client */ if (c) { f = c->frame; @@ -167,26 +184,24 @@ focus_client(Client * c, int raise, int up) focus_frame(f, raise, up, 0); } -static void -resize_clients(Frame * f, int tabh, int bw) +static void resize_clients(Frame * f, int tabh, int bw) { - int i; + int i; for (i = 0; f->clients && f->clients[i]; i++) { - Client *c = f->clients[i]; + Client *c = f->clients[i]; c->rect.x = bw; c->rect.y = tabh ? tabh : bw; c->rect.width = f->rect.width - 2 * bw; c->rect.height = f->rect.height - bw - (tabh ? tabh : bw); XMoveResizeWindow(dpy, c->win, c->rect.x, c->rect.y, - c->rect.width, c->rect.height); + c->rect.width, c->rect.height); configure_client(c); } } -static void -check_dimensions(Frame * f, unsigned int tabh, unsigned int bw) +static void check_dimensions(Frame * f, unsigned int tabh, unsigned int bw) { - Client *c = f->clients ? f->clients[f->sel] : 0; + Client *c = f->clients ? f->clients[f->sel] : 0; if (!c) return; @@ -211,12 +226,12 @@ check_dimensions(Frame * f, unsigned int tabh, unsigned int bw) static void resize_incremental(Frame * f, unsigned int tabh, unsigned int bw) { - Client *c = f->clients ? f->clients[f->sel] : 0; + Client *c = f->clients ? f->clients[f->sel] : 0; if (!c) return; /* increment stuff, see chapter 4.1.2.3 of the ICCCM Manual */ if (c->size.flags & PResizeInc) { - int base_width = 0, base_height = 0; + int base_width = 0, base_height = 0; if (c->size.flags & PBaseSize) { base_width = c->size.base_width; @@ -227,19 +242,22 @@ resize_incremental(Frame * f, unsigned int tabh, unsigned int bw) base_height = c->size.min_height; } /* client_width = base_width + i * c->size.width_inc for an integer i */ - f->rect.width -= (f->rect.width - 2 * bw - base_width) % c->size.width_inc; - f->rect.height -= (f->rect.height - bw - (tabh ? tabh : bw) - base_height) % c->size.height_inc; + f->rect.width -= + (f->rect.width - 2 * bw - base_width) % c->size.width_inc; + f->rect.height -= + (f->rect.height - bw - (tabh ? tabh : bw) - + base_height) % c->size.height_inc; } } void resize_frame(Frame * f, XRectangle * r, XPoint * pt, int ignore_layout) { - unsigned int tabh = tab_height(f); - unsigned int bw = border_width(f); + unsigned int tabh = tab_height(f); + unsigned int bw = border_width(f); /* do layout stuff if necessary */ if (!ignore_layout) { - Area *a = f->area; + Area *a = f->area; if (a && a->layout) { a->layout->resize(f, r, pt); } else @@ -251,18 +269,18 @@ resize_frame(Frame * f, XRectangle * r, XPoint * pt, int ignore_layout) check_dimensions(f, tabh, bw); if (f->files[F_HANDLE_INC]->content - && ((char *) f->files[F_HANDLE_INC]->content)[0] == '1') + && ((char *) f->files[F_HANDLE_INC]->content)[0] == '1') resize_incremental(f, tabh, bw); - XMoveResizeWindow(dpy, f->win, f->rect.x, f->rect.y, f->rect.width, f->rect.height); + XMoveResizeWindow(dpy, f->win, f->rect.x, f->rect.y, f->rect.width, + f->rect.height); resize_clients(f, (tabh ? tabh : bw), bw); } -void -draw_tab(Frame * f, char *text, int x, int y, int w, int h, int sel) +void draw_tab(Frame * f, char *text, int x, int y, int w, int h, int sel) { - Draw d = {0}; + Draw d = { 0 }; d.drawable = f->win; d.gc = f->gc; d.rect.x = x; @@ -271,14 +289,26 @@ draw_tab(Frame * f, char *text, int x, int y, int w, int h, int sel) d.rect.height = h; d.data = text; if (sel) { - d.bg = blitz_loadcolor(dpy, screen_num, f->files[F_SEL_BG_COLOR]->content); - d.fg = blitz_loadcolor(dpy, screen_num, f->files[F_SEL_FG_COLOR]->content); - d.border = blitz_loadcolor(dpy, screen_num, f->files[F_SEL_BORDER_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, + f->files[F_SEL_BG_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, + f->files[F_SEL_FG_COLOR]->content); + d.border = + blitz_loadcolor(dpy, screen_num, + f->files[F_SEL_BORDER_COLOR]->content); d.font = font; } else { - d.bg = blitz_loadcolor(dpy, screen_num, f->files[F_NORM_BG_COLOR]->content); - d.fg = blitz_loadcolor(dpy, screen_num, f->files[F_NORM_FG_COLOR]->content); - d.border = blitz_loadcolor(dpy, screen_num, f->files[F_NORM_BORDER_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, + f->files[F_NORM_BG_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, + f->files[F_NORM_FG_COLOR]->content); + d.border = + blitz_loadcolor(dpy, screen_num, + f->files[F_NORM_BORDER_COLOR]->content); d.font = font; } blitz_drawlabel(dpy, &d); @@ -301,12 +331,11 @@ draw_tab(Frame * f, char *text, int x, int y, int w, int h, int sel) * ./norm-style/bg-color "#RRGGBBAA" * ./norm-style/border-color "#RRGGBBAA [#RRGGBBAA [#RRGGBBAA [#RRGGBBAA]]]" */ -void -draw_frame(Frame * f) +void draw_frame(Frame * f) { - Draw d = {0}; - int bw = border_width(f); - XRectangle notch; + Draw d = { 0 }; + int bw = border_width(f); + XRectangle notch; if (bw) { notch.x = bw; notch.y = bw; @@ -317,13 +346,25 @@ draw_frame(Frame * f) /* define ground plate (i = 0) */ if (ISSELFRAME(f)) { - d.bg = blitz_loadcolor(dpy, screen_num, f->files[F_SEL_BG_COLOR]->content); - d.fg = blitz_loadcolor(dpy, screen_num, f->files[F_SEL_FG_COLOR]->content); - d.border = blitz_loadcolor(dpy, screen_num, f->files[F_SEL_BORDER_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, + f->files[F_SEL_BG_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, + f->files[F_SEL_FG_COLOR]->content); + d.border = + blitz_loadcolor(dpy, screen_num, + f->files[F_SEL_BORDER_COLOR]->content); } else { - d.bg = blitz_loadcolor(dpy, screen_num, f->files[F_NORM_BG_COLOR]->content); - d.fg = blitz_loadcolor(dpy, screen_num, f->files[F_NORM_FG_COLOR]->content); - d.border = blitz_loadcolor(dpy, screen_num, f->files[F_NORM_BORDER_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, + f->files[F_NORM_BG_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, + f->files[F_NORM_FG_COLOR]->content); + d.border = + blitz_loadcolor(dpy, screen_num, + f->files[F_NORM_BORDER_COLOR]->content); } d.rect = f->rect; d.rect.x = d.rect.y = 0; @@ -335,12 +376,11 @@ draw_frame(Frame * f) XSync(dpy, False); } -void -handle_frame_buttonpress(XButtonEvent * e, Frame * f) +void handle_frame_buttonpress(XButtonEvent * e, Frame * f) { - int bindex; - int size = count_items((void **) f->clients); - int cindex = e->x / f->rect.width / size; + int bindex; + int size = count_items((void **) f->clients); + int cindex = e->x / f->rect.width / size; if (!f->area->page->sel) XRaiseWindow(dpy, f->win); if (cindex != f->sel) { @@ -359,13 +399,14 @@ handle_frame_buttonpress(XButtonEvent * e, Frame * f) draw_frame(f); } -void -attach_client_to_frame(Frame * f, Client * c) +void attach_client_to_frame(Frame * f, Client * c) { - int size = count_items((void **) f->clients); + int size = count_items((void **) f->clients); wmii_move_ixpfile(c->files[C_PREFIX], f->files[F_CLIENT_PREFIX]); f->files[F_SEL_CLIENT]->content = c->files[C_PREFIX]->content; - f->clients = (Client **) attach_item_end((void **) f->clients, c, sizeof(Client *)); + f->clients = + (Client **) attach_item_end((void **) f->clients, c, + sizeof(Client *)); f->sel = size; c->frame = f; reparent_client(c, f->win, border_width(f), tab_height(f)); @@ -374,16 +415,15 @@ attach_client_to_frame(Frame * f, Client * c) focus_client(c, 1, 1); } -void -attach_client(Client * c) +void attach_client(Client * c) { - Page *p = 0; - Frame *f = 0; + Page *p = 0; + Frame *f = 0; if (!pages) alloc_page("0"); /* transient stuff */ if (c && c->trans && !f) { - Client *t = win_to_client(c->trans); + Client *t = win_to_client(c->trans); if (t && t->frame) { focus_client(t, 1, 1); f = alloc_frame(&c->rect, 1, 1); @@ -412,10 +452,9 @@ attach_client(Client * c) invoke_core_event(defaults[WM_EVENT_PAGE_UPDATE]); } -void -detach_client_from_frame(Client * c, int unmapped, int destroyed) +void detach_client_from_frame(Client * c, int unmapped, int destroyed) { - Frame *f = c->frame; + Frame *f = c->frame; wmii_move_ixpfile(c->files[C_PREFIX], defaults[WM_DETACHED_CLIENT]); c->frame = 0; f->clients = @@ -429,7 +468,7 @@ detach_client_from_frame(Client * c, int unmapped, int destroyed) hide_client(c); detached = (Client **) attach_item_begin((void **) detached, c, - sizeof(Client *)); + sizeof(Client *)); } reparent_client(c, root, border_width(f), tab_height(f)); } @@ -445,11 +484,10 @@ detach_client_from_frame(Client * c, int unmapped, int destroyed) invoke_core_event(defaults[WM_EVENT_PAGE_UPDATE]); } -static void -mouse() +static void mouse() { - Frame *f; - Align align; + Frame *f; + Align align; if (!pages) return; @@ -462,11 +500,10 @@ mouse() mouse_resize(f, align); } -static void -select_client(void *obj, char *cmd) +static void select_client(void *obj, char *cmd) { - Frame *f = obj; - int size = count_items((void **) f->clients); + Frame *f = obj; + int size = count_items((void **) f->clients); if (!f || !cmd || size == 1) return; if (!strncmp(cmd, "prev", 5)) { @@ -484,16 +521,16 @@ select_client(void *obj, char *cmd) draw_frame(f); } -static void -handle_before_read_frame(IXPServer * s, File * f) +static void handle_before_read_frame(IXPServer * s, File * f) { - int i = 0; + int i = 0; for (i = 0; frames && frames[i]; i++) { if (f == frames[i]->files[F_SIZE]) { - char buf[64]; - snprintf(buf, 64, "%d,%d,%d,%d", frames[i]->rect.x, frames[i]->rect.y, - frames[i]->rect.width, frames[i]->rect.height); + char buf[64]; + snprintf(buf, 64, "%d,%d,%d,%d", frames[i]->rect.x, + frames[i]->rect.y, frames[i]->rect.width, + frames[i]->rect.height); if (f->content) free(f->content); f->content = estrdup(buf); @@ -503,10 +540,9 @@ handle_before_read_frame(IXPServer * s, File * f) } } -static void -handle_after_write_frame(IXPServer * s, File * f) +static void handle_after_write_frame(IXPServer * s, File * f) { - int i; + int i; for (i = 0; frames && frames[i]; i++) { if (f == frames[i]->files[F_CTL]) { @@ -514,17 +550,17 @@ handle_after_write_frame(IXPServer * s, File * f) return; } if (f == frames[i]->files[F_TAB] - || f == frames[i]->files[F_BORDER] - || f == frames[i]->files[F_HANDLE_INC]) { + || f == frames[i]->files[F_BORDER] + || f == frames[i]->files[F_HANDLE_INC]) { if (frames[i]->area) { frames[i]->area->layout->arrange(frames[i]->area); draw_page(frames[i]->area->page); } return; } else if (f == frames[i]->files[F_SIZE]) { - char *size = frames[i]->files[F_SIZE]->content; + char *size = frames[i]->files[F_SIZE]->content; if (size && strrchr(size, ',')) { - XRectangle frect; + XRectangle frect; blitz_strtorect(dpy, &rect, &frect, size); resize_frame(frames[i], &frect, 0, 0); draw_page(frames[i]->area->page); diff --git a/cmd/wm/layout_column.c b/cmd/wm/layout_column.c @@ -16,44 +16,44 @@ typedef struct Acme Acme; typedef struct Column Column; struct Acme { - int sel; - Column **column; + int sel; + Column **column; }; struct Column { - int sel; - int refresh; - Frame **frames; - XRectangle rect; + int sel; + int refresh; + Frame **frames; + XRectangle rect; }; -static void init_col(Area *a); -static void deinit_col(Area *a); -static void arrange_col(Area *a); -static void attach_col(Area *a, Client *c); -static void detach_col(Area *a, Client *c, int unmapped, int destroyed); -static void resize_col(Frame *f, XRectangle *new, XPoint * pt); +static void init_col(Area * a); +static void deinit_col(Area * a); +static void arrange_col(Area * a); +static void attach_col(Area * a, Client * c); +static void detach_col(Area * a, Client * c, int unmapped, int destroyed); +static void resize_col(Frame * f, XRectangle * new, XPoint * pt); -static Layout lcol = {"col", init_col, deinit_col, arrange_col, attach_col, detach_col, resize_col}; +static Layout lcol = + { "col", init_col, deinit_col, arrange_col, attach_col, detach_col, +resize_col }; -static Column zero_column = {0}; -static Acme zero_acme = {0}; +static Column zero_column = { 0 }; +static Acme zero_acme = { 0 }; -void -init_layout_column() +void init_layout_column() { layouts = - (Layout **) attach_item_end((void **) layouts, &lcol, - sizeof(Layout *)); + (Layout **) attach_item_end((void **) layouts, &lcol, + sizeof(Layout *)); } -static void -arrange_column(Area *a, Column *col) +static void arrange_column(Area * a, Column * col) { - int i; - int n = count_items((void **) col->frames); - unsigned int height = a->rect.height / n; + int i; + int n = count_items((void **) col->frames); + unsigned int height = a->rect.height / n; for (i = 0; col->frames && col->frames[i]; i++) { if (col->refresh) { col->frames[i]->rect = col->rect; @@ -64,11 +64,10 @@ arrange_column(Area *a, Column *col) } } -static void -arrange_col(Area *a) +static void arrange_col(Area * a) { - Acme *acme = a->aux; - int i; + Acme *acme = a->aux; + int i; if (!acme) { fprintf(stderr, "%s", "wmiiwm: fatal, page has no layout\n"); @@ -78,29 +77,28 @@ arrange_col(Area *a) arrange_column(a, acme->column[i]); } -static void -init_col(Area *a) +static void init_col(Area * a) { - Acme *acme = emalloc(sizeof(Acme)); - int i, j, n, cols = 1; - unsigned int width = 1; - Column *col; + Acme *acme = emalloc(sizeof(Acme)); + int i, j, n, cols = 1; + unsigned int width = 1; + Column *col; *acme = zero_acme; a->aux = acme; /* processing argv */ /* - for (i = 1; (i < argc) && (argv[i][0] == '-'); i++) { - switch (argv[i][1]) { - case 'c': - cols = _strtonum(argv[++i], 0, 32); - if (cols < 1) - cols = 1; - break; - } - } - */ + for (i = 1; (i < argc) && (argv[i][0] == '-'); i++) { + switch (argv[i][1]) { + case 'c': + cols = _strtonum(argv[++i], 0, 32); + if (cols < 1) + cols = 1; + break; + } + } + */ width = a->rect.width / cols; acme->column = emalloc((cols + 1) * sizeof(Column *)); @@ -112,7 +110,7 @@ init_col(Area *a) acme->column[i]->rect.width = width; acme->column[i]->refresh = 1; } - acme->column[cols] = 0; /* null termination of array */ + acme->column[cols] = 0; /* null termination of array */ /* * Frame attaching strategy works as follows: 1. If more clients than @@ -127,7 +125,11 @@ init_col(Area *a) j = 0; for (i = 0; i < (cols - 1); i++) { col = acme->column[i]; - col->frames = (Frame **) attach_item_end((void **) col->frames, alloc_frame(&clients[i]->rect, 1, 1), sizeof(Frame *)); + col->frames = + (Frame **) attach_item_end((void **) col->frames, + alloc_frame(&clients[i]->rect, + 1, 1), + sizeof(Frame *)); col->frames[0]->aux = col; attach_frame_to_area(a, col->frames[0]); attach_client_to_frame(col->frames[0], clients[j]); @@ -147,7 +149,11 @@ init_col(Area *a) j = 0; for (i = cols - 1; j < n; i--) { col = acme->column[i]; - col->frames = (Frame **) attach_item_end((void **) col->frames, alloc_frame(&clients[i]->rect, 1, 1), sizeof(Frame *)); + col->frames = + (Frame **) attach_item_end((void **) col->frames, + alloc_frame(&clients[i]->rect, + 1, 1), + sizeof(Frame *)); col->frames[0]->aux = col; attach_frame_to_area(a, col->frames[0]); attach_client_to_frame(col->frames[0], clients[j]); @@ -157,17 +163,16 @@ init_col(Area *a) arrange_col(a); } -static void -deinit_col(Area *a) +static void deinit_col(Area * a) { - Acme *acme = a->aux; - int i; + Acme *acme = a->aux; + int i; for (i = 0; acme->column && acme->column[i]; i++) { - Column *col = acme->column[i]; - int j; + Column *col = acme->column[i]; + int j; for (j = 0; col->frames && col->frames[j]; j++) { - Frame *f = col->frames[j]; + Frame *f = col->frames[j]; while (f->clients && f->clients[0]) detach_client_from_frame(f->clients[0], 0, 0); detach_frame_from_area(f, 1); @@ -180,17 +185,16 @@ deinit_col(Area *a) a->aux = 0; } -static void -attach_col(Area *a, Client *c) +static void attach_col(Area * a, Client * c) { - Acme *acme = a->aux; - Column *col; - Frame *f; + Acme *acme = a->aux; + Column *col; + Frame *f; col = acme->column[acme->sel]; f = alloc_frame(&c->rect, 1, 1); col->frames = (Frame **) attach_item_end((void **) col->frames, f, - sizeof(Frame *)); + sizeof(Frame *)); f->aux = col; col->refresh = 1; attach_frame_to_area(a, f); @@ -199,17 +203,16 @@ attach_col(Area *a, Client *c) arrange_col(a); } -static void -detach_col(Area *a, Client *c, int unmapped, int destroyed) +static void detach_col(Area * a, Client * c, int unmapped, int destroyed) { - Frame *f = c->frame; - Column *col = f->aux; + Frame *f = c->frame; + Column *col = f->aux; if (!col) - return; /* client was not attached, maybe exit(1) in - * such case */ + return; /* client was not attached, maybe exit(1) in + * such case */ col->frames = (Frame **) detach_item((void **) col->frames, c->frame, - sizeof(Frame *)); + sizeof(Frame *)); col->refresh = 1; detach_client_from_frame(c, unmapped, destroyed); detach_frame_from_area(f, 1); @@ -218,16 +221,15 @@ detach_col(Area *a, Client *c, int unmapped, int destroyed) arrange_col(a); } -static void -drop_resize(Frame * f, XRectangle * new) +static void drop_resize(Frame * f, XRectangle * new) { - Column *col = f->aux; - Acme *acme = f->area->aux; - int i, idx, n = 0; + Column *col = f->aux; + Acme *acme = f->area->aux; + int i, idx, n = 0; if (!col) { fprintf(stderr, "%s", - "wmii: fatal: frame has no associated column\n"); + "wmii: fatal: frame has no associated column\n"); exit(1); } for (i = 0; acme->column && acme->column[i]; i++) { @@ -239,19 +241,19 @@ drop_resize(Frame * f, XRectangle * new) /* horizontal resizals are */ if (new->x < f->rect.x) { if (idx && new->x > acme->column[idx - 1]->rect.x) { - Column *west = acme->column[idx - 1]; + Column *west = acme->column[idx - 1]; west->rect.width = new->x - west->rect.x; col->rect.width += f->rect.x - new->x; col->rect.x = new->x; for (i = 0; west->frames && west->frames[i]; i++) { - Frame *f = west->frames[i]; + Frame *f = west->frames[i]; f->rect.x = west->rect.x; f->rect.width = west->rect.width; resize_frame(f, &f->rect, 0, 1); } for (i = 0; col->frames && col->frames[i]; i++) { - Frame *f = col->frames[i]; + Frame *f = col->frames[i]; f->rect.x = col->rect.x; f->rect.width = col->rect.width; resize_frame(f, &f->rect, 0, 1); @@ -260,22 +262,22 @@ drop_resize(Frame * f, XRectangle * new) } if (new->x + new->width > f->rect.x + f->rect.width) { if ((idx + 1 < n) && - (new->x + new->width < acme->column[idx + 1]->rect.x - + acme->column[idx + 1]->rect.width)) { - Column *east = acme->column[idx + 1]; + (new->x + new->width < acme->column[idx + 1]->rect.x + + acme->column[idx + 1]->rect.width)) { + Column *east = acme->column[idx + 1]; east->rect.width -= new->x + new->width - east->rect.x; east->rect.x = new->x + new->width; col->rect.x = new->x; col->rect.width = new->width; for (i = 0; col->frames && col->frames[i]; i++) { - Frame *f = col->frames[i]; + Frame *f = col->frames[i]; f->rect.x = col->rect.x; f->rect.width = col->rect.width; resize_frame(f, &f->rect, 0, 1); } for (i = 0; east->frames && east->frames[i]; i++) { - Frame *f = east->frames[i]; + Frame *f = east->frames[i]; f->rect.x = east->rect.x; f->rect.width = east->rect.width; resize_frame(f, &f->rect, 0, 1); @@ -292,7 +294,7 @@ drop_resize(Frame * f, XRectangle * new) if (new->y < f->rect.y) { if (idx && new->y > col->frames[idx - 1]->rect.y) { - Frame *north = col->frames[idx - 1]; + Frame *north = col->frames[idx - 1]; north->rect.height = new->y - north->rect.y; f->rect.width += new->y - north->rect.y; f->rect.y = new->y; @@ -302,9 +304,9 @@ drop_resize(Frame * f, XRectangle * new) } if (new->y + new->height > f->rect.y + f->rect.height) { if ((idx + 1 < n) && - (new->y + new->height < col->frames[idx + 1]->rect.y - + col->frames[idx + 1]->rect.height)) { - Frame *south = col->frames[idx + 1]; + (new->y + new->height < col->frames[idx + 1]->rect.y + + col->frames[idx + 1]->rect.height)) { + Frame *south = col->frames[idx + 1]; south->rect.width -= new->x + new->width - south->rect.x; south->rect.x = new->x + new->width; f->rect.x = new->x; @@ -315,20 +317,19 @@ drop_resize(Frame * f, XRectangle * new) } } -static void -_drop_move(Frame * f, XRectangle * new, XPoint * pt) +static void _drop_move(Frame * f, XRectangle * new, XPoint * pt) { - Column *tgt = 0, *src = f->aux; - Acme *acme = f->area->aux; - int i; + Column *tgt = 0, *src = f->aux; + Acme *acme = f->area->aux; + int i; if (!src) { fprintf(stderr, "%s", - "wmii: fatal: frame has no associated column\n"); + "wmii: fatal: frame has no associated column\n"); exit(1); } for (i = 0; acme->column && acme->column[i]; i++) { - Column *colp = acme->column[i]; + Column *colp = acme->column[i]; if (blitz_ispointinrect(pt->x, pt->y, &colp->rect)) { tgt = colp; break; @@ -339,15 +340,15 @@ _drop_move(Frame * f, XRectangle * new, XPoint * pt) if (tgt == src) { /* only change order within column */ for (i = 0; tgt->frames && tgt->frames[i]; i++) { - Frame *fp = tgt->frames[i]; + Frame *fp = tgt->frames[i]; if (blitz_ispointinrect(pt->x, pt->y, &fp->rect)) { if (fp == f) - return; /* just ignore */ + return; /* just ignore */ else { - int idxf = index_item((void **) tgt->frames, f); - int idxfp = index_item((void **) tgt->frames, fp); - Frame *tmpf = f; - XRectangle tmpr = f->rect; + int idxf = index_item((void **) tgt->frames, f); + int idxfp = index_item((void **) tgt->frames, fp); + Frame *tmpf = f; + XRectangle tmpr = f->rect; f->rect = fp->rect; fp->rect = tmpr; @@ -362,10 +363,10 @@ _drop_move(Frame * f, XRectangle * new, XPoint * pt) } else { /* detach, attach and change order in target column */ src->frames = (Frame **) detach_item((void **) src->frames, - f, sizeof(Frame *)); + f, sizeof(Frame *)); tgt->frames = (Frame **) attach_item_end((void **) tgt->frames, f, - sizeof(Frame *)); + sizeof(Frame *)); tgt->refresh = 1; arrange_column(f->area, tgt); @@ -373,11 +374,10 @@ _drop_move(Frame * f, XRectangle * new, XPoint * pt) } } -static void -resize_col(Frame * f, XRectangle * new, XPoint * pt) +static void resize_col(Frame * f, XRectangle * new, XPoint * pt) { if ((f->rect.width == new->width) - && (f->rect.height == new->height)) + && (f->rect.height == new->height)) _drop_move(f, new, pt); else drop_resize(f, new); diff --git a/cmd/wm/mouse.c b/cmd/wm/mouse.c @@ -7,11 +7,10 @@ #include "wm.h" -Cursor -cursor_for_motion(Frame * f, int x, int y) +Cursor cursor_for_motion(Frame * f, int x, int y) { - int n, e, w, s, tn, te, tw, ts; - int tabh, bw; + int n, e, w, s, tn, te, tw, ts; + int tabh, bw; bw = border_width(f); tabh = tab_height(f); @@ -50,18 +49,17 @@ cursor_for_motion(Frame * f, int x, int y) return normal_cursor; } -Align -xy_to_align(XRectangle * rect, int x, int y) +Align xy_to_align(XRectangle * rect, int x, int y) { - int w = x <= rect->x + rect->width / 2; - int n = y <= rect->y + rect->height / 2; - int e = x > rect->x + rect->width / 2; - int s = y > rect->y + rect->height / 2; - int nw = w && n; - int ne = e && n; - int sw = w && s; - int se = e && s; + int w = x <= rect->x + rect->width / 2; + int n = y <= rect->y + rect->height / 2; + int e = x > rect->x + rect->width / 2; + int s = y > rect->y + rect->height / 2; + int nw = w && n; + int ne = e && n; + int sw = w && s; + int se = e && s; if (nw) return NWEST; @@ -82,8 +80,7 @@ xy_to_align(XRectangle * rect, int x, int y) return CENTER; } -Align -cursor_to_align(Cursor cursor) +Align cursor_to_align(Cursor cursor) { if (cursor == w_cursor) return WEST; @@ -101,35 +98,33 @@ cursor_to_align(Cursor cursor) return SOUTH; else if (cursor == sw_cursor) return SWEST; - return CENTER; /* should not happen */ + return CENTER; /* should not happen */ } -static int -check_vert_match(XRectangle * r, XRectangle * neighbor) +static int check_vert_match(XRectangle * r, XRectangle * neighbor) { /* check if neighbor matches edge */ return (((neighbor->y <= r->y) - && (neighbor->y + neighbor->height >= r->y)) - || ((neighbor->y >= r->y) - && (r->y + r->height >= neighbor->y))); + && (neighbor->y + neighbor->height >= r->y)) + || ((neighbor->y >= r->y) + && (r->y + r->height >= neighbor->y))); } -static int -check_horiz_match(XRectangle * r, XRectangle * neighbor) +static int check_horiz_match(XRectangle * r, XRectangle * neighbor) { /* check if neighbor matches edge */ return (((neighbor->x <= r->x) - && (neighbor->x + neighbor->width >= r->x)) - || ((neighbor->x >= r->x) - && (r->x + r->width >= neighbor->x))); + && (neighbor->x + neighbor->width >= r->x)) + || ((neighbor->x >= r->x) + && (r->x + r->width >= neighbor->x))); } static void snap_move(XRectangle * r, XRectangle * rects, - unsigned int num, int snapw, int snaph) + unsigned int num, int snapw, int snaph) { - int i, j, w = 0, n = 0, e = 0, s = 0; + int i, j, w = 0, n = 0, e = 0, s = 0; /* snap to other windows */ for (i = 0; i <= snapw && !(w && e); i++) { @@ -281,10 +276,9 @@ snap_move(XRectangle * r, XRectangle * rects, } } -static void -draw_pseudo_border(XRectangle * r) +static void draw_pseudo_border(XRectangle * r) { - XRectangle pseudo = *r; + XRectangle pseudo = *r; pseudo.x += 2; pseudo.y += 2; @@ -295,20 +289,23 @@ draw_pseudo_border(XRectangle * r) } -void -mouse_move(Frame * f) +void mouse_move(Frame * f) { - int px = 0, py = 0, wex, wey, ex, ey, first = 1, i; - Window dummy; - XEvent ev; + int px = 0, py = 0, wex, wey, ex, ey, first = 1, i; + Window dummy; + XEvent ev; /* borders */ - int snapw = rect.width * _strtonum(defaults[WM_SNAP_VALUE]->content, 0, 1000) / 1000; - int snaph = rect.height * _strtonum(defaults[WM_SNAP_VALUE]->content, 0, 1000) / 1000; - unsigned int num; - unsigned int dmask; - XRectangle *rects = rectangles(&num); - XRectangle frect = f->rect; - XPoint pt; + int snapw = + rect.width * _strtonum(defaults[WM_SNAP_VALUE]->content, 0, + 1000) / 1000; + int snaph = + rect.height * _strtonum(defaults[WM_SNAP_VALUE]->content, 0, + 1000) / 1000; + unsigned int num; + unsigned int dmask; + XRectangle *rects = rectangles(&num); + XRectangle frect = f->rect; + XPoint pt; XQueryPointer(dpy, f->win, &dummy, &dummy, &i, &i, &wex, &wey, &dmask); XTranslateCoordinates(dpy, f->win, root, wex, wey, &ex, &ey, &dummy); @@ -317,11 +314,12 @@ mouse_move(Frame * f) XSync(dpy, False); XGrabServer(dpy); XGrabPointer(dpy, root, False, ButtonMotionMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, move_cursor, - CurrentTime); + GrabModeAsync, GrabModeAsync, None, move_cursor, + CurrentTime); for (;;) { while (!XCheckMaskEvent(dpy, - ButtonReleaseMask | ButtonMotionMask, &ev)) { + ButtonReleaseMask | ButtonMotionMask, + &ev)) { usleep(20000); continue; } @@ -343,7 +341,7 @@ mouse_move(Frame * f) pt.x = ev.xmotion.x; pt.y = ev.xmotion.y; XTranslateCoordinates(dpy, f->win, root, ev.xmotion.x, - ev.xmotion.y, &px, &py, &dummy); + ev.xmotion.y, &px, &py, &dummy); if (first) first = 0; else @@ -359,11 +357,11 @@ mouse_move(Frame * f) static void snap_resize(XRectangle * r, XRectangle * o, Align align, - XRectangle * rects, unsigned int num, int px, int ox, int py, - int oy, int snapw, int snaph) + XRectangle * rects, unsigned int num, int px, int ox, int py, + int oy, int snapw, int snaph) { - int i, j, pend = 0; - int w, h; + int i, j, pend = 0; + int w, h; /* x */ switch (align) { @@ -538,30 +536,34 @@ snap_resize(XRectangle * r, XRectangle * o, Align align, } -void -mouse_resize(Frame * f, Align align) +void mouse_resize(Frame * f, Align align) { - int px = 0, py = 0, i, ox, oy, first = 1; - Window dummy; - XEvent ev; + int px = 0, py = 0, i, ox, oy, first = 1; + Window dummy; + XEvent ev; /* borders */ - int snapw = rect.width * _strtonum(defaults[WM_SNAP_VALUE]->content, 0, 1000) / 1000; - int snaph = rect.height * _strtonum(defaults[WM_SNAP_VALUE]->content, 0, 1000) / 1000; - unsigned int dmask; - unsigned int num; - XRectangle *rects = rectangles(&num); - XRectangle frect = f->rect; - XRectangle origin = frect; + int snapw = + rect.width * _strtonum(defaults[WM_SNAP_VALUE]->content, 0, + 1000) / 1000; + int snaph = + rect.height * _strtonum(defaults[WM_SNAP_VALUE]->content, 0, + 1000) / 1000; + unsigned int dmask; + unsigned int num; + XRectangle *rects = rectangles(&num); + XRectangle frect = f->rect; + XRectangle origin = frect; XQueryPointer(dpy, f->win, &dummy, &dummy, &i, &i, &ox, &oy, &dmask); XSync(dpy, False); XGrabServer(dpy); XGrabPointer(dpy, f->win, False, ButtonMotionMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, resize_cursor, - CurrentTime); + GrabModeAsync, GrabModeAsync, None, resize_cursor, + CurrentTime); for (;;) { while (!XCheckMaskEvent(dpy, - ButtonReleaseMask | ButtonMotionMask, &ev)) { + ButtonReleaseMask | ButtonMotionMask, + &ev)) { usleep(20000); continue; } @@ -569,7 +571,7 @@ mouse_resize(Frame * f, Align align) switch (ev.type) { case ButtonRelease: if (!first) { - XPoint pt; + XPoint pt; draw_pseudo_border(&frect); pt.x = px; pt.y = py; @@ -582,7 +584,7 @@ mouse_resize(Frame * f, Align align) break; case MotionNotify: XTranslateCoordinates(dpy, f->win, root, ev.xmotion.x, - ev.xmotion.y, &px, &py, &dummy); + ev.xmotion.y, &px, &py, &dummy); if (first) first = 0; @@ -590,7 +592,7 @@ mouse_resize(Frame * f, Align align) draw_pseudo_border(&frect); snap_resize(&frect, &origin, align, rects, num, px, - ox, py, oy, snapw, snaph); + ox, py, oy, snapw, snaph); draw_pseudo_border(&frect); break; } @@ -598,19 +600,19 @@ mouse_resize(Frame * f, Align align) } -void -drop_move(Frame * f, XRectangle * new, XPoint * pt) +void drop_move(Frame * f, XRectangle * new, XPoint * pt) { - Area *a = f->area; - int cx, cy; - unsigned int i, idx = index_item((void **) a->frames, f); + Area *a = f->area; + int cx, cy; + unsigned int i, idx = index_item((void **) a->frames, f); if ((f->rect.x == new->x) && (f->rect.y == new->y)) return; cx = (pt ? pt->x : new->x + new->width / 2); cy = (pt ? pt->y : new->y + new->height / 2); for (i = 0; a->frames[i]; i++) { - if ((a->frames[i] != f) && blitz_ispointinrect(cx, cy, &a->frames[i]->rect)) { + if ((a->frames[i] != f) + && blitz_ispointinrect(cx, cy, &a->frames[i]->rect)) { swap((void **) &a->frames[i], (void **) &a->frames[idx]); a->sel = i; a->layout->arrange(a); diff --git a/cmd/wm/page.c b/cmd/wm/page.c @@ -11,23 +11,22 @@ #include <cext.h> -static Page zero_page = {0}; +static Page zero_page = { 0 }; -static void select_frame(void *obj, char *cmd); -static void handle_after_write_page(IXPServer * s, File * f); +static void select_frame(void *obj, char *cmd); +static void handle_after_write_page(IXPServer * s, File * f); /* action table for /page/?/ namespace */ -Action page_acttbl[] = { +Action page_acttbl[] = { {"select", select_frame}, {0, 0} }; -Page * -alloc_page(char *autodestroy) +Page *alloc_page(char *autodestroy) { - Page *p = emalloc(sizeof(Page)); - char buf[MAX_BUF]; - int id = count_items((void **) pages) + 1; + Page *p = emalloc(sizeof(Page)); + char buf[MAX_BUF]; + int id = count_items((void **) pages) + 1; *p = zero_page; snprintf(buf, sizeof(buf), "/page/%d", id); @@ -49,8 +48,7 @@ alloc_page(char *autodestroy) return p; } -void -free_page(Page * p) +void free_page(Page * p) { pages = (Page **) detach_item((void **) pages, p, sizeof(Page *)); if (pages) { @@ -66,25 +64,23 @@ free_page(Page * p) free(p); } -void -draw_page(Page * p) +void draw_page(Page * p) { - int i; + int i; if (!p) return; for (i = 0; p->areas && p->areas[i]; i++) draw_area(p->areas[i]); } -XRectangle * -rectangles(unsigned int *num) +XRectangle *rectangles(unsigned int *num) { - XRectangle *result = 0; - int i, j = 0; - Window d1, d2; - Window *wins; + XRectangle *result = 0; + int i, j = 0; + Window d1, d2; + Window *wins; XWindowAttributes wa; - XRectangle r; + XRectangle r; if (XQueryTree(dpy, root, &d1, &d2, &wins, num)) { result = emalloc(*num * sizeof(XRectangle)); @@ -107,13 +103,12 @@ rectangles(unsigned int *num) return result; } -static void -center_pointer(Frame * f) +static void center_pointer(Frame * f) { - Window dummy; - int wex, wey, ex, ey, i; - unsigned int dmask; + Window dummy; + int wex, wey, ex, ey, i; + unsigned int dmask; if (!f) return; XQueryPointer(dpy, f->win, &dummy, &dummy, &i, &i, &wex, &wey, &dmask); @@ -122,19 +117,19 @@ center_pointer(Frame * f) return; /* suppress EnterNotify's while mouse warping */ XSelectInput(dpy, root, ROOT_MASK & ~StructureNotifyMask); - XWarpPointer(dpy, None, f->win, 0, 0, 0, 0, f->rect.width / 2, f->rect.height / 2); + XWarpPointer(dpy, None, f->win, 0, 0, 0, 0, f->rect.width / 2, + f->rect.height / 2); XSync(dpy, False); XSelectInput(dpy, root, ROOT_MASK); } -static void -select_frame(void *obj, char *cmd) +static void select_frame(void *obj, char *cmd) { int i; Frame *f, *old; f = old = pages ? SELFRAME(pages[sel]) : 0; - if(!f || !cmd) + if (!f || !cmd) return; if (!strncmp(cmd, "prev", 5)) { i = index_prev_item((void **) f->area->frames, f); @@ -151,28 +146,25 @@ select_frame(void *obj, char *cmd) } } -void -hide_page(Page * p) +void hide_page(Page * p) { - int i; + int i; for (i = 0; p->areas && p->areas[i]; i++) hide_area(p->areas[i]); } -void -show_page(Page * p) +void show_page(Page * p) { - int i; + int i; for (i = 0; p->areas && p->areas[i]; i++) show_area(p->areas[i]); } -Layout * -get_layout(char *name) +Layout *get_layout(char *name) { - int i = 0; - size_t len; + int i = 0; + size_t len; if (!name) return 0; len = strlen(name); @@ -183,76 +175,75 @@ get_layout(char *name) return 0; } -static void -handle_after_write_page(IXPServer * s, File * f) +static void handle_after_write_page(IXPServer * s, File * f) { - int i; + int i; for (i = 0; pages && pages[i]; i++) { - Page *p = pages[i]; + Page *p = pages[i]; if (p->files[P_CTL] == f) { run_action(f, p, page_acttbl); return; } /* - else if (p->files[P_MANAGED_SIZE] == f) { - / resize stuff / - blitz_strtorect(dpy, &rect, &p->managed_rect, - p->files[P_MANAGED_SIZE]->content); - if (!p->managed_rect.width) - p->managed_rect.width = 10; - if (!p->managed_rect.height) - p->managed_rect.height = 10; - if (p->layout) - p->layout->arrange(p); - draw_page(p); - return; - } else if (p->files[P_MANAGED_LAYOUT] == f) { - int had_valid_layout = p->layout ? 1 : 0; - if (p->layout) - p->layout->deinit(p); - p->layout = get_layout(p->files[P_MANAGED_LAYOUT]->content); - if (p->layout) { - p->layout->init(p); - p->layout->arrange(p); - if (!had_valid_layout) { - int j; - Frame **tmp = 0; - for (j = 0; p->floating && p->floating[j]; j++) { - if (!p->floating[j]->floating) - tmp = - (Frame **) attach_item_begin((void **) tmp, - p-> - floating[j], - sizeof(Frame - *)); - } - for (j = 0; tmp && tmp[j]; j++) - toggle_frame(tmp[j]); - free(tmp); - } - } - if (!p->layout) { - / make all managed clients floating / - int j; - Frame **tmp = 0; - while (p->managed) { - tmp = (Frame **) attach_item_begin((void **) tmp, - p->managed[0], - sizeof(Frame *)); - detach_frame_from_page(p->managed[0], 1); - } - for (j = 0; tmp && tmp[j]; j++) { - attach_Frameo_page(p, tmp[j], 0); - resize_frame(tmp[j], rect_of_frame(tmp[j]), 0, 1); - } - free(tmp); - } - draw_page(p); - invoke_core_event(core_files[CORE_EVENT_PAGE_UPDATE]); - return; - } -*/ + else if (p->files[P_MANAGED_SIZE] == f) { + / resize stuff / + blitz_strtorect(dpy, &rect, &p->managed_rect, + p->files[P_MANAGED_SIZE]->content); + if (!p->managed_rect.width) + p->managed_rect.width = 10; + if (!p->managed_rect.height) + p->managed_rect.height = 10; + if (p->layout) + p->layout->arrange(p); + draw_page(p); + return; + } else if (p->files[P_MANAGED_LAYOUT] == f) { + int had_valid_layout = p->layout ? 1 : 0; + if (p->layout) + p->layout->deinit(p); + p->layout = get_layout(p->files[P_MANAGED_LAYOUT]->content); + if (p->layout) { + p->layout->init(p); + p->layout->arrange(p); + if (!had_valid_layout) { + int j; + Frame **tmp = 0; + for (j = 0; p->floating && p->floating[j]; j++) { + if (!p->floating[j]->floating) + tmp = + (Frame **) attach_item_begin((void **) tmp, + p-> + floating[j], + sizeof(Frame + *)); + } + for (j = 0; tmp && tmp[j]; j++) + toggle_frame(tmp[j]); + free(tmp); + } + } + if (!p->layout) { + / make all managed clients floating / + int j; + Frame **tmp = 0; + while (p->managed) { + tmp = (Frame **) attach_item_begin((void **) tmp, + p->managed[0], + sizeof(Frame *)); + detach_frame_from_page(p->managed[0], 1); + } + for (j = 0; tmp && tmp[j]; j++) { + attach_Frameo_page(p, tmp[j], 0); + resize_frame(tmp[j], rect_of_frame(tmp[j]), 0, 1); + } + free(tmp); + } + draw_page(p); + invoke_core_event(core_files[CORE_EVENT_PAGE_UPDATE]); + return; + } + */ } } diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c @@ -13,27 +13,25 @@ #include "wm.h" -static int other_wm_running; -static int (*x_error_handler) (Display *, XErrorEvent *); +static int other_wm_running; +static int (*x_error_handler) (Display *, XErrorEvent *); -char *version[] = { +char *version[] = { "wmiiwm - window manager improved 2 - " VERSION "\n" - " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 + " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 }; -static void -usage() +static void usage() { fprintf(stderr, "%s", - "usage: wmiiwm -s <socket file> [-c] [-v]\n" - " -s socket file\n" - " -c checks if another WM is already running\n" - " -v version info\n"); + "usage: wmiiwm -s <socket file> [-c] [-v]\n" + " -s socket file\n" + " -c checks if another WM is already running\n" + " -v version info\n"); exit(1); } -static void -init_atoms() +static void init_atoms() { wm_state = XInternAtom(dpy, "WM_STATE", False); wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False); @@ -43,8 +41,7 @@ init_atoms() net_wm_desktop = XInternAtom(dpy, "_NET_WM_DESKTOP", False); } -static void -init_cursors() +static void init_cursors() { normal_cursor = XCreateFontCursor(dpy, XC_left_ptr); resize_cursor = XCreateFontCursor(dpy, XC_sizing); @@ -60,47 +57,73 @@ init_cursors() se_cursor = XCreateFontCursor(dpy, XC_bottom_right_corner); } -static void -init_defaults() +static void init_defaults() { defaults[WM_DETACHED_FRAME] = ixp_create(ixps, "/detached/frame"); defaults[WM_DETACHED_CLIENT] = ixp_create(ixps, "/detached/client"); - defaults[WM_TRANS_COLOR] = wmii_create_ixpfile(ixps, "/default/transcolor", BLITZ_SEL_FG_COLOR); + defaults[WM_TRANS_COLOR] = + wmii_create_ixpfile(ixps, "/default/transcolor", + BLITZ_SEL_FG_COLOR); defaults[WM_TRANS_COLOR]->after_write = handle_after_write; - defaults[WM_SEL_BG_COLOR] = wmii_create_ixpfile(ixps, "/default/selstyle/bgcolor", BLITZ_SEL_BG_COLOR); - defaults[WM_SEL_FG_COLOR] = wmii_create_ixpfile(ixps, "/default/selstyle/fgcolor", BLITZ_SEL_FG_COLOR); - defaults[WM_SEL_BORDER_COLOR] = wmii_create_ixpfile(ixps, "/default/selstyle/fgcolor", BLITZ_SEL_BORDER_COLOR); - defaults[WM_NORM_BG_COLOR] = wmii_create_ixpfile(ixps, "/default/normstyle/bgcolor", BLITZ_NORM_BG_COLOR); - defaults[WM_NORM_FG_COLOR] = wmii_create_ixpfile(ixps, "/default/normstyle/fgcolor", BLITZ_NORM_FG_COLOR); - defaults[WM_NORM_BORDER_COLOR] = wmii_create_ixpfile(ixps, "/default/normstyle/fgcolor", BLITZ_NORM_BORDER_COLOR); - defaults[WM_FONT] = wmii_create_ixpfile(ixps, "/default/font", BLITZ_FONT); + defaults[WM_SEL_BG_COLOR] = + wmii_create_ixpfile(ixps, "/default/selstyle/bgcolor", + BLITZ_SEL_BG_COLOR); + defaults[WM_SEL_FG_COLOR] = + wmii_create_ixpfile(ixps, "/default/selstyle/fgcolor", + BLITZ_SEL_FG_COLOR); + defaults[WM_SEL_BORDER_COLOR] = + wmii_create_ixpfile(ixps, "/default/selstyle/fgcolor", + BLITZ_SEL_BORDER_COLOR); + defaults[WM_NORM_BG_COLOR] = + wmii_create_ixpfile(ixps, "/default/normstyle/bgcolor", + BLITZ_NORM_BG_COLOR); + defaults[WM_NORM_FG_COLOR] = + wmii_create_ixpfile(ixps, "/default/normstyle/fgcolor", + BLITZ_NORM_FG_COLOR); + defaults[WM_NORM_BORDER_COLOR] = + wmii_create_ixpfile(ixps, "/default/normstyle/fgcolor", + BLITZ_NORM_BORDER_COLOR); + defaults[WM_FONT] = + wmii_create_ixpfile(ixps, "/default/font", BLITZ_FONT); defaults[WM_FONT]->after_write = handle_after_write; - defaults[WM_PAGE_SIZE] = wmii_create_ixpfile(ixps, "/default/pagesize", "0,0,east,south-16"); + defaults[WM_PAGE_SIZE] = + wmii_create_ixpfile(ixps, "/default/pagesize", + "0,0,east,south-16"); defaults[WM_SNAP_VALUE] = wmii_create_ixpfile(ixps, "/default/snapvalue", "20"); /* 0..1000 */ - defaults[WM_BORDER] = wmii_create_ixpfile(ixps, "/default/border", "1"); + defaults[WM_BORDER] = + wmii_create_ixpfile(ixps, "/default/border", "1"); defaults[WM_TAB] = wmii_create_ixpfile(ixps, "/default/tab", "1"); - defaults[WM_HANDLE_INC] = wmii_create_ixpfile(ixps, "/default/handleinc", "1"); - defaults[WM_LOCKED] = wmii_create_ixpfile(ixps, "/default/locked", "1"); - defaults[WM_LAYOUT] = wmii_create_ixpfile(ixps, "/default/layout", LAYOUT); + defaults[WM_HANDLE_INC] = + wmii_create_ixpfile(ixps, "/default/handleinc", "1"); + defaults[WM_LOCKED] = + wmii_create_ixpfile(ixps, "/default/locked", "1"); + defaults[WM_LAYOUT] = + wmii_create_ixpfile(ixps, "/default/layout", LAYOUT); defaults[WM_SEL_PAGE] = ixp_create(ixps, "/page/sel"); - defaults[WM_EVENT_PAGE_UPDATE] = ixp_create(ixps, "/default/event/pageupdate"); - defaults[WM_EVENT_CLIENT_UPDATE] = ixp_create(ixps, "/default/event/clientupdate"); - defaults[WM_EVENT_B1PRESS] = ixp_create(ixps, "/defaults/event/b1press"); - defaults[WM_EVENT_B2PRESS] = ixp_create(ixps, "/defaults/event/b2press"); - defaults[WM_EVENT_B3PRESS] = ixp_create(ixps, "/defaults/event/b3press"); - defaults[WM_EVENT_B4PRESS] = ixp_create(ixps, "/defaults/event/b4press"); - defaults[WM_EVENT_B5PRESS] = ixp_create(ixps, "/defaults/event/b5press"); + defaults[WM_EVENT_PAGE_UPDATE] = + ixp_create(ixps, "/default/event/pageupdate"); + defaults[WM_EVENT_CLIENT_UPDATE] = + ixp_create(ixps, "/default/event/clientupdate"); + defaults[WM_EVENT_B1PRESS] = + ixp_create(ixps, "/defaults/event/b1press"); + defaults[WM_EVENT_B2PRESS] = + ixp_create(ixps, "/defaults/event/b2press"); + defaults[WM_EVENT_B3PRESS] = + ixp_create(ixps, "/defaults/event/b3press"); + defaults[WM_EVENT_B4PRESS] = + ixp_create(ixps, "/defaults/event/b4press"); + defaults[WM_EVENT_B5PRESS] = + ixp_create(ixps, "/defaults/event/b5press"); } -static void -init_screen() +static void init_screen() { - XGCValues gcv; + XGCValues gcv; XSetWindowAttributes wa; XAllocNamedColor(dpy, DefaultColormap(dpy, screen_num), - defaults[WM_TRANS_COLOR]->content, - &xorcolor, &xorcolor); + defaults[WM_TRANS_COLOR]->content, + &xorcolor, &xorcolor); gcv.subwindow_mode = IncludeInferiors; gcv.function = GXxor; gcv.foreground = xorcolor.pixel; @@ -108,8 +131,8 @@ init_screen() gcv.plane_mask = AllPlanes; gcv.graphics_exposures = False; xorgc = XCreateGC(dpy, root, GCForeground | GCGraphicsExposures - | GCFunction | GCSubwindowMode | GCLineWidth - | GCPlaneMask, &gcv); + | GCFunction | GCSubwindowMode | GCLineWidth + | GCPlaneMask, &gcv); rect.x = rect.y = 0; rect.width = DisplayWidth(dpy, screen_num); rect.height = DisplayHeight(dpy, screen_num); @@ -119,11 +142,11 @@ init_screen() wa.event_mask = ExposureMask | ButtonPressMask | PointerMotionMask | SubstructureRedirectMask | SubstructureNotifyMask; transient = XCreateWindow(dpy, root, 0, 0, rect.width, rect.height, - 0, DefaultDepth(dpy, screen_num), - CopyFromParent, DefaultVisual(dpy, - screen_num), - CWOverrideRedirect | CWBackPixmap | - CWEventMask, &wa); + 0, DefaultDepth(dpy, screen_num), + CopyFromParent, DefaultVisual(dpy, + screen_num), + CWOverrideRedirect | CWBackPixmap | + CWEventMask, &wa); XSync(dpy, False); transient_gc = XCreateGC(dpy, transient, 0, 0); @@ -138,20 +161,19 @@ init_screen() * Other types of errors call Xlib's default error handler, which * calls exit(). */ -static int -wmii_error_handler(Display * dpy, XErrorEvent * error) +static int wmii_error_handler(Display * dpy, XErrorEvent * error) { if (error->error_code == BadWindow - || (error->request_code == X_SetInputFocus - && error->error_code == BadMatch) - || (error->request_code == X_PolyText8 - && error->error_code == BadDrawable) - || (error->request_code == X_PolyFillRectangle - && error->error_code == BadDrawable) - || (error->request_code == X_PolySegment - && error->error_code == BadDrawable) - || (error->request_code == X_ConfigureWindow - && error->error_code == BadMatch)) + || (error->request_code == X_SetInputFocus + && error->error_code == BadMatch) + || (error->request_code == X_PolyText8 + && error->error_code == BadDrawable) + || (error->request_code == X_PolyFillRectangle + && error->error_code == BadDrawable) + || (error->request_code == X_PolySegment + && error->error_code == BadDrawable) + || (error->request_code == X_ConfigureWindow + && error->error_code == BadMatch)) return 0; fprintf(stderr, "%s", "wmiiwm: fatal error"); return x_error_handler(dpy, error); /* calls exit() */ @@ -161,25 +183,24 @@ wmii_error_handler(Display * dpy, XErrorEvent * error) * Startup Error handler to check if another window manager * is already running. */ -static int -startup_error_handler(Display * dpy, XErrorEvent * error) +static int startup_error_handler(Display * dpy, XErrorEvent * error) { other_wm_running = 1; return -1; } -static void -cleanup() +static void cleanup() { - int i; - XWindowChanges wc; + int i; + XWindowChanges wc; for (i = 0; clients && clients[i]; i++) { - Client *c = clients[i]; - Frame *f = c->frame; + Client *c = clients[i]; + Frame *f = c->frame; if (f) { gravitate(c, tab_height(f), border_width(f), 1); - XReparentWindow(dpy, c->win, root, f->rect.x + c->rect.x, f->rect.y + c->rect.y); + XReparentWindow(dpy, c->win, root, f->rect.x + c->rect.x, + f->rect.y + c->rect.y); wc.border_width = c->border; XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); } @@ -187,8 +208,7 @@ cleanup() XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); } -static void -run() +static void run() { /* init */ init_event_hander(); @@ -217,18 +237,17 @@ run() /* main event loop */ run_server_with_fd_support(ixps, ConnectionNumber(dpy), check_event, - 0); + 0); cleanup(); deinit_server(ixps); XCloseDisplay(dpy); } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - int i; - int checkwm = 0; - char *sockfile = 0; + int i; + int checkwm = 0; + char *sockfile = 0; /* command line args */ if (argc > 1) { @@ -269,7 +288,7 @@ main(int argc, char *argv[]) XSync(dpy, False); if (other_wm_running) { fprintf(stderr, - "wmiiwm: another window manager is already running\n"); + "wmiiwm: another window manager is already running\n"); exit(1); } if (checkwm) { diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -24,7 +24,7 @@ enum { A_PREFIX, A_SEL_FRAME, A_CTL, - A_SIZE, + A_GEOMETRY, A_LAYOUT, A_LAST }; @@ -113,177 +113,179 @@ typedef struct Client Client; */ struct Page { - Area **areas; - unsigned int sel; - File *files[P_LAST]; + Area **areas; + unsigned int sel; + File *files[P_LAST]; }; struct Layout { - char *name; - void (*init) (Area *); /* called when layout is initialized */ - void (*deinit) (Area *); /* called when layout is uninitialized */ - void (*arrange) (Area *); /* called when area is resized */ - void (*attach) (Area *, Client *); /* called on attach */ - void (*detach) (Area *, Client *, int, int); /* called on detach */ - void (*resize) (Frame *, XRectangle *, XPoint * pt); /* called after resize */ + char *name; + void (*init) (Area *); /* called when layout is initialized */ + void (*deinit) (Area *); /* called when layout is uninitialized */ + void (*arrange) (Area *); /* called when area is resized */ + void (*attach) (Area *, Client *); /* called on attach */ + void (*detach) (Area *, Client *, int, int); /* called on detach */ + void (*resize) (Frame *, XRectangle *, XPoint * pt); /* called after resize */ }; struct Area { - Layout *layout; - Page *page; - Frame **frames; - unsigned int sel; - XRectangle rect; - void *aux; /* free pointer */ - File *files[A_LAST]; + Layout *layout; + Page *page; + Frame **frames; + unsigned int sel; + XRectangle rect; + void *aux; /* free pointer */ + File *files[A_LAST]; }; struct Frame { - Area *area; - Window win; - GC gc; - XRectangle rect; - Cursor cursor; - Client **clients; - int sel; - void *aux; /* free pointer */ - File *files[F_LAST]; + Area *area; + Window win; + GC gc; + XRectangle rect; + Cursor cursor; + Client **clients; + int sel; + void *aux; /* free pointer */ + File *files[F_LAST]; }; struct Client { - int proto; - unsigned int border; - Window win; - Window trans; - XRectangle rect; - XSizeHints size; - Frame *frame; - File *files[C_LAST]; + int proto; + unsigned int border; + Window win; + Window trans; + XRectangle rect; + XSizeHints size; + Frame *frame; + File *files[C_LAST]; }; #define SELFRAME(x) (x && x->areas[x->sel]->frames ? x->areas[x->sel]->frames[x->areas[x->sel]->sel] : 0) #define ISSELFRAME(x) (pages && SELFRAME(pages[sel]) == x) /* global variables */ -Display *dpy; -IXPServer *ixps; -int screen_num; -Window root; -Window transient; -XRectangle rect; -Client **detached; -Page **pages; -unsigned int sel; -Frame **frames; -Client **clients; -XFontStruct *font; -XColor xorcolor; -GC xorgc; -GC transient_gc; -Layout **layouts; +Display *dpy; +IXPServer *ixps; +int screen_num; +Window root; +Window transient; +XRectangle rect; +Client **detached; +Page **pages; +unsigned int sel; +Frame **frames; +Client **clients; +XFontStruct *font; +XColor xorcolor; +GC xorgc; +GC transient_gc; +Layout **layouts; -Atom wm_state; -Atom wm_change_state; -Atom wm_protocols; -Atom wm_delete; -Atom motif_wm_hints; -Atom net_wm_desktop; +Atom wm_state; +Atom wm_change_state; +Atom wm_protocols; +Atom wm_delete; +Atom motif_wm_hints; +Atom net_wm_desktop; -Cursor normal_cursor; -Cursor resize_cursor; -Cursor move_cursor; -Cursor drag_cursor; -Cursor w_cursor; -Cursor e_cursor; -Cursor n_cursor; -Cursor s_cursor; -Cursor nw_cursor; -Cursor ne_cursor; -Cursor sw_cursor; -Cursor se_cursor; +Cursor normal_cursor; +Cursor resize_cursor; +Cursor move_cursor; +Cursor drag_cursor; +Cursor w_cursor; +Cursor e_cursor; +Cursor n_cursor; +Cursor s_cursor; +Cursor nw_cursor; +Cursor ne_cursor; +Cursor sw_cursor; +Cursor se_cursor; /* default file pointers */ -File *defaults[WM_LAST]; +File *defaults[WM_LAST]; -unsigned int valid_mask, num_lock_mask; +unsigned int valid_mask, num_lock_mask; /* area.c */ -void destroy_area(Area *a); -void free_area(Area *a); -void attach_frame_to_area(Area *a, Frame * f); -void detach_frame_from_area(Frame * f, int ignore_focus_and_destroy); -void draw_area(Area *a); -void hide_area(Area *a); -void show_area(Area *a); +Area *alloc_area(Page *p, XRectangle * r); +void destroy_area(Area * a); +void free_area(Area * a); +void attach_frame_to_area(Area * a, Frame * f); +void detach_frame_from_area(Frame * f, int ignore_focus_and_destroy); +void draw_area(Area * a); +void hide_area(Area * a); +void show_area(Area * a); /* client.c */ -Client *alloc_client(Window w); -void _init_client(Client * c, XWindowAttributes * wa); -void free_client(Client * c); -void configure_client(Client * c); -void handle_client_property(Client * c, XPropertyEvent * e); -void close_client(Client * c); -void draw_client(Client * c); -void draw_clients(Frame * f); -void gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert); -int manage_class_instance(Client * c); -void grab_client(Client * c, unsigned long mod, unsigned int button); -void ungrab_client(Client * c, unsigned long mod, unsigned int button); -void hide_client(Client * c); -void show_client(Client * c); -void reparent_client(Client * c, Window w, int x, int y); +Client *alloc_client(Window w); +void _init_client(Client * c, XWindowAttributes * wa); +void free_client(Client * c); +void configure_client(Client * c); +void handle_client_property(Client * c, XPropertyEvent * e); +void close_client(Client * c); +void draw_client(Client * c); +void draw_clients(Frame * f); +void gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert); +int manage_class_instance(Client * c); +void grab_client(Client * c, unsigned long mod, unsigned int button); +void ungrab_client(Client * c, unsigned long mod, unsigned int button); +void hide_client(Client * c); +void show_client(Client * c); +void reparent_client(Client * c, Window w, int x, int y); /* core.c */ -unsigned int tab_height(Frame *f); -unsigned int border_width(Frame *f); -void invoke_core_event(File * f); -void run_action(File * f, void *obj, Action * acttbl); -void scan_wins(); -Client *win_to_client(Window w); -int win_proto(Window w); -int win_state(Window w); -void handle_after_write(IXPServer * s, File * f); -void focus_page(Page * p, int raise, int down); -void detach(Frame * f, int client_destroyed); -void destroy_page(Page * p); -void set_client_state(Client * c, int state); +unsigned int tab_height(Frame * f); +unsigned int border_width(Frame * f); +void invoke_core_event(File * f); +void run_action(File * f, void *obj, Action * acttbl); +void scan_wins(); +Client *win_to_client(Window w); +int win_proto(Window w); +int win_state(Window w); +void handle_after_write(IXPServer * s, File * f); +void focus_page(Page * p, int raise, int down); +void detach(Frame * f, int client_destroyed); +void destroy_page(Page * p); +void set_client_state(Client * c, int state); /* frame.c */ -void focus_frame(Frame * f, int raise, int up, int down); -Frame *win_to_frame(Window w); -Frame *alloc_frame(XRectangle * r, int add_frame_border, int floating); -void destroy_frame(Frame * f); -void resize_frame(Frame * f, XRectangle * r, XPoint * pt, int ignore_layout); -void draw_frame(Frame * f); -void handle_frame_buttonpress(XButtonEvent * e, Frame * f); -void attach_client(Client * c); -void attach_client_to_frame(Frame * f, Client * c); -void detach_client_from_frame(Client * c, int unmapped, int destroyed); -void draw_tab(Frame * f, char *text, int x, int y, int w, int h, int sel); -void focus_client(Client * c, int raise, int up); +void focus_frame(Frame * f, int raise, int up, int down); +Frame *win_to_frame(Window w); +Frame *alloc_frame(XRectangle * r, int add_frame_border, int floating); +void destroy_frame(Frame * f); +void resize_frame(Frame * f, XRectangle * r, XPoint * pt, + int ignore_layout); +void draw_frame(Frame * f); +void handle_frame_buttonpress(XButtonEvent * e, Frame * f); +void attach_client(Client * c); +void attach_client_to_frame(Frame * f, Client * c); +void detach_client_from_frame(Client * c, int unmapped, int destroyed); +void draw_tab(Frame * f, char *text, int x, int y, int w, int h, int sel); +void focus_client(Client * c, int raise, int up); /* event.c */ -void init_event_hander(); -void check_event(Connection * c); +void init_event_hander(); +void check_event(Connection * c); /* mouse.c */ -void mouse_resize(Frame * f, Align align); -void mouse_move(Frame * f); -Cursor cursor_for_motion(Frame * f, int x, int y); -Align cursor_to_align(Cursor cursor); -Align xy_to_align(XRectangle * rect, int x, int y); -void drop_move(Frame * f, XRectangle * new, XPoint * pt); +void mouse_resize(Frame * f, Align align); +void mouse_move(Frame * f); +Cursor cursor_for_motion(Frame * f, int x, int y); +Align cursor_to_align(Cursor cursor); +Align xy_to_align(XRectangle * rect, int x, int y); +void drop_move(Frame * f, XRectangle * new, XPoint * pt); /* page.c */ -Page *alloc_page(char *autodestroy); -void free_page(Page * p); -void focus_area(Area *a, int raise, int up, int down); -XRectangle *rectangles(unsigned int *num); -void hide_page(Page * p); -void show_page(Page * p); -void draw_page(Page * p); -Layout *get_layout(char *name); -Frame *select_floating(Page * p, Frame * f, char *what); +Page *alloc_page(char *autodestroy); +void free_page(Page * p); +void focus_area(Area * a, int raise, int up, int down); +XRectangle *rectangles(unsigned int *num); +void hide_page(Page * p); +void show_page(Page * p); +void draw_page(Page * p); +Layout *get_layout(char *name); +Frame *select_floating(Page * p, Frame * f, char *what); /* layout.c */ -void init_layouts(); +void init_layouts(); diff --git a/cmd/wmibar.c b/cmd/wmibar.c @@ -29,37 +29,37 @@ typedef enum { B_BORDER_COLOR, B_BG_COLOR, B_LAST -} BarIndexes; +} BarIndexes; typedef struct { - File *root; - Draw d; -} Item; + File *root; + Draw d; +} Item; static IXPServer *ixps = 0; static Display *dpy; -static GC gc; -static Window win; +static GC gc; +static Window win; static XRectangle rect; static XRectangle brect; -static int screen_num; -static int displayed = 0; -static char *sockfile = 0; -static File *files[B_LAST]; -static Item **items = 0; +static int screen_num; +static int displayed = 0; +static char *sockfile = 0; +static File *files[B_LAST]; +static Item **items = 0; static unsigned int id = 0; -static Pixmap pmap; +static Pixmap pmap; -static Draw zero_draw = {0}; +static Draw zero_draw = { 0 }; -static void draw_bar(void *obj, char *arg); -static void quit(void *obj, char *arg); -static void display(void *obj, char *arg); -static void reset(void *obj, char *arg); -static void _destroy(void *obj, char *arg); -static void handle_after_write(IXPServer * s, File * f); +static void draw_bar(void *obj, char *arg); +static void quit(void *obj, char *arg); +static void display(void *obj, char *arg); +static void reset(void *obj, char *arg); +static void _destroy(void *obj, char *arg); +static void handle_after_write(IXPServer * s, File * f); -static Action acttbl[] = { +static Action acttbl[] = { {"quit", quit}, {"display", display}, {"update", draw_bar}, @@ -68,17 +68,16 @@ static Action acttbl[] = { {0, 0} }; -static char *version[] = { +static char *version[] = { "wmibar - window manager improved bar - " VERSION "\n" - " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 + " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 }; -static void -usage() +static void usage() { fprintf(stderr, "%s", - "usage: wmibar -s <socket file> [-v] [<x>,<y>,<width>,<height>]\n" - " -s socket file\n" " -v version info\n"); + "usage: wmibar -s <socket file> [-v] [<x>,<y>,<width>,<height>]\n" + " -s socket file\n" " -v version info\n"); exit(1); } @@ -93,12 +92,11 @@ usage() * <path>/b4press "<command>" * <path>/b5press "<command>" */ -static void -create_label(char *path) +static void create_label(char *path) { - File *f; - char file[MAX_BUF]; - int i; + File *f; + char file[MAX_BUF]; + int i; snprintf(file, MAX_BUF, "%s/data", path); f = ixp_create(ixps, file); @@ -115,10 +113,9 @@ create_label(char *path) } } -static void -_destroy(void *obj, char *arg) +static void _destroy(void *obj, char *arg) { - char buf[512]; + char buf[512]; if (!arg) return; snprintf(buf, sizeof(buf), "/%s", arg); @@ -126,11 +123,10 @@ _destroy(void *obj, char *arg) draw_bar(0, 0); } -static void -reset(void *obj, char *arg) +static void reset(void *obj, char *arg) { - int i; - char buf[512]; + int i; + char buf[512]; for (i = 0; i < id; i++) { snprintf(buf, sizeof(buf), "/%d", i + 1); ixps->remove(ixps, buf); @@ -139,14 +135,12 @@ reset(void *obj, char *arg) draw_bar(0, 0); } -static void -quit(void *obj, char *arg) +static void quit(void *obj, char *arg) { ixps->runlevel = SHUTDOWN; } -static void -display(void *obj, char *arg) +static void display(void *obj, char *arg) { if (!arg) return; @@ -160,11 +154,10 @@ display(void *obj, char *arg) } } -static void -init_draw_label(char *path, Draw * d) +static void init_draw_label(char *path, Draw * d) { - char buf[MAX_BUF]; - File *f; + char buf[MAX_BUF]; + File *f; /* text stuff */ snprintf(buf, MAX_BUF, "%s/data", path); @@ -182,8 +175,7 @@ init_draw_label(char *path, Draw * d) d->border = blitz_loadcolor(dpy, screen_num, f->content); } -static void -init_item(char *path, Item * i) +static void init_item(char *path, Item * i) { i->d = zero_draw; i->root = ixp_walk(ixps, path); @@ -194,19 +186,17 @@ init_item(char *path, Item * i) init_draw_label(path, &i->d); } -static int -comp_str(const void *s1, const void *s2) +static int comp_str(const void *s1, const void *s2) { return strcmp(*(char **) s1, *(char **) s2); } -static void -draw() +static void draw() { - unsigned int n = 0, i, w, xoff = 0; - XFontStruct *font; - unsigned expandable = 0; - char buf[32]; + unsigned int n = 0, i, w, xoff = 0; + XFontStruct *font; + unsigned expandable = 0; + char buf[32]; if (!items) return; @@ -229,7 +219,8 @@ draw() items[i]->d.rect.width = brect.height / 2; else items[i]->d.rect.width += - XTextWidth(font, items[i]->d.data, strlen(items[i]->d.data)); + XTextWidth(font, items[i]->d.data, + strlen(items[i]->d.data)); } w += items[i]->d.rect.width; } @@ -256,13 +247,12 @@ draw() XFreeFont(dpy, font); } -static void -draw_bar(void *obj, char *arg) +static void draw_bar(void *obj, char *arg) { - File *label = 0; - unsigned int i = 0, n = 0; - Item *item; - char buf[512]; + File *label = 0; + unsigned int i = 0, n = 0; + Item *item; + char buf[512]; if (!displayed) return; @@ -276,19 +266,23 @@ draw_bar(void *obj, char *arg) snprintf(buf, sizeof(buf), "%s", "/1"); label = ixp_walk(ixps, buf); if (!label) { - Draw d = {0}; + Draw d = { 0 }; /* default stuff */ d.gc = gc; d.drawable = pmap; d.rect.width = brect.width; d.rect.height = brect.height; - d.bg = blitz_loadcolor(dpy, screen_num, files[B_BG_COLOR]->content); - d.fg = blitz_loadcolor(dpy, screen_num, files[B_FG_COLOR]->content); - d.border = blitz_loadcolor(dpy, screen_num, files[B_BORDER_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, files[B_BG_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, files[B_FG_COLOR]->content); + d.border = + blitz_loadcolor(dpy, screen_num, + files[B_BORDER_COLOR]->content); blitz_drawlabelnoborder(dpy, &d); } else { - File *f; - char **paths = 0; + File *f; + char **paths = 0; /* * take order into account, directory names are used in * alphabetical order @@ -304,7 +298,9 @@ draw_bar(void *obj, char *arg) for (i = 0; i < n; i++) { snprintf(buf, sizeof(buf), "/%s", paths[i]); item = emalloc(sizeof(Item)); - items = (Item **) attach_item_end((void **) items, item, sizeof(Item *)); + items = + (Item **) attach_item_end((void **) items, item, + sizeof(Item *)); init_item(buf, item); } draw(); @@ -312,23 +308,21 @@ draw_bar(void *obj, char *arg) } } -static Item * -get_item_for_file(File * f) +static Item *get_item_for_file(File * f) { - int i; + int i; for (i = 0; items && items[i]; i++) if (items[i]->root == f) return items[i]; return 0; } -static void -handle_buttonpress(XButtonPressedEvent * e) +static void handle_buttonpress(XButtonPressedEvent * e) { - File *p; - char buf[MAX_BUF]; - char path[512]; - int i; + File *p; + char buf[MAX_BUF]; + char path[512]; + int i; for (i = 0; items && items[i]; i++) { if (blitz_ispointinrect(e->x, e->y, &items[i]->d.rect)) { @@ -343,10 +337,9 @@ handle_buttonpress(XButtonPressedEvent * e) } } -static void -check_event(Connection * e) +static void check_event(Connection * e) { - XEvent ev; + XEvent ev; while (XPending(dpy)) { XNextEvent(dpy, &ev); @@ -366,8 +359,7 @@ check_event(Connection * e) } } -static void -update_geometry(char *size) +static void update_geometry(char *size) { blitz_strtorect(dpy, &rect, &brect, size); if (!brect.width) @@ -376,13 +368,12 @@ update_geometry(char *size) brect.height = 20; } -static void -handle_after_write(IXPServer * s, File * f) +static void handle_after_write(IXPServer * s, File * f) { - int i; - size_t len; - Item *item; - char buf[512]; + int i; + size_t len; + Item *item; + char buf[512]; buf[0] = '\0'; if (!strncmp(f->name, "data", 5)) { @@ -392,14 +383,14 @@ handle_after_write(IXPServer * s, File * f) draw(); } } else if (files[B_GEOMETRY] == f) { - char *geom = files[B_GEOMETRY]->content; + char *geom = files[B_GEOMETRY]->content; if (geom && strrchr(geom, ',')) { update_geometry(geom); XMoveResizeWindow(dpy, win, brect.x, brect.y, - brect.width, brect.height); + brect.width, brect.height); XSync(dpy, False); pmap = XCreatePixmap(dpy, win, brect.width, brect.height, - DefaultDepth(dpy, screen_num)); + DefaultDepth(dpy, screen_num)); XSync(dpy, False); draw_bar(0, 0); } @@ -419,13 +410,12 @@ handle_after_write(IXPServer * s, File * f) check_event(0); } -static void -handle_before_read(IXPServer * s, File * f) +static void handle_before_read(IXPServer * s, File * f) { - char buf[64]; + char buf[64]; if (f == files[B_GEOMETRY]) { snprintf(buf, sizeof(buf), "%d,%d,%d,%d", brect.x, brect.y, - brect.width, brect.height); + brect.width, brect.height); if (f->content) free(f->content); f->content = strdup(buf); @@ -441,11 +431,10 @@ handle_before_read(IXPServer * s, File * f) } } -static void -run(char *geom) +static void run(char *geom) { XSetWindowAttributes wa; - XGCValues gcv; + XGCValues gcv; /* init */ if (!(files[B_CTL] = ixp_create(ixps, "/ctl"))) { @@ -456,9 +445,12 @@ run(char *geom) files[B_NEW] = ixp_create(ixps, "/new"); files[B_NEW]->before_read = handle_before_read; files[B_FONT] = wmii_create_ixpfile(ixps, "/font", BLITZ_FONT); - files[B_BG_COLOR] = wmii_create_ixpfile(ixps, "/bgcolor", BLITZ_NORM_BG_COLOR); - files[B_FG_COLOR] = wmii_create_ixpfile(ixps, "/fgcolor", BLITZ_NORM_FG_COLOR); - files[B_BORDER_COLOR] = wmii_create_ixpfile(ixps, "/bordercolor", BLITZ_NORM_BORDER_COLOR); + files[B_BG_COLOR] = + wmii_create_ixpfile(ixps, "/bgcolor", BLITZ_NORM_BG_COLOR); + files[B_FG_COLOR] = + wmii_create_ixpfile(ixps, "/fgcolor", BLITZ_NORM_FG_COLOR); + files[B_BORDER_COLOR] = + wmii_create_ixpfile(ixps, "/bordercolor", BLITZ_NORM_BORDER_COLOR); files[B_GEOMETRY] = ixp_create(ixps, "/geometry"); files[B_GEOMETRY]->before_read = handle_before_read; files[B_GEOMETRY]->after_write = handle_after_write; @@ -466,7 +458,9 @@ run(char *geom) wa.override_redirect = 1; wa.background_pixmap = ParentRelative; - wa.event_mask = ExposureMask | ButtonPressMask | SubstructureRedirectMask | SubstructureNotifyMask; + wa.event_mask = + ExposureMask | ButtonPressMask | SubstructureRedirectMask | + SubstructureNotifyMask; brect.x = brect.y = brect.width = brect.height = 0; rect.x = rect.y = 0; @@ -475,11 +469,11 @@ run(char *geom) update_geometry(geom); win = XCreateWindow(dpy, RootWindow(dpy, screen_num), brect.x, brect.y, - brect.width, brect.height, 0, DefaultDepth(dpy, - screen_num), - CopyFromParent, DefaultVisual(dpy, screen_num), - CWOverrideRedirect | CWBackPixmap | CWEventMask, - &wa); + brect.width, brect.height, 0, DefaultDepth(dpy, + screen_num), + CopyFromParent, DefaultVisual(dpy, screen_num), + CWOverrideRedirect | CWBackPixmap | CWEventMask, + &wa); XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_left_ptr)); XSync(dpy, False); @@ -489,28 +483,26 @@ run(char *geom) pmap = XCreatePixmap(dpy, win, brect.width, brect.height, - DefaultDepth(dpy, screen_num)); + DefaultDepth(dpy, screen_num)); /* main event loop */ run_server_with_fd_support(ixps, ConnectionNumber(dpy), - check_event, 0); + check_event, 0); deinit_server(ixps); XFreePixmap(dpy, pmap); XFreeGC(dpy, gc); XCloseDisplay(dpy); } -static int -dummy_error_handler(Display * dpy, XErrorEvent * err) +static int dummy_error_handler(Display * dpy, XErrorEvent * err) { return 0; } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - char geom[64]; - int i; + char geom[64]; + int i; /* command line args */ for (i = 1; (i < argc) && (argv[i][0] == '-'); i++) { diff --git a/cmd/wmibar2.c b/cmd/wmibar2.c @@ -39,12 +39,12 @@ * /1/fgcolor Fcolor <#RRGGBB, #RGB> * /1/bordercolor Fcolor <#RRGGBB, #RGB> ... */ -enum { /* 8-bit qid.path.type */ +enum { /* 8-bit qid.path.type */ Droot, Ditem, Fdisplay, Fnew, - Fdata, /* data to display */ + Fdata, /* data to display */ Fevent, Fcolor, Ffont @@ -53,11 +53,11 @@ enum { /* 8-bit qid.path.type */ #define NONE (u16)0xffff typedef struct { - char *name; - u8 type; -} QFile; + char *name; + u8 type; +} QFile; -static QFile qfilelist[] = { +static QFile qfilelist[] = { {"display", Fdisplay}, {"font", Ffont}, {"new", Fnew}, @@ -74,30 +74,30 @@ static QFile qfilelist[] = { }; typedef struct { - u32 fid; - Qid qid; -} Map; + u32 fid; + Qid qid; +} Map; typedef struct { - int id; - char text[256]; - int value; - unsigned long bg; - unsigned long fg; - unsigned long border[4]; - XFontStruct *font; - char event[5][256]; -} Item; - -static Item **items = 0; -static char *sockfile = 0; -static pid_t mypid = 0; -static IXPServer srv = {0}; -static Qid root_qid; + int id; + char text[256]; + int value; + unsigned long bg; + unsigned long fg; + unsigned long border[4]; + XFontStruct *font; + char event[5][256]; +} Item; + +static Item **items = 0; +static char *sockfile = 0; +static pid_t mypid = 0; +static IXPServer srv = { 0 }; +static Qid root_qid; static Display *dpy; -static int screen_num; -static char *align = 0; -static char *font = 0; +static int screen_num; +static char *align = 0; +static char *font = 0; /* static GC gc; static Window win; @@ -108,48 +108,42 @@ static Pixmap pmap; static Draw zero_draw = { 0 }; */ -static char *version[] = { +static char *version[] = { "wmibar - window manager improved bar - " VERSION "\n" - " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 + " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 }; -static void -usage() +static void usage() { fprintf(stderr, "%s %d", - "usage: wmibar -s <socket file> [-v]\n" - " -s socket file\n" " -v version info\n", - NONE); + "usage: wmibar -s <socket file> [-v]\n" + " -s socket file\n" " -v version info\n", + NONE); exit(1); } -static int -dummy_error_handler(Display * dpy, XErrorEvent * err) +static int dummy_error_handler(Display * dpy, XErrorEvent * err) { return 0; } -static void -exit_cleanup() +static void exit_cleanup() { if (mypid == getpid()) unlink(sockfile); } -static u64 -make_qpath(u8 type, u16 item, u16 file) +static u64 make_qpath(u8 type, u16 item, u16 file) { return ((u64) file << 24) | ((u64) item << 8) | (u64) type; } -static u8 -qpath_type(u64 path) +static u8 qpath_type(u64 path) { return path & 0xff; } -static u16 -qpath_item(u64 path) +static u16 qpath_item(u64 path) { return (path >> 8) & 0xffff; } @@ -162,20 +156,18 @@ qpath_file(u64 path) } */ -static Map * -fid_to_map(Map ** maps, u32 fid) +static Map *fid_to_map(Map ** maps, u32 fid) { - u32 i; + u32 i; for (i = 0; maps && maps[i]; i++) if (maps[i]->fid == fid) return maps[i]; return nil; } -static int -qfile_index(char *name, u16 * index) +static int qfile_index(char *name, u16 * index) { - int i; + int i; for (i = 0; qfilelist[i].name; i++) if (!strncmp(name, qfilelist[i].name, strlen(qfilelist[i].name))) { *index = i; @@ -184,11 +176,10 @@ qfile_index(char *name, u16 * index) return FALSE; } -static int -make_qid(Qid * dir, char *wname, Qid * new) +static int make_qid(Qid * dir, char *wname, Qid * new) { - u16 idx; - const char *errstr; + u16 idx; + const char *errstr; if (dir->type != IXP_QTDIR) return FALSE; new->version = 0; @@ -215,25 +206,25 @@ make_qid(Qid * dir, char *wname, Qid * new) return TRUE; } -static int -attach(IXPServer * s, IXPConn * c) +static int attach(IXPServer * s, IXPConn * c) { - Map *map = emalloc(sizeof(Map)); - fprintf(stderr, "attaching %d %s %s\n", s->fcall.afid, s->fcall.uname, s->fcall.aname); + Map *map = emalloc(sizeof(Map)); + fprintf(stderr, "attaching %d %s %s\n", s->fcall.afid, s->fcall.uname, + s->fcall.aname); map->qid = root_qid; map->fid = s->fcall.fid; - c->aux = (Map **) attach_item_begin((void **) c->aux, map, sizeof(Map *)); + c->aux = + (Map **) attach_item_begin((void **) c->aux, map, sizeof(Map *)); s->fcall.id = RATTACH; s->fcall.qid = root_qid; return TRUE; } -static int -walk(IXPServer * s, IXPConn * c) +static int walk(IXPServer * s, IXPConn * c) { - u16 nwqid = 0; - Qid qid; - Map *map; + u16 nwqid = 0; + Qid qid; + Map *map; fprintf(stderr, "%s", "walking\n"); if (!(map = fid_to_map(c->aux, s->fcall.fid))) { @@ -241,15 +232,15 @@ walk(IXPServer * s, IXPConn * c) return FALSE; } if (s->fcall.fid != s->fcall.newfid - && (fid_to_map(c->aux, s->fcall.newfid))) { + && (fid_to_map(c->aux, s->fcall.newfid))) { s->errstr = "fid alreay in use"; return FALSE; } if (s->fcall.nwname) { qid = map->qid; for (nwqid = 0; (nwqid < s->fcall.nwname) - && make_qid(&qid, s->fcall.wname[nwqid], - &s->fcall.wqid[nwqid]); nwqid++) + && make_qid(&qid, s->fcall.wname[nwqid], + &s->fcall.wqid[nwqid]); nwqid++) qid = s->fcall.wqid[nwqid]; if (!nwqid) { s->errstr = "file not found"; @@ -271,17 +262,16 @@ walk(IXPServer * s, IXPConn * c) map->fid = s->fcall.newfid; c->aux = (Map **) attach_item_begin((void **) c->aux, map, - sizeof(Map *)); + sizeof(Map *)); } s->fcall.id = RWALK; s->fcall.nwqid = nwqid; return TRUE; } -static int -_open(IXPServer * s, IXPConn * c) +static int _open(IXPServer * s, IXPConn * c) { - Map *map = fid_to_map(c->aux, s->fcall.fid); + Map *map = fid_to_map(c->aux, s->fcall.fid); fprintf(stderr, "%s", "opening\n"); if (!map) { @@ -299,12 +289,11 @@ _open(IXPServer * s, IXPConn * c) return TRUE; } -static int -_read(IXPServer * s, IXPConn * c) +static int _read(IXPServer * s, IXPConn * c) { - Map *map = fid_to_map(c->aux, s->fcall.fid); - Stat stat = {0}; - u8 *p; + Map *map = fid_to_map(c->aux, s->fcall.fid); + Stat stat = { 0 }; + u8 *p; fprintf(stderr, "%s", "reading\n"); if (!map) { @@ -362,18 +351,16 @@ _read(IXPServer * s, IXPConn * c) return TRUE; } -static int -_write(IXPServer * s, IXPConn * c) +static int _write(IXPServer * s, IXPConn * c) { return FALSE; } -static int -clunk(IXPServer * s, IXPConn * c) +static int clunk(IXPServer * s, IXPConn * c) { - Map *map = fid_to_map(c->aux, s->fcall.fid); + Map *map = fid_to_map(c->aux, s->fcall.fid); if (!map) { s->errstr = "invalid fid"; @@ -385,12 +372,11 @@ clunk(IXPServer * s, IXPConn * c) return TRUE; } -static void -freeconn(IXPServer * s, IXPConn * c) +static void freeconn(IXPServer * s, IXPConn * c) { - Map **maps = c->aux; + Map **maps = c->aux; if (maps) { - int i; + int i; for (i = 0; maps[i]; i++) free(maps[i]); free(maps); @@ -408,11 +394,10 @@ static IXPTFunc funcs[] = { {0, 0} }; -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - int i; - Item *item; + int i; + Item *item; /* command line args */ for (i = 1; (i < argc) && (argv[i][0] == '-'); i++) { diff --git a/cmd/wmifs.c b/cmd/wmifs.c @@ -15,66 +15,64 @@ typedef enum { F_CTL, F_LAST -} FsIndexes; +} FsIndexes; typedef struct Route Route; struct Route { - File dest; - int src; + File dest; + int src; }; typedef struct Bind Bind; struct Bind { - IXPClient *client; - Route route[MAX_CONN * MAX_OPEN_FILES]; - File *mount; - char *prefix; + IXPClient *client; + Route route[MAX_CONN * MAX_OPEN_FILES]; + File *mount; + char *prefix; }; -static Bind zero_bind = {0}; +static Bind zero_bind = { 0 }; static Display *dpy; static IXPServer *ixps; -static char *sockfile = 0; -static File *files[F_LAST]; -static Bind **bindings = 0; +static char *sockfile = 0; +static File *files[F_LAST]; +static Bind **bindings = 0; -static void quit(void *obj, char *arg); -static void bind(void *obj, char *arg); -static void unbind(void *obj, char *arg); -static Bind *path_to_bind(char *path); +static void quit(void *obj, char *arg); +static void bind(void *obj, char *arg); +static void unbind(void *obj, char *arg); +static Bind *path_to_bind(char *path); -static Action acttbl[] = { +static Action acttbl[] = { {"quit", quit}, {"unbind", unbind}, {"bind", bind}, {0, 0} }; -static char *version[] = { +static char *version[] = { "wmifs - window manager improved filesystem - " VERSION "\n" - " (C)opyright MMV Anselm R. Garbe\n", 0 + " (C)opyright MMV Anselm R. Garbe\n", 0 }; -static void -usage() +static void usage() { fprintf(stderr, - "usage: wmifs -s <socket file> [-v]\n" - " -s socket file\n" " -v version info\n"); + "usage: wmifs -s <socket file> [-v]\n" + " -s socket file\n" " -v version info\n"); exit(1); } -static void -quit(void *obj, char *arg) +static void quit(void *obj, char *arg) { - int i; + int i; for (i = 0; bindings && bindings[i]; i++) { if (bindings[i]->mount) { bindings[i]->mount->content = 0; ixp_remove(ixps, bindings[i]->prefix); if (ixps->errstr) fprintf(stderr, "wmifs: error on quit: remove %s: %s\n", - bindings[i]->prefix, ixps->errstr); + bindings[i]->prefix, ixps->errstr); } /* free stuff */ if (bindings[i]->prefix) @@ -86,18 +84,17 @@ quit(void *obj, char *arg) ixps->runlevel = SHUTDOWN; } -static void -_unbind(Bind * b) +static void _unbind(Bind * b) { bindings = - (Bind **) detach_item((void **) bindings, b, sizeof(Bind *)); + (Bind **) detach_item((void **) bindings, b, sizeof(Bind *)); if (b->mount) { b->mount->content = 0; ixp_remove(ixps, b->prefix); if (ixps->errstr) fprintf(stderr, "wmifs: error on _unbind: remove %s: %s\n", - b->prefix, ixps->errstr); + b->prefix, ixps->errstr); } /* free stuff */ deinit_client(b->client); @@ -105,10 +102,9 @@ _unbind(Bind * b) free(b); } -static void -unbind(void *obj, char *arg) +static void unbind(void *obj, char *arg) { - Bind *b = path_to_bind(arg); + Bind *b = path_to_bind(arg); if (!b) { fprintf(stderr, "wmifs: unbind: '%s' no such path\n", arg); @@ -117,12 +113,11 @@ unbind(void *obj, char *arg) _unbind(b); } -static void -bind(void *obj, char *arg) +static void bind(void *obj, char *arg) { - Bind *b = 0; - char cmd[1024]; - char *sfile; + Bind *b = 0; + char cmd[1024]; + char *sfile; if (!arg) return; @@ -130,17 +125,17 @@ bind(void *obj, char *arg) sfile = strchr(cmd, ' '); if (!sfile) { fprintf(stderr, - "wmifs: bind: '%s' without socket argument, ignoring\n", - arg); - return; /* shortcut with empty argument */ + "wmifs: bind: '%s' without socket argument, ignoring\n", + arg); + return; /* shortcut with empty argument */ } *sfile = '\0'; sfile++; if (*sfile == '\0') { fprintf(stderr, - "wmifs: bind: '%s' without socket argument, ignoring\n", - arg); - return; /* shortcut with empty argument */ + "wmifs: bind: '%s' without socket argument, ignoring\n", + arg); + return; /* shortcut with empty argument */ } b = emalloc(sizeof(Bind)); *b = zero_bind; @@ -149,8 +144,8 @@ bind(void *obj, char *arg) if (!b->client) { fprintf(stderr, - "wmifs: bind: cannot connect to server '%s', ignoring\n", - sfile); + "wmifs: bind: cannot connect to server '%s', ignoring\n", + sfile); free(b); return; } @@ -162,11 +157,10 @@ bind(void *obj, char *arg) (Bind **) attach_item_end((void **) bindings, b, sizeof(Bind *)); } -static void -handle_after_write(IXPServer * s, File * f) +static void handle_after_write(IXPServer * s, File * f) { - int i; - size_t len; + int i; + size_t len; for (i = 0; acttbl[i].name; i++) { len = strlen(acttbl[i].name); @@ -181,22 +175,20 @@ handle_after_write(IXPServer * s, File * f) } } -static Bind * -path_to_bind(char *path) +static Bind *path_to_bind(char *path) { - int i; + int i; for (i = 0; bindings && bindings[i]; i++) if (!strncmp - (bindings[i]->prefix, path, strlen(bindings[i]->prefix))) + (bindings[i]->prefix, path, strlen(bindings[i]->prefix))) return bindings[i]; return 0; } -static Bind * -fd_to_bind(int fd, int *client_fd) +static Bind *fd_to_bind(int fd, int *client_fd) { - File *f = fd_to_file(ixps, fd); - int i, j; + File *f = fd_to_file(ixps, fd); + int i, j; if (!f) return 0; @@ -211,14 +203,13 @@ fd_to_bind(int fd, int *client_fd) return 0; } -static File * -fixp_create(IXPServer * s, char *path) +static File *fixp_create(IXPServer * s, char *path) { - Bind *b = path_to_bind(path); - size_t len; + Bind *b = path_to_bind(path); + size_t len; if (!b) { - File *f = ixp_create(s, path); + File *f = ixp_create(s, path); return f; } /* route to b */ @@ -231,15 +222,14 @@ fixp_create(IXPServer * s, char *path) return 0; } -static File * -fixp_open(IXPServer * s, char *path) +static File *fixp_open(IXPServer * s, char *path) { - Bind *b = path_to_bind(path); - int fd; - size_t len; + Bind *b = path_to_bind(path); + int fd; + size_t len; if (!b) { - File *f = ixp_open(s, path); + File *f = ixp_open(s, path); return f; } /* route to b */ @@ -255,13 +245,13 @@ fixp_open(IXPServer * s, char *path) return &b->route[fd].dest; } -static size_t +static size_t fixp_read(IXPServer * s, int fd, size_t offset, void *out_buf, - size_t out_buf_len) + size_t out_buf_len) { - int cfd; - Bind *b = fd_to_bind(fd, &cfd); - size_t result; + int cfd; + Bind *b = fd_to_bind(fd, &cfd); + size_t result; if (!b) { result = ixp_read(s, fd, offset, out_buf, out_buf_len); @@ -279,10 +269,10 @@ fixp_read(IXPServer * s, int fd, size_t offset, void *out_buf, static void fixp_write(IXPServer * s, int fd, size_t offset, void *content, - size_t in_len) + size_t in_len) { - int cfd; - Bind *b = fd_to_bind(fd, &cfd); + int cfd; + Bind *b = fd_to_bind(fd, &cfd); if (!b) { ixp_write(s, fd, offset, content, in_len); @@ -297,11 +287,10 @@ fixp_write(IXPServer * s, int fd, size_t offset, void *content, } } -static void -fixp_close(IXPServer * s, int fd) +static void fixp_close(IXPServer * s, int fd) { - int cfd; - Bind *b = fd_to_bind(fd, &cfd); + int cfd; + Bind *b = fd_to_bind(fd, &cfd); if (!b) { ixp_close(s, fd); @@ -316,11 +305,10 @@ fixp_close(IXPServer * s, int fd) } } -static void -fixp_remove(IXPServer * s, char *path) +static void fixp_remove(IXPServer * s, char *path) { - Bind *b = path_to_bind(path); - size_t len; + Bind *b = path_to_bind(path); + size_t len; if (!b) { ixp_remove(s, path); @@ -336,10 +324,9 @@ fixp_remove(IXPServer * s, char *path) } } -static void -check_event(Connection * e) +static void check_event(Connection * e) { - XEvent ev; + XEvent ev; while (XPending(dpy)) { /* * wmifs isn't interested in any X events, so just drop them @@ -350,8 +337,7 @@ check_event(Connection * e) /* why check them? because X won't kill wmifs when X dies */ } -static void -run() +static void run() { if (!(files[F_CTL] = ixp_create(ixps, "/ctl"))) { perror("wmifs: cannot connect IXP server"); @@ -369,15 +355,14 @@ run() /* main event loop */ run_server_with_fd_support(ixps, ConnectionNumber(dpy), - check_event, 0); + check_event, 0); deinit_server(ixps); } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - int i; + int i; /* command line args */ for (i = 1; (i < argc) && (argv[i][0] == '-'); i++) { @@ -400,7 +385,7 @@ main(int argc, char *argv[]) if (!getenv("HOME")) { fprintf(stderr, "%s", - "wmifs: $HOME environment variable is not set\n"); + "wmifs: $HOME environment variable is not set\n"); usage(); } /* just for the case X crashes/gets quit */ diff --git a/cmd/wmikeys.c b/cmd/wmikeys.c @@ -29,78 +29,75 @@ typedef enum { K_BG_COLOR, K_BORDER_COLOR, K_LAST -} KeyIndexes; +} KeyIndexes; typedef struct Shortcut Shortcut; struct Shortcut { - char name[MAX_BUF]; - unsigned long mod; - KeyCode key; - Shortcut *next; - File *cmdfile; + char name[MAX_BUF]; + unsigned long mod; + KeyCode key; + Shortcut *next; + File *cmdfile; }; static IXPServer *ixps = 0; static Display *dpy; -static GC gc; -static Window win; -static Window root; +static GC gc; +static Window win; +static Window root; static XRectangle krect; static XRectangle rect; -static int screen_num; -static char *sockfile = 0; +static int screen_num; +static char *sockfile = 0; static Shortcut **shortcuts = 0; -static File *files[K_LAST]; -static int grabkb = 0; +static File *files[K_LAST]; +static int grabkb = 0; static unsigned int num_lock_mask, valid_mask; -static char buf[MAX_BUF]; +static char buf[MAX_BUF]; -static Shortcut zero_shortcut = {"", 0, 0, 0, 0}; +static Shortcut zero_shortcut = { "", 0, 0, 0, 0 }; -static void grab_shortcut(Shortcut * s); -static void ungrab_shortcut(Shortcut * s); -static void draw_shortcut_box(char *text); -static void quit(void *obj, char *arg); +static void grab_shortcut(Shortcut * s); +static void ungrab_shortcut(Shortcut * s); +static void draw_shortcut_box(char *text); +static void quit(void *obj, char *arg); -static Action acttbl[] = { +static Action acttbl[] = { {"quit", quit}, {0, 0} }; -static char *version[] = { +static char *version[] = { "wmikeys - window manager improved keys - " VERSION "\n" - " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 + " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 }; -static void -center() +static void center() { krect.x = rect.width / 2 - krect.width / 2; krect.y = rect.height / 2 - krect.height / 2; } -static void -usage() +static void usage() { fprintf(stderr, "%s", - "usage: wmikeys [-s <socket file>] [-v] [<x>,<y>,<width>,<height>]\n" - " -s socket file (default: /tmp/.ixp-$USER/wmikeys-$WMII_IDENT)\n" - " -v version info\n"); + "usage: wmikeys [-s <socket file>] [-v] [<x>,<y>,<width>,<height>]\n" + " -s socket file (default: /tmp/.ixp-$USER/wmikeys-$WMII_IDENT)\n" + " -v version info\n"); exit(1); } /* grabs shortcut on all screens */ -static void -grab_shortcut(Shortcut * s) +static void grab_shortcut(Shortcut * s) { XGrabKey(dpy, s->key, s->mod, root, - True, GrabModeAsync, GrabModeAsync); + True, GrabModeAsync, GrabModeAsync); if (num_lock_mask) { XGrabKey(dpy, s->key, s->mod | num_lock_mask, root, - True, GrabModeAsync, GrabModeAsync); + True, GrabModeAsync, GrabModeAsync); XGrabKey(dpy, s->key, s->mod | num_lock_mask | LockMask, root, - True, GrabModeAsync, GrabModeAsync); + True, GrabModeAsync, GrabModeAsync); } XSync(dpy, False); } @@ -109,25 +106,22 @@ grab_shortcut(Shortcut * s) * don't handle evil keys anymore, just define more shortcuts if you cannot * live without evil key handling */ -static void -ungrab_shortcut(Shortcut * s) +static void ungrab_shortcut(Shortcut * s) { XUngrabKey(dpy, s->key, s->mod, root); if (num_lock_mask) { XUngrabKey(dpy, s->key, s->mod | num_lock_mask, root); - XUngrabKey(dpy, s->key, s->mod | num_lock_mask | - LockMask, root); + XUngrabKey(dpy, s->key, s->mod | num_lock_mask | LockMask, root); } XSync(dpy, False); } -static void -create_shortcut(File * f) +static void create_shortcut(File * f) { - static char *chain[8]; - char *k; - size_t i, toks; - Shortcut *s = 0, *r = 0; + static char *chain[8]; + char *k; + size_t i, toks; + Shortcut *s = 0, *r = 0; _strlcpy(buf, f->name, sizeof(buf)); toks = tokenize(chain, 8, buf, ','); @@ -151,13 +145,14 @@ create_shortcut(File * f) } if (r) { s->cmdfile = f; - shortcuts = (Shortcut **) attach_item_end((void **) shortcuts, r, sizeof(Shortcut *)); + shortcuts = + (Shortcut **) attach_item_end((void **) shortcuts, r, + sizeof(Shortcut *)); grab_shortcut(r); } } -static void -destroy_shortcut(Shortcut * s, int ungrab) +static void destroy_shortcut(Shortcut * s, int ungrab) { if (s->next) destroy_shortcut(s->next, 0); @@ -166,11 +161,10 @@ destroy_shortcut(Shortcut * s, int ungrab) free(s); } -static void -next_keystroke(unsigned long *mod, KeyCode * key) +static void next_keystroke(unsigned long *mod, KeyCode * key) { - XEvent e; - KeySym sym; + XEvent e; + KeySym sym; *mod = 0; do { XMaskEvent(dpy, KeyPressMask, &e); @@ -180,12 +174,11 @@ next_keystroke(unsigned long *mod, KeyCode * key) } while (IsModifierKey(sym)); } -static void -emulate_key_press(unsigned long mod, KeyCode key) +static void emulate_key_press(unsigned long mod, KeyCode key) { - XEvent e; - Window client_win; - int revert; + XEvent e; + Window client_win; + int revert; XGetInputFocus(dpy, &client_win, &revert); @@ -202,15 +195,16 @@ emulate_key_press(unsigned long mod, KeyCode key) } static void -handle_shortcut_chain(Window w, Shortcut * processed, char *prefix, int grab) +handle_shortcut_chain(Window w, Shortcut * processed, char *prefix, + int grab) { - unsigned long mod; - KeyCode key; - Shortcut *s = processed->next; + unsigned long mod; + KeyCode key; + Shortcut *s = processed->next; if (grab) { XGrabKeyboard(dpy, w, True, GrabModeAsync, - GrabModeAsync, CurrentTime); + GrabModeAsync, CurrentTime); XMapRaised(dpy, win); } draw_shortcut_box(prefix); @@ -234,11 +228,10 @@ handle_shortcut_chain(Window w, Shortcut * processed, char *prefix, int grab) } } -static void -handle_shortcut_gkb(Window w, unsigned long mod, KeyCode key) +static void handle_shortcut_gkb(Window w, unsigned long mod, KeyCode key) { - int i; - Shortcut *s; + int i; + Shortcut *s; if (!files[K_LOOKUP]->content) return; for (i = 0; shortcuts && shortcuts[i]; i++) { @@ -252,11 +245,10 @@ handle_shortcut_gkb(Window w, unsigned long mod, KeyCode key) XBell(dpy, 0); } -static void -handle_shortcut(Window w, unsigned long mod, KeyCode key) +static void handle_shortcut(Window w, unsigned long mod, KeyCode key) { - int i; - Shortcut *s; + int i; + Shortcut *s; if (!files[K_LOOKUP]->content) return; for (i = 0; shortcuts && shortcuts[i]; i++) { @@ -273,24 +265,22 @@ handle_shortcut(Window w, unsigned long mod, KeyCode key) handle_shortcut_chain(w, s, s->name, 1); } -static void -quit(void *obj, char *arg) +static void quit(void *obj, char *arg) { ixps->runlevel = SHUTDOWN; } -static void -update() +static void update() { - int i; - File *f, *p; + int i; + File *f, *p; if (!files[K_LOOKUP]->content) return; f = ixp_walk(ixps, files[K_LOOKUP]->content); if (!f || !is_directory(f)) - return; /* cannot update */ + return; /* cannot update */ /* destroy existing shortcuts if any */ for (i = 0; shortcuts && shortcuts[i]; i++) @@ -300,7 +290,7 @@ update() if (grabkb) { XGrabKeyboard(dpy, root, True, GrabModeAsync, - GrabModeAsync, CurrentTime); + GrabModeAsync, CurrentTime); return; } /* create new shortcuts */ @@ -316,16 +306,15 @@ update() * /box/style/text-color "#RRGGBBAA" * /box/style/bg-color "#RRGGBBAA" */ -static void -draw_shortcut_box(char *text) +static void draw_shortcut_box(char *text) { - Draw d = {0}; + Draw d = { 0 }; d.font = blitz_getfont(dpy, files[K_TEXT_FONT]->content); krect.width = XTextWidth(d.font, text, strlen(text)) + krect.height; center(); XMoveResizeWindow(dpy, win, krect.x, krect.y, krect.width, - krect.height); + krect.height); /* default stuff */ d.gc = gc; @@ -341,10 +330,9 @@ draw_shortcut_box(char *text) blitz_drawlabel(dpy, &d); } -static void -check_event(Connection * c) +static void check_event(Connection * c) { - XEvent ev; + XEvent ev; while (XPending(dpy)) { XNextEvent(dpy, &ev); @@ -353,10 +341,10 @@ check_event(Connection * c) ev.xkey.state &= valid_mask; if (grabkb) handle_shortcut_gkb(root, ev.xkey.state, - (KeyCode) ev.xkey.keycode); + (KeyCode) ev.xkey.keycode); else handle_shortcut(root, ev.xkey.state, - (KeyCode) ev.xkey.keycode); + (KeyCode) ev.xkey.keycode); break; case KeymapNotify: update(); @@ -367,11 +355,10 @@ check_event(Connection * c) } } -static void -handle_after_write(IXPServer * s, File * f) +static void handle_after_write(IXPServer * s, File * f) { - int i; - size_t len; + int i; + size_t len; if (f == files[K_CTL]) { for (i = 0; acttbl[i].name; i++) { @@ -386,7 +373,7 @@ handle_after_write(IXPServer * s, File * f) } } } else if (files[K_SIZE] == f) { - char *size = files[K_SIZE]->content; + char *size = files[K_SIZE]->content; if (size && strrchr(size, ',')) blitz_strtorect(dpy, &rect, &krect, size); } else if (f == files[K_GRAB_KB]) { @@ -403,24 +390,22 @@ handle_after_write(IXPServer * s, File * f) check_event(0); } -static void -handle_before_read(IXPServer * s, File * f) +static void handle_before_read(IXPServer * s, File * f) { if (f != files[K_SIZE]) return; snprintf(buf, sizeof(buf), "%d,%d,%d,%d", krect.x, krect.y, - krect.width, krect.height); + krect.width, krect.height); if (f->content) free(f->content); f->content = strdup(buf); f->size = strlen(buf); } -static void -run(char *size) +static void run(char *size) { XSetWindowAttributes wa; - XGCValues gcv; + XGCValues gcv; /* init */ if (!(files[K_CTL] = ixp_create(ixps, "/ctl"))) { @@ -435,10 +420,17 @@ run(char *size) files[K_SIZE]->after_write = handle_after_write; files[K_GRAB_KB] = wmii_create_ixpfile(ixps, "/grab-keyb", "0"); files[K_GRAB_KB]->after_write = handle_after_write; - files[K_TEXT_FONT] = wmii_create_ixpfile(ixps, "/box/style/text-font", BLITZ_FONT); - files[K_TEXT_COLOR] = wmii_create_ixpfile(ixps, "/box/style/text-color", BLITZ_SEL_FG_COLOR); - files[K_BG_COLOR] = wmii_create_ixpfile(ixps, "/box/style/bg-color", BLITZ_SEL_BG_COLOR); - files[K_BORDER_COLOR] = wmii_create_ixpfile(ixps, "/box/style/border-color", BLITZ_SEL_BORDER_COLOR); + files[K_TEXT_FONT] = + wmii_create_ixpfile(ixps, "/box/style/text-font", BLITZ_FONT); + files[K_TEXT_COLOR] = + wmii_create_ixpfile(ixps, "/box/style/text-color", + BLITZ_SEL_FG_COLOR); + files[K_BG_COLOR] = + wmii_create_ixpfile(ixps, "/box/style/bg-color", + BLITZ_SEL_BG_COLOR); + files[K_BORDER_COLOR] = + wmii_create_ixpfile(ixps, "/box/style/border-color", + BLITZ_SEL_BORDER_COLOR); wa.override_redirect = 1; wa.background_pixmap = ParentRelative; @@ -464,11 +456,11 @@ run(char *size) init_lock_modifiers(dpy, &valid_mask, &num_lock_mask); win = XCreateWindow(dpy, RootWindow(dpy, screen_num), krect.x, krect.y, - krect.width, krect.height, 0, DefaultDepth(dpy, - screen_num), - CopyFromParent, DefaultVisual(dpy, screen_num), - CWOverrideRedirect | CWBackPixmap | CWEventMask, - &wa); + krect.width, krect.height, 0, DefaultDepth(dpy, + screen_num), + CopyFromParent, DefaultVisual(dpy, screen_num), + CWOverrideRedirect | CWBackPixmap | CWEventMask, + &wa); XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_left_ptr)); XSync(dpy, False); @@ -479,23 +471,21 @@ run(char *size) /* main event loop */ run_server_with_fd_support(ixps, ConnectionNumber(dpy), - check_event, 0); + check_event, 0); deinit_server(ixps); XFreeGC(dpy, gc); XCloseDisplay(dpy); } -static int -dummy_error_handler(Display * dpy, XErrorEvent * err) +static int dummy_error_handler(Display * dpy, XErrorEvent * err) { return 0; } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - char size[64]; - int i; + char size[64]; + int i; /* command line args */ for (i = 1; (i < argc) && (argv[i][0] == '-'); i++) { diff --git a/cmd/wmimenu.c b/cmd/wmimenu.c @@ -37,7 +37,7 @@ typedef enum { M_NORMAL_BORDER_COLOR, M_RETARDED, M_LAST -} InputIndexes; +} InputIndexes; enum { OFF_NEXT, OFF_PREV, OFF_CURR, OFF_LAST @@ -45,66 +45,63 @@ enum { static IXPServer *ixps = 0; static Display *dpy; -static GC gc; -static Window win; +static GC gc; +static Window win; static XRectangle rect; static XRectangle mrect; -static int screen_num; -static char *sockfile = 0; -static File *files[M_LAST]; -static File **items = 0; -static size_t item_size = 0; -static int item = 0; -static int offset[OFF_LAST]; +static int screen_num; +static char *sockfile = 0; +static File *files[M_LAST]; +static File **items = 0; +static size_t item_size = 0; +static int item = 0; +static int offset[OFF_LAST]; static unsigned int cmdw = 0; -static File **history = 0; -static int sel_history = 0; -static Pixmap pmap; -static const int seek = 30; /* 30px */ - -static void check_event(Connection * c); -static void draw_menu(void); -static void handle_kpress(XKeyEvent * e); -static void set_text(char *text); -static void quit(void *obj, char *arg); -static void display(void *obj, char *arg); -static int update_items(char *prefix); - -static Action acttbl[2] = { +static File **history = 0; +static int sel_history = 0; +static Pixmap pmap; +static const int seek = 30; /* 30px */ + +static void check_event(Connection * c); +static void draw_menu(void); +static void handle_kpress(XKeyEvent * e); +static void set_text(char *text); +static void quit(void *obj, char *arg); +static void display(void *obj, char *arg); +static int update_items(char *prefix); + +static Action acttbl[2] = { {"quit", quit}, {"display", display} }; -static char *version[] = { +static char *version[] = { "wmimenu - window manager improved menu - " VERSION "\n" - " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 + " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 }; -static void -usage() +static void usage() { fprintf(stderr, "%s", - "usage: wmimenu [-s <socket file>] [-r] [-v] [<x>,<y>,<width>,<height>]\n" - " -s socket file (default: /tmp/.ixp-$USER/wmimenu-%s-%s)\n" - " -v version info\n"); + "usage: wmimenu [-s <socket file>] [-r] [-v] [<x>,<y>,<width>,<height>]\n" + " -s socket file (default: /tmp/.ixp-$USER/wmimenu-%s-%s)\n" + " -v version info\n"); exit(1); } -static void -add_history(char *cmd) +static void add_history(char *cmd) { - char buf[MAX_BUF]; + char buf[MAX_BUF]; snprintf(buf, MAX_BUF, "/history/%ld", (long) time(0)); history = (File **) attach_item_begin((void **) history, - wmii_create_ixpfile(ixps, buf, - cmd), - sizeof(File *)); + wmii_create_ixpfile(ixps, buf, + cmd), + sizeof(File *)); } -static void -_exec(char *cmd) +static void _exec(char *cmd) { - char *rc = cmd; + char *rc = cmd; if (!cmd || cmd[0] == '\0') return; @@ -117,10 +114,10 @@ _exec(char *cmd) } add_history(cmd); if (files[M_PRE_COMMAND]->content) { - size_t len = strlen(cmd) + files[M_PRE_COMMAND]->size + 2; + size_t len = strlen(cmd) + files[M_PRE_COMMAND]->size + 2; rc = emalloc(len); snprintf(rc, len, "%s %s", (char *) files[M_PRE_COMMAND]->content, - cmd); + cmd); } /* fallback */ spawn(dpy, rc); @@ -129,14 +126,12 @@ _exec(char *cmd) free(rc); } -static void -quit(void *obj, char *arg) +static void quit(void *obj, char *arg) { ixps->runlevel = SHUTDOWN; } -static void -show() +static void show() { set_text(0); XMapRaised(dpy, win); @@ -144,21 +139,19 @@ show() update_items(files[M_COMMAND]->content); draw_menu(); while (XGrabKeyboard - (dpy, RootWindow(dpy, screen_num), True, GrabModeAsync, - GrabModeAsync, CurrentTime) != GrabSuccess) + (dpy, RootWindow(dpy, screen_num), True, GrabModeAsync, + GrabModeAsync, CurrentTime) != GrabSuccess) usleep(1000); } -static void -hide() +static void hide() { XUngrabKeyboard(dpy, CurrentTime); XUnmapWindow(dpy, win); XSync(dpy, False); } -static void -display(void *obj, char *arg) +static void display(void *obj, char *arg) { if (!arg) return; @@ -169,8 +162,7 @@ display(void *obj, char *arg) check_event(0); } -void -set_text(char *text) +void set_text(char *text) { if (files[M_COMMAND]->content) { free(files[M_COMMAND]->content); @@ -183,12 +175,11 @@ set_text(char *text) } } -static void -update_offsets() +static void update_offsets() { - int i; - XFontStruct *font; - unsigned int w = cmdw + 2 * seek; + int i; + XFontStruct *font; + unsigned int w = cmdw + 2 * seek; if (!items) return; @@ -197,7 +188,8 @@ update_offsets() /* calc next offset */ for (i = offset[OFF_CURR]; items[i]; i++) { - w += XTextWidth(font, items[i]->content, strlen(items[i]->content)) + mrect.height; + w += XTextWidth(font, items[i]->content, + strlen(items[i]->content)) + mrect.height; if (w > mrect.width) break; } @@ -206,7 +198,8 @@ update_offsets() w = cmdw + 2 * seek; for (i = offset[OFF_CURR] - 1; i >= 0; i--) { - w += XTextWidth(font, items[i]->content, strlen(items[i]->content)) + mrect.height; + w += XTextWidth(font, items[i]->content, + strlen(items[i]->content)) + mrect.height; if (w > mrect.width) break; } @@ -214,14 +207,12 @@ update_offsets() XFreeFont(dpy, font); } -static int -update_items(char *pattern) +static int update_items(char *pattern) { - size_t plen = pattern ? strlen(pattern) : 0, size = 0, max = 0, - len; - int matched = pattern ? plen == 0 : 1; - XFontStruct *font; - File *f, *p, *maxitem = 0; + size_t plen = pattern ? strlen(pattern) : 0, size = 0, max = 0, len; + int matched = pattern ? plen == 0 : 1; + XFontStruct *font; + File *f, *p, *maxitem = 0; cmdw = 0; item = -1; @@ -265,20 +256,20 @@ update_items(char *pattern) for (p = f->content; p; p = p->next) { if (!p->content) - continue; /* ignore bogus files */ + continue; /* ignore bogus files */ if (matched || !strncmp(pattern, p->name, plen)) { items[size++] = p; - p->parent = 0; /* HACK to prevent doubled items */ + p->parent = 0; /* HACK to prevent doubled items */ } } for (p = f->content; p; p = p->next) { if (!p->content) - continue; /* ignore bogus files */ + continue; /* ignore bogus files */ if (p->parent && strstr(p->name, pattern)) items[size++] = p; else - p->parent = f; /* restore HACK */ + p->parent = f; /* restore HACK */ } items[size] = 0; update_offsets(); @@ -287,27 +278,32 @@ update_items(char *pattern) } /* creates draw structs for menu mode drawing */ -static void -draw_menu() +static void draw_menu() { - Draw d = {0}; - unsigned int offx = 0; - int i = 0; - XFontStruct *font = blitz_getfont(dpy, files[M_TEXT_FONT]->content); + Draw d = { 0 }; + unsigned int offx = 0; + int i = 0; + XFontStruct *font = blitz_getfont(dpy, files[M_TEXT_FONT]->content); d.gc = gc; d.drawable = pmap; d.rect = mrect; d.rect.x = 0; d.rect.y = 0; - d.bg = blitz_loadcolor(dpy, screen_num, files[M_NORMAL_BG_COLOR]->content); - d.border = blitz_loadcolor(dpy, screen_num, files[M_NORMAL_BORDER_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, + files[M_NORMAL_BG_COLOR]->content); + d.border = + blitz_loadcolor(dpy, screen_num, + files[M_NORMAL_BORDER_COLOR]->content); blitz_drawlabelnoborder(dpy, &d); /* print command */ d.align = WEST; d.font = font; - d.fg = blitz_loadcolor(dpy, screen_num, files[M_NORMAL_TEXT_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, + files[M_NORMAL_TEXT_COLOR]->content); d.data = files[M_COMMAND]->content; if (cmdw && items && items[0]) d.rect.width = cmdw; @@ -316,8 +312,12 @@ draw_menu() d.align = CENTER; if (items && items[0]) { - d.bg = blitz_loadcolor(dpy, screen_num, files[M_NORMAL_BG_COLOR]->content); - d.fg = blitz_loadcolor(dpy, screen_num, files[M_NORMAL_TEXT_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, + files[M_NORMAL_BG_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, + files[M_NORMAL_TEXT_COLOR]->content); d.data = offset[OFF_CURR] ? "<" : 0; d.rect.x = offx; d.rect.width = seek; @@ -328,29 +328,54 @@ draw_menu() for (i = offset[OFF_CURR]; items[i] && (i < offset[OFF_NEXT]); i++) { d.data = items[i]->name; d.rect.x = offx; - d.rect.width = XTextWidth(d.font, d.data, strlen(d.data)) + mrect.height; + d.rect.width = + XTextWidth(d.font, d.data, strlen(d.data)) + mrect.height; offx += d.rect.width; if (i == item) { - d.bg = blitz_loadcolor(dpy, screen_num, files[M_SELECTED_BG_COLOR]->content); - d.fg = blitz_loadcolor(dpy, screen_num, files[M_SELECTED_TEXT_COLOR]->content); - d.border = blitz_loadcolor(dpy, screen_num, files[M_SELECTED_BORDER_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, + files[M_SELECTED_BG_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, + files[M_SELECTED_TEXT_COLOR]->content); + d.border = + blitz_loadcolor(dpy, screen_num, + files[M_SELECTED_BORDER_COLOR]-> + content); blitz_drawlabel(dpy, &d); } else if (!i && item == -1) { /* fg and bg are inverted */ - d.fg = blitz_loadcolor(dpy, screen_num, files[M_SELECTED_BG_COLOR]->content); - d.bg = blitz_loadcolor(dpy, screen_num, files[M_SELECTED_TEXT_COLOR]->content); - d.border = blitz_loadcolor(dpy, screen_num, files[M_SELECTED_BORDER_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, + files[M_SELECTED_BG_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, + files[M_SELECTED_TEXT_COLOR]->content); + d.border = + blitz_loadcolor(dpy, screen_num, + files[M_SELECTED_BORDER_COLOR]-> + content); blitz_drawlabel(dpy, &d); } else { - d.bg = blitz_loadcolor(dpy, screen_num, files[M_NORMAL_BG_COLOR]->content); - d.fg = blitz_loadcolor(dpy, screen_num, files[M_NORMAL_TEXT_COLOR]->content); - d.border = blitz_loadcolor(dpy, screen_num, files[M_NORMAL_BORDER_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, + files[M_NORMAL_BG_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, + files[M_NORMAL_TEXT_COLOR]->content); + d.border = + blitz_loadcolor(dpy, screen_num, + files[M_NORMAL_BORDER_COLOR]->content); blitz_drawlabelnoborder(dpy, &d); } } - d.bg = blitz_loadcolor(dpy, screen_num, files[M_NORMAL_BG_COLOR]->content); - d.fg = blitz_loadcolor(dpy, screen_num, files[M_NORMAL_TEXT_COLOR]->content); + d.bg = + blitz_loadcolor(dpy, screen_num, + files[M_NORMAL_BG_COLOR]->content); + d.fg = + blitz_loadcolor(dpy, screen_num, + files[M_NORMAL_TEXT_COLOR]->content); d.data = items[i] ? ">" : 0; d.rect.x = mrect.width - seek; d.rect.width = seek; @@ -361,14 +386,13 @@ draw_menu() XFreeFont(dpy, font); } -static void -handle_kpress(XKeyEvent * e) +static void handle_kpress(XKeyEvent * e) { - KeySym ksym; - char buf[32]; - int idx, num; - static char text[4096]; - size_t len = 0; + KeySym ksym; + char buf[32]; + int idx, num; + static char text[4096]; + size_t len = 0; text[0] = '\0'; if (files[M_COMMAND]->content) { @@ -379,8 +403,8 @@ handle_kpress(XKeyEvent * e) num = XLookupString(e, buf, sizeof(buf), &ksym, 0); if (IsFunctionKey(ksym) || IsKeypadKey(ksym) - || IsMiscFunctionKey(ksym) || IsPFKey(ksym) - || IsPrivateKeypadKey(ksym)) + || IsMiscFunctionKey(ksym) || IsPFKey(ksym) + || IsPrivateKeypadKey(ksym)) return; /* first check if a control mask is omitted */ @@ -408,7 +432,7 @@ handle_kpress(XKeyEvent * e) draw_menu(); return; break; - default: /* ignore other control sequences */ + default: /* ignore other control sequences */ return; break; } @@ -464,8 +488,8 @@ handle_kpress(XKeyEvent * e) break; case XK_BackSpace: if (len) { - int size = 0; - size_t i = len; + int size = 0; + size_t i = len; for (size = 0; items && items[size]; size++); if (i) { do @@ -499,10 +523,9 @@ handle_kpress(XKeyEvent * e) draw_menu(); } -static void -check_event(Connection * c) +static void check_event(Connection * c) { - XEvent ev; + XEvent ev; while (XPending(dpy)) { XNextEvent(dpy, &ev); @@ -521,11 +544,10 @@ check_event(Connection * c) } } -static void -handle_after_write(IXPServer * s, File * f) +static void handle_after_write(IXPServer * s, File * f) { - int i; - size_t len; + int i; + size_t len; if (files[M_CTL] == f) { for (i = 0; i < 2; i++) { @@ -540,15 +562,15 @@ handle_after_write(IXPServer * s, File * f) } } } else if (files[M_SIZE] == f) { - char *size = files[M_SIZE]->content; + char *size = files[M_SIZE]->content; if (size && strrchr(size, ',')) { blitz_strtorect(dpy, &rect, &mrect, size); XFreePixmap(dpy, pmap); XMoveResizeWindow(dpy, win, mrect.x, mrect.y, - mrect.width, mrect.height); + mrect.width, mrect.height); XSync(dpy, False); pmap = XCreatePixmap(dpy, win, mrect.width, mrect.height, - DefaultDepth(dpy, screen_num)); + DefaultDepth(dpy, screen_num)); XSync(dpy, False); draw_menu(); } @@ -559,25 +581,23 @@ handle_after_write(IXPServer * s, File * f) check_event(0); } -static void -handle_before_read(IXPServer * s, File * f) +static void handle_before_read(IXPServer * s, File * f) { - char buf[64]; + char buf[64]; if (f != files[M_SIZE]) return; snprintf(buf, sizeof(buf), "%d,%d,%d,%d", mrect.x, mrect.y, - mrect.width, mrect.height); + mrect.width, mrect.height); if (f->content) free(f->content); f->content = strdup(buf); f->size = strlen(buf); } -static void -run(char *size) +static void run(char *size) { XSetWindowAttributes wa; - XGCValues gcv; + XGCValues gcv; /* init */ if (!(files[M_CTL] = ixp_create(ixps, "/ctl"))) { @@ -594,13 +614,26 @@ run(char *size) files[M_HISTORY] = ixp_create(ixps, "/history"); add_history(""); files[M_LOOKUP] = ixp_create(ixps, "/lookup"); - files[M_TEXT_FONT] = wmii_create_ixpfile(ixps, "/style/text-font", BLITZ_FONT); - files[M_SELECTED_BG_COLOR] = wmii_create_ixpfile(ixps, "/sel-style/bg-color", BLITZ_SEL_BG_COLOR); - files[M_SELECTED_TEXT_COLOR] = wmii_create_ixpfile(ixps, "/sel-style/text-color", BLITZ_SEL_FG_COLOR); - files[M_SELECTED_BORDER_COLOR] = wmii_create_ixpfile(ixps, "/sel-style/border-color", BLITZ_SEL_BORDER_COLOR); - files[M_NORMAL_BG_COLOR] = wmii_create_ixpfile(ixps, "/norm-style/bg-color", BLITZ_NORM_BG_COLOR); - files[M_NORMAL_TEXT_COLOR] = wmii_create_ixpfile(ixps, "/norm-style/text-color", BLITZ_NORM_FG_COLOR); - files[M_NORMAL_BORDER_COLOR] = wmii_create_ixpfile(ixps, "/norm-style/border-color", BLITZ_NORM_BORDER_COLOR); + files[M_TEXT_FONT] = + wmii_create_ixpfile(ixps, "/style/text-font", BLITZ_FONT); + files[M_SELECTED_BG_COLOR] = + wmii_create_ixpfile(ixps, "/sel-style/bg-color", + BLITZ_SEL_BG_COLOR); + files[M_SELECTED_TEXT_COLOR] = + wmii_create_ixpfile(ixps, "/sel-style/text-color", + BLITZ_SEL_FG_COLOR); + files[M_SELECTED_BORDER_COLOR] = + wmii_create_ixpfile(ixps, "/sel-style/border-color", + BLITZ_SEL_BORDER_COLOR); + files[M_NORMAL_BG_COLOR] = + wmii_create_ixpfile(ixps, "/norm-style/bg-color", + BLITZ_NORM_BG_COLOR); + files[M_NORMAL_TEXT_COLOR] = + wmii_create_ixpfile(ixps, "/norm-style/text-color", + BLITZ_NORM_FG_COLOR); + files[M_NORMAL_BORDER_COLOR] = + wmii_create_ixpfile(ixps, "/norm-style/border-color", + BLITZ_NORM_BORDER_COLOR); files[M_RETARDED] = ixp_create(ixps, "/retarded"); wa.override_redirect = 1; @@ -618,11 +651,11 @@ run(char *size) mrect.height = 40; win = XCreateWindow(dpy, RootWindow(dpy, screen_num), mrect.x, mrect.y, - mrect.width, mrect.height, 0, DefaultDepth(dpy, - screen_num), - CopyFromParent, DefaultVisual(dpy, screen_num), - CWOverrideRedirect | CWBackPixmap | CWEventMask, - &wa); + mrect.width, mrect.height, 0, DefaultDepth(dpy, + screen_num), + CopyFromParent, DefaultVisual(dpy, screen_num), + CWOverrideRedirect | CWBackPixmap | CWEventMask, + &wa); XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm)); XSync(dpy, False); @@ -633,22 +666,21 @@ run(char *size) gc = XCreateGC(dpy, win, 0, 0); pmap = XCreatePixmap(dpy, win, mrect.width, mrect.height, - DefaultDepth(dpy, screen_num)); + DefaultDepth(dpy, screen_num)); /* main event loop */ run_server_with_fd_support(ixps, ConnectionNumber(dpy), - check_event, 0); + check_event, 0); deinit_server(ixps); XFreePixmap(dpy, pmap); XFreeGC(dpy, gc); XCloseDisplay(dpy); } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - char size[64]; - int i; + char size[64]; + int i; /* command line args */ for (i = 1; (i < argc) && (argv[i][0] == '-'); i++) { diff --git a/cmd/wmiplumb.c b/cmd/wmiplumb.c @@ -10,32 +10,30 @@ #include <X11/Xlib.h> #include <X11/Xatom.h> -static char *version[] = { +static char *version[] = { "wmiplumb - window manager improved plumb - " VERSION "\n" - " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 + " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 }; -static void -usage() +static void usage() { fprintf(stderr, "%s\n", - "usage: wmiplumb [-v]\n" " -v version info\n"); + "usage: wmiplumb [-v]\n" " -v version info\n"); exit(1); } -static void -print_sel(Display * dpy, Window w, XSelectionEvent * e) +static void print_sel(Display * dpy, Window w, XSelectionEvent * e) { - Atom typeret; - int format; - unsigned long nitems, bytesleft; - unsigned char *data; + Atom typeret; + int format; + unsigned long nitems, bytesleft; + unsigned char *data; XGetWindowProperty(dpy, w, e->property, 0L, 4096L, False, - AnyPropertyType, &typeret, &format, - &nitems, &bytesleft, &data); + AnyPropertyType, &typeret, &format, + &nitems, &bytesleft, &data); if (format == 8) { - int i; + int i; for (i = 0; i < nitems; i++) putchar(data[i]); putchar('\n'); @@ -43,14 +41,13 @@ print_sel(Display * dpy, Window w, XSelectionEvent * e) XDeleteProperty(dpy, w, e->property); } -int -main(int argc, char **argv) +int main(int argc, char **argv) { - Display *dpy; - Atom xa_clip_string; - Window w; - XEvent ev; - int pdone = 0; + Display *dpy; + Atom xa_clip_string; + Window w; + XEvent ev; + int pdone = 0; /* command line args */ @@ -68,10 +65,10 @@ main(int argc, char **argv) } xa_clip_string = XInternAtom(dpy, "PLUMB_STRING", False); w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200, - 1, CopyFromParent, CopyFromParent); + 1, CopyFromParent, CopyFromParent); while (1 && !pdone) { XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string, - w, CurrentTime); + w, CurrentTime); XFlush(dpy); XNextEvent(dpy, &ev); switch (ev.type) { diff --git a/cmd/wmir.c b/cmd/wmir.c @@ -10,35 +10,33 @@ #include "ixp.h" static IXPClient *c; -static int exit_code = 0; +static int exit_code = 0; -static char *version[] = { +static char *version[] = { "wmir - window manager improved remote - " VERSION "\n" - " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 + " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 }; -static void -usage() +static void usage() { fprintf(stderr, "%s", - "usage: wmir [-s <socket file>] [-v] <action> <action_arg> [...]\n" - " -s socket file (default: $WMIR_SOCKET)\n" - " -f read actions from stdin\n" - " -v version info\n" - "actions:\n" - " create <file> [<content>] -- creates and optionally writes content to a file\n" - " write <file> <content> -- writes content to a file\n" - " read <directory/file> -- reads file or directory contents\n" - " remove <directory/file> -- removes file or directory, use with care!\n"); + "usage: wmir [-s <socket file>] [-v] <action> <action_arg> [...]\n" + " -s socket file (default: $WMIR_SOCKET)\n" + " -f read actions from stdin\n" + " -v version info\n" + "actions:\n" + " create <file> [<content>] -- creates and optionally writes content to a file\n" + " write <file> <content> -- writes content to a file\n" + " read <directory/file> -- reads file or directory contents\n" + " remove <directory/file> -- removes file or directory, use with care!\n"); exit(1); } -static void -perform(char *action, char *file, char *content) +static void perform(char *action, char *file, char *content) { - size_t out_len = 0; - char output[2050]; - int crt, fd = -1; + size_t out_len = 0; + char output[2050]; + int crt, fd = -1; if (!action) return; @@ -52,7 +50,7 @@ perform(char *action, char *file, char *content) c->create(c, file); if (c->errstr) { fprintf(stderr, "wmir: error: create %s: %s\n", file, - c->errstr); + c->errstr); exit_code = 1; return; } @@ -68,7 +66,7 @@ perform(char *action, char *file, char *content) c->write(c, fd, content, strlen(content)); if (c->errstr) { fprintf(stderr, "wmir: error: write %s: %s\n", file, - c->errstr); + c->errstr); exit_code = 1; if (!strncmp(c->errstr, DEAD_SERVER, strlen(DEAD_SERVER) + 1)) return; @@ -86,10 +84,10 @@ perform(char *action, char *file, char *content) out_len = c->read(c, fd, output, 2048); if (c->errstr) { fprintf(stderr, "wmir: error: read %s: %s\n", file, - c->errstr); + c->errstr); exit_code = 1; if (!strncmp - (c->errstr, DEAD_SERVER, strlen(DEAD_SERVER) + 1)) + (c->errstr, DEAD_SERVER, strlen(DEAD_SERVER) + 1)) return; break; } @@ -104,7 +102,7 @@ perform(char *action, char *file, char *content) c->remove(c, file); if (c->errstr) { fprintf(stderr, "wmir: error: remove %s: %s\n", file, - c->errstr); + c->errstr); exit_code = 1; return; } @@ -113,19 +111,18 @@ perform(char *action, char *file, char *content) c->close(c, fd); if (c->errstr) { fprintf(stderr, "wmir: error: close %s: %s\n", file, - c->errstr); + c->errstr); exit_code = 1; return; } } } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - int i = 0, read_stdin = 0; - char line[4096], *p; - char *sockfile = getenv("WMIR_SOCKET"); + int i = 0, read_stdin = 0; + char line[4096], *p; + char *sockfile = getenv("WMIR_SOCKET"); /* command line args */ if (argc > 1) { @@ -160,7 +157,7 @@ main(int argc, char *argv[]) } if (!sockfile) { fprintf(stderr, "%s", - "wmir: error: WMIR_SOCKET environment not set\n"); + "wmir: error: WMIR_SOCKET environment not set\n"); usage(); } /* open socket */ @@ -170,29 +167,29 @@ main(int argc, char *argv[]) } if (read_stdin) { /* simple shell */ - char *action, *file, *content; + char *action, *file, *content; while (fgets(line, 4096, stdin)) { p = line; while (*p != '\0' && (*p == ' ' || *p == '\t')) p++; if (*p == '\0') - continue; /* empty line */ + continue; /* empty line */ if (strncmp(p, "create ", 7) && - strncmp(p, "write ", 6) && - strncmp(p, "read ", 5) && strncmp(p, "remove ", 7)) + strncmp(p, "write ", 6) && + strncmp(p, "read ", 5) && strncmp(p, "remove ", 7)) continue; action = p; while (*p != '\0' && *p != ' ' && *p != '\t' && *p != '\n') p++; if (*p == '\0' || *p == '\n') - continue; /* ignore bogus command */ + continue; /* ignore bogus command */ *p = '\0'; p++; while (*p != '\0' && (*p == ' ' || *p == '\t')) p++; if (*p == '\0') - continue; /* ignore bogus command */ + continue; /* ignore bogus command */ file = p; while (*p != '\0' && *p != ' ' && *p != '\t' && *p != '\n') p++; @@ -207,14 +204,14 @@ main(int argc, char *argv[]) if (file[0] == '\0') continue; if (content) { - static size_t len; + static size_t len; if ((len = strlen(content))) content[len - 1] = '\0'; } perform(action, file, content); if (c->errstr) fprintf(stderr, "wmir: error: read %s: %s\n", file, - c->errstr); + c->errstr); } } else { perform(argv[i], argv[i + 1], (i + 2) < argc ? argv[i + 2] : 0); diff --git a/cmd/wmir2.c b/cmd/wmir2.c @@ -12,49 +12,47 @@ #include <cext.h> typedef struct { - char *name; - int (*cmd) (char **argv); - int min_argc; -} Command; - -static int xcreate(char **argv); -static int xread(char **argv); -static int xwrite(char **argv); -static int xremove(char **argv); -static Command cmds[] = { + char *name; + int (*cmd) (char **argv); + int min_argc; +} Command; + +static int xcreate(char **argv); +static int xread(char **argv); +static int xwrite(char **argv); +static int xremove(char **argv); +static Command cmds[] = { {"create", xcreate, 2}, {"read", xread, 1}, {"write", xwrite, 2}, {"remove", xremove, 1}, {0, 0} }; -static IXPClient c = {0}; +static IXPClient c = { 0 }; -static char *version[] = { +static char *version[] = { "wmir - window manager improved remote - " VERSION "\n" - " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 + " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 }; -static void -usage() +static void usage() { fprintf(stderr, "%s", - "usage: wmir [-s <socket file>] [-v] <command> <args> [...]\n" - " -s socket file (default: $WMIR_SOCKET)\n" - " -f read commands from stdin\n" - " -v version info\n" - "commands:\n" - " create <file> <content> -- creates file\n" - " read <file/directory> -- reads file/directory contents\n" - " write <file> <content> -- writes content to a file\n" - " remove <file/directory> -- removes file\n"); + "usage: wmir [-s <socket file>] [-v] <command> <args> [...]\n" + " -s socket file (default: $WMIR_SOCKET)\n" + " -f read commands from stdin\n" + " -v version info\n" + "commands:\n" + " create <file> <content> -- creates file\n" + " read <file/directory> -- reads file/directory contents\n" + " write <file> <content> -- writes content to a file\n" + " remove <file/directory> -- removes file\n"); exit(1); } -static u32 -write_data(u32 fid, u8 * data, u32 count) +static u32 write_data(u32 fid, u8 * data, u32 count) { - u32 len, i, runs = count / c.fcall.iounit; + u32 len, i, runs = count / c.fcall.iounit; for (i = 0; i <= runs; i++) { /* write */ @@ -62,8 +60,8 @@ write_data(u32 fid, u8 * data, u32 count) if (len > c.fcall.iounit) len = c.fcall.iounit; if (ixp_client_write - (&c, fid, i * c.fcall.iounit, len, - &data[i * c.fcall.iounit]) != count) { + (&c, fid, i * c.fcall.iounit, len, + &data[i * c.fcall.iounit]) != count) { fprintf(stderr, "wmir: cannot write file: %s\n", c.errstr); return 0; } @@ -71,18 +69,17 @@ write_data(u32 fid, u8 * data, u32 count) return count; } -static int -xcreate(char **argv) +static int xcreate(char **argv) { - u32 fid; - char *p = strrchr(argv[0], '/'); + u32 fid; + char *p = strrchr(argv[0], '/'); fid = c.root_fid << 2; /* walk to bottom-most directory */ *p = 0; if (!ixp_client_walk(&c, fid, argv[0])) { fprintf(stderr, "wmir: cannot walk to %s: %s\n", argv[0], - c.errstr); + c.errstr); return 1; } /* create */ @@ -95,11 +92,10 @@ xcreate(char **argv) return !ixp_client_close(&c, fid); } -static int -xwrite(char **argv) +static int xwrite(char **argv) { /* open */ - u32 fid = c.root_fid << 2; + u32 fid = c.root_fid << 2; if (!ixp_client_open(&c, fid, argv[0], IXP_OWRITE)) { fprintf(stderr, "wmir: cannot open file: %s\n", c.errstr); return 1; @@ -108,12 +104,11 @@ xwrite(char **argv) return !ixp_client_close(&c, fid); } -static void -print_directory(void *result, u32 msize) +static void print_directory(void *result, u32 msize) { - void *p = result; - static Stat stat, zerostat = {0}; - u32 len = 0; + void *p = result; + static Stat stat, zerostat = { 0 }; + u32 len = 0; do { p = ixp_dec_stat(p, &stat); len += stat.size + sizeof(u16); @@ -126,12 +121,11 @@ print_directory(void *result, u32 msize) while (len < msize); } -static int -xread(char **argv) +static int xread(char **argv) { - u32 count, fid = c.root_fid << 2; - int is_directory = FALSE; - static u8 result[IXP_MAX_MSG]; + u32 count, fid = c.root_fid << 2; + int is_directory = FALSE; + static u8 result[IXP_MAX_MSG]; /* open */ if (!ixp_client_open(&c, fid, argv[0], IXP_OREAD)) { @@ -141,7 +135,7 @@ xread(char **argv) is_directory = !c.fcall.nwqid || (c.fcall.qid.type == IXP_QTDIR); /* read */ if (!(count = ixp_client_read(&c, fid, 0, result, IXP_MAX_MSG)) - && c.errstr) { + && c.errstr) { fprintf(stderr, "wmir: cannot read file: %s\n", c.errstr); return 1; } @@ -149,7 +143,7 @@ xread(char **argv) if (is_directory) print_directory(result, count); else { - u32 i; + u32 i; for (i = 0; i < count; i++) putchar(result[i]); } @@ -157,10 +151,9 @@ xread(char **argv) return !ixp_client_close(&c, fid); } -static int -xremove(char **argv) +static int xremove(char **argv) { - u32 fid; + u32 fid; /* remove */ fid = c.root_fid << 2; @@ -171,10 +164,9 @@ xremove(char **argv) return 0; } -static int -perform_cmd(int argc, char **argv) +static int perform_cmd(int argc, char **argv) { - int i; + int i; for (i = 0; cmds[i].name; i++) if (!strncmp(cmds[i].name, argv[0], strlen(cmds[i].name))) { if (cmds[i].min_argc <= argc) @@ -186,12 +178,11 @@ perform_cmd(int argc, char **argv) return 1; } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - int i = 0, ret, read_stdin = 0; - char line[4096]; - char *sockfile = getenv("WMIR_SOCKET"); + int i = 0, ret, read_stdin = 0; + char line[4096]; + char *sockfile = getenv("WMIR_SOCKET"); /* command line args */ if (argc > 1) { @@ -225,7 +216,7 @@ main(int argc, char *argv[]) } if (!sockfile) { fprintf(stderr, "%s", - "wmir: error: WMIR_SOCKET environment not set\n"); + "wmir: error: WMIR_SOCKET environment not set\n"); usage(); } /* open socket */ @@ -235,8 +226,8 @@ main(int argc, char *argv[]) } /* wether perform directly or read from stdin */ if (read_stdin) { - char *_argv[3]; - int _argc; + char *_argv[3]; + int _argc; while (fgets(line, 4096, stdin)) if ((_argc = tokenize(_argv, 3, line, ' '))) { if ((ret = perform_cmd(_argc, _argv))) diff --git a/cmd/wmiwarp.c b/cmd/wmiwarp.c @@ -10,24 +10,22 @@ #include <X11/Xutil.h> #include <X11/Xatom.h> -static char *version[] = { +static char *version[] = { "wmiwarp - window manager improved warp - " VERSION "\n" - " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 + " (C)opyright MMIV-MMV Anselm R. Garbe\n", 0 }; -static void -usage() +static void usage() { fprintf(stderr, - "usage: wmiwarp [-v] <x>,<y>\n" " -v version info\n"); + "usage: wmiwarp [-v] <x>,<y>\n" " -v version info\n"); exit(1); } -int -main(int argc, char **argv) +int main(int argc, char **argv) { - Display *dpy; - int x, y; + Display *dpy; + int x, y; /* command line args */ if (argc != 2) @@ -49,7 +47,7 @@ main(int argc, char **argv) usage(); } XWarpPointer(dpy, None, RootWindow(dpy, DefaultScreen(dpy)), - 0, 0, 0, 0, x, y); + 0, 0, 0, 0, x, y); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XCloseDisplay(dpy); return 0; diff --git a/libcext/array.c b/libcext/array.c @@ -7,11 +7,10 @@ #include "cext.h" -void ** -attach_item_begin(void **old, void *item, size_t size_item) +void **attach_item_begin(void **old, void *item, size_t size_item) { - int i, size_old; - void **result = 0; + int i, size_old; + void **result = 0; for (size_old = 0; old && old[size_old]; size_old++); result = emalloc(size_item * (size_old + 2)); result[0] = item; @@ -23,11 +22,10 @@ attach_item_begin(void **old, void *item, size_t size_item) return result; } -void ** -attach_item_end(void **old, void *item, size_t size_item) +void **attach_item_end(void **old, void *item, size_t size_item) { - int i, size_old; - void **result = 0; + int i, size_old; + void **result = 0; for (size_old = 0; old && old[size_old]; size_old++); result = emalloc(size_item * (size_old + 2)); for (i = 0; old && old[i]; i++) @@ -39,11 +37,10 @@ attach_item_end(void **old, void *item, size_t size_item) return result; } -void ** -detach_item(void **old, void *item, size_t size_item) +void **detach_item(void **old, void *item, size_t size_item) { - int size_old, i, j = 0; - void **result = 0; + int size_old, i, j = 0; + void **result = 0; for (size_old = 0; old && old[size_old]; size_old++); if (size_old != 1) { result = emalloc(size_item * size_old); @@ -57,26 +54,23 @@ detach_item(void **old, void *item, size_t size_item) return result; } -int -index_item(void **items, void *item) +int index_item(void **items, void *item) { - int i = 0; + int i = 0; for (i = 0; items && items[i] && (items[i] != item); i++); return items[i] ? i : -1; } -int -count_items(void **items) +int count_items(void **items) { - int i; + int i; for (i = 0; items && items[i]; i++); return i; } -int -index_next_item(void **items, void *item) +int index_next_item(void **items, void *item) { - int idx = index_item(items, item); + int idx = index_item(items, item); if (idx == -1) return idx; if (idx == count_items(items) - 1) @@ -85,10 +79,9 @@ index_next_item(void **items, void *item) return idx + 1; } -int -index_prev_item(void **items, void *item) +int index_prev_item(void **items, void *item) { - int idx = index_item(items, item); + int idx = index_item(items, item); if (idx == -1) return idx; if (idx == 0) diff --git a/libcext/cext.h b/libcext/cext.h @@ -16,30 +16,30 @@ #endif /* array.c */ -void **attach_item_end(void **old, void *item, size_t size_item); -void **attach_item_begin(void **old, void *item, size_t size_item); -void **detach_item(void **old, void *item, size_t size_item); -int index_item(void **items, void *item); -int index_next_item(void **items, void *item); -int index_prev_item(void **items, void *item); -int count_items(void **items); +void **attach_item_end(void **old, void *item, size_t size_item); +void **attach_item_begin(void **old, void *item, size_t size_item); +void **detach_item(void **old, void *item, size_t size_item); +int index_item(void **items, void *item); +int index_next_item(void **items, void *item); +int index_prev_item(void **items, void *item); +int count_items(void **items); /* emalloc.c */ -void *emalloc(size_t size); +void *emalloc(size_t size); /* estrdup.c */ -char *estrdup(const char *s); +char *estrdup(const char *s); /* strlcat.c */ -size_t _strlcat(char *dst, const char *src, size_t siz); +size_t _strlcat(char *dst, const char *src, size_t siz); /* strlcpy.c */ -size_t _strlcpy(char *dst, const char *src, size_t siz); +size_t _strlcpy(char *dst, const char *src, size_t siz); /* strtonum.c */ -long long +long long __strtonum(const char *numstr, long long minval, - long long maxval, const char **errstrp); + long long maxval, const char **errstrp); /* tokenize.c */ -size_t tokenize(char **result, size_t reslen, char *str, char delim); +size_t tokenize(char **result, size_t reslen, char *str, char delim); diff --git a/libcext/emalloc.c b/libcext/emalloc.c @@ -8,14 +8,13 @@ #include "cext.h" -void * -emalloc(size_t size) +void *emalloc(size_t size) { - void *res = malloc(size); + void *res = malloc(size); if (!res) { fprintf(stderr, "fatal: could not malloc() %d bytes\n", - (int) size); + (int) size); exit(1); } return res; diff --git a/libcext/estrdup.c b/libcext/estrdup.c @@ -9,10 +9,9 @@ #include "cext.h" -char * -estrdup(const char *s) +char *estrdup(const char *s) { - char *tmp; + char *tmp; tmp = (char *) emalloc(strlen(s) + 1); strcpy(tmp, (char *) s); diff --git a/libcext/strlcat.c b/libcext/strlcat.c @@ -26,13 +26,12 @@ * Returns strlen(src) + MIN(siz, strlen(initial dst)). * If retval >= siz, truncation occurred. */ -size_t -_strlcat(char *dst, const char *src, size_t siz) +size_t _strlcat(char *dst, const char *src, size_t siz) { - register char *d = dst; + register char *d = dst; register const char *s = src; register size_t n = siz; - size_t dlen; + size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end */ while (n-- != 0 && *d != '\0') diff --git a/libcext/strlcpy.c b/libcext/strlcpy.c @@ -23,10 +23,9 @@ * will be copied. Always NUL terminates (unless siz == 0). * Returns strlen(src); if retval >= siz, truncation occurred. */ -size_t -_strlcpy(char *dst, const char *src, size_t siz) +size_t _strlcpy(char *dst, const char *src, size_t siz) { - register char *d = dst; + register char *d = dst; register const char *s = src; register size_t n = siz; @@ -40,8 +39,8 @@ _strlcpy(char *dst, const char *src, size_t siz) /* Not enough room in dst, add NUL and traverse rest of src */ if (n == 0) { if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ + *d = '\0'; /* NUL-terminate dst */ while (*s++); } - return (s - src - 1); /* count does not include NUL */ + return (s - src - 1); /* count does not include NUL */ } diff --git a/libcext/strtonum.c b/libcext/strtonum.c @@ -25,25 +25,20 @@ long long __strtonum(const char *numstr, long long minval, long long maxval, - const char **errstrp) + const char **errstrp) { - long long ll = 0; - char *ep; - int error = 0; + long long ll = 0; + char *ep; + int error = 0; struct errval { - const char *errstr; - int err; - } ev[4] = { + const char *errstr; + int err; + } ev[4] = { { - NULL, 0 - }, { - "invalid", EINVAL - }, { - "too small", ERANGE - }, { - "too large", ERANGE - }, - }; + NULL, 0}, { + "invalid", EINVAL}, { + "too small", ERANGE}, { + "too large", ERANGE},}; ev[0].err = errno; errno = 0; diff --git a/libcext/tokenize.c b/libcext/tokenize.c @@ -7,11 +7,10 @@ #include "cext.h" -size_t -tokenize(char **result, size_t reslen, char *str, char delim) +size_t tokenize(char **result, size_t reslen, char *str, char delim) { - char *p, *n; - size_t i = 0; + char *p, *n; + size_t i = 0; if (!str) return 0; @@ -30,5 +29,5 @@ tokenize(char **result, size_t reslen, char *str, char delim) } if (strlen(p)) result[i++] = p; - return i; /* number of tokens */ + return i; /* number of tokens */ } diff --git a/libixp/client.c b/libixp/client.c @@ -16,13 +16,12 @@ #include <cext.h> -static IXPClient zero_client = {0}; -static size_t offsets[MAX_CONN * MAX_OPEN_FILES][2]; /* set of possible fd's */ +static IXPClient zero_client = { 0 }; +static size_t offsets[MAX_CONN * MAX_OPEN_FILES][2]; /* set of possible fd's */ -static void -check_error(IXPClient * c, void *msg) +static void check_error(IXPClient * c, void *msg) { - ResHeader h; + ResHeader h; if (c->errstr) free(c->errstr); @@ -33,8 +32,7 @@ check_error(IXPClient * c, void *msg) c->errstr = strdup((char *) msg + sizeof(ResHeader)); } -static void -handle_dead_server(IXPClient * c) +static void handle_dead_server(IXPClient * c) { if (c->errstr) free(c->errstr); @@ -46,13 +44,12 @@ handle_dead_server(IXPClient * c) c->fd = -1; } -static void * -poll_server(IXPClient * c, void *request, size_t req_len, - size_t * out_len) +static void *poll_server(IXPClient * c, void *request, size_t req_len, + size_t * out_len) { - size_t num = 0; - void *result = 0; - int r, header = 0; + size_t num = 0; + void *result = 0; + int r, header = 0; if (c->errstr) free(c->errstr); @@ -94,7 +91,7 @@ poll_server(IXPClient * c, void *request, size_t req_len, num += r; } } - free(request); /* cleanup */ + free(request); /* cleanup */ num = 0; header = 0; @@ -146,13 +143,12 @@ poll_server(IXPClient * c, void *request, size_t req_len, return result; } -static void -cixp_create(IXPClient * c, char *path) +static void cixp_create(IXPClient * c, char *path) { - ResHeader h; - size_t req_len, res_len; - void *req = tcreate_message(path, &req_len); - void *result = poll_server(c, req, req_len, &res_len); + ResHeader h; + size_t req_len, res_len; + void *req = tcreate_message(path, &req_len); + void *result = poll_server(c, req, req_len, &res_len); if (!result) return; @@ -160,13 +156,12 @@ cixp_create(IXPClient * c, char *path) free(result); } -static int -cixp_open(IXPClient * c, char *path) +static int cixp_open(IXPClient * c, char *path) { - ResHeader h; - size_t req_len, res_len; - void *req = topen_message(path, &req_len); - void *result = poll_server(c, req, req_len, &res_len); + ResHeader h; + size_t req_len, res_len; + void *req = topen_message(path, &req_len); + void *result = poll_server(c, req, req_len, &res_len); if (!result) return -1; @@ -176,10 +171,10 @@ cixp_open(IXPClient * c, char *path) return h.fd; } -static size_t +static size_t cixp_read(IXPClient * c, int fd, void *out_buf, size_t out_buf_len) { - size_t len; + size_t len; len = seek_read(c, fd, offsets[fd][0], out_buf, out_buf_len); if (c->errstr) @@ -191,12 +186,12 @@ cixp_read(IXPClient * c, int fd, void *out_buf, size_t out_buf_len) size_t seek_read(IXPClient * c, int fd, size_t offset, - void *out_buf, size_t out_buf_len) + void *out_buf, size_t out_buf_len) { - ResHeader h; - size_t req_len, res_len; - void *req = tread_message(fd, offset, out_buf_len, &req_len); - void *result = poll_server(c, req, req_len, &res_len); + ResHeader h; + size_t req_len, res_len; + void *req = tread_message(fd, offset, out_buf_len, &req_len); + void *result = poll_server(c, req, req_len, &res_len); if (!result) return -1; @@ -206,8 +201,7 @@ seek_read(IXPClient * c, int fd, size_t offset, return h.buf_len; } -static void -cixp_write(IXPClient * c, int fd, void *content, size_t in_len) +static void cixp_write(IXPClient * c, int fd, void *content, size_t in_len) { seek_write(c, fd, offsets[fd][1], content, in_len); if (!c->errstr) @@ -216,12 +210,12 @@ cixp_write(IXPClient * c, int fd, void *content, size_t in_len) void seek_write(IXPClient * c, int fd, size_t offset, void *content, - size_t in_len) + size_t in_len) { - ResHeader h; - size_t req_len, res_len; - void *req = twrite_message(fd, offset, content, in_len, &req_len); - void *result = poll_server(c, req, req_len, &res_len); + ResHeader h; + size_t req_len, res_len; + void *req = twrite_message(fd, offset, content, in_len, &req_len); + void *result = poll_server(c, req, req_len, &res_len); if (!result) return; @@ -229,13 +223,12 @@ seek_write(IXPClient * c, int fd, size_t offset, void *content, free(result); } -static void -cixp_close(IXPClient * c, int fd) +static void cixp_close(IXPClient * c, int fd) { - ResHeader h; - size_t req_len, res_len; - void *req = tclose_message(fd, &req_len); - void *result = poll_server(c, req, req_len, &res_len); + ResHeader h; + size_t req_len, res_len; + void *req = tclose_message(fd, &req_len); + void *result = poll_server(c, req, req_len, &res_len); if (!result) return; @@ -244,13 +237,12 @@ cixp_close(IXPClient * c, int fd) offsets[fd][0] = offsets[fd][1] = 0; } -static void -cixp_remove(IXPClient * c, char *path) +static void cixp_remove(IXPClient * c, char *path) { - ResHeader h; - size_t req_len, res_len; - void *req = tremove_message(path, &req_len); - void *result = poll_server(c, req, req_len, &res_len); + ResHeader h; + size_t req_len, res_len; + void *req = tremove_message(path, &req_len); + void *result = poll_server(c, req, req_len, &res_len); if (!result) return; @@ -258,14 +250,13 @@ cixp_remove(IXPClient * c, char *path) free(result); } -IXPClient * -init_client(char *sockfile) +IXPClient *init_client(char *sockfile) { - struct sockaddr_un addr = {0}; - socklen_t su_len; + struct sockaddr_un addr = { 0 }; + socklen_t su_len; /* init */ - IXPClient *c = (IXPClient *) emalloc(sizeof(IXPClient)); + IXPClient *c = (IXPClient *) emalloc(sizeof(IXPClient)); *c = zero_client; c->create = cixp_create; c->open = cixp_open; @@ -282,7 +273,7 @@ init_client(char *sockfile) free(c); return 0; } - if (connect(c->fd, (struct sockaddr *) & addr, su_len)) { + if (connect(c->fd, (struct sockaddr *) &addr, su_len)) { close(c->fd); free(c); return 0; @@ -290,8 +281,7 @@ init_client(char *sockfile) return c; } -void -deinit_client(IXPClient * c) +void deinit_client(IXPClient * c) { if (c->fd) { shutdown(c->fd, SHUT_RDWR); diff --git a/libixp/ixp.h b/libixp/ixp.h @@ -52,137 +52,135 @@ typedef struct Connection Connection; typedef struct File File; typedef struct IXPClient IXPClient; typedef struct IXPServer IXPServer; -typedef int IXPRequest; -typedef int IXPResponse; +typedef int IXPRequest; +typedef int IXPResponse; typedef enum { HALT, SHUTDOWN, RUNNING -} IXPRunlevel; +} IXPRunlevel; struct ReqHeader { - IXPRequest req; - int fd; - size_t offset; - size_t buf_len; + IXPRequest req; + int fd; + size_t offset; + size_t buf_len; }; struct ResHeader { - IXPResponse res; - int fd; - size_t buf_len; + IXPResponse res; + int fd; + size_t buf_len; }; /** Definition of a connection to IXP */ struct Connection { - IXPServer *s; /* !< server for this connection */ - int index; /* !< index inside server */ - int fd; /* !< file descriptor */ - int mode; /* 0 for reading, 1 for writing */ - int header; - void *data; - size_t len; - size_t remain; - void (*read) (Connection *); - void (*write) (Connection *); - File *files[MAX_OPEN_FILES]; - int seen[MAX_OPEN_FILES]; + IXPServer *s; /* !< server for this connection */ + int index; /* !< index inside server */ + int fd; /* !< file descriptor */ + int mode; /* 0 for reading, 1 for writing */ + int header; + void *data; + size_t len; + size_t remain; + void (*read) (Connection *); + void (*write) (Connection *); + File *files[MAX_OPEN_FILES]; + int seen[MAX_OPEN_FILES]; }; struct File { - char *name; - void *content; - size_t size; - int lock; - int bind; - File *parent; - File *next; + char *name; + void *content; + size_t size; + int lock; + int bind; + File *parent; + File *next; /* introduced IXPServer in signature for IXPServer->errstr */ - void (*after_write) (IXPServer * s, File *); - void (*before_read) (IXPServer * s, File *); + void (*after_write) (IXPServer * s, File *); + void (*before_read) (IXPServer * s, File *); }; struct IXPClient { - int fd; - fd_set rd, wr; - char *errstr; /* 0 if succes, CHECK AFTER EACH of following - * operations */ + int fd; + fd_set rd, wr; + char *errstr; /* 0 if succes, CHECK AFTER EACH of following + * operations */ /* returns fd if path exists */ - void (*create) (IXPClient *, char *path); - void (*remove) (IXPClient *, char *path); - int (*open) (IXPClient *, char *path); - void (*close) (IXPClient *, int fd); - size_t(*read) (IXPClient *, int fd, void *out_buf, - size_t out_buf_len); - void (*write) (IXPClient *, int fd, void *content, size_t in_len); + void (*create) (IXPClient *, char *path); + void (*remove) (IXPClient *, char *path); + int (*open) (IXPClient *, char *path); + void (*close) (IXPClient *, int fd); + size_t(*read) (IXPClient *, int fd, void *out_buf, + size_t out_buf_len); + void (*write) (IXPClient *, int fd, void *content, size_t in_len); }; struct IXPServer { - char *sockfile; - IXPRunlevel runlevel; - Connection conn[MAX_CONN]; - fd_set rd, wr; /* socks to wakeup while select() */ - int nfds; /* number of file descriptors */ - File *root; - char *errstr; /* 0 if succes, CHECK AFTER EACH of following - * operations */ - File *(*create) (IXPServer *, char *); - File *(*open) (IXPServer *, char *); - size_t(*read) (IXPServer *, int, size_t, void *, size_t); - void (*write) (IXPServer *, int, size_t, void *, size_t); - void (*close) (IXPServer *, int); - void (*remove) (IXPServer *, char *); + char *sockfile; + IXPRunlevel runlevel; + Connection conn[MAX_CONN]; + fd_set rd, wr; /* socks to wakeup while select() */ + int nfds; /* number of file descriptors */ + File *root; + char *errstr; /* 0 if succes, CHECK AFTER EACH of following + * operations */ + File *(*create) (IXPServer *, char *); + File *(*open) (IXPServer *, char *); + size_t(*read) (IXPServer *, int, size_t, void *, size_t); + void (*write) (IXPServer *, int, size_t, void *, size_t); + void (*close) (IXPServer *, int); + void (*remove) (IXPServer *, char *); }; /* client.c, implements client stub functions for fs access */ -IXPClient *init_client(char *sockfile); -void deinit_client(IXPClient * c); -size_t +IXPClient *init_client(char *sockfile); +void deinit_client(IXPClient * c); +size_t seek_read(IXPClient * c, int fd, size_t offset, void *out_buf, - size_t out_buf_len); -void + size_t out_buf_len); +void seek_write(IXPClient * c, int fd, size_t offset, - void *content, size_t in_len); + void *content, size_t in_len); /* message.c */ -void *tcreate_message(char *path, size_t * msg_len); -void *topen_message(char *path, size_t * msg_len); -void * -tread_message(int fd, size_t offset, size_t buf_len, - size_t * msg_len); -void * -twrite_message(int fd, size_t offset, void *msg, size_t in_len, - size_t * msg_len); -void *tclose_message(int fd, size_t * msg_len); -void *tremove_message(char *path, size_t * msg_len); -void *rcreate_message(size_t * msg_len); -void *ropen_message(int fd, size_t * msg_len); -void *rread_message(void *content, size_t content_len, size_t * msg_len); -void *rwrite_message(size_t * msg_len); -void *rclose_message(size_t * msg_len); -void *rremove_message(size_t * msg_len); -void *rerror_message(char *errstr, size_t * msg_len); +void *tcreate_message(char *path, size_t * msg_len); +void *topen_message(char *path, size_t * msg_len); +void *tread_message(int fd, size_t offset, size_t buf_len, + size_t * msg_len); +void *twrite_message(int fd, size_t offset, void *msg, size_t in_len, + size_t * msg_len); +void *tclose_message(int fd, size_t * msg_len); +void *tremove_message(char *path, size_t * msg_len); +void *rcreate_message(size_t * msg_len); +void *ropen_message(int fd, size_t * msg_len); +void *rread_message(void *content, size_t content_len, size_t * msg_len); +void *rwrite_message(size_t * msg_len); +void *rclose_message(size_t * msg_len); +void *rremove_message(size_t * msg_len); +void *rerror_message(char *errstr, size_t * msg_len); /* ramfs.c */ -int is_directory(File * f); -File *ixp_walk(IXPServer * s, char *path); -File *ixp_create(IXPServer * s, char *path); -File *ixp_open(IXPServer * s, char *path); -size_t +int is_directory(File * f); +File *ixp_walk(IXPServer * s, char *path); +File *ixp_create(IXPServer * s, char *path); +File *ixp_open(IXPServer * s, char *path); +size_t ixp_read(IXPServer * s, int fd, size_t offset, void *out_buf, - size_t out_buf_len); -void + size_t out_buf_len); +void ixp_write(IXPServer * s, int fd, size_t offset, - void *content, size_t in_len); -void ixp_close(IXPServer * s, int fd); -void ixp_remove(IXPServer * s, char *path); -void ixp_remove_file(IXPServer * s, File * f); + void *content, size_t in_len); +void ixp_close(IXPServer * s, int fd); +void ixp_remove(IXPServer * s, char *path); +void ixp_remove_file(IXPServer * s, File * f); /* server.c, uses fs directly for manipulation */ -IXPServer *init_server(char *sockfile, void (*cleanup) (void)); -void deinit_server(IXPServer * s); -File *fd_to_file(IXPServer * s, int fd); -void run_server(IXPServer * s); -void run_server_with_fd_support(IXPServer * s, int fd, void (*fd_read) (Connection *), /* callback for read on - * fd */ - void (*fd_write) (Connection *)); /* callback for write on - * fd */ -void set_error(IXPServer * s, char *errstr); +IXPServer *init_server(char *sockfile, void (*cleanup) (void)); +void deinit_server(IXPServer * s); +File *fd_to_file(IXPServer * s, int fd); +void run_server(IXPServer * s); +void run_server_with_fd_support(IXPServer * s, int fd, void (*fd_read) (Connection *), /* callback for read on + * fd */ + void (*fd_write) (Connection *)); /* callback for write on + * fd */ +void set_error(IXPServer * s, char *errstr); diff --git a/libixp/message.c b/libixp/message.c @@ -12,11 +12,10 @@ /* request messages ------------------------------------------------ */ -void * -tcreate_message(char *path, size_t * msg_len) +void *tcreate_message(char *path, size_t * msg_len) { - char *msg; - ReqHeader h; + char *msg; + ReqHeader h; *msg_len = sizeof(ReqHeader) + strlen(path) + 1; msg = emalloc(*msg_len); h.req = TCREATE; @@ -25,11 +24,10 @@ tcreate_message(char *path, size_t * msg_len) return msg; } -void * -topen_message(char *path, size_t * msg_len) +void *topen_message(char *path, size_t * msg_len) { - char *msg; - ReqHeader h; + char *msg; + ReqHeader h; *msg_len = sizeof(ReqHeader) + strlen(path) + 1; msg = emalloc(*msg_len); h.req = TOPEN; @@ -38,12 +36,11 @@ topen_message(char *path, size_t * msg_len) return msg; } -void * -tread_message(int fd, size_t offset, size_t buf_len, - size_t * msg_len) +void *tread_message(int fd, size_t offset, size_t buf_len, + size_t * msg_len) { - char *msg; - ReqHeader h; + char *msg; + ReqHeader h; *msg_len = sizeof(ReqHeader); msg = emalloc(*msg_len); h.req = TREAD; @@ -54,12 +51,11 @@ tread_message(int fd, size_t offset, size_t buf_len, return msg; } -void * -twrite_message(int fd, size_t offset, void *content, - size_t content_len, size_t * msg_len) +void *twrite_message(int fd, size_t offset, void *content, + size_t content_len, size_t * msg_len) { - char *msg; - ReqHeader h; + char *msg; + ReqHeader h; *msg_len = sizeof(ReqHeader) + content_len; msg = emalloc(*msg_len); h.req = TWRITE; @@ -71,11 +67,10 @@ twrite_message(int fd, size_t offset, void *content, return msg; } -void * -tclose_message(int fd, size_t * msg_len) +void *tclose_message(int fd, size_t * msg_len) { - char *msg; - ReqHeader h; + char *msg; + ReqHeader h; *msg_len = sizeof(ReqHeader); msg = emalloc(*msg_len); h.req = TCLUNK; @@ -84,11 +79,10 @@ tclose_message(int fd, size_t * msg_len) return msg; } -void * -tremove_message(char *path, size_t * msg_len) +void *tremove_message(char *path, size_t * msg_len) { - char *msg; - ReqHeader h; + char *msg; + ReqHeader h; *msg_len = sizeof(ReqHeader) + strlen(path) + 1; msg = emalloc(*msg_len); h.req = TREMOVE; @@ -99,11 +93,10 @@ tremove_message(char *path, size_t * msg_len) /* response messages ----------------------------------------------- */ -void * -rcreate_message(size_t * msg_len) +void *rcreate_message(size_t * msg_len) { - char *msg; - ResHeader h; + char *msg; + ResHeader h; *msg_len = sizeof(ResHeader); msg = emalloc(*msg_len); h.res = RCREATE; @@ -111,11 +104,10 @@ rcreate_message(size_t * msg_len) return msg; } -void * -ropen_message(int fd, size_t * msg_len) +void *ropen_message(int fd, size_t * msg_len) { - char *msg; - ResHeader h; + char *msg; + ResHeader h; *msg_len = sizeof(ResHeader); msg = emalloc(*msg_len); h.res = ROPEN; @@ -124,11 +116,10 @@ ropen_message(int fd, size_t * msg_len) return msg; } -void * -rread_message(void *content, size_t content_len, size_t * msg_len) +void *rread_message(void *content, size_t content_len, size_t * msg_len) { - char *msg; - ResHeader h; + char *msg; + ResHeader h; *msg_len = sizeof(ResHeader) + content_len; msg = emalloc(*msg_len); h.res = RREAD; @@ -138,11 +129,10 @@ rread_message(void *content, size_t content_len, size_t * msg_len) return msg; } -void * -rwrite_message(size_t * msg_len) +void *rwrite_message(size_t * msg_len) { - char *msg; - ResHeader h; + char *msg; + ResHeader h; *msg_len = sizeof(ResHeader); msg = emalloc(*msg_len); h.res = RWRITE; @@ -150,11 +140,10 @@ rwrite_message(size_t * msg_len) return msg; } -void * -rclose_message(size_t * msg_len) +void *rclose_message(size_t * msg_len) { - char *msg; - ResHeader h; + char *msg; + ResHeader h; *msg_len = sizeof(ResHeader); msg = emalloc(*msg_len); h.res = RCLUNK; @@ -162,11 +151,10 @@ rclose_message(size_t * msg_len) return msg; } -void * -rremove_message(size_t * msg_len) +void *rremove_message(size_t * msg_len) { - char *msg; - ResHeader h; + char *msg; + ResHeader h; *msg_len = sizeof(ResHeader); msg = emalloc(*msg_len); h.res = RREMOVE; @@ -174,12 +162,11 @@ rremove_message(size_t * msg_len) return msg; } -void * -rerror_message(char *errstr, size_t * msg_len) +void *rerror_message(char *errstr, size_t * msg_len) { - char *msg; - size_t len = strlen(errstr) + 1; - ResHeader h; + char *msg; + size_t len = strlen(errstr) + 1; + ResHeader h; *msg_len = sizeof(ResHeader) + len; msg = emalloc(*msg_len); h.res = RERROR; diff --git a/libixp/ramfs.c b/libixp/ramfs.c @@ -11,20 +11,18 @@ #include <cext.h> -static File zero_file = {0}; +static File zero_file = { 0 }; -int -is_directory(File * f) +int is_directory(File * f) { return !f->size && f->content; } -File * -ixp_create(IXPServer * s, char *path) +File *ixp_create(IXPServer * s, char *path) { - File *f, *p; - char *buf = strdup(path); - char *tok, *tok_ptr; + File *f, *p; + char *buf = strdup(path); + char *tok, *tok_ptr; if (!path) return 0; @@ -50,8 +48,8 @@ ixp_create(IXPServer * s, char *path) } if (p->size && tok) { free(buf); - return 0; /* cannot create subdirectory, if file has - * content */ + return 0; /* cannot create subdirectory, if file has + * content */ } /* only create missing parts, if file is directory */ while (tok) { @@ -75,22 +73,20 @@ ixp_create(IXPServer * s, char *path) return f; } -static int -comp_file_name(const void *f1, const void *f2) +static int comp_file_name(const void *f1, const void *f2) { - File *f = (File *) f1; - File *p = (File *) f2; + File *f = (File *) f1; + File *p = (File *) f2; return strcmp(*(char **) f->name, *(char **) p->name); } -static char * -_ls(File * f) +static char *_ls(File * f) { - File *p; - char *result = 0; - size_t size = 1; /* for \n */ - int num = 0, i; - File **tmp; + File *p; + char *result = 0; + size_t size = 1; /* for \n */ + int num = 0, i; + File **tmp; for (p = f; p; p = p->next) num++; @@ -116,10 +112,9 @@ _ls(File * f) return result; } -File * -ixp_open(IXPServer * s, char *path) +File *ixp_open(IXPServer * s, char *path) { - File *f; + File *f; f = ixp_walk(s, path); if (!f) { @@ -130,10 +125,9 @@ ixp_open(IXPServer * s, char *path) return f; } -void -ixp_close(IXPServer * s, int fd) +void ixp_close(IXPServer * s, int fd) { - File *f = fd_to_file(s, fd); + File *f = fd_to_file(s, fd); if (!f) set_error(s, "invalid file descriptor"); else if (f->lock > 0) @@ -142,11 +136,11 @@ ixp_close(IXPServer * s, int fd) size_t ixp_read(IXPServer * s, int fd, size_t offset, void *out_buf, - size_t out_buf_len) + size_t out_buf_len) { - File *f = fd_to_file(s, fd); - void *result = 0; - size_t len = 0, res_len = 0; + File *f = fd_to_file(s, fd); + void *result = 0; + size_t len = 0, res_len = 0; if (!f) { set_error(s, "invalid file descriptor"); @@ -181,9 +175,9 @@ ixp_read(IXPServer * s, int fd, size_t offset, void *out_buf, void ixp_write(IXPServer * s, int fd, size_t offset, void *content, - size_t in_len) + size_t in_len) { - File *f = fd_to_file(s, fd); + File *f = fd_to_file(s, fd); if (!f) { set_error(s, "invalid file descriptor"); @@ -215,8 +209,7 @@ ixp_write(IXPServer * s, int fd, size_t offset, void *content, f->after_write(s, f); } -static void -_ixp_remove(IXPServer * s, File * f) +static void _ixp_remove(IXPServer * s, File * f) { if (!f) return; @@ -227,7 +220,7 @@ _ixp_remove(IXPServer * s, File * f) } if (f->lock) { set_error(s, "cannot remove opened file"); - return; /* a file is opened, so stop removing tree */ + return; /* a file is opened, so stop removing tree */ } if (!f->bind && is_directory(f)) { _ixp_remove(s, f->content); @@ -245,10 +238,9 @@ _ixp_remove(IXPServer * s, File * f) } } -void -ixp_remove_file(IXPServer * s, File * f) +void ixp_remove_file(IXPServer * s, File * f) { - File *p, *n; + File *p, *n; set_error(s, 0); if (!f) { set_error(s, "file does not exist"); @@ -278,19 +270,17 @@ ixp_remove_file(IXPServer * s, File * f) } -void -ixp_remove(IXPServer * s, char *path) +void ixp_remove(IXPServer * s, char *path) { ixp_remove_file(s, ixp_walk(s, path)); } -File * -ixp_walk(IXPServer * s, char *path) +File *ixp_walk(IXPServer * s, char *path) { - File *f = 0; - File *n; - char *buf; - char *tok, *tok_ptr; + File *f = 0; + File *n; + char *buf; + char *tok, *tok_ptr; if (!path) { return 0; diff --git a/libixp/server.c b/libixp/server.c @@ -17,13 +17,12 @@ #include <cext.h> -static File zero_file = {0}; -static IXPServer zero_server = {0}; -static Connection zero_conn = {0}; -static int user_fd = -1; +static File zero_file = { 0 }; +static IXPServer zero_server = { 0 }; +static Connection zero_conn = { 0 }; +static int user_fd = -1; -void -set_error(IXPServer * s, char *errstr) +void set_error(IXPServer * s, char *errstr) { if (s->errstr) free(s->errstr); @@ -33,17 +32,15 @@ set_error(IXPServer * s, char *errstr) s->errstr = 0; } -File * -fd_to_file(IXPServer * s, int fd) +File *fd_to_file(IXPServer * s, int fd) { - int cidx = fd / MAX_CONN; - int fidx = fd - (cidx * MAX_CONN); + int cidx = fd / MAX_CONN; + int fidx = fd - (cidx * MAX_CONN); return s->conn[cidx].files[fidx]; } -static void -handle_ixp_create(Connection * c) +static void handle_ixp_create(Connection * c) { c->s->create(c->s, ((char *) c->data) + sizeof(ReqHeader)); free(c->data); @@ -52,20 +49,19 @@ handle_ixp_create(Connection * c) c->remain = c->len; } -static void -handle_ixp_open(Connection * c) +static void handle_ixp_open(Connection * c) { - int i; + int i; /* seek next free slot */ for (i = 0; (i < MAX_OPEN_FILES) && c->files[i]; i++); if (i == MAX_OPEN_FILES) { fprintf(stderr, "%s", - "ixp: server: maximum of open files, try again later.\n"); + "ixp: server: maximum of open files, try again later.\n"); free(c->data); c->data = rerror_message("maximum open files reached, close files first", - &c->len); + &c->len); c->remain = c->len; return; } @@ -74,17 +70,16 @@ handle_ixp_open(Connection * c) free(c->data); c->data = c->s->errstr ? rerror_message(c->s->errstr, - &c->len) : ropen_message(i + MAX_CONN * c->index, - &c->len); + &c->len) : ropen_message(i + MAX_CONN * c->index, + &c->len); c->remain = c->len; } -static void -handle_ixp_read(Connection * c, ReqHeader * h) +static void handle_ixp_read(Connection * c, ReqHeader * h) { - int fidx = h->fd - (c->index * MAX_CONN); - void *data = 0; - size_t out_len; + int fidx = h->fd - (c->index * MAX_CONN); + void *data = 0; + size_t out_len; data = emalloc(h->buf_len); out_len = c->s->read(c->s, h->fd, h->offset, data, h->buf_len); @@ -100,12 +95,11 @@ handle_ixp_read(Connection * c, ReqHeader * h) free(data); } -static void -handle_ixp_write(Connection * c, ReqHeader * h) +static void handle_ixp_write(Connection * c, ReqHeader * h) { - int fidx = h->fd - (c->index * MAX_CONN); + int fidx = h->fd - (c->index * MAX_CONN); c->s->write(c->s, h->fd, h->offset, - ((char *) c->data) + sizeof(ReqHeader), h->buf_len); + ((char *) c->data) + sizeof(ReqHeader), h->buf_len); free(c->data); if (c->s->errstr) { c->data = rerror_message(c->s->errstr, &c->len); @@ -117,10 +111,9 @@ handle_ixp_write(Connection * c, ReqHeader * h) c->remain = c->len; } -static void -handle_ixp_close(Connection * c, ReqHeader * h) +static void handle_ixp_close(Connection * c, ReqHeader * h) { - int fidx = h->fd - (c->index * MAX_CONN); + int fidx = h->fd - (c->index * MAX_CONN); c->s->close(c->s, h->fd); c->files[fidx] = 0; @@ -135,8 +128,7 @@ handle_ixp_close(Connection * c, ReqHeader * h) c->remain = c->len; } -static void -handle_ixp_remove(Connection * c) +static void handle_ixp_remove(Connection * c) { c->s->remove(c->s, ((char *) c->data) + sizeof(ReqHeader)); free(c->data); @@ -145,10 +137,9 @@ handle_ixp_remove(Connection * c) c->remain = c->len; } -static void -check_ixp_request(Connection * c) +static void check_ixp_request(Connection * c) { - ReqHeader h; + ReqHeader h; /* check pending request */ if (c->s->errstr) set_error(c->s, 0); @@ -180,10 +171,9 @@ check_ixp_request(Connection * c) } } -static void -update_conns(IXPServer * s) +static void update_conns(IXPServer * s) { - int i; + int i; FD_ZERO(&s->rd); FD_ZERO(&s->wr); @@ -191,7 +181,7 @@ update_conns(IXPServer * s) if (s->conn[i].fd >= 0) { s->nfds = _MAX(s->nfds, s->conn[i].fd); if (s->conn[i].read && !s->conn[i].mode - && (!s->conn[i].len || s->conn[i].remain)) { + && (!s->conn[i].len || s->conn[i].remain)) { FD_SET(s->conn[i].fd, &s->rd); } if (s->conn[i].write && s->conn[i].mode && s->conn[i].remain) { @@ -201,10 +191,9 @@ update_conns(IXPServer * s) } } -static void -close_conn(Connection * c) +static void close_conn(Connection * c) { - int i; + int i; /* shutdown connection and cleanup open files */ shutdown(c->fd, SHUT_RDWR); close(c->fd); @@ -219,10 +208,9 @@ close_conn(Connection * c) } } -static void -read_conn(Connection * c) +static void read_conn(Connection * c) { - size_t r; + size_t r; if (!c->header) { r = read(c->fd, &c->len, sizeof(size_t)); @@ -243,16 +231,15 @@ read_conn(Connection * c) if (c->remain == 0) { /* check IXP request */ - c->mode = 1; /* next mode is response */ + c->mode = 1; /* next mode is response */ check_ixp_request(c); c->header = 0; } } -static void -write_conn(Connection * c) +static void write_conn(Connection * c) { - size_t r; + size_t r; if (!c->header) { r = write(c->fd, &c->len, sizeof(size_t)); @@ -275,21 +262,20 @@ write_conn(Connection * c) } } -static void -new_conn(Connection * c) +static void new_conn(Connection * c) { - int r, i; - socklen_t l; - struct sockaddr_un name = {0}; + int r, i; + socklen_t l; + struct sockaddr_un name = { 0 }; l = sizeof(name); - if ((r = accept(c->fd, (struct sockaddr *) & name, &l)) < 0) { + if ((r = accept(c->fd, (struct sockaddr *) &name, &l)) < 0) { perror("ixp: server: cannot accept connection"); return; } if (c->s->runlevel == SHUTDOWN) { fprintf(stderr, "%s", - "ixp: server: connection refused, server is shutting down.\n"); + "ixp: server: connection refused, server is shutting down.\n"); close(r); return; } @@ -307,16 +293,15 @@ new_conn(Connection * c) if (i == MAX_CONN) { fprintf(stderr, "%s", - "ixp: server: connection refused, try again later.\n"); + "ixp: server: connection refused, try again later.\n"); close(r); } } -static int -check_open_files(Connection * c) +static int check_open_files(Connection * c) { - int i; + int i; for (i = 0; i < MAX_OPEN_FILES; i++) { if (c->files[i] && c->seen[i]) { c->seen[i]--; @@ -326,10 +311,9 @@ check_open_files(Connection * c) return 0; } -static void -handle_socks(IXPServer * s) +static void handle_socks(IXPServer * s) { - int i, now = 1; + int i, now = 1; for (i = 0; i < MAX_CONN; i++) { if (s->conn[i].fd >= 0) { if (FD_ISSET(s->conn[i].fd, &s->rd) && s->conn[i].read) { @@ -344,31 +328,30 @@ handle_socks(IXPServer * s) * still responses are sent or still opened files */ if ((s->runlevel == SHUTDOWN) - && (check_open_files(&s->conn[i]) - || (s->conn[i].remain > 0) - || s->conn[i].mode)) + && (check_open_files(&s->conn[i]) + || (s->conn[i].remain > 0) + || s->conn[i].mode)) now = 0; } } if ((s->runlevel == SHUTDOWN) && now) - s->runlevel = HALT; /* real stop */ + s->runlevel = HALT; /* real stop */ } -IXPServer * -init_server(char *sockfile, void (*cleanup) (void)) +IXPServer *init_server(char *sockfile, void (*cleanup) (void)) { - int i; - struct sockaddr_un addr = {0}; - int yes = 1; - socklen_t su_len; - IXPServer *s; + int i; + struct sockaddr_un addr = { 0 }; + int yes = 1; + socklen_t su_len; + IXPServer *s; /* init */ s = (IXPServer *) emalloc(sizeof(IXPServer)); *s = zero_server; s->sockfile = sockfile; s->root = (File *) emalloc(sizeof(File)); - s->runlevel = HALT; /* initially server is not running */ + s->runlevel = HALT; /* initially server is not running */ s->create = ixp_create; s->remove = ixp_remove; s->open = ixp_open; @@ -390,7 +373,7 @@ init_server(char *sockfile, void (*cleanup) (void)) return 0; } if (setsockopt(s->conn[0].fd, SOL_SOCKET, SO_REUSEADDR, - (char *) &yes, sizeof(yes)) < 0) { + (char *) &yes, sizeof(yes)) < 0) { perror("ixp: server: setsockopt"); close(s->conn[0].fd); free(s); @@ -400,7 +383,7 @@ init_server(char *sockfile, void (*cleanup) (void)) strncpy(addr.sun_path, sockfile, sizeof(addr.sun_path)); su_len = sizeof(struct sockaddr) + strlen(addr.sun_path); - if (bind(s->conn[0].fd, (struct sockaddr *) & addr, su_len) < 0) { + if (bind(s->conn[0].fd, (struct sockaddr *) &addr, su_len) < 0) { perror("ixp: server: cannot bind socket"); close(s->conn[0].fd); free(s); @@ -425,8 +408,8 @@ init_server(char *sockfile, void (*cleanup) (void)) void run_server_with_fd_support(IXPServer * s, int fd, - void (*fd_read) (Connection *), - void (*fd_write) (Connection *)) + void (*fd_read) (Connection *), + void (*fd_write) (Connection *)) { s->conn[1] = zero_conn; s->conn[1].index = 1; @@ -437,10 +420,9 @@ run_server_with_fd_support(IXPServer * s, int fd, run_server(s); } -void -run_server(IXPServer * s) +void run_server(IXPServer * s) { - int r, i; + int r, i; s->runlevel = RUNNING; /* main loop */ @@ -453,7 +435,7 @@ run_server(IXPServer * s) continue; if (r < 0) { perror("ixp: server: select"); - break; /* allow cleanups in IXP using app */ + break; /* allow cleanups in IXP using app */ } else if (r > 0) { handle_socks(s); } @@ -466,8 +448,7 @@ run_server(IXPServer * s) } } -void -deinit_server(IXPServer * s) +void deinit_server(IXPServer * s) { unlink(s->sockfile); ixp_remove(s, "/"); diff --git a/libixp2/client.c b/libixp2/client.c @@ -13,12 +13,11 @@ #include "cext.h" #include "ixp.h" -static u8 msg[IXP_MAX_MSG]; +static u8 msg[IXP_MAX_MSG]; -static int -do_fcall(IXPClient * c) +static int do_fcall(IXPClient * c) { - u32 msize = ixp_fcall_to_msg(&c->fcall, msg, IXP_MAX_MSG); + u32 msize = ixp_fcall_to_msg(&c->fcall, msg, IXP_MAX_MSG); c->errstr = 0; if (ixp_send_message(c->fd, msg, msize, &c->errstr) != msize) return FALSE; @@ -35,8 +34,7 @@ do_fcall(IXPClient * c) return TRUE; } -int -ixp_client_init(IXPClient * c, char *sockfile) +int ixp_client_init(IXPClient * c, char *sockfile) { if ((c->fd = ixp_connect_sock(sockfile)) < 0) { c->errstr = "cannot connect server"; @@ -54,7 +52,7 @@ ixp_client_init(IXPClient * c, char *sockfile) if (strncmp(c->fcall.version, IXP_VERSION, strlen(IXP_VERSION))) { c->errstr = "9P versions differ"; ixp_client_deinit(c); - return FALSE; /* we cannot handle this version */ + return FALSE; /* we cannot handle this version */ } c->root_fid = getpid(); @@ -73,8 +71,7 @@ ixp_client_init(IXPClient * c, char *sockfile) return TRUE; } -int -ixp_client_remove(IXPClient * c, u32 newfid, char *filepath) +int ixp_client_remove(IXPClient * c, u32 newfid, char *filepath) { if (!ixp_client_walk(c, newfid, filepath)) return FALSE; @@ -85,9 +82,8 @@ ixp_client_remove(IXPClient * c, u32 newfid, char *filepath) return do_fcall(c); } -int -ixp_client_create(IXPClient * c, u32 dirfid, char *name, u32 perm, - u8 mode) +int +ixp_client_create(IXPClient * c, u32 dirfid, char *name, u32 perm, u8 mode) { /* create */ c->fcall.id = TCREATE; @@ -99,8 +95,7 @@ ixp_client_create(IXPClient * c, u32 dirfid, char *name, u32 perm, return do_fcall(c); } -int -ixp_client_walk(IXPClient * c, u32 newfid, char *filepath) +int ixp_client_walk(IXPClient * c, u32 newfid, char *filepath) { /* walk */ c->fcall.id = TWALK; @@ -110,13 +105,12 @@ ixp_client_walk(IXPClient * c, u32 newfid, char *filepath) _strlcpy(c->fcall.name, filepath, sizeof(c->fcall.name)); c->fcall.nwname = tokenize((char **) c->fcall.wname, IXP_MAX_WELEM, - c->fcall.name, '/'); + c->fcall.name, '/'); } return do_fcall(c); } -int -ixp_client_open(IXPClient * c, u32 newfid, char *filepath, u8 mode) +int ixp_client_open(IXPClient * c, u32 newfid, char *filepath, u8 mode) { if (!ixp_client_walk(c, newfid, filepath)) return FALSE; @@ -129,13 +123,13 @@ ixp_client_open(IXPClient * c, u32 newfid, char *filepath, u8 mode) return do_fcall(c); } -u32 +u32 ixp_client_read(IXPClient * c, u32 fid, u64 offset, void *result, - u32 res_len) + u32 res_len) { - u32 bytes = - c->fcall.maxmsg - (sizeof(u8) + sizeof(u16) + 2 * sizeof(u32) + - sizeof(u64)); + u32 bytes = + c->fcall.maxmsg - (sizeof(u8) + sizeof(u16) + 2 * sizeof(u32) + + sizeof(u64)); /* read */ c->fcall.id = TREAD; c->fcall.tag = IXP_NOTAG; @@ -148,13 +142,12 @@ ixp_client_read(IXPClient * c, u32 fid, u64 offset, void *result, return c->fcall.count; } -u32 -ixp_client_write(IXPClient * c, u32 fid, u64 offset, u32 count, - u8 * data) +u32 +ixp_client_write(IXPClient * c, u32 fid, u64 offset, u32 count, u8 * data) { if (count > - c->fcall.maxmsg - (sizeof(u8) + sizeof(u16) + 2 * sizeof(u32) + - sizeof(u64))) { + c->fcall.maxmsg - (sizeof(u8) + sizeof(u16) + 2 * sizeof(u32) + + sizeof(u64))) { c->errstr = "message size exceeds buffer size"; return 0; } @@ -170,8 +163,7 @@ ixp_client_write(IXPClient * c, u32 fid, u64 offset, u32 count, return c->fcall.count; } -int -ixp_client_close(IXPClient * c, u32 fid) +int ixp_client_close(IXPClient * c, u32 fid) { /* clunk */ c->fcall.id = TCLUNK; @@ -180,8 +172,7 @@ ixp_client_close(IXPClient * c, u32 fid) return do_fcall(c); } -void -ixp_client_deinit(IXPClient * c) +void ixp_client_deinit(IXPClient * c) { /* session finished, now shutdown */ if (c->fd) { diff --git a/libixp2/convert.c b/libixp2/convert.c @@ -9,37 +9,32 @@ /* encode/decode stuff */ -void * -ixp_enc_u8(u8 * msg, u8 val) +void *ixp_enc_u8(u8 * msg, u8 val) { msg[0] = val; return &msg[1]; } -void * -ixp_dec_u8(u8 * msg, u8 * val) +void *ixp_dec_u8(u8 * msg, u8 * val) { *val = msg[0]; return &msg[1]; } -void * -ixp_enc_u16(u8 * msg, u16 val) +void *ixp_enc_u16(u8 * msg, u16 val) { msg[0] = val; msg[1] = val >> 8; return &msg[2]; } -void * -ixp_dec_u16(u8 * msg, u16 * val) +void *ixp_dec_u16(u8 * msg, u16 * val) { *val = msg[0] | (msg[1] << 8); return &msg[2]; } -void * -ixp_enc_u32(u8 * msg, u32 val) +void *ixp_enc_u32(u8 * msg, u32 val) { msg[0] = val; msg[1] = val >> 8; @@ -48,15 +43,13 @@ ixp_enc_u32(u8 * msg, u32 val) return &msg[4]; } -void * -ixp_dec_u32(u8 * msg, u32 * val) +void *ixp_dec_u32(u8 * msg, u32 * val) { *val = msg[0] | (msg[1] << 8) | (msg[2] << 16) | (msg[3] << 24); return &msg[4]; } -void * -ixp_enc_u64(u8 * msg, u64 val) +void *ixp_enc_u64(u8 * msg, u64 val) { msg[0] = val; msg[1] = val >> 8; @@ -69,28 +62,25 @@ ixp_enc_u64(u8 * msg, u64 val) return &msg[8]; } -void * -ixp_dec_u64(u8 * msg, u64 * val) +void *ixp_dec_u64(u8 * msg, u64 * val) { *val = (u64) msg[0] | ((u64) msg[1] << 8) | - ((u64) msg[2] << 16) | ((u64) msg[3] << 24) | - ((u64) msg[4] << 32) | ((u64) msg[5] << 40) | - ((u64) msg[6] << 48) | ((u64) msg[7] << 56); + ((u64) msg[2] << 16) | ((u64) msg[3] << 24) | + ((u64) msg[4] << 32) | ((u64) msg[5] << 40) | + ((u64) msg[6] << 48) | ((u64) msg[7] << 56); return &msg[8]; } -void * -ixp_enc_string(u8 * msg, const char *s) +void *ixp_enc_string(u8 * msg, const char *s) { - u16 len = s ? strlen(s) : 0; + u16 len = s ? strlen(s) : 0; msg = ixp_enc_u16(msg, len); if (s) memcpy(msg, s, len); return &msg[len]; } -void * -ixp_dec_string(u8 * msg, char *string, u16 stringlen, u16 * len) +void *ixp_dec_string(u8 * msg, char *string, u16 stringlen, u16 * len) { msg = ixp_dec_u16(msg, len); if (!(*len)) @@ -105,54 +95,47 @@ ixp_dec_string(u8 * msg, char *string, u16 stringlen, u16 * len) return &msg[*len]; } -void * -ixp_enc_data(u8 * msg, u8 * data, u32 datalen) +void *ixp_enc_data(u8 * msg, u8 * data, u32 datalen) { memcpy(msg, data, datalen); return &msg[datalen]; } -void * -ixp_dec_data(u8 * msg, u8 * data, u32 datalen) +void *ixp_dec_data(u8 * msg, u8 * data, u32 datalen) { memcpy(data, msg, datalen); return &msg[datalen]; } -void * -ixp_enc_prefix(u8 * msg, u32 size, u8 id, u16 tag) +void *ixp_enc_prefix(u8 * msg, u32 size, u8 id, u16 tag) { msg = ixp_enc_u32(msg, size); msg = ixp_enc_u8(msg, id); return ixp_enc_u16(msg, tag); } -void * -ixp_dec_prefix(u8 * msg, u32 * size, u8 * id, u16 * tag) +void *ixp_dec_prefix(u8 * msg, u32 * size, u8 * id, u16 * tag) { msg = ixp_dec_u32(msg, size); msg = ixp_dec_u8(msg, id); return ixp_dec_u16(msg, tag); } -void * -ixp_enc_qid(u8 * msg, Qid * qid) +void *ixp_enc_qid(u8 * msg, Qid * qid) { msg = ixp_enc_u8(msg, qid->type); msg = ixp_enc_u32(msg, qid->version); return ixp_enc_u64(msg, qid->path); } -void * -ixp_dec_qid(u8 * msg, Qid * qid) +void *ixp_dec_qid(u8 * msg, Qid * qid) { msg = ixp_dec_u8(msg, &qid->type); msg = ixp_dec_u32(msg, &qid->version); return ixp_dec_u64(msg, &qid->path); } -void * -ixp_enc_stat(u8 * msg, Stat * stat) +void *ixp_enc_stat(u8 * msg, Stat * stat) { msg = ixp_enc_u16(msg, stat->size); msg = ixp_enc_u16(msg, stat->type); @@ -168,10 +151,9 @@ ixp_enc_stat(u8 * msg, Stat * stat) return ixp_enc_string(msg, stat->muid); } -void * -ixp_dec_stat(u8 * msg, Stat * stat) +void *ixp_dec_stat(u8 * msg, Stat * stat) { - u16 len; + u16 len; msg = ixp_dec_u16(msg, &stat->size); msg = ixp_dec_u16(msg, &stat->type); msg = ixp_dec_u32(msg, &stat->dev); diff --git a/libixp2/ixp.h b/libixp2/ixp.h @@ -23,7 +23,7 @@ #define IXP_MAX_FLEN 128 #define IXP_MAX_ULEN 32 #define IXP_MAX_STAT 64 -#define IXP_MAX_WELEM 16 /* MAXWELEM */ +#define IXP_MAX_WELEM 16 /* MAXWELEM */ #define IXP_MAX_TFUNCS 14 /* 9P message types */ @@ -93,149 +93,147 @@ typedef unsigned long long u64; #define IXP_NOFID (u32)~0 /* No auth */ typedef struct { - u8 type; - u32 version; - u64 path; -} Qid; + u8 type; + u32 version; + u64 path; +} Qid; /* stat structure */ typedef struct { - u16 size; - u16 type; - u32 dev; - Qid qid; - u32 mode; - u32 atime; - u32 mtime; - u64 length; - char name[IXP_MAX_FLEN]; - char uid[IXP_MAX_ULEN]; - char gid[IXP_MAX_ULEN]; - char muid[IXP_MAX_ULEN]; -} Stat; + u16 size; + u16 type; + u32 dev; + Qid qid; + u32 mode; + u32 atime; + u32 mtime; + u64 length; + char name[IXP_MAX_FLEN]; + char uid[IXP_MAX_ULEN]; + char gid[IXP_MAX_ULEN]; + char muid[IXP_MAX_ULEN]; +} Stat; typedef struct { - u8 id; - u16 tag; - u32 fid; - u32 maxmsg; /* Tversion, Rversion */ - char version[IXP_MAX_VERSION]; /* Tversion, Rversion */ - u16 oldtag; /* Tflush */ - char errstr[IXP_MAX_ERROR]; /* Rerror */ - Qid qid; /* Rattach, Ropen, Rcreate */ - u32 iounit; /* Ropen, Rcreate */ - Qid aqid; /* Rauth */ - u32 afid; /* Tauth, Tattach */ - char uname[IXP_MAX_ULEN]; /* Tauth, Tattach */ - char aname[IXP_MAX_FLEN]; /* Tauth, Tattach */ - u32 perm; /* Tcreate */ - char name[IXP_MAX_FLEN]; /* Tcreate */ - u8 mode; /* Tcreate, Topen */ - u32 newfid; /* Twalk */ - u16 nwname; /* Twalk */ - char *wname[IXP_MAX_WELEM]; /* Twalk */ - u16 nwqid; /* Rwalk */ - Qid wqid[IXP_MAX_WELEM]; /* Rwalk */ - u64 offset; /* Tread, Twrite */ - u32 count; /* Tread, Twrite, Rread */ - Stat stat; /* Rstat */ - u16 nstat; /* Twstat, Rstat */ - u8 data[IXP_MAX_MSG]; /* Twrite, Rread, Twstat, - * Rstat */ -} Fcall; + u8 id; + u16 tag; + u32 fid; + u32 maxmsg; /* Tversion, Rversion */ + char version[IXP_MAX_VERSION]; /* Tversion, Rversion */ + u16 oldtag; /* Tflush */ + char errstr[IXP_MAX_ERROR]; /* Rerror */ + Qid qid; /* Rattach, Ropen, Rcreate */ + u32 iounit; /* Ropen, Rcreate */ + Qid aqid; /* Rauth */ + u32 afid; /* Tauth, Tattach */ + char uname[IXP_MAX_ULEN]; /* Tauth, Tattach */ + char aname[IXP_MAX_FLEN]; /* Tauth, Tattach */ + u32 perm; /* Tcreate */ + char name[IXP_MAX_FLEN]; /* Tcreate */ + u8 mode; /* Tcreate, Topen */ + u32 newfid; /* Twalk */ + u16 nwname; /* Twalk */ + char *wname[IXP_MAX_WELEM]; /* Twalk */ + u16 nwqid; /* Rwalk */ + Qid wqid[IXP_MAX_WELEM]; /* Rwalk */ + u64 offset; /* Tread, Twrite */ + u32 count; /* Tread, Twrite, Rread */ + Stat stat; /* Rstat */ + u16 nstat; /* Twstat, Rstat */ + u8 data[IXP_MAX_MSG]; /* Twrite, Rread, Twstat, + * Rstat */ +} Fcall; typedef struct IXPServer IXPServer; typedef struct IXPConn IXPConn; typedef struct { - u8 id; - int (*tfunc) (IXPServer *, IXPConn *); -} IXPTFunc; + u8 id; + int (*tfunc) (IXPServer *, IXPConn *); +} IXPTFunc; struct IXPConn { - int fd; - int dont_close; - void (*read) (IXPServer *, IXPConn *); - void *aux; + int fd; + int dont_close; + void (*read) (IXPServer *, IXPConn *); + void *aux; }; struct IXPServer { - int running; - IXPConn conn[IXP_MAX_CONN]; - void (*freeconn) (IXPServer *, IXPConn *); - int maxfd; - fd_set rd; - IXPTFunc *funcs; - Fcall fcall; - char *errstr; + int running; + IXPConn conn[IXP_MAX_CONN]; + void (*freeconn) (IXPServer *, IXPConn *); + int maxfd; + fd_set rd; + IXPTFunc *funcs; + Fcall fcall; + char *errstr; }; typedef struct { - int fd; - u32 root_fid; - Qid root_qid; - Fcall fcall; - char *errstr; -} IXPClient; + int fd; + u32 root_fid; + Qid root_qid; + Fcall fcall; + char *errstr; +} IXPClient; /* client.c */ -int ixp_client_init(IXPClient * c, char *sockfile); -void ixp_client_deinit(IXPClient * c); -int ixp_client_remove(IXPClient * c, u32 newfid, char *filepath); -int +int ixp_client_init(IXPClient * c, char *sockfile); +void ixp_client_deinit(IXPClient * c); +int ixp_client_remove(IXPClient * c, u32 newfid, char *filepath); +int ixp_client_create(IXPClient * c, u32 dirfid, char *name, u32 perm, - u8 mode); -int ixp_client_walk(IXPClient * c, u32 newfid, char *filepath); -int ixp_client_open(IXPClient * c, u32 newfid, char *filepath, u8 mode); -u32 + u8 mode); +int ixp_client_walk(IXPClient * c, u32 newfid, char *filepath); +int ixp_client_open(IXPClient * c, u32 newfid, char *filepath, u8 mode); +u32 ixp_client_read(IXPClient * c, u32 fid, u64 offset, void *result, - u32 res_len); -u32 -ixp_client_write(IXPClient * c, u32 fid, u64 offset, u32 count, - u8 * data); -int ixp_client_close(IXPClient * c, u32 fid); + u32 res_len); +u32 +ixp_client_write(IXPClient * c, u32 fid, u64 offset, u32 count, u8 * data); +int ixp_client_close(IXPClient * c, u32 fid); /* convert.c */ -void *ixp_enc_u8(u8 * msg, u8 val); -void *ixp_dec_u8(u8 * msg, u8 * val); -void *ixp_enc_u16(u8 * msg, u16 val); -void *ixp_dec_u16(u8 * msg, u16 * val); -void *ixp_enc_u32(u8 * msg, u32 val); -void *ixp_dec_u32(u8 * msg, u32 * val); -void *ixp_enc_u64(u8 * msg, u64 val); -void *ixp_dec_u64(u8 * msg, u64 * val); -void *ixp_enc_string(u8 * msg, const char *s); -void *ixp_dec_string(u8 * msg, char *string, u16 stringlen, u16 * len); -void *ixp_enc_data(u8 * msg, u8 * data, u32 datalen); -void *ixp_dec_data(u8 * msg, u8 * data, u32 datalen); -void *ixp_enc_prefix(u8 * msg, u32 size, u8 id, u16 tag); -void *ixp_dec_prefix(u8 * msg, u32 * size, u8 * id, u16 * tag); -void *ixp_enc_qid(u8 * msg, Qid * qid); -void *ixp_dec_qid(u8 * msg, Qid * qid); -void *ixp_enc_stat(u8 * msg, Stat * stat); -void *ixp_dec_stat(u8 * msg, Stat * stat); +void *ixp_enc_u8(u8 * msg, u8 val); +void *ixp_dec_u8(u8 * msg, u8 * val); +void *ixp_enc_u16(u8 * msg, u16 val); +void *ixp_dec_u16(u8 * msg, u16 * val); +void *ixp_enc_u32(u8 * msg, u32 val); +void *ixp_dec_u32(u8 * msg, u32 * val); +void *ixp_enc_u64(u8 * msg, u64 val); +void *ixp_dec_u64(u8 * msg, u64 * val); +void *ixp_enc_string(u8 * msg, const char *s); +void *ixp_dec_string(u8 * msg, char *string, u16 stringlen, u16 * len); +void *ixp_enc_data(u8 * msg, u8 * data, u32 datalen); +void *ixp_dec_data(u8 * msg, u8 * data, u32 datalen); +void *ixp_enc_prefix(u8 * msg, u32 size, u8 id, u16 tag); +void *ixp_dec_prefix(u8 * msg, u32 * size, u8 * id, u16 * tag); +void *ixp_enc_qid(u8 * msg, Qid * qid); +void *ixp_dec_qid(u8 * msg, Qid * qid); +void *ixp_enc_stat(u8 * msg, Stat * stat); +void *ixp_dec_stat(u8 * msg, Stat * stat); /* message.c */ -u16 ixp_sizeof_stat(Stat * stat); -u32 ixp_fcall_to_msg(Fcall * fcall, void *msg, u32 msglen); -u32 ixp_msg_to_fcall(void *msg, u32 msglen, Fcall * fcall); +u16 ixp_sizeof_stat(Stat * stat); +u32 ixp_fcall_to_msg(Fcall * fcall, void *msg, u32 msglen); +u32 ixp_msg_to_fcall(void *msg, u32 msglen, Fcall * fcall); /* server.c */ -IXPConn * -ixp_server_add_conn(IXPServer * s, int fd, int dont_close, - void (*read) (IXPServer *, IXPConn *)); - int ixp_server_tversion(IXPServer *, IXPConn * c); - void ixp_server_rm_conn(IXPServer * s, IXPConn * c); - void ixp_server_loop(IXPServer * s); - int ixp_server_init(IXPServer * s, char *sockfile, IXPTFunc * funcs, - void (*freeconn) (IXPServer *, IXPConn *)); - void ixp_server_deinit(IXPServer * s); +IXPConn *ixp_server_add_conn(IXPServer * s, int fd, int dont_close, + void (*read) (IXPServer *, IXPConn *)); +int ixp_server_tversion(IXPServer *, IXPConn * c); +void ixp_server_rm_conn(IXPServer * s, IXPConn * c); +void ixp_server_loop(IXPServer * s); +int ixp_server_init(IXPServer * s, char *sockfile, IXPTFunc * funcs, + void (*freeconn) (IXPServer *, IXPConn *)); +void ixp_server_deinit(IXPServer * s); /* socket.c */ - int ixp_connect_sock(char *sockfile); - int ixp_accept_sock(int fd); - int ixp_create_sock(char *sockfile, char **errstr); +int ixp_connect_sock(char *sockfile); +int ixp_accept_sock(int fd); +int ixp_create_sock(char *sockfile, char **errstr); /* transport.c */ - u32 ixp_send_message(int fd, void *msg, u32 msize, char **errstr); - u32 ixp_recv_message(int fd, void *msg, u32 msglen, char **errstr); +u32 ixp_send_message(int fd, void *msg, u32 msize, char **errstr); +u32 ixp_recv_message(int fd, void *msg, u32 msglen, char **errstr); diff --git a/libixp2/message.c b/libixp2/message.c @@ -7,30 +7,27 @@ #include <string.h> #include "ixp.h" -static u16 -sizeof_string(const char *s) +static u16 sizeof_string(const char *s) { return sizeof(u16) + strlen(s); } -u16 -ixp_sizeof_stat(Stat * stat) +u16 ixp_sizeof_stat(Stat * stat) { return sizeof(Qid) - + 2 * sizeof(u16) - + 4 * sizeof(u32) - + sizeof(u64) - + sizeof_string(stat->name) - + sizeof_string(stat->uid) - + sizeof_string(stat->gid) - + sizeof_string(stat->muid); + + 2 * sizeof(u16) + + 4 * sizeof(u32) + + sizeof(u64) + + sizeof_string(stat->name) + + sizeof_string(stat->uid) + + sizeof_string(stat->gid) + + sizeof_string(stat->muid); } -u32 -ixp_fcall_to_msg(Fcall * fcall, void *msg, u32 msglen) +u32 ixp_fcall_to_msg(Fcall * fcall, void *msg, u32 msglen) { - u32 i, msize = sizeof(u8) + sizeof(u16) + sizeof(u32); - void *p = msg; + u32 i, msize = sizeof(u8) + sizeof(u16) + sizeof(u32); + void *p = msg; switch (fcall->id) { case TVERSION: @@ -192,14 +189,13 @@ ixp_fcall_to_msg(Fcall * fcall, void *msg, u32 msglen) return msize; } -u32 -ixp_msg_to_fcall(void *msg, u32 msglen, Fcall * fcall) +u32 ixp_msg_to_fcall(void *msg, u32 msglen, Fcall * fcall) { - u32 i, msize; - u16 len; - void *p = ixp_dec_prefix(msg, &msize, &fcall->id, &fcall->tag); + u32 i, msize; + u16 len; + void *p = ixp_dec_prefix(msg, &msize, &fcall->id, &fcall->tag); - if (msize > msglen) /* bad message */ + if (msize > msglen) /* bad message */ return 0; switch (fcall->id) { @@ -207,7 +203,7 @@ ixp_msg_to_fcall(void *msg, u32 msglen, Fcall * fcall) case RVERSION: p = ixp_dec_u32(p, &fcall->maxmsg); p = ixp_dec_string(p, fcall->version, sizeof(fcall->version), - &len); + &len); break; case TAUTH: p = ixp_dec_u32(p, &fcall->afid); diff --git a/libixp2/server.c b/libixp2/server.c @@ -17,23 +17,21 @@ #include "ixp.h" #include "cext.h" -static IXPConn zero_conn = {-1, 0, 0, 0}; -static u8 msg[IXP_MAX_MSG]; +static IXPConn zero_conn = { -1, 0, 0, 0 }; +static u8 msg[IXP_MAX_MSG]; -static IXPConn * -next_free_conn(IXPServer * s) +static IXPConn *next_free_conn(IXPServer * s) { - int i; + int i; for (i = 0; i < IXP_MAX_CONN; i++) if (s->conn[i].fd < 0) return &s->conn[i]; return nil; } -static void -prepare_select(IXPServer * s) +static void prepare_select(IXPServer * s) { - int i; + int i; FD_ZERO(&s->rd); for (i = 0; i < IXP_MAX_CONN; i++) { if (s->conn[i].fd >= 0) { @@ -45,8 +43,7 @@ prepare_select(IXPServer * s) } } -void -ixp_server_rm_conn(IXPServer * s, IXPConn * c) +void ixp_server_rm_conn(IXPServer * s, IXPConn * c) { if (!c->dont_close) { shutdown(c->fd, SHUT_RDWR); @@ -57,9 +54,8 @@ ixp_server_rm_conn(IXPServer * s, IXPConn * c) *c = zero_conn; } -static IXPConn * -init_conn(IXPConn * c, int fd, int dont_close, - void (*read) (IXPServer *, IXPConn *)) +static IXPConn *init_conn(IXPConn * c, int fd, int dont_close, + void (*read) (IXPServer *, IXPConn *)) { *c = zero_conn; c->fd = fd; @@ -68,20 +64,18 @@ init_conn(IXPConn * c, int fd, int dont_close, return c; } -IXPConn * -ixp_server_add_conn(IXPServer * s, int fd, int dont_close, - void (*read) (IXPServer *, IXPConn *)) +IXPConn *ixp_server_add_conn(IXPServer * s, int fd, int dont_close, + void (*read) (IXPServer *, IXPConn *)) { - IXPConn *c = next_free_conn(s); + IXPConn *c = next_free_conn(s); if (!c) return nil; return init_conn(c, fd, dont_close, read); } -static void -handle_conns(IXPServer * s) +static void handle_conns(IXPServer * s) { - int i; + int i; for (i = 0; i < IXP_MAX_CONN; i++) { if (s->conn[i].fd >= 0) { if (FD_ISSET(s->conn[i].fd, &s->rd) && s->conn[i].read) @@ -91,10 +85,9 @@ handle_conns(IXPServer * s) } } -static void -server_client_read(IXPServer * s, IXPConn * c) +static void server_client_read(IXPServer * s, IXPConn * c) { - u32 i, msize; + u32 i, msize; s->errstr = 0; if (!(msize = ixp_recv_message(c->fd, msg, IXP_MAX_MSG, &s->errstr))) { ixp_server_rm_conn(s, c); @@ -108,7 +101,8 @@ server_client_read(IXPServer * s, IXPConn * c) break; msize = ixp_fcall_to_msg(&s->fcall, msg, s->fcall.maxmsg); fprintf(stderr, "msize=%d\n", msize); - if (ixp_send_message(c->fd, msg, msize, &s->errstr) != msize) + if (ixp_send_message(c->fd, msg, msize, &s->errstr) != + msize) break; return; } @@ -123,19 +117,17 @@ server_client_read(IXPServer * s, IXPConn * c) ixp_server_rm_conn(s, c); } -static void -server_read(IXPServer * s, IXPConn * c) +static void server_read(IXPServer * s, IXPConn * c) { - int fd; - IXPConn *new = next_free_conn(s); + int fd; + IXPConn *new = next_free_conn(s); if (new && ((fd = ixp_accept_sock(c->fd)) >= 0)) init_conn(new, fd, 0, server_client_read); } -void -ixp_server_loop(IXPServer * s) +void ixp_server_loop(IXPServer * s) { - int r; + int r; s->running = TRUE; s->errstr = 0; @@ -149,32 +141,30 @@ ixp_server_loop(IXPServer * s) continue; if (r < 0) { s->errstr = "fatal select error"; - break; /* allow cleanups in IXP using app */ + break; /* allow cleanups in IXP using app */ } else if (r > 0) handle_conns(s); } } -int -ixp_server_tversion(IXPServer * s, IXPConn * c) +int ixp_server_tversion(IXPServer * s, IXPConn * c) { - fprintf(stderr, "got version %s (%s) %d (%d)\n", s->fcall.version, IXP_VERSION, - s->fcall.maxmsg, IXP_MAX_MSG); + fprintf(stderr, "got version %s (%s) %d (%d)\n", s->fcall.version, + IXP_VERSION, s->fcall.maxmsg, IXP_MAX_MSG); if (strncmp(s->fcall.version, IXP_VERSION, strlen(IXP_VERSION))) { s->errstr = "9P versions differ"; return FALSE; - } - else if (s->fcall.maxmsg > IXP_MAX_MSG) + } else if (s->fcall.maxmsg > IXP_MAX_MSG) s->fcall.maxmsg = IXP_MAX_MSG; s->fcall.id = RVERSION; return TRUE; } -int +int ixp_server_init(IXPServer * s, char *sockfile, IXPTFunc * funcs, - void (*freeconn) (IXPServer *, IXPConn *)) + void (*freeconn) (IXPServer *, IXPConn *)) { - int fd, i; + int fd, i; s->funcs = funcs; s->freeconn = freeconn; s->errstr = 0; @@ -190,10 +180,9 @@ ixp_server_init(IXPServer * s, char *sockfile, IXPTFunc * funcs, return TRUE; } -void -ixp_server_deinit(IXPServer * s) +void ixp_server_deinit(IXPServer * s) { - int i; + int i; /* shut down server */ for (i = 0; i < IXP_MAX_CONN; i++) if (s->conn[i].fd >= 0) diff --git a/libixp2/socket.c b/libixp2/socket.c @@ -16,12 +16,11 @@ #include "cext.h" #include "ixp.h" -int -ixp_connect_sock(char *sockfile) +int ixp_connect_sock(char *sockfile) { - int fd = 0; - struct sockaddr_un addr = {0}; - socklen_t su_len; + int fd = 0; + struct sockaddr_un addr = { 0 }; + socklen_t su_len; /* init */ addr.sun_family = AF_UNIX; @@ -30,30 +29,28 @@ ixp_connect_sock(char *sockfile) if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) return -1; - if (connect(fd, (struct sockaddr *) & addr, su_len)) { + if (connect(fd, (struct sockaddr *) &addr, su_len)) { close(fd); return -1; } return fd; } -int -ixp_accept_sock(int fd) +int ixp_accept_sock(int fd) { - socklen_t su_len; - struct sockaddr_un addr = {0}; + socklen_t su_len; + struct sockaddr_un addr = { 0 }; su_len = sizeof(struct sockaddr); - return accept(fd, (struct sockaddr *) & addr, &su_len); + return accept(fd, (struct sockaddr *) &addr, &su_len); } -int -ixp_create_sock(char *sockfile, char **errstr) +int ixp_create_sock(char *sockfile, char **errstr) { - int fd; - int yes = 1; - struct sockaddr_un addr = {0}; - socklen_t su_len; + int fd; + int yes = 1; + struct sockaddr_un addr = { 0 }; + socklen_t su_len; signal(SIGPIPE, SIG_IGN); if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { @@ -61,7 +58,7 @@ ixp_create_sock(char *sockfile, char **errstr) return -1; } if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, - (char *) &yes, sizeof(yes)) < 0) { + (char *) &yes, sizeof(yes)) < 0) { *errstr = "cannot set socket options"; close(fd); return -1; @@ -70,7 +67,7 @@ ixp_create_sock(char *sockfile, char **errstr) strncpy(addr.sun_path, sockfile, sizeof(addr.sun_path)); su_len = sizeof(struct sockaddr) + strlen(addr.sun_path); - if (bind(fd, (struct sockaddr *) & addr, su_len) < 0) { + if (bind(fd, (struct sockaddr *) &addr, su_len) < 0) { *errstr = "cannot bind socket"; close(fd); return -1; diff --git a/libixp2/transport.c b/libixp2/transport.c @@ -17,11 +17,10 @@ #include <cext.h> -u32 -ixp_send_message(int fd, void *msg, u32 msize, char **errstr) +u32 ixp_send_message(int fd, void *msg, u32 msize, char **errstr) { - u32 num = 0; - int r; + u32 num = 0; + int r; /* send message */ while (num < msize) { @@ -37,11 +36,10 @@ ixp_send_message(int fd, void *msg, u32 msize, char **errstr) return num; } -static u32 -ixp_recv_data(int fd, void *msg, u32 msize, char **errstr) +static u32 ixp_recv_data(int fd, void *msg, u32 msize, char **errstr) { - u32 num = 0; - int r = 0; + u32 num = 0; + int r = 0; /* receive data */ while (num < msize) { @@ -57,10 +55,9 @@ ixp_recv_data(int fd, void *msg, u32 msize, char **errstr) return num; } -u32 -ixp_recv_message(int fd, void *msg, u32 msglen, char **errstr) +u32 ixp_recv_message(int fd, void *msg, u32 msglen, char **errstr) { - u32 msize; + u32 msize; /* receive header */ if (ixp_recv_data(fd, msg, sizeof(u32), errstr) != sizeof(u32)) @@ -72,7 +69,7 @@ ixp_recv_message(int fd, void *msg, u32 msglen, char **errstr) } /* receive message */ if (ixp_recv_data(fd, msg + sizeof(u32), msize - sizeof(u32), errstr) - != msize - sizeof(u32)) + != msize - sizeof(u32)) return 0; return msize; } diff --git a/liblitz/blitz.h b/liblitz/blitz.h @@ -16,49 +16,48 @@ typedef enum { CENTER, WEST, NWEST, NORTH, NEAST, EAST, SEAST, SOUTH, SWEST -} Align; +} Align; typedef struct Draw Draw; struct Draw { - Drawable drawable; - GC gc; - unsigned long bg; - unsigned long fg; - unsigned long border; - Align align; - XFontStruct *font; - XRectangle rect; /* relative rect */ - XRectangle *notch; /* relative notch rect */ - char *data; + Drawable drawable; + GC gc; + unsigned long bg; + unsigned long fg; + unsigned long border; + Align align; + XFontStruct *font; + XRectangle rect; /* relative rect */ + XRectangle *notch; /* relative notch rect */ + char *data; }; /* draw.c */ -XFontStruct *blitz_getfont(Display * dpy, char *fontstr); -unsigned long blitz_loadcolor(Display * dpy, int mon, char *colstr); -void blitz_drawlabel(Display * dpy, Draw * r); -void blitz_drawmeter(Display * dpy, Draw * r); -void blitz_drawlabelnoborder(Display * dpy, Draw * r); +XFontStruct *blitz_getfont(Display * dpy, char *fontstr); +unsigned long blitz_loadcolor(Display * dpy, int mon, char *colstr); +void blitz_drawlabel(Display * dpy, Draw * r); +void blitz_drawmeter(Display * dpy, Draw * r); +void blitz_drawlabelnoborder(Display * dpy, Draw * r); /* geometry.c */ -int +int blitz_strtorect(Display * dpy, XRectangle * root, XRectangle * r, - char *val); -int blitz_ispointinrect(int x, int y, XRectangle * r); -int blitz_distance(XRectangle * origin, XRectangle * target); -void + char *val); +int blitz_ispointinrect(int x, int y, XRectangle * r); +int blitz_distance(XRectangle * origin, XRectangle * target); +void blitz_getbasegeometry(void **items, unsigned int *size, - unsigned int *cols, unsigned int *rows); + unsigned int *cols, unsigned int *rows); /* mouse.c */ -char *blitz_buttontostr(unsigned int button); -unsigned int blitz_strtobutton(char *val); +char *blitz_buttontostr(unsigned int button); +unsigned int blitz_strtobutton(char *val); /* kb.c */ -char *blitz_modtostr(unsigned long mod); -unsigned long blitz_strtomod(char *val); +char *blitz_modtostr(unsigned long mod); +unsigned long blitz_strtomod(char *val); /* util.c */ -long long -_strtonum(const char *numstr, long long minval, - long long maxval); +long long +_strtonum(const char *numstr, long long minval, long long maxval); diff --git a/liblitz/draw.c b/liblitz/draw.c @@ -9,10 +9,9 @@ #include <cext.h> -XFontStruct * -blitz_getfont(Display * dpy, char *fontstr) +XFontStruct *blitz_getfont(Display * dpy, char *fontstr) { - XFontStruct *font; + XFontStruct *font; font = XLoadQueryFont(dpy, fontstr); if (!font) { font = XLoadQueryFont(dpy, "fixed"); @@ -24,11 +23,10 @@ blitz_getfont(Display * dpy, char *fontstr) return font; } -unsigned long -blitz_loadcolor(Display * dpy, int mon, char *colstr) +unsigned long blitz_loadcolor(Display * dpy, int mon, char *colstr) { - XColor color; - char col[8]; + XColor color; + char col[8]; _strlcpy(col, colstr, sizeof(col)); col[7] = '\0'; @@ -36,10 +34,9 @@ blitz_loadcolor(Display * dpy, int mon, char *colstr) return color.pixel; } -static void -draw_bg(Display * dpy, Draw * d) +static void draw_bg(Display * dpy, Draw * d) { - XRectangle rect[4]; + XRectangle rect[4]; XSetForeground(dpy, d->gc, d->bg); if (!d->notch) { XFillRectangles(dpy, d->drawable, d->gc, &d->rect, 1); @@ -61,10 +58,9 @@ draw_bg(Display * dpy, Draw * d) XFillRectangles(dpy, d->drawable, d->gc, rect, 4); } -static void -_draw_border(Display * dpy, Draw * d) +static void _draw_border(Display * dpy, Draw * d) { - XPoint points[5]; + XPoint points[5]; XSetLineAttributes(dpy, d->gc, 1, LineSolid, CapButt, JoinMiter); XSetForeground(dpy, d->gc, d->border); @@ -81,12 +77,11 @@ _draw_border(Display * dpy, Draw * d) XDrawLines(dpy, d->drawable, d->gc, points, 5, CoordModePrevious); } -static void -draw_text(Display * dpy, Draw * d) +static void draw_text(Display * dpy, Draw * d) { - unsigned int x, y, w, h, shortened = FALSE; - size_t len = 0; - static char text[2048]; + unsigned int x, y, w, h, shortened = FALSE; + size_t len = 0; + static char text[2048]; if (!d->data) return; @@ -123,7 +118,7 @@ draw_text(Display * dpy, Draw * d) case EAST: x = d->rect.x + d->rect.width - (h / 2 + w); break; - default: /* CENTER */ + default: /* CENTER */ x = d->rect.x + (d->rect.width - w) / 2; break; } @@ -139,10 +134,9 @@ draw_text(Display * dpy, Draw * d) } /* draws meter */ -void -blitz_drawmeter(Display * dpy, Draw * d) +void blitz_drawmeter(Display * dpy, Draw * d) { - unsigned int offy, mh, val, w = d->rect.width - 4; + unsigned int offy, mh, val, w = d->rect.width - 4; if (!d->data || strncmp(d->data, "%m:", 3)) return; @@ -158,8 +152,7 @@ blitz_drawmeter(Display * dpy, Draw * d) XFillRectangle(dpy, d->drawable, d->gc, d->rect.x + 2, offy, w, mh); } -static void -_draw_label(Display * dpy, Draw * d) +static void _draw_label(Display * dpy, Draw * d) { draw_bg(dpy, d); if (d->data) @@ -167,15 +160,13 @@ _draw_label(Display * dpy, Draw * d) } /* draws label */ -void -blitz_drawlabel(Display * dpy, Draw * d) +void blitz_drawlabel(Display * dpy, Draw * d) { _draw_label(dpy, d); _draw_border(dpy, d); } -void -blitz_drawlabelnoborder(Display * dpy, Draw * d) +void blitz_drawlabelnoborder(Display * dpy, Draw * d) { _draw_label(dpy, d); } diff --git a/liblitz/geometry.c b/liblitz/geometry.c @@ -10,8 +10,7 @@ #include "blitz.h" #include <cext.h> -static int -strtoalign(Align * result, char *val) +static int strtoalign(Align * result, char *val) { /* * note, resize allows syntax like "east-20", this we cannot do @@ -47,14 +46,14 @@ strtoalign(Align * result, char *val) * Each component can be of following format: * <...> = [+|-]0..n|<alignment>[[+|-]0..n] */ -int +int blitz_strtorect(Display * dpy, XRectangle * root, XRectangle * r, - char *val) + char *val) { - char buf[64]; - char *x, *y, *w, *h; - char *p; - int sx, sy, sw, sh; + char buf[64]; + char *x, *y, *w, *h; + char *p; + int sx, sy, sw, sh; if (!val) return FALSE; @@ -82,8 +81,8 @@ blitz_strtorect(Display * dpy, XRectangle * root, XRectangle * r, r->height = _strtonum(h, 0, 65535); if (!sx && !sw && x && w - && x[0] != '-' && x[0] != '+' && w[0] != '-' && w[0] != '+') { - Align ax, aw; + && x[0] != '-' && x[0] != '+' && w[0] != '-' && w[0] != '+') { + Align ax, aw; strtoalign(&ax, x); strtoalign(&aw, w); if ((ax == CENTER) && (aw == EAST)) { @@ -98,7 +97,7 @@ blitz_strtorect(Display * dpy, XRectangle * root, XRectangle * r, } } } else if (!sx && x && x[0] != '-' && x[0] != '+') { - Align ax; + Align ax; strtoalign(&ax, x); if (ax == CENTER) { r->x = root->x + (root->width / 2) - (r->width / 2); @@ -108,7 +107,7 @@ blitz_strtorect(Display * dpy, XRectangle * root, XRectangle * r, r->x = root->x; } } else if (!sw && w && w[0] != '-' && w[0] != '+') { - Align aw; + Align aw; strtoalign(&aw, w); if (aw == CENTER) { r->width = (root->width / 2) - r->x; @@ -117,8 +116,8 @@ blitz_strtorect(Display * dpy, XRectangle * root, XRectangle * r, } } if (!sy && !sh && y && h - && y[0] != '-' && y[0] != '+' && h[0] != '-' && h[0] != '+') { - Align ay, ah; + && y[0] != '-' && y[0] != '+' && h[0] != '-' && h[0] != '+') { + Align ay, ah; strtoalign(&ay, y); strtoalign(&ah, h); if ((ay == CENTER) && (ah == SOUTH)) { @@ -133,7 +132,7 @@ blitz_strtorect(Display * dpy, XRectangle * root, XRectangle * r, } } } else if (!sy && y && y[0] != '-' && y[0] != '+') { - Align ay; + Align ay; strtoalign(&ay, y); if (ay == CENTER) { r->y = root->y + (root->height / 2) - (r->height / 2); @@ -143,7 +142,7 @@ blitz_strtorect(Display * dpy, XRectangle * root, XRectangle * r, r->y = root->y; } } else if (!sh && h && h[0] != '-' && h[0] != '+') { - Align ah; + Align ah; strtoalign(&ah, h); if (ah == CENTER) { r->height = (root->height / 2) - r->y; @@ -187,30 +186,28 @@ blitz_strtorect(Display * dpy, XRectangle * root, XRectangle * r, return TRUE; } -int -blitz_ispointinrect(int x, int y, XRectangle * r) +int blitz_ispointinrect(int x, int y, XRectangle * r) { return (x >= r->x) && (x <= r->x + r->width) - && (y >= r->y) && (y <= r->y + r->height); + && (y >= r->y) && (y <= r->y + r->height); } -int -blitz_distance(XRectangle * origin, XRectangle * target) +int blitz_distance(XRectangle * origin, XRectangle * target) { - int ox = origin->x + origin->width / 2; - int oy = origin->y + origin->height / 2; - int tx = target->x + target->width / 2; - int ty = target->y + target->height / 2; + int ox = origin->x + origin->width / 2; + int oy = origin->y + origin->height / 2; + int tx = target->x + target->width / 2; + int ty = target->y + target->height / 2; return (int) sqrt((double) (((ox - tx) * (ox - tx)) + - ((oy - ty) * (oy - ty)))); + ((oy - ty) * (oy - ty)))); } -void +void blitz_getbasegeometry(void **items, unsigned int *size, - unsigned int *cols, unsigned int *rows) + unsigned int *cols, unsigned int *rows) { - float sq, dummy; + float sq, dummy; *size = count_items((void **) items); sq = sqrt(*size); diff --git a/liblitz/kb.c b/liblitz/kb.c @@ -10,10 +10,9 @@ #include <cext.h> /* free the result manually! */ -char * -blitz_modtostr(unsigned long mod) +char *blitz_modtostr(unsigned long mod) { - char result[60]; + char result[60]; result[0] = '\0'; if (mod & ShiftMask) @@ -33,10 +32,9 @@ blitz_modtostr(unsigned long mod) return estrdup(result); } -unsigned long -blitz_strtomod(char *val) +unsigned long blitz_strtomod(char *val) { - unsigned long mod = 0; + unsigned long mod = 0; if (strstr(val, "S-")) mod |= ShiftMask; if (strstr(val, "C-")) diff --git a/liblitz/mouse.c b/liblitz/mouse.c @@ -12,19 +12,17 @@ #include <cext.h> /* free the result manually! */ -char * -blitz_buttontostr(unsigned int button) +char *blitz_buttontostr(unsigned int button) { - char result[8]; + char result[8]; result[0] = '\0'; snprintf(result, 8, "Button%ud", button - Button1); return estrdup(result); } -unsigned int -blitz_strtobutton(char *val) +unsigned int blitz_strtobutton(char *val) { - unsigned int res = 0; + unsigned int res = 0; if (val && strlen(val) > 6 && !strncmp(val, "Button", 6)) res = _strtonum(&val[6], 1, 5) + Button1; return res; diff --git a/liblitz/util.c b/liblitz/util.c @@ -8,14 +8,13 @@ #include "cext.h" #include "blitz.h" -long long -_strtonum(const char *numstr, long long minval, long long maxval) +long long _strtonum(const char *numstr, long long minval, long long maxval) { - const char *errstr; - long long ret = __strtonum(numstr, minval, maxval, &errstr); + const char *errstr; + long long ret = __strtonum(numstr, minval, maxval, &errstr); if (errstr) fprintf(stderr, - "liblitz: cannot convert '%s' into integer: %s\n", - numstr, errstr); + "liblitz: cannot convert '%s' into integer: %s\n", + numstr, errstr); return ret; } diff --git a/libwmii/ixputil.c b/libwmii/ixputil.c @@ -14,17 +14,16 @@ #include <cext.h> -static pid_t mypid; -static char *mysockfile; +static pid_t mypid; +static char *mysockfile; /* convenience stuff ----------------------------------------------- */ -File * -wmii_create_ixpfile(IXPServer * s, char *key, char *val) +File *wmii_create_ixpfile(IXPServer * s, char *key, char *val) { - File *f = ixp_create(s, key); + File *f = ixp_create(s, key); if (f && !is_directory(f)) { - size_t l = val ? strlen(val) : 0; + size_t l = val ? strlen(val) : 0; f->content = l ? strdup(val) : 0; f->size = l; return f; @@ -33,10 +32,9 @@ wmii_create_ixpfile(IXPServer * s, char *key, char *val) return 0; } -void -wmii_get_ixppath(File * f, char *path, size_t size) +void wmii_get_ixppath(File * f, char *path, size_t size) { - char buf[512]; + char buf[512]; buf[0] = '\0'; if (path) @@ -48,11 +46,10 @@ wmii_get_ixppath(File * f, char *path, size_t size) wmii_get_ixppath(f->parent, path, size); } -void -wmii_move_ixpfile(File * f, File * to_parent) +void wmii_move_ixpfile(File * f, File * to_parent) { - File *p = f->parent; - File *fil = p->content; + File *p = f->parent; + File *fil = p->content; /* detach */ if (p->content == f) @@ -75,17 +72,15 @@ wmii_move_ixpfile(File * f, File * to_parent) f->parent = to_parent; } -static void -exit_cleanup() +static void exit_cleanup() { if (mypid == getpid()) unlink(mysockfile); } -IXPServer * -wmii_setup_server(char *sockfile) +IXPServer *wmii_setup_server(char *sockfile) { - IXPServer *s; + IXPServer *s; if (!sockfile) { fprintf(stderr, "%s\n", "libwmii: no socket file provided"); diff --git a/libwmii/spawn.c b/libwmii/spawn.c @@ -13,8 +13,7 @@ #include <cext.h> -void -spawn(void *dpy, char *cmd) +void spawn(void *dpy, char *cmd) { /* the questionable double-fork is done to catch all zombies */ if (fork() == 0) { diff --git a/libwmii/util.c b/libwmii/util.c @@ -5,10 +5,9 @@ #include "wmii.h" -void -swap(void **p1, void **p2) +void swap(void **p1, void **p2) { - void *tmp = *p1; + void *tmp = *p1; *p1 = *p2; *p2 = tmp; } diff --git a/libwmii/wm.c b/libwmii/wm.c @@ -17,15 +17,15 @@ int property(Display * dpy, Window w, Atom a, Atom t, long l, - unsigned char **prop) + unsigned char **prop) { - Atom real; - int format; - unsigned long res, extra; - int status; + Atom real; + int format; + unsigned long res, extra; + int status; status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, - &res, &extra, prop); + &res, &extra, prop); if (status != Success || *prop == 0) { return 0; @@ -36,10 +36,9 @@ property(Display * dpy, Window w, Atom a, Atom t, long l, return res; } -void -win_prop(Display * dpy, Window w, Atom a, char *res, int len) +void win_prop(Display * dpy, Window w, Atom a, char *res, int len) { - unsigned char *prop; + unsigned char *prop; if (property(dpy, w, a, XA_STRING, 100L, &prop)) { _strlcpy(res, (char *) prop, len); @@ -49,10 +48,9 @@ win_prop(Display * dpy, Window w, Atom a, char *res, int len) XSync(dpy, False); } -void -send_message(Display * dpy, Window w, Atom a, long value) +void send_message(Display * dpy, Window w, Atom a, long value) { - XEvent e; + XEvent e; e.type = ClientMessage; e.xclient.window = w; e.xclient.message_type = a; @@ -67,22 +65,22 @@ send_message(Display * dpy, Window w, Atom a, long value) #define NUM_MASKS 8 void init_lock_modifiers(Display * dpy, unsigned int *valid_mask, - unsigned int *num_lock_mask) + unsigned int *num_lock_mask) { XModifierKeymap *modmap; - KeyCode num_lock; - static int masks[NUM_MASKS] = { + KeyCode num_lock; + static int masks[NUM_MASKS] = { ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask }; - int i; + int i; *num_lock_mask = 0; modmap = XGetModifierMapping(dpy); num_lock = XKeysymToKeycode(dpy, XStringToKeysym("Num_Lock")); if (modmap && modmap->max_keypermod > 0) { - int max = NUM_MASKS * modmap->max_keypermod; + int max = NUM_MASKS * modmap->max_keypermod; for (i = 0; i < max; i++) { if (num_lock && (modmap->modifiermap[i] == num_lock)) { *num_lock_mask = masks[i / modmap->max_keypermod]; diff --git a/libwmii/wmii.h b/libwmii/wmii.h @@ -12,28 +12,28 @@ typedef struct Action Action; struct Action { - char *name; - void (*func) (void *obj, char *); + char *name; + void (*func) (void *obj, char *); }; /* ixputil.c */ -File *wmii_create_ixpfile(IXPServer * s, char *key, char *val); -void wmii_get_ixppath(File * f, char *path, size_t size); -void wmii_move_ixpfile(File * f, File * to_parent); -IXPServer *wmii_setup_server(char *sockfile); +File *wmii_create_ixpfile(IXPServer * s, char *key, char *val); +void wmii_get_ixppath(File * f, char *path, size_t size); +void wmii_move_ixpfile(File * f, File * to_parent); +IXPServer *wmii_setup_server(char *sockfile); /* spawn.c */ -void spawn(void *dpy, char *cmd); +void spawn(void *dpy, char *cmd); /* util.c */ -void swap(void **p1, void **p2); +void swap(void **p1, void **p2); /* wm.c */ -int +int property(Display * dpy, Window w, Atom a, Atom t, long l, - unsigned char **prop); -void win_prop(Display * dpy, Window w, Atom a, char *res, int len); -void send_message(Display * dpy, Window w, Atom a, long value); -void + unsigned char **prop); +void win_prop(Display * dpy, Window w, Atom a, char *res, int len); +void send_message(Display * dpy, Window w, Atom a, long value); +void init_lock_modifiers(Display * dpy, unsigned int *valid_mask, - unsigned int *num_lock_mask); + unsigned int *num_lock_mask);