wmii

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

commit e6281f3fc1a5b41bd1c547eab798f4bc7b03a61a
parent 32fc2e2c6631605c71b588d2dc7f13a58466ebd5
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Mon,  6 Feb 2006 15:20:25 +0100

proceeded with wmiikeys


Diffstat:
cmd/Makefile | 2+-
cmd/wm/client.c | 8+++++++-
cmd/wm/fs.c | 9+--------
cmd/wm/page.c | 8++++++++
cmd/wm/wm.c | 12------------
cmd/wm/wm.h | 1-
cmd/wmiibar.c | 56++++----------------------------------------------------
cmd/wmiikeys.c | 147+++++++++++++++++++------------------------------------------------------------
libwmii/Makefile | 2+-
libwmii/ixp.c | 50++++++++++++++++++++++++++++++++++++++++++++++++++
libwmii/wmii.h | 24++++++++++++++----------
11 files changed, 121 insertions(+), 198 deletions(-)

diff --git a/cmd/Makefile b/cmd/Makefile @@ -29,7 +29,7 @@ SRC_warp = wmiiwarp.c OBJ_warp = ${SRC_warp:.c=.o} #all: wmiibar wmiimenu wmiir wmiifs wmiikeys wmiiplumb wmiiwarp -all: wmiikeys wmiibar wmiir wmiiplumb wmiiwarp +all: wmiibar wmiikeys wmiir wmiiplumb wmiiwarp @echo built wmii commands .c.o: diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -10,13 +10,17 @@ #include "wm.h" +/* static void max_client(void *obj, char *arg); +*/ /* action table for /?/ namespace */ +/* Action client_acttbl[] = { {"max", max_client}, {0, 0} }; +*/ Client * alloc_client(Window w, XWindowAttributes *wa) @@ -495,13 +499,14 @@ resize_client(Client *c, XRectangle *r, XPoint *pt) configure_client(c); } +/* static void max_client(void *obj, char *arg) { Client *c = obj; if(c->maximized) { - /* XXX: do we really need this ? */ c->frame.rect = c->frame.revert; + c->frame.rect = c->frame.revert; resize_client(c, &c->frame.revert, nil); } else { @@ -512,6 +517,7 @@ max_client(void *obj, char *arg) } c->maximized = !c->maximized; } +*/ int index_of_client_id(Area *a, unsigned short id) diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c @@ -59,14 +59,7 @@ * /1/1/1/ctl Fctl command interface (client) */ -static char E9pversion[] = "9P version not supported"; -static char Enoperm[] = "permission denied"; -static char Enofid[] = "fid not assigned"; -static char Enofile[] = "file not found"; -static char Enomode[] = "mode not supported"; -static char Enofunc[] = "function not supported"; -static char Enocommand[] = "command not supported"; - +Qid root_qid; const char *err; /* IXP stuff */ diff --git a/cmd/wm/page.c b/cmd/wm/page.c @@ -10,12 +10,15 @@ #include "wm.h" +/* static void select_client(void *obj, char *arg); static void xexec(void *obj, char *arg); static void swap_client(void *obj, char *arg); static void xnew_column(void *obj, char *arg); +*/ /* action table for /?/ namespace */ +/* Action page_acttbl[] = { {"exec", xexec}, {"swap", swap_client}, @@ -23,6 +26,7 @@ Action page_acttbl[] = { {"select", select_client}, {0, 0} }; +*/ Page * alloc_page() @@ -135,6 +139,7 @@ rectangles(unsigned int *num) return result; } +/* static void xexec(void *obj, char *arg) { @@ -142,7 +147,9 @@ xexec(void *obj, char *arg) sizeof(Page *), &aqsz); wmii_spawn(dpy, arg); } +*/ +/* static void swap_client(void *obj, char *arg) { @@ -230,6 +237,7 @@ select_client(void *obj, char *arg) } } } +*/ int index_of_page_id(unsigned short id) diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c @@ -388,18 +388,6 @@ scan_wins() XFree(wins); } -void * -get_func(void *acttbl[][2], int rows, char *fname) -{ - int i; - for(i = 0; i < rows; i++) { - if(!strncmp((char *) acttbl[i][0], fname, MAX_BUF)) { - return acttbl[i][1]; - } - } - return 0; -} - int win_proto(Window w) { diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -119,7 +119,6 @@ XFontStruct *xfont; GC gc_xor; GC gc_transient; IXPServer srv; -Qid root_qid; /* default values */ typedef struct { diff --git a/cmd/wmiibar.c b/cmd/wmiibar.c @@ -55,20 +55,11 @@ typedef struct { XRectangle rect; } Item; -static char E9pversion[] = "9P version not supported"; -static char Enoperm[] = "permission denied"; -static char Enofid[] = "fid not assigned"; -static char Enofile[] = "file not found"; -static char Enomode[] = "mode not supported"; -static char Enofunc[] = "function not supported"; -static char Enocommand[] = "command not supported"; - static size_t nitem = 0; static size_t itemsz = 0; static size_t iexpand = 0; static Item **item = 0; static IXPServer srv = { 0 }; -static Qid root_qid; static Display *dpy; static int screen; static char *font = nil; @@ -79,6 +70,7 @@ static XRectangle brect, rect; static Pixmap pmap; static char defcolstr[24]; static Color defcolor; +Qid root_qid; static void do_pend_fcall(char *event); @@ -366,32 +358,6 @@ mkqid(Qid *dir, char *wname, Qid *new, Bool iswalk) } -static char * -xversion(IXPConn *c, Fcall *fcall) -{ - if(strncmp(fcall->version, IXP_VERSION, strlen(IXP_VERSION))) - return E9pversion; - else if(fcall->maxmsg > IXP_MAX_MSG) - fcall->maxmsg = IXP_MAX_MSG; - fcall->id = RVERSION; - ixp_server_respond_fcall(c, fcall); - return nil; -} - -static char * -xattach(IXPConn *c, Fcall *fcall) -{ - IXPMap *new = cext_emallocz(sizeof(IXPMap)); - new->qid = root_qid; - new->fid = fcall->fid; - c->map = (IXPMap **)cext_array_attach((void **)c->map, new, - sizeof(IXPMap *), &c->mapsz); - fcall->id = RATTACH; - fcall->qid = root_qid; - ixp_server_respond_fcall(c, fcall); - return nil; -} - static char * xwalk(IXPConn *c, Fcall *fcall) { @@ -765,20 +731,6 @@ xwrite(IXPConn *c, Fcall *fcall) return nil; } -static char * -xclunk(IXPConn *c, Fcall *fcall) -{ - IXPMap *m = ixp_server_fid2map(c, fcall->fid); - - if(!m) - return Enofid; - cext_array_detach((void **)c->map, m, &c->mapsz); - free(m); - fcall->id = RCLUNK; - ixp_server_respond_fcall(c, fcall); - return nil; -} - static void do_fcall(IXPConn *c) { @@ -789,14 +741,14 @@ do_fcall(IXPConn *c) if((msize = ixp_server_receive_fcall(c, &fcall))) { /*fprintf(stderr, "fcall=%d\n", fcall.id);*/ switch(fcall.id) { - case TVERSION: errstr = xversion(c, &fcall); break; - case TATTACH: errstr = xattach(c, &fcall); break; + case TVERSION: errstr = wmii_ixp_version(c, &fcall); break; + case TATTACH: errstr = wmii_ixp_attach(c, &fcall); break; case TWALK: errstr = xwalk(c, &fcall); break; case TREMOVE: errstr = xremove(c, &fcall); break; case TOPEN: errstr = xopen(c, &fcall); break; case TREAD: errstr = xread(c, &fcall); break; case TWRITE: errstr = xwrite(c, &fcall); break; - case TCLUNK: errstr = xclunk(c, &fcall); break; + case TCLUNK: errstr = wmii_ixp_clunk(c, &fcall); break; case TSTAT: errstr = xstat(c, &fcall); break; default: errstr = Enofunc; break; } diff --git a/cmd/wmiikeys.c b/cmd/wmiikeys.c @@ -8,6 +8,7 @@ #include <string.h> #include <sys/stat.h> #include <sys/wait.h> +#include <time.h> #include <X11/Xlib.h> #include <X11/keysym.h> #include <X11/Xatom.h> @@ -31,7 +32,7 @@ /* 8-bit qid.path.type */ enum { Droot, - Dshortcut + Dshortcut, Fctl, Ffont, Fcolor, @@ -43,22 +44,13 @@ typedef struct Shortcut Shortcut; struct Shortcut { unsigned short id; - char name[MAX_BUF]; + char name[256]; char *cmd; unsigned long mod; KeyCode key; Shortcut *next; }; -static char E9pversion[] = "9P version not supported"; -static char Enoperm[] = "permission denied"; -static char Enofid[] = "fid not assigned"; -static char Enofile[] = "file not found"; -static char Enomode[] = "mode not supported"; -static char Enofunc[] = "function not supported"; -static char Enocommand[] = "command not supported"; - - static IXPServer srv; static Display *dpy; static Window win; @@ -73,6 +65,7 @@ static unsigned int num_lock_mask, valid_mask; static char *font; static char *colstr; static Draw box; +Qid root_qid; static void draw_shortcut_box(char *prefix); @@ -141,7 +134,7 @@ create_shortcut(char *name, char *cmd) s->next = cext_emallocz(sizeof(Shortcut)); s = s->next; } - cext_strlcpy(s->name, chain[i], MAX_BUF); + cext_strlcpy(s->name, chain[i], sizeof(s->name)); k = strrchr(chain[i], '-'); if(k) k++; @@ -319,12 +312,22 @@ dummy_error_handler(Display * dpy, XErrorEvent * err) return 0; } +static Shortcut * +shortcut_of_name(char *name) +{ + size_t i; + for(i = 0; i < nshortcut; i++) + if(!strncmp(shortcut[i]->name, name, sizeof(shortcut[i]->name))) + return shortcut[i]; + return nil; +} + static int index_of_id(unsigned short id) { int i; - for(i = 0; i < nitem; i++) - if(item[i]->id == id) + for(i = 0; i < nshortcut; i++) + if(shortcut[i]->id == id) return i; return -1; } @@ -355,23 +358,17 @@ qid_to_name(Qid *qid) unsigned char type = qpath_type(qid->path); unsigned short id = qpath_id(qid->path); int i; - static char buf[32]; if(id && ((i = index_of_id(id)) == -1)) return nil; switch(type) { case Droot: return "/"; break; - case Ditem: - snprintf(buf, sizeof(buf), "%u", i + 1); - return buf; - break; + case Dshortcut: return "shortcut"; break; case Fctl: return "ctl"; break; case Ffont: return "font"; break; - case Fdefcolor: return "defcolor"; break; - case Fexpand: return "expand"; break; - case Fdata: return "data"; break; - case Fevent: return "event"; break; case Fcolor: return "color"; break; + case Freset: return "reset"; break; + case Fshortcut: return shortcut[i]->name; break; default: return nil; break; } } @@ -379,36 +376,26 @@ qid_to_name(Qid *qid) static int name_to_type(char *name) { - const char *err; - unsigned int i; if(!name || !name[0] || !strncmp(name, "/", 2) || !strncmp(name, "..", 3)) return Droot; - if(!strncmp(name, "new", 4)) - return Ditem; + if(!strncmp(name, "shortcut", 4)) + return Dshortcut; if(!strncmp(name, "ctl", 4)) return Fctl; if(!strncmp(name, "font", 5)) return Ffont; - if(!strncmp(name, "defcolor", 9)) - return Fdefcolor; - if(!strncmp(name, "expand", 7)) - return Fexpand; - if(!strncmp(name, "data", 5)) - return Fdata; - if(!strncmp(name, "event", 6)) - return Fevent; if(!strncmp(name, "color", 6)) return Fcolor; - i = (unsigned short) cext_strtonum(name, 1, 0xffff, &err); - if(!err && (i - 1 <= nitem)) - return Ditem; + if(!strncmp(name, "reset", 6)) + return Freset; + if(shortcut_of_name(name)) + return Fshortcut; return -1; } static int mkqid(Qid *dir, char *wname, Qid *new, Bool iswalk) { - const char *err; unsigned short id = qpath_id(dir->path); int i, type = name_to_type(wname); @@ -424,25 +411,12 @@ mkqid(Qid *dir, char *wname, Qid *new, Bool iswalk) case Droot: *new = root_qid; break; - case Ditem: + case Dshortcut: new->type = IXP_QTDIR; - if(!strncmp(wname, "new", 4)) { - /*fprintf(stderr, "mkqid iswalk=%d, wname=%s\n", iswalk, wname);*/ - if(iswalk) - new->path = mkqpath(Ditem, new_item()->id); - else - new->path = mkqpath(Ditem, 0); - } - else { - i = cext_strtonum(wname, 1, 0xffff, &err); - if(err || (i - 1 >= nitem)) - return -1; - new->path = mkqpath(Ditem, item[i - 1]->id); - } + new->path = mkqpath(Dshortcut, 0); break; - case Fdata: - case Fcolor: - if(i >= nitem) + case Fshortcut: + if(i >= nshortcut) return -1; default: new->type = IXP_QTFILE; @@ -452,33 +426,6 @@ mkqid(Qid *dir, char *wname, Qid *new, Bool iswalk) return 0; } - -static char * -xversion(IXPConn *c, Fcall *fcall) -{ - if(strncmp(fcall->version, IXP_VERSION, strlen(IXP_VERSION))) - return E9pversion; - else if(fcall->maxmsg > IXP_MAX_MSG) - fcall->maxmsg = IXP_MAX_MSG; - fcall->id = RVERSION; - ixp_server_respond_fcall(c, fcall); - return nil; -} - -static char * -xattach(IXPConn *c, Fcall *fcall) -{ - IXPMap *new = cext_emallocz(sizeof(IXPMap)); - new->qid = root_qid; - new->fid = fcall->fid; - c->map = (IXPMap **)cext_array_attach((void **)c->map, new, - sizeof(IXPMap *), &c->mapsz); - fcall->id = RATTACH; - fcall->qid = root_qid; - ixp_server_respond_fcall(c, fcall); - return nil; -} - static char * xwalk(IXPConn *c, Fcall *fcall) { @@ -552,36 +499,26 @@ type_to_stat(Stat *stat, char *name, Qid *dir) { int i, type = name_to_type(name); unsigned short id = qpath_id(dir->path); - char buf[16]; if(id && ((i = index_of_id(id)) == -1)) return 0; switch (type) { case Droot: - case Ditem: + case Dshortcut: return mkstat(stat, dir, name, 0, DMDIR | DMREAD | DMEXEC); break; case Fctl: + case Freset: return mkstat(stat, dir, name, 0, DMWRITE); break; - case Fevent: - return mkstat(stat, dir, name, 0, DMREAD); - break; case Ffont: return mkstat(stat, dir, name, strlen(font), DMREAD | DMWRITE); break; - case Fdefcolor: - return mkstat(stat, dir, name, 23, DMREAD | DMWRITE); - break; - case Fexpand: - snprintf(buf, sizeof(buf), "%u", iexpand + 1); - return mkstat(stat, dir, name, strlen(buf), DMREAD | DMWRITE); - break; - case Fdata: - return mkstat(stat, dir, name, (i == nitem) ? 0 : strlen(item[i]->data), DMREAD | DMWRITE); - break; case Fcolor: return mkstat(stat, dir, name, 23, DMREAD | DMWRITE); + break; + case Fshortcut: + return mkstat(stat, dir, name, strlen(shortcut[i]->cmd), DMREAD | DMWRITE); break; } return 0; @@ -852,20 +789,6 @@ xwrite(IXPConn *c, Fcall *fcall) return nil; } -static char * -xclunk(IXPConn *c, Fcall *fcall) -{ - IXPMap *m = ixp_server_fid2map(c, fcall->fid); - - if(!m) - return Enofid; - cext_array_detach((void **)c->map, m, &c->mapsz); - free(m); - fcall->id = RCLUNK; - ixp_server_respond_fcall(c, fcall); - return nil; -} - static void do_fcall(IXPConn *c) { diff --git a/libwmii/Makefile b/libwmii/Makefile @@ -6,7 +6,7 @@ include ../config.mk CFLAGS += -I../liblitz -I../libixp -I../libcext LDFLAGS += -L../liblitz -llitz -L../libixp -lixp -L../libcext -lcext -SRC = spawn.c wm.c +SRC = ixp.c spawn.c wm.c OBJ = ${SRC:.c=.o} diff --git a/libwmii/ixp.c b/libwmii/ixp.c @@ -0,0 +1,50 @@ +/* + * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> + * See LICENSE file for license details. + */ +#include <string.h> +#include <stdlib.h> + +#include "wmii.h" + +/* default handler */ + +char * +wmii_ixp_version(IXPConn *c, Fcall *fcall) +{ + if(strncmp(fcall->version, IXP_VERSION, strlen(IXP_VERSION))) + return E9pversion; + else if(fcall->maxmsg > IXP_MAX_MSG) + fcall->maxmsg = IXP_MAX_MSG; + fcall->id = RVERSION; + ixp_server_respond_fcall(c, fcall); + return nil; +} + +char * +wmii_ixp_attach(IXPConn *c, Fcall *fcall) +{ + IXPMap *new = cext_emallocz(sizeof(IXPMap)); + new->qid = root_qid; + new->fid = fcall->fid; + c->map = (IXPMap **)cext_array_attach((void **)c->map, new, + sizeof(IXPMap *), &c->mapsz); + fcall->id = RATTACH; + fcall->qid = root_qid; + ixp_server_respond_fcall(c, fcall); + return nil; +} + +char * +wmii_ixp_clunk(IXPConn *c, Fcall *fcall) +{ + IXPMap *m = ixp_server_fid2map(c, fcall->fid); + + if(!m) + return Enofid; + cext_array_detach((void **)c->map, m, &c->mapsz); + free(m); + fcall->id = RCLUNK; + ixp_server_respond_fcall(c, fcall); + return nil; +} diff --git a/libwmii/wmii.h b/libwmii/wmii.h @@ -6,22 +6,26 @@ #include "ixp.h" #include "blitz.h" -#define MAX_ID 20 -#define MAX_BUF 128 +/* ixp.c */ +#define E9pversion "9P version not supported" +#define Enoperm "permission denied" +#define Enofid "fid not assigned" +#define Enofile "file not found" +#define Enomode "mode not supported" +#define Enofunc "function not supported" +#define Enocommand "command not supported" -typedef struct Action Action; - -struct Action { - char *name; - void (*func) (void *obj, char *); -}; +char *wmii_ixp_version(IXPConn *c, Fcall *fcall); +char *wmii_ixp_attach(IXPConn *c, Fcall *fcall); +char *wmii_ixp_clunk(IXPConn *c, Fcall *fcall); /* spawn.c */ void wmii_spawn(void *dpy, char *cmd); /* wm.c */ -int wmii_property(Display * dpy, Window w, Atom a, Atom t, long l, - unsigned char **prop); +int wmii_property(Display * dpy, Window w, Atom a, Atom t, long l, unsigned char **prop); void wmii_send_message(Display * dpy, Window w, Atom a, long value); void wmii_init_lock_modifiers(Display * dpy, unsigned int *valid_mask, unsigned int *num_lock_mask); + +extern Qid root_qid;