From 3b31f2bcca3b2c9f0b66a63be1d1400cdff356e2 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 24 May 2007 17:23:36 -0400 Subject: [PATCH] Explicitly prototype (void) functions. --- DISTRIBUTERS | 42 -- cmd/wmii/area.c | 16 +- cmd/wmii/client.c | 56 +- cmd/wmii/column.c | 4 +- cmd/wmii/dat.h | 1 + cmd/wmii/fns.h | 22 +- cmd/wmii/frame.c | 10 +- cmd/wmii/fs.c | 2 +- cmd/wmii/geom.c | 2 +- cmd/wmii/key.c | 4 +- cmd/wmii/main.c | 18 +- cmd/wmii/message.c | 2 +- cmd/wmii/mouse.c | 6 +- cmd/wmii/printevent.c | 1478 +++++++++++++++++++++-------------------- cmd/wmii/printevent.h | 1 - cmd/wmii/view.c | 2 +- cmd/wmii/x11.c | 4 +- 17 files changed, 828 insertions(+), 842 deletions(-) delete mode 100644 DISTRIBUTERS diff --git a/DISTRIBUTERS b/DISTRIBUTERS deleted file mode 100644 index 5ee76107..00000000 --- a/DISTRIBUTERS +++ /dev/null @@ -1,42 +0,0 @@ -The following conditions apply to any distribution which -uses the name wmii. These conditions apply only to wmii -name, and not to its source code or any other materials. - -When in doubt about any of these conditions or other matters -of packaging or distrobution, , please contact the wmii -mailing lists or -, or Kris Maglione . - -Any binary distribution of wmii MUST have a properly set -version string. This string may normally be set in -'mk/wmii.mk', and is set automatically to the Mercurial -revision number for builds from a Mercurial tree, so long as -the 'hg' command is present and properly functioning. - -Any version which not an official release or snapshot MUST -be contain the hg revision number in its version string. -This SHOULD be formated as hgXXXX, where XXXX is the decimal -revision number. - -The version string of any snapshot release MUST contain the -date of the snapshot in the form YYYYMMDD, and SHOULD -contain the word snap or snapshot. The version string of a -snapshot MAY contain the version of a full release that the -snapshot is expected to lead to, but it MUST be either -directly preceded, or directly followed by, the word 'pre', -optionally separated by a non-alphanumeric character, -including -~_,./, the version. - -Any binary distribution which is modified in any non-trivial -way MUST signify the modifications in its name or version -string. This includes patches to use Xft for font display, -but does NOT include minor patches to improve consistency -with the rest of the system, including changing the default -terminal emulator or changing any build flags as set in -config.mk. - -Source form distribution MAY include non-trivial patches -without such modifications, provided that the user is made -clearly aware of them at build time and/or prompted in some -way to enable or disable them. - diff --git a/cmd/wmii/area.c b/cmd/wmii/area.c index 00f56ae1..124fd376 100644 --- a/cmd/wmii/area.c +++ b/cmd/wmii/area.c @@ -246,11 +246,11 @@ detach_from_area(Frame *f) { static void bit_set(uint *field, uint width, uint x, uint y, Bool set) { - enum { devisor = sizeof(uint) * 8 }; + enum { divisor = sizeof(uint) * 8 }; uint bx, mask; - bx = x / devisor; - mask = 1 << x % devisor; + bx = x / divisor; + mask = 1 << x % divisor; if(set) field[y*width + bx] |= mask; else @@ -259,18 +259,18 @@ bit_set(uint *field, uint width, uint x, uint y, Bool set) { static Bool bit_get(uint *field, uint width, uint x, uint y) { - enum { devisor = sizeof(uint) * 8 }; + enum { divisor = sizeof(uint) * 8 }; uint bx, mask; - bx = x / devisor; - mask = 1 << x % devisor; + bx = x / divisor; + mask = 1 << x % divisor; return (field[y*width + bx] & mask) != 0; } static void place_frame(Frame *f) { - enum { devisor = sizeof(uint) * 8 }; + enum { divisor = sizeof(uint) * 8 }; enum { dx = 8, dy = 8 }; static uint mwidth, mx, my; @@ -301,7 +301,7 @@ place_frame(Frame *f) { if(!field) { mx = Dx(screen->r) / dx; my = Dy(screen->r) / dy; - mwidth = ceil((float)mx / devisor); + mwidth = ceil((float)mx / divisor); field = emallocz(sizeof(uint) * mwidth * my); } diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c index d28eb4fd..25ccee47 100644 --- a/cmd/wmii/client.c +++ b/cmd/wmii/client.c @@ -2,6 +2,7 @@ * Copyright ©2006-2007 Kris Maglione * See LICENSE file for license details. */ +#include #include #include #include @@ -10,6 +11,8 @@ #include "dat.h" #include "fns.h" +#define Mbsearch(k, l, cmp) bsearch(k, l, nelem(l), sizeof(*l), cmp) + static Handlers handlers; Rectangle gravclient(Client*, Rectangle); @@ -186,7 +189,7 @@ destroy_client(Client *c) { /* Convenience functions */ Client * -selclient() { +selclient(void) { if(screen->sel->sel->sel) return screen->sel->sel->sel->client; return nil; @@ -325,7 +328,7 @@ focus_client(Client *c) { Debug fprintf(stderr, "focus_client(%p[%x]) => %s\n", c, clientwin(c), clientname(c)); - if(screen->focus != c) { + if((c == nil || !c->noinput) && screen->focus != c) { Debug fprintf(stderr, "\t%s => %s\n", clientname(screen->focus), clientname(c)); if(c) @@ -566,6 +569,7 @@ prop_client(Client *c, Atom a) { case XA_WM_HINTS: wmh = XGetWMHints(display, c->w.w); if(wmh) { + c->noinput = !((wmh->flags&InputFocus) && wmh->input); set_urgent(c, (wmh->flags & XUrgencyHint) != 0, False); XFree(wmh); } @@ -798,10 +802,21 @@ update_client_views(Client *c, char **tags) { } static int -compare_tags(const void *a, const void *b) { +bsstrcmp(const void *a, const void *b) { + return strcmp((char*)a, (char*)b); +} + +static int +strpcmp(const void *a, const void *b) { return strcmp(*(char **)a, *(char **)b); } +static char *badtags[] = { + ".", + "..", + "sel", +}; + void apply_tags(Client *c, const char *tags) { uint i, j, k, n; @@ -810,8 +825,10 @@ apply_tags(Client *c, const char *tags) { char *toks[32], *cur; buf[0] = 0; + for(n = 0; tags[n]; n++) - if(tags[n] != ' ' && tags[n] != '\t') break; + if(!isspace(tags[n])) + break; if(tags[n] == '+' || tags[n] == '-') strncpy(buf, c->tags, sizeof(c->tags)); @@ -820,7 +837,6 @@ apply_tags(Client *c, const char *tags) { trim(buf, " \t/"); n = 0; - j = 0; add = True; if(buf[0] == '+') n++; @@ -828,6 +844,8 @@ apply_tags(Client *c, const char *tags) { n++; add = False; } + + j = 0; while(buf[n] && n < sizeof(buf) && j < 32) { for(i = n; i < sizeof(buf) - 1; i++) if(buf[i] == '+' || buf[i] == '-' || buf[i] == '\0') @@ -836,14 +854,12 @@ apply_tags(Client *c, const char *tags) { buf[i] = '\0'; cur = nil; - if(!strncmp(&buf[n], "~", 2)) + if(!strcmp(buf+n, "~")) c->floating = add; - else if(!strncmp(&buf[n], "!", 2)) - cur = view ? screen->sel->name : "nil"; - else if(strcmp(&buf[n], "sel") - && strcmp(&buf[n], ".") - && strcmp(&buf[n], "..")) - cur = &buf[n]; + else if(!strcmp(buf+n, "!")) + cur = screen->sel->name; + else if(!Mbsearch(buf+n, badtags, bsstrcmp)) + cur = buf+n; n = i + 1; if(cur) { @@ -870,14 +886,15 @@ apply_tags(Client *c, const char *tags) { } } - c->tags[0] = '\0'; if(!j) return; - qsort(toks, j, sizeof(char *), compare_tags); + qsort(toks, j, sizeof(char *), strpcmp); + + c->tags[0] = '\0'; for(i=0, n=0; i < j; i++) - if(!n || strcmp(toks[i], toks[n-1])) { - if(i) + if(n == 0 || strcmp(toks[i], toks[n-1])) { + if(i > 0) strlcat(c->tags, "+", sizeof(c->tags)); strlcat(c->tags, toks[i], sizeof(c->tags)); toks[n++] = toks[i]; @@ -893,16 +910,17 @@ void apply_rules(Client *c) { Rule *r; regmatch_t rm; - + if(strlen(c->tags)) return; + if(def.tagrules.string) for(r=def.tagrules.rule; r; r=r->next) if(!regexec(&r->regex, c->props, 1, &rm, 0)) { apply_tags(c, r->value); - if(strlen(c->tags) && strcmp(c->tags, "nil")) + if(strcmp(c->tags, "nil")) break; } - if(!strlen(c->tags)) + if(c->tags[0] == '\0') apply_tags(c, "nil"); } diff --git a/cmd/wmii/column.c b/cmd/wmii/column.c index 94bd7ee3..8d863365 100644 --- a/cmd/wmii/column.c +++ b/cmd/wmii/column.c @@ -104,7 +104,7 @@ drawdiv(Divide *d) { } void -update_imgs() { +update_imgs(void) { Divide *d; int w, h; @@ -133,7 +133,7 @@ update_imgs() { } void -update_divs() { +update_divs(void) { Divide **dp, *d; Area *a; View *v; diff --git a/cmd/wmii/dat.h b/cmd/wmii/dat.h index 45999f9a..aa886cfa 100644 --- a/cmd/wmii/dat.h +++ b/cmd/wmii/dat.h @@ -131,6 +131,7 @@ struct Client { Bool urgent; Bool borderless; Bool titleless; + Bool noinput; int unmapped; Window w; XWindow trans; diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h index 10ad38c4..535ef760 100644 --- a/cmd/wmii/fns.h +++ b/cmd/wmii/fns.h @@ -17,7 +17,7 @@ void initbar(WMScreen *s); Bar *create_bar(Bar **b_link, char *name); void destroy_bar(Bar **b_link, Bar*); void draw_bar(WMScreen *s); -void resize_bar(); +void resize_bar(WMScreen *s); Bar *bar_of_name(Bar *b_link, const char *name); /* client.c */ @@ -43,7 +43,7 @@ void resize_client(Client*, Rectangle*); void apply_sizehints(Client*, Rectangle*, Bool floating, Bool frame, Align sticky); void move_client(Client*, char *arg); void size_client(Client*, char *arg); -Client *selclient(); +Client *selclient(void); Client *win2client(XWindow); uint clientwin(Client *c); char *clientname(Client*); @@ -51,7 +51,7 @@ void apply_rules(Client*); void apply_tags(Client*, const char*); /* column.c */ -void update_divs(); +void update_divs(void); void draw_div(Divide*); void setdiv(Divide*, int x); void arrange_column(Area*, Bool dirty); @@ -74,13 +74,13 @@ void resize_frame(Frame*, Rectangle); Bool frame_to_top(Frame *f); void set_frame_cursor(Frame*, Point); void swap_frames(Frame*, Frame*); -int frame_delta_h(); +int frame_delta_h(void); Rectangle frame_hints(Frame*, Rectangle, Align); Rectangle frame2client(Frame*, Rectangle); Rectangle client2frame(Frame*, Rectangle); int ingrabbox(Frame*, int x, int y); void draw_frame(Frame*); -void draw_frames(); +void draw_frames(void); void update_frame_widget_colors(Frame*); Rectangle constrain(Rectangle); @@ -106,8 +106,8 @@ Align get_sticky(Rectangle src, Rectangle dst); /* key.c */ void kpress(XWindow, ulong mod, KeyCode); -void update_keys(); -void init_lock_keys(); +void update_keys(void); +void init_lock_keys(void); ulong str2modmask(char*); /* map.c */ @@ -122,7 +122,7 @@ Area * strarea(View*, char*); char * message_view(View*, Message*); char * parse_colors(Message*, CTuple*); char * message_root(void*, Message*); -char * read_root_ctl(); +char * read_root_ctl(void); char * message_client(Client*, Message*); char *select_area(Area*, Message*); char *send_client(View*, Message*, Bool swap); @@ -156,7 +156,7 @@ char *message_view(View *v, Message *m); void restack_view(View*); uchar *view_index(View*); void destroy_view(View*); -void update_views(); +void update_views(void); uint newcolw(View*, int i); /* wm.c */ @@ -172,7 +172,7 @@ Point divpt(Point, Point); Rectangle insetrect(Rectangle, int); Rectangle rectaddpt(Rectangle, Point); Rectangle rectsubpt(Rectangle, Point); -void initdisplay(); +void initdisplay(void); Image * allocimage(int w, int h, int depth); void freeimage(Image *); Window *createwindow(Window *parent, Rectangle, int depth, uint class, WinAttr*, int valuemask); @@ -214,7 +214,7 @@ Point querypointer(Window*); void warppointer(Point); Point translate(Window*, Window*, Point); int grabpointer(Window*, Window *confine, Cursor, int mask); -void ungrabpointer(); +void ungrabpointer(void); Rectangle gravitate(Rectangle dst, Rectangle src, Point grav); Rectangle sizehint(WinHints*, Rectangle); void sethints(Window*); diff --git a/cmd/wmii/frame.c b/cmd/wmii/frame.c index 7e52e890..d4ae9654 100644 --- a/cmd/wmii/frame.c +++ b/cmd/wmii/frame.c @@ -285,9 +285,9 @@ resize_frame(Frame *f, Rectangle r) { } pt = ZP; - if(!f->client->borderless) + if(!f->client->borderless || !f->area->floating) pt.y += 1; - if(!f->client->titleless) + if(!f->client->titleless || !f->area->floating) pt.y += labelh(def.font) - 1; if(f->area->floating) { @@ -324,7 +324,7 @@ swap_frames(Frame *fa, Frame *fb) { Client *c; if(fa == fb) return; - + for(fp = &fa->client->frame; *fp; fp = &(*fp)->cnext) if(*fp == fa) break; *fp = (*fp)->cnext; @@ -378,7 +378,7 @@ focus_frame(Frame *f, Bool restack) { } int -frame_delta_h() { +frame_delta_h(void) { return def.border + labelh(def.font); } @@ -438,7 +438,7 @@ draw_frame(Frame *f) { } void -draw_frames() { +draw_frames(void) { Client *c; for(c=client; c; c=c->next) diff --git a/cmd/wmii/fs.c b/cmd/wmii/fs.c index b3546391..a245e5a2 100644 --- a/cmd/wmii/fs.c +++ b/cmd/wmii/fs.c @@ -135,7 +135,7 @@ static Dirtab *dirtab[] = { /* Utility Functions */ static FileId * -get_file() { +get_file(void) { FileId *temp; if(!free_fileid) { uint i = 15; diff --git a/cmd/wmii/geom.c b/cmd/wmii/geom.c index dc17d177..efd892f1 100644 --- a/cmd/wmii/geom.c +++ b/cmd/wmii/geom.c @@ -1,4 +1,4 @@ -/* Copyright ©2004-2006 Anselm R. Garbe +/* Copyright ©2006-2007 Kris Maglione * See LICENSE file for license details. */ #include diff --git a/cmd/wmii/key.c b/cmd/wmii/key.c index 63a51659..8693fb80 100644 --- a/cmd/wmii/key.c +++ b/cmd/wmii/key.c @@ -9,7 +9,7 @@ #include "fns.h" void -init_lock_keys() { +init_lock_keys(void) { XModifierKeymap *modmap; KeyCode num_lock; static int masks[] = { @@ -213,7 +213,7 @@ kpress(XWindow w, ulong mod, KeyCode keycode) { } void -update_keys() { +update_keys(void) { Key *k, *n; char *l, *p; diff --git a/cmd/wmii/main.c b/cmd/wmii/main.c index ac7abe85..ffe538b5 100644 --- a/cmd/wmii/main.c +++ b/cmd/wmii/main.c @@ -29,12 +29,12 @@ static struct passwd *passwd; static int sleeperfd, sock, exitsignal; static void -usage() { +usage(void) { fatal("usage: wmii [-a
] [-r ] [-v]\n"); } static void -scan_wins() { +scan_wins(void) { int i; uint num; XWindow *wins; @@ -63,7 +63,7 @@ scan_wins() { } static char* -ns_display() { +ns_display(void) { char *s, *disp; disp = getenv("DISPLAY"); @@ -102,7 +102,7 @@ rmkdir(char *path, int mode) { } static void -init_ns() { +init_ns(void) { struct stat st; char *s; @@ -131,7 +131,7 @@ init_ns() { } static void -init_environment() { +init_environment(void) { init_ns(); if(address == nil) { @@ -144,7 +144,7 @@ init_environment() { } static void -init_atoms() { +init_atoms(void) { Atom net[] = { xatom("_NET_SUPPORTED"), xatom("_NET_WM_NAME") }; changeprop(&scr.root, "_NET_SUPPORTED", "ATOM", net, nelem(net)); @@ -156,7 +156,7 @@ create_cursor(int ident, uint shape) { } static void -init_cursors() { +init_cursors(void) { Pixmap pix; XColor black, dummy; @@ -218,7 +218,7 @@ init_screen(WMScreen *screen) { } static void -cleanup() { +cleanup(void) { while(client) destroy_client(client); ixp_server_close(&srv); @@ -282,7 +282,7 @@ cleanup_handler(int signal) { } static void -init_traps() { +init_traps(void) { char buf[1]; int fd[2]; diff --git a/cmd/wmii/message.c b/cmd/wmii/message.c index ce1a28aa..a8bec29b 100644 --- a/cmd/wmii/message.c +++ b/cmd/wmii/message.c @@ -324,7 +324,7 @@ message_root(void *p, Message *m) { } char * -read_root_ctl() { +read_root_ctl(void) { uint i = 0; i += snprintf(&buffer[i], (sizeof(buffer) - i), "view %s\n", screen->sel->name); i += snprintf(&buffer[i], (sizeof(buffer) - i), "focuscolors %s\n", def.focuscolor.colstr); diff --git a/cmd/wmii/mouse.c b/cmd/wmii/mouse.c index 04287ebe..f1e8a250 100644 --- a/cmd/wmii/mouse.c +++ b/cmd/wmii/mouse.c @@ -245,7 +245,7 @@ do_managed_move(Client *c) { pt2.x = f->area->r.min.x; pt2.y = pt.y; fw = framewin(f, pt2, OHoriz, Dx(f->area->r)); - + r = screen->r; r.min.y += fw->gb.min.y + Dy(fw->gb)/2; r.max.y = r.min.y + 1; @@ -415,7 +415,7 @@ mouse_resizecolframe(Frame *f, Align align) { } } if(align&WEST) { - if(a->prev) { + if(a->prev != v->area) { r.min.x = a->prev->r.min.x + min.x; r.max.x = a->r.max.x - min.x; }else { @@ -446,7 +446,7 @@ mouse_resizecolframe(Frame *f, Align align) { if(!grabpointer(&scr.root, cwin, cursor[CurSizing], MouseMask)) goto done; - + pt.x = ((align&WEST) ? f->r.min.x : f->r.max.x); pt.y = ((align&NORTH) ? f->r.min.y : f->r.max.y); warppointer(pt); diff --git a/cmd/wmii/printevent.c b/cmd/wmii/printevent.c index 7385a50f..22e623d2 100644 --- a/cmd/wmii/printevent.c +++ b/cmd/wmii/printevent.c @@ -1,49 +1,47 @@ /* * Original code posted to comp.sources.x * Modifications by Russ Cox . + * Further modifications by Kris Maglione */ /* -Path: uunet!wyse!mikew -From: mikew@wyse.wyse.com (Mike Wexler) -Newsgroups: comp.sources.x -Subject: v02i056: subroutine to print events in human readable form, Part01/01 -Message-ID: <1935@wyse.wyse.com> -Date: 22 Dec 88 19:28:25 GMT -Organization: Wyse Technology, San Jose -Lines: 1093 -Approved: mikew@wyse.com - -Submitted-by: richsun!darkstar!ken -Posting-number: Volume 2, Issue 56 -Archive-name: showevent/part01 - - -There are times during debugging when it would be real useful to be able to -print the fields of an event in a human readable form. Too many times I found -myself scrounging around in section 8 of the Xlib manual looking for the valid -fields for the events I wanted to see, then adding printf's to display the -numeric values of the fields, and then scanning through X.h trying to decode -the cryptic detail and state fields. After playing with xev, I decided to -write a couple of standard functions that I could keep in a library and call -on whenever I needed a little debugging verbosity. The first function, -GetType(), is useful for returning the string representation of the type of -an event. The second function, ShowEvent(), is used to display all the fields -of an event in a readable format. The functions are not complicated, in fact, -they are mind-numbingly boring - but that's just the point nobody wants to -spend the time writing functions like this, they just want to have them when -they need them. - -A simple, sample program is included which does little else but to demonstrate -the use of these two functions. These functions have saved me many an hour -during debugging and I hope you find some benefit to these. If you have any -comments, suggestions, improvements, or if you find any blithering errors you -can get it touch with me at the following location: - - ken@richsun.UUCP -*/ + * Path: uunet!wyse!mikew From: mikew@wyse.wyse.com (Mike Wexler) Newsgroups: + * comp.sources.x Subject: v02i056: subroutine to print events in human + * readable form, Part01/01 Message-ID: <1935@wyse.wyse.com> Date: 22 Dec 88 + * 19:28:25 GMT Organization: Wyse Technology, San Jose Lines: 1093 Approved: + * mikew@wyse.com + * + * Submitted-by: richsun!darkstar!ken Posting-number: Volume 2, Issue 56 + * Archive-name: showevent/part01 + * + * + * There are times during debugging when it would be real useful to be able to + * print the fields of an event in a human readable form. Too many times I + * found myself scrounging around in section 8 of the Xlib manual looking for + * the valid fields for the events I wanted to see, then adding printf's to + * display the numeric values of the fields, and then scanning through X.h + * trying to decode the cryptic detail and state fields. After playing with + * xev, I decided to write a couple of standard functions that I could keep + * in a library and call on whenever I needed a little debugging verbosity. + * The first function, GetType(), is useful for returning the string + * representation of the type of an event. The second function, ShowEvent(), + * is used to display all the fields of an event in a readable format. The + * functions are not complicated, in fact, they are mind-numbingly boring - + * but that's just the point nobody wants to spend the time writing functions + * like this, they just want to have them when they need them. + * + * A simple, sample program is included which does little else but to + * demonstrate the use of these two functions. These functions have saved me + * many an hour during debugging and I hope you find some benefit to these. + * If you have any comments, suggestions, improvements, or if you find any + * blithering errors you can get it touch with me at the following location: + * + * ken@richsun.UUCP + */ +#include #include +#include #include #include #include @@ -51,413 +49,511 @@ can get it touch with me at the following location: //#include "fns.h" #include "printevent.h" +#define nil ((void*)0) + +typedef struct Pair Pair; + +struct Pair { + int key; + char *val; +}; + static char* sep = " "; +char * +search(Pair *lst, int key, char *(*def)(int)) { + for(; lst->val; lst++) + if(lst->key == key) + return lst->val; + return def(key); +} + +static char buffer[512]; + +char * +unmask(Pair * list, uint val) +{ + Pair *p; + char *s, *end; + Boolean first = True; + + buffer[0] = '\0'; + end = buffer + sizeof buffer; + s = buffer; + + s += strlcat(s, "(", end - s); + + for (p = list; p->val; p++) + if (val & p->key) { + if (!first) + s += strlcat(s, "|", end - s); + first = False; + s += strlcat(s, p->val, end - s); + } + + s += strlcat(s, ")", end - s); + + return buffer; +} + +static char * +strhex(int key) { + sprintf(buffer, "0x%x", key); + return buffer; +} + +static char * +strdec(int key) { + sprintf(buffer, "%d", key); + return buffer; +} + +static char * +strign(int key) { + return "?"; +} + /******************************************************************************/ /**** Miscellaneous routines to convert values to their string equivalents ****/ /******************************************************************************/ -/* Returns the string equivalent of a boolean parameter */ -static char* -TorF(int bool) +static char * +Self(char *str) { - switch (bool) { - case True: - return ("True"); - - case False: - return ("False"); - - default: - return ("?"); - } -} - -/* Returns the string equivalent of a property notify state */ -static char* -PropertyState(int state) -{ - switch (state) { - case PropertyNewValue: - return ("PropertyNewValue"); - - case PropertyDelete: - return ("PropertyDelete"); - - default: - return ("?"); - } -} - -/* Returns the string equivalent of a visibility notify state */ -static char* -VisibilityState(int state) -{ - switch (state) { - case VisibilityUnobscured: - return ("VisibilityUnobscured"); - - case VisibilityPartiallyObscured: - return ("VisibilityPartiallyObscured"); - - case VisibilityFullyObscured: - return ("VisibilityFullyObscured"); - - default: - return ("?"); - } + strncpy(buffer, str, sizeof buffer); + free(str); + return buffer; } /* Returns the string equivalent of a timestamp */ -static char* +static char * ServerTime(Time time) { - ulong msec; - ulong sec; - ulong min; - ulong hr; - ulong day; - static char buffer[32]; + ulong msec; + ulong sec; + ulong min; + ulong hr; + ulong day; - msec = time % 1000; - time /= 1000; - sec = time % 60; - time /= 60; - min = time % 60; - time /= 60; - hr = time % 24; - time /= 24; - day = time; + msec = time % 1000; + time /= 1000; + sec = time % 60; + time /= 60; + min = time % 60; + time /= 60; + hr = time % 24; + time /= 24; + day = time; -if(0) - sprintf(buffer, "%lu day%s %02lu:%02lu:%02lu.%03lu", - day, day == 1 ? "" : "(s)", hr, min, sec, msec); + if (0) + sprintf(buffer, "%lu day%s %02lu:%02lu:%02lu.%03lu", + day, day == 1 ? "" : "(s)", hr, min, sec, msec); - sprintf(buffer, "%lud%luh%lum%lu.%03lds", day, hr, min, sec, msec); - return (buffer); + sprintf(buffer, "%lud%luh%lum%lu.%03lds", day, hr, min, sec, msec); + return buffer; } -/* Simple structure to ease the interpretation of masks */ -typedef struct MaskType MaskType; -struct MaskType +/* Returns the string equivalent of a boolean parameter */ +static char * +TorF(int key) { - uint value; - char *string; -}; + static Pair list[] = { + {True, "True"}, + {False, "False"}, + {0, nil}, + }; + + return search(list, key, strign); +} + +/* Returns the string equivalent of a property notify state */ +static char * +PropertyState(int key) +{ + static Pair list[] = { + {PropertyNewValue, "PropertyNewValue"}, + {PropertyDelete, "PropertyDelete"}, + {0, nil}, + }; + + return search(list, key, strign); +} + +/* Returns the string equivalent of a visibility notify state */ +static char * +VisibilityState(int key) +{ + static Pair list[] = { + {VisibilityUnobscured, "VisibilityUnobscured"}, + {VisibilityPartiallyObscured, "VisibilityPartiallyObscured"}, + {VisibilityFullyObscured, "VisibilityFullyObscured"}, + {0, nil}, + }; + + return search(list, key, strign); +} /* Returns the string equivalent of a mask of buttons and/or modifier keys */ -static char* +static char * ButtonAndOrModifierState(uint state) { - static char buffer[256]; - static MaskType masks[] = { - {Button1Mask, "Button1Mask"}, - {Button2Mask, "Button2Mask"}, - {Button3Mask, "Button3Mask"}, - {Button4Mask, "Button4Mask"}, - {Button5Mask, "Button5Mask"}, - {ShiftMask, "ShiftMask"}, - {LockMask, "LockMask"}, - {ControlMask, "ControlMask"}, - {Mod1Mask, "Mod1Mask"}, - {Mod2Mask, "Mod2Mask"}, - {Mod3Mask, "Mod3Mask"}, - {Mod4Mask, "Mod4Mask"}, - {Mod5Mask, "Mod5Mask"}, - }; - int num_masks = sizeof(masks) / sizeof(MaskType); - int i; - Boolean first = True; + static Pair list[] = { + {Button1Mask, "Button1Mask"}, + {Button2Mask, "Button2Mask"}, + {Button3Mask, "Button3Mask"}, + {Button4Mask, "Button4Mask"}, + {Button5Mask, "Button5Mask"}, + {ShiftMask, "ShiftMask"}, + {LockMask, "LockMask"}, + {ControlMask, "ControlMask"}, + {Mod1Mask, "Mod1Mask"}, + {Mod2Mask, "Mod2Mask"}, + {Mod3Mask, "Mod3Mask"}, + {Mod4Mask, "Mod4Mask"}, + {Mod5Mask, "Mod5Mask"}, + {0, nil}, + }; - buffer[0] = 0; - - for (i = 0; i < num_masks; i++) - if (state & masks[i].value) { - if (first) { - first = False; - strcpy(buffer, masks[i].string); - } else { - strcat(buffer, " | "); - strcat(buffer, masks[i].string); - } - } - return (buffer); + return unmask(list, state); } /* Returns the string equivalent of a mask of configure window values */ -static char* +static char * ConfigureValueMask(uint valuemask) { - static char buffer[256]; - static MaskType masks[] = { - {CWX, "CWX"}, - {CWY, "CWY"}, - {CWWidth, "CWWidth"}, - {CWHeight, "CWHeight"}, - {CWBorderWidth, "CWBorderWidth"}, - {CWSibling, "CWSibling"}, - {CWStackMode, "CWStackMode"}, - }; - int num_masks = sizeof(masks) / sizeof(MaskType); - int i; - Boolean first = True; + static Pair list[] = { + {CWX, "CWX"}, + {CWY, "CWY"}, + {CWWidth, "CWWidth"}, + {CWHeight, "CWHeight"}, + {CWBorderWidth, "CWBorderWidth"}, + {CWSibling, "CWSibling"}, + {CWStackMode, "CWStackMode"}, + {0, nil}, + }; - buffer[0] = 0; - - for (i = 0; i < num_masks; i++) - if (valuemask & masks[i].value) { - if (first) { - first = False; - strcpy(buffer, masks[i].string); - } else { - strcat(buffer, " | "); - strcat(buffer, masks[i].string); - } - } - - return (buffer); + return unmask(list, valuemask); } /* Returns the string equivalent of a motion hint */ -static char* -IsHint(char is_hint) +#if 0 +static char * +IsHint(char key) { - switch (is_hint) { - case NotifyNormal: - return ("NotifyNormal"); + static Pair list[] = { + {NotifyNormal, "NotifyNormal"}, + {NotifyHint, "NotifyHint"}, + {0, nil}, + }; - case NotifyHint: - return ("NotifyHint"); - - default: - return ("?"); - } + return search(list, key, strign); } +#endif /* Returns the string equivalent of an id or the value "None" */ -static char* -MaybeNone(int value) +static char * +MaybeNone(int key) { - static char buffer[16]; + static Pair list[] = { + {None, "None"}, + {0, nil}, + }; - if (value == None) - return ("None"); - else { - sprintf(buffer, "0x%x", value); - return (buffer); - } + return search(list, key, strhex); } /* Returns the string equivalent of a colormap state */ -static char* -ColormapState(int state) +static char * +ColormapState(int key) { - switch (state) { - case ColormapInstalled: - return ("ColormapInstalled"); + static Pair list[] = { + {ColormapInstalled, "ColormapInstalled"}, + {ColormapUninstalled, "ColormapUninstalled"}, + {0, nil}, + }; - case ColormapUninstalled: - return ("ColormapUninstalled"); - - default: - return ("?"); - } + return search(list, key, strign); } /* Returns the string equivalent of a crossing detail */ -static char* -CrossingDetail(int detail) +static char * +CrossingDetail(int key) { - switch (detail) { - case NotifyAncestor: - return ("NotifyAncestor"); + static Pair list[] = { + {NotifyAncestor, "NotifyAncestor"}, + {NotifyInferior, "NotifyInferior"}, + {NotifyVirtual, "NotifyVirtual"}, + {NotifyNonlinear, "NotifyNonlinear"}, + {NotifyNonlinearVirtual, "NotifyNonlinearVirtual"}, + {0, nil}, + }; - case NotifyInferior: - return ("NotifyInferior"); - - case NotifyVirtual: - return ("NotifyVirtual"); - - case NotifyNonlinear: - return ("NotifyNonlinear"); - - case NotifyNonlinearVirtual: - return ("NotifyNonlinearVirtual"); - - default: - return ("?"); - } + return search(list, key, strign); } /* Returns the string equivalent of a focus change detail */ -static char* -FocusChangeDetail(int detail) +static char * +FocusChangeDetail(int key) { - switch (detail) { - case NotifyAncestor: - return ("NotifyAncestor"); + static Pair list[] = { + {NotifyAncestor, "NotifyAncestor"}, + {NotifyInferior, "NotifyInferior"}, + {NotifyVirtual, "NotifyVirtual"}, + {NotifyNonlinear, "NotifyNonlinear"}, + {NotifyNonlinearVirtual, "NotifyNonlinearVirtual"}, + {NotifyPointer, "NotifyPointer"}, + {NotifyPointerRoot, "NotifyPointerRoot"}, + {NotifyDetailNone, "NotifyDetailNone"}, + {0, nil}, + }; - case NotifyInferior: - return ("NotifyInferior"); - - case NotifyVirtual: - return ("NotifyVirtual"); - - case NotifyNonlinear: - return ("NotifyNonlinear"); - - case NotifyNonlinearVirtual: - return ("NotifyNonlinearVirtual"); - - case NotifyPointer: - return ("NotifyPointer"); - - case NotifyPointerRoot: - return ("NotifyPointerRoot"); - - case NotifyDetailNone: - return ("NotifyDetailNone"); - - default: - return ("?"); - } + return search(list, key, strign); } /* Returns the string equivalent of a configure detail */ -static char* -ConfigureDetail(int detail) +static char * +ConfigureDetail(int key) { - switch (detail) { - case Above: - return ("Above"); + static Pair list[] = { + {Above, "Above"}, + {Below, "Below"}, + {TopIf, "TopIf"}, + {BottomIf, "BottomIf"}, + {Opposite, "Opposite"}, + {0, nil}, + }; - case Below: - return ("Below"); - - case TopIf: - return ("TopIf"); - - case BottomIf: - return ("BottomIf"); - - case Opposite: - return ("Opposite"); - - default: - return ("?"); - } + return search(list, key, strign); } /* Returns the string equivalent of a grab mode */ -static char* -GrabMode(int mode) +static char * +GrabMode(int key) { - switch (mode) { - case NotifyNormal: - return ("NotifyNormal"); + static Pair list[] = { + {NotifyNormal, "NotifyNormal"}, + {NotifyGrab, "NotifyGrab"}, + {NotifyUngrab, "NotifyUngrab"}, + {NotifyWhileGrabbed, "NotifyWhileGrabbed"}, + {0, nil}, + }; - case NotifyGrab: - return ("NotifyGrab"); - - case NotifyUngrab: - return ("NotifyUngrab"); - - case NotifyWhileGrabbed: - return ("NotifyWhileGrabbed"); - - default: - return ("?"); - } + return search(list, key, strign); } /* Returns the string equivalent of a mapping request */ -static char* -MappingRequest(int request) +static char * +MappingRequest(int key) { - switch (request) { - case MappingModifier: - return ("MappingModifier"); + static Pair list[] = { + {MappingModifier, "MappingModifier"}, + {MappingKeyboard, "MappingKeyboard"}, + {MappingPointer, "MappingPointer"}, + {0, nil}, + }; - case MappingKeyboard: - return ("MappingKeyboard"); - - case MappingPointer: - return ("MappingPointer"); - - default: - return ("?"); - } + return search(list, key, strign); } /* Returns the string equivalent of a stacking order place */ -static char* -Place(int place) +static char * +Place(int key) { - switch (place) { - case PlaceOnTop: - return ("PlaceOnTop"); + static Pair list[] = { + {PlaceOnTop, "PlaceOnTop"}, + {PlaceOnBottom, "PlaceOnBottom"}, + {0, nil}, + }; - case PlaceOnBottom: - return ("PlaceOnBottom"); - - default: - return ("?"); - } + return search(list, key, strign); } /* Returns the string equivalent of a major code */ -static char* -MajorCode(int code) +static char * +MajorCode(int key) { - static char buffer[32]; + static Pair list[] = { + {X_CopyArea, "X_CopyArea"}, + {X_CopyPlane, "X_CopyPlane"}, + {0, nil}, + }; - switch (code) { - case X_CopyArea: - return ("X_CopyArea"); - - case X_CopyPlane: - return ("X_CopyPlane"); - - default: - sprintf(buffer, "0x%x", code); - return (buffer); - } + return search(list, key, strhex); } +static char * +eventtype(int key) +{ + static Pair list[] = { + {ButtonPress, "ButtonPress"}, + {ButtonRelease, "ButtonRelease"}, + {CirculateNotify, "CirculateNotify"}, + {CirculateRequest, "CirculateRequest"}, + {ClientMessage, "ClientMessage"}, + {ColormapNotify, "ColormapNotify"}, + {ConfigureNotify, "ConfigureNotify"}, + {ConfigureRequest, "ConfigureRequest"}, + {CreateNotify, "CreateNotify"}, + {DestroyNotify, "DestroyNotify"}, + {EnterNotify, "EnterNotify"}, + {Expose, "Expose"}, + {FocusIn, "FocusIn"}, + {FocusOut, "FocusOut"}, + {GraphicsExpose, "GraphicsExpose"}, + {GravityNotify, "GravityNotify"}, + {KeyPress, "KeyPress"}, + {KeyRelease, "KeyRelease"}, + {KeymapNotify, "KeymapNotify"}, + {LeaveNotify, "LeaveNotify"}, + {MapNotify, "MapNotify"}, + {MapRequest, "MapRequest"}, + {MappingNotify, "MappingNotify"}, + {MotionNotify, "MotionNotify"}, + {NoExpose, "NoExpose"}, + {PropertyNotify, "PropertyNotify"}, + {ReparentNotify, "ReparentNotify"}, + {ResizeRequest, "ResizeRequest"}, + {SelectionClear, "SelectionClear"}, + {SelectionNotify, "SelectionNotify"}, + {SelectionRequest, "SelectionRequest"}, + {UnmapNotify, "UnmapNotify"}, + {VisibilityNotify, "VisibilityNotify"}, + {0, nil}, + }; + + return search(list, key, strdec); +} /* Returns the string equivalent the keycode contained in the key event */ static char* -Keycode(XKeyEvent *ev) +Keycode(XKeyEvent * ev) { - static char buffer[256]; - KeySym keysym_str; - char *keysym_name; - char string[256]; + KeySym keysym_str; + char *keysym_name; - XLookupString(ev, string, 64, &keysym_str, NULL); + XLookupString(ev, buffer, sizeof buffer, &keysym_str, NULL); - if (keysym_str == NoSymbol) - keysym_name = "NoSymbol"; - else if (!(keysym_name = XKeysymToString(keysym_str))) - keysym_name = "(no name)"; - sprintf(buffer, "%u (keysym 0x%x \"%s\")", - (int)ev->keycode, (int)keysym_str, keysym_name); - return (buffer); + if (keysym_str == NoSymbol) + keysym_name = "NoSymbol"; + else + keysym_name = XKeysymToString(keysym_str); + if(keysym_name == nil) + keysym_name = "(no name)"; + + snprintf(buffer, sizeof buffer, "%u (keysym 0x%x \"%s\")", + (int)ev->keycode, (int)keysym_str, keysym_name); + return buffer; } -/* Returns the string equivalent of an atom or "None"*/ -static char* -AtomName(Display *dpy, Atom atom) +/* Returns the string equivalent of an atom or "None" */ +static char * +AtomName(Atom atom) { - static char buffer[256]; - char *atom_name; + extern Display *display; + char *atom_name; - if (atom == None) - return ("None"); + if (atom == None) + return "None"; - atom_name = XGetAtomName(dpy, atom); - strncpy(buffer, atom_name, 256); - XFree(atom_name); - return (buffer); + atom_name = XGetAtomName(display, atom); + strncpy(buffer, atom_name, sizeof buffer); + XFree(atom_name); + + return buffer; +} + +#define _(m) #m, ev->m + +enum { + TEnd, + TAtom, + TBool, + TColMap, + TConfDetail, + TConfMask, + TFocus, + TGrabMode, + TInt, + TIntNone, + TMajor, + TMapping, + TModState, + TPlace, + TPropState, + TString, + TTime, + TVis, + TWindow, + TXing, +}; + +typedef struct TypeTab TypeTab; + +struct TypeTab { + int size; + char *(*fn)(); +} ttab[] = { + [TEnd] = {0, nil}, + [TAtom] = {sizeof(Atom), AtomName}, + [TBool] = {sizeof(Bool), TorF}, + [TColMap] = {sizeof(int), ColormapState}, + [TConfDetail] = {sizeof(int), ConfigureDetail}, + [TConfMask] = {sizeof(int), ConfigureValueMask}, + [TFocus] = {sizeof(int), FocusChangeDetail}, + [TGrabMode] = {sizeof(int), GrabMode}, + [TIntNone] = {sizeof(int), MaybeNone}, + [TInt] = {sizeof(int), strdec}, + [TMajor] = {sizeof(int), MajorCode}, + [TMapping] = {sizeof(int), MappingRequest}, + [TModState] = {sizeof(int), ButtonAndOrModifierState}, + [TPlace] = {sizeof(int), Place}, + [TPropState] = {sizeof(int), PropertyState}, + [TString] = {sizeof(char*), Self}, + [TTime] = {sizeof(Time), ServerTime}, + [TVis] = {sizeof(int), VisibilityState}, + [TWindow] = {sizeof(Window), strhex}, + [TXing] = {sizeof(int), CrossingDetail}, +}; + +static void +pevent(void *ev, ...) { + static char buf[4096]; + static char *bend = buf + sizeof(buf); + va_list ap; + TypeTab *t; + char *p, *key, *val; + int n, type, valint; + + va_start(ap, ev); + + p = buf; + *p = '\0'; + n = 0; + for(;;) { + type = va_arg(ap, int); + if(type == TEnd) + break; + t = &ttab[type]; + + key = va_arg(ap, char*); + switch(t->size) { + default: + break; /* Can't continue */ + case sizeof(int): + valint = va_arg(ap, int); + val = t->fn(valint); + break; + } + + if(n++ != 0) + p += strlcat(p, sep, bend-p); + p += snprintf(p, bend-p, "%s=%s", key, val); + + if(p >= bend) + break; + } + fprintf(stderr, "%s\n", buf); + + va_end(ap); } /******************************************************************************/ @@ -467,534 +563,448 @@ AtomName(Display *dpy, Atom atom) static void VerbMotion(XMotionEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "root=0x%x%s", (int)ev->root, sep); - fprintf(stderr, "subwindow=0x%x%s", (int)ev->subwindow, sep); - fprintf(stderr, "time=%s%s", ServerTime(ev->time), sep); - fprintf(stderr, "x=%d y=%d%s", ev->x, ev->y, sep); - fprintf(stderr, "x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - fprintf(stderr, "state=%s%s", ButtonAndOrModifierState(ev->state), sep); - fprintf(stderr, "is_hint=%s%s", IsHint(ev->is_hint), sep); - fprintf(stderr, "same_screen=%s\n", TorF(ev->same_screen)); + pevent(ev, + TWindow, _(window), + TWindow, _(root), + TWindow, _(subwindow), + TTime, _(time), + TInt, _(x), TInt, _(y), + TInt, _(x_root), TInt, _(y_root), + TModState, _(state), + TBool, _(same_screen), + TEnd + ); + //fprintf(stderr, "is_hint=%s%s", IsHint(ev->is_hint), sep); } static void VerbButton(XButtonEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "root=0x%x%s", (int)ev->root, sep); - fprintf(stderr, "subwindow=0x%x%s", (int)ev->subwindow, sep); - fprintf(stderr, "time=%s%s", ServerTime(ev->time), sep); - fprintf(stderr, "x=%d y=%d%s", ev->x, ev->y, sep); - fprintf(stderr, "x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - fprintf(stderr, "state=%s%s", ButtonAndOrModifierState(ev->state), sep); - fprintf(stderr, "button=%s%s", ButtonAndOrModifierState(ev->button), sep); - fprintf(stderr, "same_screen=%s\n", TorF(ev->same_screen)); + pevent(ev, + TWindow, _(window), + TWindow, _(root), + TWindow, _(subwindow), + TTime, _(time), + TInt, _(x), TInt, _(y), + TInt, _(x_root), TInt, _(y_root), + TModState, _(state), + TModState, _(button), + TBool, _(same_screen), + TEnd + ); } static void VerbColormap(XColormapEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "colormap=%s%s", MaybeNone(ev->colormap), sep); - fprintf(stderr, "new=%s%s", TorF(ev->new), sep); - fprintf(stderr, "state=%s\n", ColormapState(ev->state)); + pevent(ev, + TWindow, _(window), + TIntNone, _(colormap), + TBool, _(new), + TColMap, _(state), + TEnd + ); } static void VerbCrossing(XCrossingEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "root=0x%x%s", (int)ev->root, sep); - fprintf(stderr, "subwindow=0x%x%s", (int)ev->subwindow, sep); - fprintf(stderr, "time=%s%s", ServerTime(ev->time), sep); - fprintf(stderr, "x=%d y=%d%s", ev->x, ev->y, sep); - fprintf(stderr, "x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - fprintf(stderr, "mode=%s%s", GrabMode(ev->mode), sep); - fprintf(stderr, "detail=%s%s", CrossingDetail(ev->detail), sep); - fprintf(stderr, "same_screen=%s%s", TorF(ev->same_screen), sep); - fprintf(stderr, "focus=%s%s", TorF(ev->focus), sep); - fprintf(stderr, "state=%s\n", ButtonAndOrModifierState(ev->state)); + pevent(ev, + TWindow, _(window), + TWindow, _(root), + TWindow, _(subwindow), + TTime, _(time), + TInt, _(x), TInt, _(y), + TInt, _(x_root), TInt, _(y_root), + TGrabMode, _(mode), + TXing, _(detail), + TBool, _(same_screen), + TBool, _(focus), + TModState, _(state), + TEnd + ); } static void VerbExpose(XExposeEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "x=%d y=%d%s", ev->x, ev->y, sep); - fprintf(stderr, "width=%d height=%d%s", ev->width, ev->height, sep); - fprintf(stderr, "count=%d\n", ev->count); + pevent(ev, + TWindow, _(window), + TInt, _(x), TInt, _(y), + TInt, _(width), TInt, _(height), + TInt, _(count), + TEnd + ); } static void VerbGraphicsExpose(XGraphicsExposeEvent *ev) { - fprintf(stderr, "drawable=0x%x%s", (int)ev->drawable, sep); - fprintf(stderr, "x=%d y=%d%s", ev->x, ev->y, sep); - fprintf(stderr, "width=%d height=%d%s", ev->width, ev->height, sep); - fprintf(stderr, "major_code=%s%s", MajorCode(ev->major_code), sep); - fprintf(stderr, "minor_code=%d\n", ev->minor_code); + pevent(ev, + TWindow, _(drawable), + TInt, _(x), TInt, _(y), + TInt, _(width), TInt, _(height), + TMajor, _(major_code), + TInt, _(minor_code), + TEnd + ); } static void VerbNoExpose(XNoExposeEvent *ev) { - fprintf(stderr, "drawable=0x%x%s", (int)ev->drawable, sep); - fprintf(stderr, "major_code=%s%s", MajorCode(ev->major_code), sep); - fprintf(stderr, "minor_code=%d\n", ev->minor_code); + pevent(ev, + TWindow, _(drawable), + TMajor, _(major_code), + TInt, _(minor_code), + TEnd + ); } static void VerbFocus(XFocusChangeEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "mode=%s%s", GrabMode(ev->mode), sep); - fprintf(stderr, "detail=%s\n", FocusChangeDetail(ev->detail)); + pevent(ev, + TWindow, _(window), + TGrabMode, _(mode), + TFocus, _(detail), + TEnd + ); } static void -VerbKeymap(XKeymapEvent *ev) +VerbKeymap(XKeymapEvent * ev) { - int i; + int i; - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "key_vector="); - for (i = 0; i < 32; i++) - fprintf(stderr, "%02x", ev->key_vector[i]); - fprintf(stderr, "\n"); + fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); + fprintf(stderr, "key_vector="); + for (i = 0; i < 32; i++) + fprintf(stderr, "%02x", ev->key_vector[i]); + fprintf(stderr, "\n"); } static void VerbKey(XKeyEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "root=0x%x%s", (int)ev->root, sep); - if(ev->subwindow) - fprintf(stderr, "subwindow=0x%x%s", (int)ev->subwindow, sep); - fprintf(stderr, "time=%s%s", ServerTime(ev->time), sep); - fprintf(stderr, "[%d,%d]%s", ev->x, ev->y, sep); - fprintf(stderr, "root=[%d,%d]%s", ev->x_root, ev->y_root, sep); - if(ev->state) - fprintf(stderr, "state=%s%s", ButtonAndOrModifierState(ev->state), sep); - fprintf(stderr, "keycode=%s%s", Keycode(ev), sep); - if(!ev->same_screen) - fprintf(stderr, "!same_screen"); - fprintf(stderr, "\n"); - return; - - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "root=0x%x%s", (int)ev->root, sep); - fprintf(stderr, "subwindow=0x%x%s", (int)ev->subwindow, sep); - fprintf(stderr, "time=%s%s", ServerTime(ev->time), sep); - fprintf(stderr, "x=%d y=%d%s", ev->x, ev->y, sep); - fprintf(stderr, "x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - fprintf(stderr, "state=%s%s", ButtonAndOrModifierState(ev->state), sep); - fprintf(stderr, "keycode=%s%s", Keycode(ev), sep); - fprintf(stderr, "same_screen=%s\n", TorF(ev->same_screen)); + pevent(ev, + TWindow, _(window), + TWindow, _(root), + TWindow, _(subwindow), + TTime, _(time), + TInt, _(x), TInt, _(y), + TInt, _(x_root), TInt, _(y_root), + TModState, _(state), + TString, "keycode", estrdup(Keycode(ev)), + TBool, _(same_screen), + TEnd + ); } static void VerbProperty(XPropertyEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "atom=%s%s", AtomName(ev->display, ev->atom), sep); - fprintf(stderr, "time=%s%s", ServerTime(ev->time), sep); - fprintf(stderr, "state=%s\n", PropertyState(ev->state)); + pevent(ev, + TWindow, _(window), + TAtom, _(atom), + TTime, _(time), + TPropState, _(state), + TEnd + ); } static void VerbResizeRequest(XResizeRequestEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "width=%d height=%d\n", ev->width, ev->height); + pevent(ev, + TWindow, _(window), + TInt, _(width), TInt, _(height), + TEnd + ); } static void VerbCirculate(XCirculateEvent *ev) { - fprintf(stderr, "event=0x%x%s", (int)ev->event, sep); - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "place=%s\n", Place(ev->place)); + pevent(ev, + TWindow, _(event), + TWindow, _(window), + TPlace, _(place), + TEnd + ); } static void VerbConfigure(XConfigureEvent *ev) { - fprintf(stderr, "event=0x%x%s", (int)ev->event, sep); - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "x=%d y=%d%s", ev->x, ev->y, sep); - fprintf(stderr, "width=%d height=%d%s", ev->width, ev->height, sep); - fprintf(stderr, "border_width=%d%s", ev->border_width, sep); - fprintf(stderr, "above=%s%s", MaybeNone(ev->above), sep); - fprintf(stderr, "override_redirect=%s\n", TorF(ev->override_redirect)); + pevent(ev, + TWindow, _(event), + TWindow, _(window), + TInt, _(x), TInt, _(y), + TInt, _(width), TInt, _(height), + TInt, _(border_width), + TIntNone, _(above), + TBool, _(override_redirect), + TEnd + ); } static void VerbCreateWindow(XCreateWindowEvent *ev) { - fprintf(stderr, "parent=0x%x%s", (int)ev->parent, sep); - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "x=%d y=%d%s", ev->x, ev->y, sep); - fprintf(stderr, "width=%d height=%d%s", ev->width, ev->height, sep); - fprintf(stderr, "border_width=%d%s", ev->border_width, sep); - fprintf(stderr, "override_redirect=%s\n", TorF(ev->override_redirect)); + pevent(ev, + TWindow, _(parent), + TWindow, _(window), + TInt, _(x), TInt, _(y), + TInt, _(width), TInt, _(height), + TInt, _(border_width), + TBool, _(override_redirect), + TEnd + ); } static void VerbDestroyWindow(XDestroyWindowEvent *ev) { - fprintf(stderr, "event=0x%x%s", (int)ev->event, sep); - fprintf(stderr, "window=0x%x\n", (int)ev->window); + pevent(ev, + TWindow, _(event), + TWindow, _(window), + TEnd + ); } static void VerbGravity(XGravityEvent *ev) { - fprintf(stderr, "event=0x%x%s", (int)ev->event, sep); - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "x=%d y=%d\n", ev->x, ev->y); + pevent(ev, + TWindow, _(event), + TWindow, _(window), + TInt, _(x), TInt, _(y), + TEnd + ); } static void VerbMap(XMapEvent *ev) { - fprintf(stderr, "event=0x%x%s", (int)ev->event, sep); - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "override_redirect=%s\n", TorF(ev->override_redirect)); + pevent(ev, + TWindow, _(event), + TWindow, _(window), + TBool, _(override_redirect), + TEnd + ); } static void VerbReparent(XReparentEvent *ev) { - fprintf(stderr, "event=0x%x%s", (int)ev->event, sep); - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "parent=0x%x%s", (int)ev->parent, sep); - fprintf(stderr, "x=%d y=%d%s", ev->x, ev->y, sep); - fprintf(stderr, "override_redirect=%s\n", TorF(ev->override_redirect)); + pevent(ev, + TWindow, _(event), + TWindow, _(window), + TWindow, _(parent), + TInt, _(x), TInt, _(y), + TBool, _(override_redirect), + TEnd + ); } static void VerbUnmap(XUnmapEvent *ev) { - fprintf(stderr, "event=0x%x%s", (int)ev->event, sep); - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "from_configure=%s\n", TorF(ev->from_configure)); + pevent(ev, + TWindow, _(event), + TWindow, _(window), + TBool, _(from_configure), + TEnd + ); } static void VerbCirculateRequest(XCirculateRequestEvent *ev) { - fprintf(stderr, "parent=0x%x%s", (int)ev->parent, sep); - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "place=%s\n", Place(ev->place)); + pevent(ev, + TWindow, _(parent), + TWindow, _(window), + TPlace, _(place), + TEnd + ); } static void VerbConfigureRequest(XConfigureRequestEvent *ev) { - fprintf(stderr, "parent=0x%x%s", (int)ev->parent, sep); - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "x=%d y=%d%s", ev->x, ev->y, sep); - fprintf(stderr, "width=%d height=%d%s", ev->width, ev->height, sep); - fprintf(stderr, "border_width=%d%s", ev->border_width, sep); - fprintf(stderr, "above=%s%s", MaybeNone(ev->above), sep); - fprintf(stderr, "detail=%s%s", ConfigureDetail(ev->detail), sep); - fprintf(stderr, "value_mask=%s\n", ConfigureValueMask(ev->value_mask)); + pevent(ev, + TWindow, _(parent), + TWindow, _(window), + TInt, _(x), TInt, _(y), + TInt, _(width), TInt, _(height), + TInt, _(border_width), + TIntNone, _(above), + TConfDetail, _(detail), + TConfMask, _(value_mask), + TEnd + ); } static void VerbMapRequest(XMapRequestEvent *ev) { - fprintf(stderr, "parent=0x%x%s", (int)ev->parent, sep); - fprintf(stderr, "window=0x%x\n", (int)ev->window); + pevent(ev, + TWindow, _(parent), + TWindow, _(window), + TEnd + ); } static void -VerbClient(XClientMessageEvent *ev) +VerbClient(XClientMessageEvent * ev) { - int i; + int i; - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "message_type=%s%s", AtomName(ev->display, ev->message_type), sep); - fprintf(stderr, "format=%d\n", ev->format); - fprintf(stderr, "data (shown as longs)="); - for (i = 0; i < 5; i++) - fprintf(stderr, " 0x%08lx", ev->data.l[i]); - fprintf(stderr, "\n"); + fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); + fprintf(stderr, "message_type=%s%s", AtomName(ev->message_type), sep); + fprintf(stderr, "format=%d\n", ev->format); + fprintf(stderr, "data (shown as longs)="); + for (i = 0; i < 5; i++) + fprintf(stderr, " 0x%08lx", ev->data.l[i]); + fprintf(stderr, "\n"); } static void VerbMapping(XMappingEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "request=%s%s", MappingRequest(ev->request), sep); - fprintf(stderr, "first_keycode=0x%x%s", ev->first_keycode, sep); - fprintf(stderr, "count=0x%x\n", ev->count); + pevent(ev, + TWindow, _(window), + TMapping, _(request), + TWindow, _(first_keycode), + TWindow, _(count), + TEnd + ); } static void VerbSelectionClear(XSelectionClearEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "selection=%s%s", AtomName(ev->display, ev->selection), sep); - fprintf(stderr, "time=%s\n", ServerTime(ev->time)); + pevent(ev, + TWindow, _(window), + TAtom, _(selection), + TTime, _(time), + TEnd + ); } static void VerbSelection(XSelectionEvent *ev) { - fprintf(stderr, "requestor=0x%x%s", (int)ev->requestor, sep); - fprintf(stderr, "selection=%s%s", AtomName(ev->display, ev->selection), sep); - fprintf(stderr, "target=%s%s", AtomName(ev->display, ev->target), sep); - fprintf(stderr, "property=%s%s", AtomName(ev->display, ev->property), sep); - fprintf(stderr, "time=%s\n", ServerTime(ev->time)); + pevent(ev, + TWindow, _(requestor), + TAtom, _(selection), + TAtom, _(target), + TAtom, _(property), + TTime, _(time), + TEnd + ); } static void VerbSelectionRequest(XSelectionRequestEvent *ev) { - fprintf(stderr, "owner=0x%x%s", (int)ev->owner, sep); - fprintf(stderr, "requestor=0x%x%s", (int)ev->requestor, sep); - fprintf(stderr, "selection=%s%s", AtomName(ev->display, ev->selection), sep); - fprintf(stderr, "target=%s%s", AtomName(ev->display, ev->target), sep); - fprintf(stderr, "property=%s%s", AtomName(ev->display, ev->property), sep); - fprintf(stderr, "time=%s\n", ServerTime(ev->time)); + pevent(ev, + TWindow, _(owner), + TWindow, _(requestor), + TAtom, _(selection), + TAtom, _(target), + TAtom, _(property), + TTime, _(time), + TEnd + ); } static void VerbVisibility(XVisibilityEvent *ev) { - fprintf(stderr, "window=0x%x%s", (int)ev->window, sep); - fprintf(stderr, "state=%s\n", VisibilityState(ev->state)); -} - -/******************************************************************************/ -/************ Return the string representation for type of an event ***********/ -/******************************************************************************/ - -char *eventtype(XEvent *ev) -{ - static char buffer[20]; - - switch (ev->type) { - case KeyPress: - return ("KeyPress"); - case KeyRelease: - return ("KeyRelease"); - case ButtonPress: - return ("ButtonPress"); - case ButtonRelease: - return ("ButtonRelease"); - case MotionNotify: - return ("MotionNotify"); - case EnterNotify: - return ("EnterNotify"); - case LeaveNotify: - return ("LeaveNotify"); - case FocusIn: - return ("FocusIn"); - case FocusOut: - return ("FocusOut"); - case KeymapNotify: - return ("KeymapNotify"); - case Expose: - return ("Expose"); - case GraphicsExpose: - return ("GraphicsExpose"); - case NoExpose: - return ("NoExpose"); - case VisibilityNotify: - return ("VisibilityNotify"); - case CreateNotify: - return ("CreateNotify"); - case DestroyNotify: - return ("DestroyNotify"); - case UnmapNotify: - return ("UnmapNotify"); - case MapNotify: - return ("MapNotify"); - case MapRequest: - return ("MapRequest"); - case ReparentNotify: - return ("ReparentNotify"); - case ConfigureNotify: - return ("ConfigureNotify"); - case ConfigureRequest: - return ("ConfigureRequest"); - case GravityNotify: - return ("GravityNotify"); - case ResizeRequest: - return ("ResizeRequest"); - case CirculateNotify: - return ("CirculateNotify"); - case CirculateRequest: - return ("CirculateRequest"); - case PropertyNotify: - return ("PropertyNotify"); - case SelectionClear: - return ("SelectionClear"); - case SelectionRequest: - return ("SelectionRequest"); - case SelectionNotify: - return ("SelectionNotify"); - case ColormapNotify: - return ("ColormapNotify"); - case ClientMessage: - return ("ClientMessage"); - case MappingNotify: - return ("MappingNotify"); - } - sprintf(buffer, "%d", ev->type); - return buffer; + pevent(ev, + TWindow, _(window), + TVis, _(state), + TEnd + ); } /******************************************************************************/ /**************** Print the values of all fields for any event ****************/ /******************************************************************************/ -void printevent(XEvent *e) +typedef struct Handler Handler; + +struct Handler { + int key; + void (*fn)(); +}; + +void +printevent(XEvent * e) { - extern Display* display; - XAnyEvent *ev = (void*)e; - char *name; + extern Display *display; + XAnyEvent *ev = (void *)e; + char *name; - if(ev->window) { - XFetchName(display, ev->window, &name); - if(name) { - fprintf(stderr, "\ttitle=%s\n", name); - XFree(name); - } - } - fprintf(stderr, "%3ld %-20s ", ev->serial, eventtype(e)); - if(ev->send_event) - fprintf(stderr, "(sendevent) "); - if(0){ - fprintf(stderr, "type=%s%s", eventtype(e), sep); - fprintf(stderr, "serial=%lu%s", ev->serial, sep); - fprintf(stderr, "send_event=%s%s", TorF(ev->send_event), sep); - fprintf(stderr, "display=0x%p%s", ev->display, sep); - } + if (ev->window) { + XFetchName(display, ev->window, &name); + if (name) + fprintf(stderr, "\ttitle=%s\n", name); + XFree(name); + } - switch (ev->type) { - case MotionNotify: - VerbMotion((void*)ev); - break; + fprintf(stderr, "%3ld %-20s ", ev->serial, eventtype(e->xany.type)); + if (ev->send_event) + fprintf(stderr, "(sendevent) "); + if (0) { + fprintf(stderr, "type=%s%s", eventtype(e->xany.type), sep); + fprintf(stderr, "serial=%lu%s", ev->serial, sep); + fprintf(stderr, "send_event=%s%s", TorF(ev->send_event), sep); + fprintf(stderr, "display=0x%p%s", ev->display, sep); + } + static Handler fns[] = { + {MotionNotify, VerbMotion}, + {ButtonPress, VerbButton}, + {ButtonRelease, VerbButton}, + {ColormapNotify, VerbColormap}, + {EnterNotify, VerbCrossing}, + {LeaveNotify, VerbCrossing}, + {Expose, VerbExpose}, + {GraphicsExpose, VerbGraphicsExpose}, + {NoExpose, VerbNoExpose}, + {FocusIn, VerbFocus}, + {FocusOut, VerbFocus}, + {KeymapNotify, VerbKeymap}, + {KeyPress, VerbKey}, + {KeyRelease, VerbKey}, + {PropertyNotify, VerbProperty}, + {ResizeRequest, VerbResizeRequest}, + {CirculateNotify, VerbCirculate}, + {ConfigureNotify, VerbConfigure}, + {CreateNotify, VerbCreateWindow}, + {DestroyNotify, VerbDestroyWindow}, + {GravityNotify, VerbGravity}, + {MapNotify, VerbMap}, + {ReparentNotify, VerbReparent}, + {UnmapNotify, VerbUnmap}, + {CirculateRequest, VerbCirculateRequest}, + {ConfigureRequest, VerbConfigureRequest}, + {MapRequest, VerbMapRequest}, + {ClientMessage, VerbClient}, + {MappingNotify, VerbMapping}, + {SelectionClear, VerbSelectionClear}, + {SelectionNotify, VerbSelection}, + {SelectionRequest, VerbSelectionRequest}, + {VisibilityNotify, VerbVisibility}, + {0, nil}, + }; + Handler *p; - case ButtonPress: - case ButtonRelease: - VerbButton((void*)ev); - break; - - case ColormapNotify: - VerbColormap((void*)ev); - break; - - case EnterNotify: - case LeaveNotify: - VerbCrossing((void*)ev); - break; - - case Expose: - VerbExpose((void*)ev); - break; - - case GraphicsExpose: - VerbGraphicsExpose((void*)ev); - break; - - case NoExpose: - VerbNoExpose((void*)ev); - break; - - case FocusIn: - case FocusOut: - VerbFocus((void*)ev); - break; - - case KeymapNotify: - VerbKeymap((void*)ev); - break; - - case KeyPress: - case KeyRelease: - VerbKey((void*)ev); - break; - - case PropertyNotify: - VerbProperty((void*)ev); - break; - - case ResizeRequest: - VerbResizeRequest((void*)ev); - break; - - case CirculateNotify: - VerbCirculate((void*)ev); - break; - - case ConfigureNotify: - VerbConfigure((void*)ev); - break; - - case CreateNotify: - VerbCreateWindow((void*)ev); - break; - - case DestroyNotify: - VerbDestroyWindow((void*)ev); - break; - - case GravityNotify: - VerbGravity((void*)ev); - break; - - case MapNotify: - VerbMap((void*)ev); - break; - - case ReparentNotify: - VerbReparent((void*)ev); - break; - - case UnmapNotify: - VerbUnmap((void*)ev); - break; - - case CirculateRequest: - VerbCirculateRequest((void*)ev); - break; - - case ConfigureRequest: - VerbConfigureRequest((void*)ev); - break; - - case MapRequest: - VerbMapRequest((void*)ev); - break; - - case ClientMessage: - VerbClient((void*)ev); - break; - - case MappingNotify: - VerbMapping((void*)ev); - break; - - case SelectionClear: - VerbSelectionClear((void*)ev); - break; - - case SelectionNotify: - VerbSelection((void*)ev); - break; - - case SelectionRequest: - VerbSelectionRequest((void*)ev); - break; - - case VisibilityNotify: - VerbVisibility((void*)ev); - break; - } + for (p = fns; p->fn; p++) + if (p->key == ev->type) + break; + if (p->fn) + p->fn(ev); } - diff --git a/cmd/wmii/printevent.h b/cmd/wmii/printevent.h index 0a419363..5f33de97 100644 --- a/cmd/wmii/printevent.h +++ b/cmd/wmii/printevent.h @@ -1,2 +1 @@ -char *eventtype(XEvent*); void printevent(XEvent*); diff --git a/cmd/wmii/view.c b/cmd/wmii/view.c index 2a4db436..1550aa13 100644 --- a/cmd/wmii/view.c +++ b/cmd/wmii/view.c @@ -371,7 +371,7 @@ view_index(View *v) { } void -update_views() { +update_views(void) { View *n, *v, *old; Bool found; diff --git a/cmd/wmii/x11.c b/cmd/wmii/x11.c index d28f3002..516b32f6 100644 --- a/cmd/wmii/x11.c +++ b/cmd/wmii/x11.c @@ -96,7 +96,7 @@ rectsubpt(Rectangle r, Point p) { /* Init */ void -initdisplay() { +initdisplay(void) { display = XOpenDisplay(nil); scr.screen = DefaultScreen(display); scr.colormap = DefaultColormap(display, scr.screen); @@ -654,7 +654,7 @@ grabpointer(Window *w, Window *confine, Cursor cur, int mask) { } void -ungrabpointer() { +ungrabpointer(void) { XUngrabPointer(display, CurrentTime); }