diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..1b47f11 --- /dev/null +++ b/.clang-format @@ -0,0 +1,18 @@ +TabWidth: 2 +IndentWidth: 2 +ContinuationIndentWidth: 2 +UseTab: Never +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: TopLevel +IndentCaseLabels: true +SpaceBeforeParens: ControlStatements +AlignAfterOpenBracket: AlwaysBreak +BinPackArguments: false +BinPackArguments: false +PointerAlignment: Left +BreakBeforeBraces: Attach +SortIncludes: false diff --git a/client.c b/client.c old mode 100755 new mode 100644 index c55d41e..a5718a7 --- a/client.c +++ b/client.c @@ -10,304 +10,296 @@ #include "fns.h" #include "config.h" -Client *clients; -Client *current; +Client* clients; +Client* current; void -setactive(Client *c, int on) -{ -/* dbg("setactive client %x %d", c->window, c->on); */ +setactive(Client* c, int on) { + /* dbg("setactive client %x %d", c->window, c->on); */ - if(c->parent == c->screen->root) - return; + if (c->parent == c->screen->root) return; - if(on){ - XUngrabButton(dpy, AnyButton, AnyModifier, c->parent); - XSetInputFocus(dpy, c->window, RevertToPointerRoot, timestamp()); - if(c->proto & Ptakefocus) - sendcmessage(c->window, wm_protocols, wm_take_focus, 0, 1); - cmapfocus(c); - }else{ - if(c->proto & Plosefocus) - sendcmessage(c->window, wm_protocols, wm_lose_focus, 0, 1); - XGrabButton(dpy, AnyButton, AnyModifier, c->parent, False, - ButtonMask, GrabModeAsync, GrabModeSync, None, None); - } - draw_border(c, on); + if (on) { + XUngrabButton(dpy, AnyButton, AnyModifier, c->parent); + XSetInputFocus(dpy, c->window, RevertToPointerRoot, timestamp()); + if (c->proto & Ptakefocus) + sendcmessage(c->window, wm_protocols, wm_take_focus, 0, 1); + cmapfocus(c); + } else { + if (c->proto & Plosefocus) + sendcmessage(c->window, wm_protocols, wm_lose_focus, 0, 1); + XGrabButton( + dpy, + AnyButton, + AnyModifier, + c->parent, + False, + ButtonMask, + GrabModeAsync, + GrabModeSync, + None, + None); + } + draw_border(c, on); } void -draw_border(Client *c, int active) -{ - unsigned long pixel; +draw_border(Client* c, int active) { + unsigned long pixel; - if(active){ - if(c->hold) - pixel = c->screen->activeholdborder; - else - pixel = c->screen->activeborder; - }else{ - if(c->hold) - pixel = c->screen->inactiveholdborder; - else - pixel = c->screen->inactiveborder; - } + if (active) { + if (c->hold) + pixel = c->screen->activeholdborder; + else + pixel = c->screen->activeborder; + } else { + if (c->hold) + pixel = c->screen->inactiveholdborder; + else + pixel = c->screen->inactiveborder; + } - if(debug) fprintf(stderr, "draw_border %p pixel %ld active %d hold %d\n", (void*)c, pixel, active, c->hold); - XSetWindowBackground(dpy, c->parent, pixel); - XClearWindow(dpy, c->parent); + if (debug) + fprintf( + stderr, + "draw_border %p pixel %ld active %d hold %d\n", + (void*)c, + pixel, + active, + c->hold); + XSetWindowBackground(dpy, c->parent, pixel); + XClearWindow(dpy, c->parent); } void -active(Client *c) -{ - Client *cc; +active(Client* c) { + Client* cc; - - if(c == 0){ - fprintf(stderr, "ryudo: active(c==0)\n"); - return; - } - if(c == current) - return; + if (c == 0) { + fprintf(stderr, "ryudo: active(c==0)\n"); + return; + } + if (c == current) return; #ifdef AUTOSTICK - if (isautostick(c)) - return; + if (isautostick(c)) return; #endif - if(current){ - setactive(current, 0); - if(current->screen != c->screen) - cmapnofocus(current->screen); - } - setactive(c, 1); - for(cc = clients; cc; cc = cc->next) - if(cc->revert == c) - cc->revert = c->revert; - c->revert = current; - while(c->revert && !normal(c->revert)) - c->revert = c->revert->revert; - current = c; -#ifdef DEBUG - if(debug) - dump_revert(); + if (current) { + setactive(current, 0); + if (current->screen != c->screen) cmapnofocus(current->screen); + } + setactive(c, 1); + for (cc = clients; cc; cc = cc->next) + if (cc->revert == c) cc->revert = c->revert; + c->revert = current; + while (c->revert && !normal(c->revert)) c->revert = c->revert->revert; + current = c; +#ifdef DEBUG + if (debug) dump_revert(); #endif } void -nofocus(void) -{ - static Window w = 0; - int mask; - XSetWindowAttributes attr; - Client *c; +nofocus(void) { + static Window w = 0; + int mask; + XSetWindowAttributes attr; + Client* c; - if(current){ - setactive(current, 0); - for(c = current->revert; c; c = c->revert) - if(normal(c)){ - active(c); - return; - } - cmapnofocus(current->screen); - /* if no candidates to revert to, fall through */ - } - current = 0; - if(w == 0){ - mask = CWOverrideRedirect/*|CWColormap*/; - attr.override_redirect = 1; - /* attr.colormap = screens[0].def_cmap;*/ - w = XCreateWindow(dpy, screens[0].root, 0, 0, 1, 1, 0, - 0 /*screens[0].depth*/, InputOnly, screens[0].vis, mask, &attr); - XMapWindow(dpy, w); - } - XSetInputFocus(dpy, w, RevertToPointerRoot, timestamp()); + if (current) { + setactive(current, 0); + for (c = current->revert; c; c = c->revert) + if (normal(c)) { + active(c); + return; + } + cmapnofocus(current->screen); + /* if no candidates to revert to, fall through */ + } + current = 0; + if (w == 0) { + mask = CWOverrideRedirect /*|CWColormap*/; + attr.override_redirect = 1; + /* attr.colormap = screens[0].def_cmap;*/ + w = XCreateWindow( + dpy, + screens[0].root, + 0, + 0, + 1, + 1, + 0, + 0 /*screens[0].depth*/, + InputOnly, + screens[0].vis, + mask, + &attr); + XMapWindow(dpy, w); + } + XSetInputFocus(dpy, w, RevertToPointerRoot, timestamp()); } void -top(Client *c) -{ - Client **l, *cc; +top(Client* c) { + Client **l, *cc; - l = &clients; - for(cc = *l; cc; cc = *l){ - if(cc == c){ - *l = c->next; - c->next = clients; - clients = c; - return; - } - l = &cc->next; - } - fprintf(stderr, "rio: %p not on client list in top()\n", (void*)c); + l = &clients; + for (cc = *l; cc; cc = *l) { + if (cc == c) { + *l = c->next; + c->next = clients; + clients = c; + return; + } + l = &cc->next; + } + fprintf(stderr, "rio: %p not on client list in top()\n", (void*)c); } -Client * -getclient(Window w, int create) -{ - Client *c; +Client* +getclient(Window w, int create) { + Client* c; - if(w == 0 || getscreen(w)) - return 0; + if (w == 0 || getscreen(w)) return 0; - for(c = clients; c; c = c->next) - if(c->window == w || c->parent == w) - return c; + for (c = clients; c; c = c->next) + if (c->window == w || c->parent == w) return c; - if(!create) - return 0; + if (!create) return 0; - c = (Client *)malloc(sizeof(Client)); - memset(c, 0, sizeof(Client)); - c->window = w; - /* c->parent will be set by the caller */ - c->parent = None; - c->reparenting = 0; - c->state = WithdrawnState; - c->init = 0; - c->cmap = None; - c->label = c->class = 0; - c->revert = 0; - c->is9term = 0; - c->hold = 0; - c->ncmapwins = 0; - c->cmapwins = 0; - c->wmcmaps = 0; - c->next = clients; - c->virt = virt; - clients = c; - return c; + c = (Client*)malloc(sizeof(Client)); + memset(c, 0, sizeof(Client)); + c->window = w; + /* c->parent will be set by the caller */ + c->parent = None; + c->reparenting = 0; + c->state = WithdrawnState; + c->init = 0; + c->cmap = None; + c->label = c->class = 0; + c->revert = 0; + c->is9term = 0; + c->hold = 0; + c->ncmapwins = 0; + c->cmapwins = 0; + c->wmcmaps = 0; + c->next = clients; + c->virt = virt; + clients = c; + return c; } void -rmclient(Client *c) -{ - Client *cc; +rmclient(Client* c) { + Client* cc; - for(cc = current; cc && cc->revert; cc = cc->revert) - if(cc->revert == c) - cc->revert = cc->revert->revert; + for (cc = current; cc && cc->revert; cc = cc->revert) + if (cc->revert == c) cc->revert = cc->revert->revert; - if(c == clients) - clients = c->next; - for(cc = clients; cc && cc->next; cc = cc->next) - if(cc->next == c) - cc->next = cc->next->next; + if (c == clients) clients = c->next; + for (cc = clients; cc && cc->next; cc = cc->next) + if (cc->next == c) cc->next = cc->next->next; - if(hidden(c)) - unhidec(c, 0); + if (hidden(c)) unhidec(c, 0); - if(c->parent != c->screen->root) - XDestroyWindow(dpy, c->parent); + if (c->parent != c->screen->root) XDestroyWindow(dpy, c->parent); - c->parent = c->window = None; /* paranoia */ - if(current == c){ - current = c->revert; - if(current == 0) - nofocus(); - else { - if(current->screen != c->screen) - cmapnofocus(c->screen); - setactive(current, 1); - } - } - if(c->ncmapwins != 0){ - XFree((char *)c->cmapwins); - free((char *)c->wmcmaps); - } - if(c->iconname != 0) - XFree((char*) c->iconname); - if(c->name != 0) - XFree((char*) c->name); - if(c->instance != 0) - XFree((char*) c->instance); - if(c->class != 0) - XFree((char*) c->class); - memset(c, 0, sizeof(Client)); /* paranoia */ - free(c); + c->parent = c->window = None; /* paranoia */ + if (current == c) { + current = c->revert; + if (current == 0) + nofocus(); + else { + if (current->screen != c->screen) cmapnofocus(c->screen); + setactive(current, 1); + } + } + if (c->ncmapwins != 0) { + XFree((char*)c->cmapwins); + free((char*)c->wmcmaps); + } + if (c->iconname != 0) XFree((char*)c->iconname); + if (c->name != 0) XFree((char*)c->name); + if (c->instance != 0) XFree((char*)c->instance); + if (c->class != 0) XFree((char*)c->class); + memset(c, 0, sizeof(Client)); /* paranoia */ + free(c); } -#ifdef DEBUG +#ifdef DEBUG void -dump_revert(void) -{ - Client *c; - int i; +dump_revert(void) { + Client* c; + int i; - i = 0; - for(c = current; c; c = c->revert){ - fprintf(stderr, "%s(%x:%d)", c->label ? c->label : "?", (int)c->window, c->state); - if(i++ > 100) - break; - if(c->revert) - fprintf(stderr, " -> "); - } - if(current == 0) - fprintf(stderr, "empty"); - fprintf(stderr, "\n"); + i = 0; + for (c = current; c; c = c->revert) { + fprintf( + stderr, "%s(%x:%d)", c->label ? c->label : "?", (int)c->window, c->state); + if (i++ > 100) break; + if (c->revert) fprintf(stderr, " -> "); + } + if (current == 0) fprintf(stderr, "empty"); + fprintf(stderr, "\n"); } void -dump_clients(void) -{ - Client *c; +dump_clients(void) { + Client* c; - for(c = clients; c; c = c->next) - fprintf(stderr, "w 0x%x parent 0x%x @ (%d, %d)\n", (int)c->window, (int)c->parent, c->x, c->y); + for (c = clients; c; c = c->next) + fprintf( + stderr, + "w 0x%x parent 0x%x @ (%d, %d)\n", + (int)c->window, + (int)c->parent, + c->x, + c->y); } #endif void -shuffle(int up) -{ - Client **l, *c; - - if(clients == 0 || clients->next == 0) - return; - if(!up){ - c = 0; - /*for(c=clients; c->next; c=c->next) */ - /* ; */ - for(l=&clients; (*l)->next; l=&(*l)->next) +shuffle(int up) { + Client **l, *c; + + if (clients == 0 || clients->next == 0) return; + if (!up) { + c = 0; + /*for(c=clients; c->next; c=c->next) */ + /* ; */ + for (l = &clients; (*l)->next; l = &(*l)->next) #ifdef AUTOSTICK - if ((*l)->state == 1 && !isautostick(*l)) - c = *l; + if ((*l)->state == 1 && !isautostick(*l)) c = *l; #else - if ((*l)->state == 1) - c = *l; + if ((*l)->state == 1) c = *l; #endif - if (c == 0) - return; - XMapRaised(dpy, c->parent); - top(c); + if (c == 0) return; + XMapRaised(dpy, c->parent); + top(c); active(c); - }else{ - c = clients; - for(l=&clients; *l; l=&(*l)->next) - ; - clients = c->next; - *l = c; - c->next = 0; - XLowerWindow(dpy, c->window); - } -/* XMapRaised(dpy, clients->parent); */ -/* top(clients); */ -/* active(clients); */ + } else { + c = clients; + for (l = &clients; *l; l = &(*l)->next) + ; + clients = c->next; + *l = c; + c->next = 0; + XLowerWindow(dpy, c->window); + } + /* XMapRaised(dpy, clients->parent); */ + /* top(clients); */ + /* active(clients); */ } #ifdef AUTOSTICK int -isautostick(Client *c) -{ - static char *autostick[] = AUTOSTICK; - char **a = autostick; +isautostick(Client* c) { + static char* autostick[] = AUTOSTICK; + char** a = autostick; - while(*a){ - if(c && c->class && strstr(c->class, *a)) { - return 1; - } + while (*a) { + if (c && c->class && strstr(c->class, *a)) { return 1; } ++a; } return 0; } #endif - diff --git a/color.c b/color.c old mode 100755 new mode 100644 index f1fff54..3d8df29 --- a/color.c +++ b/color.c @@ -8,38 +8,38 @@ #include "fns.h" unsigned long -colorpixel(Display *dpy, ScreenInfo *s, int depth, unsigned long rgb, unsigned long def) -{ - int r, g, b; +colorpixel( + Display* dpy, ScreenInfo* s, int depth, unsigned long rgb, + unsigned long def) { + int r, g, b; - r = rgb>>16; - g = (rgb>>8)&0xFF; - b = rgb&0xFF; + r = rgb >> 16; + g = (rgb >> 8) & 0xFF; + b = rgb & 0xFF; - switch(depth){ - case 1: - case 2: - case 4: - case 8: - default: - /* not going to waste color map entries */ - return def; - case 15: - r >>= 3; - g >>= 3; - b >>= 3; - return (r<<10) | (g<<5) | b; - case 16: - r >>= 3; - g >>= 2; - b >>= 3; - return (r<<11) | (g<<5) | b; - case 24: - case 32: - /* try to find byte order */ - if(s->vis->red_mask & 0xff) - return (r) | (g<<8) | (b<<16); /* OK on Sun */ - return rgb; - } + switch (depth) { + case 1: + case 2: + case 4: + case 8: + default: + /* not going to waste color map entries */ + return def; + case 15: + r >>= 3; + g >>= 3; + b >>= 3; + return (r << 10) | (g << 5) | b; + case 16: + r >>= 3; + g >>= 2; + b >>= 3; + return (r << 11) | (g << 5) | b; + case 24: + case 32: + /* try to find byte order */ + if (s->vis->red_mask & 0xff) + return (r) | (g << 8) | (b << 16); /* OK on Sun */ + return rgb; + } } - diff --git a/config.h b/config.h old mode 100755 new mode 100644 index 8cbd523..9b70517 --- a/config.h +++ b/config.h @@ -15,7 +15,7 @@ #define SMENUFGCOL 0x000000 #define SMENUBGCOL 0x1F9B92 -/* This sets the size ratio for windows spawned via keyboard or +/* This sets the size ratio for windows spawned via keyboard or * center-snapped */ #define CENTERNUM 2 @@ -42,13 +42,13 @@ * Lock = (1<<1) * Control = (1<<2) * Mod1 = (1<<3) - * Mod2 = (1<<4) + * Mod2 = (1<<4) * Mod3 = (1<<5) * Mod4 = (1<<6) * Mod5 = (1<<7) */ #define SHORTCUTMOD Mod4Mask -#define MODBITS (1<<6) +#define MODBITS (1 << 6) /* Shortcut keys */ @@ -86,23 +86,15 @@ * Remember the backslash at the end of non-terminating lines! */ -#define AUTOSTICK {\ - "XOsview",\ - "XClock",\ - 0\ -} +#define AUTOSTICK \ + { "XOsview", "XClock", 0 } /* List of fonts to try, in order, for rendering the menus. * Remember the backslash at the end of non-terminating lines! */ -#define FONTLIST {\ - "*-lucidatypewriter-medium-*-12-*-75-*",\ - "lucm.latin1.9",\ - "blit",\ - "*-lucidatypewriter-bold-*-14-*-75-*",\ - "9x15bold",\ - "fixed",\ - "*",\ - 0\ -} +#define FONTLIST \ + { \ + "*-lucidatypewriter-medium-*-12-*-75-*", "lucm.latin1.9", "blit", \ + "*-lucidatypewriter-bold-*-14-*-75-*", "9x15bold", "fixed", "*", 0 \ + } diff --git a/cursor.c b/cursor.c old mode 100755 new mode 100644 index 33f6352..0d74cac --- a/cursor.c +++ b/cursor.c @@ -7,142 +7,129 @@ #include "fns.h" typedef struct { - int width; - int hot[2]; - unsigned char mask[64]; - unsigned char fore[64]; + int width; + int hot[2]; + unsigned char mask[64]; + unsigned char fore[64]; } Cursordata; Cursordata bigarrow = { - 16, - {0, 0}, - { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0x3F, - 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x1F, 0xFF, 0x3F, - 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0x3F, - 0xCF, 0x1F, 0x8F, 0x0F, 0x07, 0x07, 0x03, 0x02, - }, - { 0x00, 0x00, 0xFE, 0x7F, 0xFE, 0x3F, 0xFE, 0x0F, - 0xFE, 0x07, 0xFE, 0x07, 0xFE, 0x0F, 0xFE, 0x1F, - 0xFE, 0x3F, 0xFE, 0x7F, 0xFE, 0x3F, 0xCE, 0x1F, - 0x86, 0x0F, 0x06, 0x07, 0x02, 0x02, 0x00, 0x00, - } -}; + 16, + {0, 0}, + { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0x3F, 0xFF, 0x0F, 0xFF, + 0x0F, 0xFF, 0x1F, 0xFF, 0x3F, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, + 0xFF, 0x3F, 0xCF, 0x1F, 0x8F, 0x0F, 0x07, 0x07, 0x03, 0x02, + }, + { + 0x00, 0x00, 0xFE, 0x7F, 0xFE, 0x3F, 0xFE, 0x0F, 0xFE, 0x07, 0xFE, + 0x07, 0xFE, 0x0F, 0xFE, 0x1F, 0xFE, 0x3F, 0xFE, 0x7F, 0xFE, 0x3F, + 0xCE, 0x1F, 0x86, 0x0F, 0x06, 0x07, 0x02, 0x02, 0x00, 0x00, + }}; Cursordata sweep0data = { - 16, - {7, 7}, - {0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, - 0xC0, 0x03, 0xC0, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x03, 0xC0, 0x03, - 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03}, - {0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, - 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xFE, 0x7F, - 0xFE, 0x7F, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, - 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00} -}; + 16, + {7, 7}, + {0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, + 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x03, + 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03}, + {0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, + 0x01, 0x80, 0x01, 0xFE, 0x7F, 0xFE, 0x7F, 0x80, 0x01, 0x80, 0x01, + 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00}}; Cursordata boxcursdata = { - 16, - {7, 7}, - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, - 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, - {0x00, 0x00, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, - 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, - 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, - 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0x00, 0x00} -}; + 16, + {7, 7}, + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, + 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, + {0x00, 0x00, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0x0E, 0x70, 0x0E, + 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, + 0x0E, 0x70, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0x00, 0x00}}; Cursordata sightdata = { - 16, - {7, 7}, - {0xF8, 0x1F, 0xFC, 0x3F, 0xFE, 0x7F, 0xDF, 0xFB, - 0xCF, 0xF3, 0xC7, 0xE3, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xC7, 0xE3, 0xCF, 0xF3, - 0xDF, 0x7B, 0xFE, 0x7F, 0xFC, 0x3F, 0xF8, 0x1F,}, - {0x00, 0x00, 0xF0, 0x0F, 0x8C, 0x31, 0x84, 0x21, - 0x82, 0x41, 0x82, 0x41, 0x82, 0x41, 0xFE, 0x7F, - 0xFE, 0x7F, 0x82, 0x41, 0x82, 0x41, 0x82, 0x41, - 0x84, 0x21, 0x8C, 0x31, 0xF0, 0x0F, 0x00, 0x00,} -}; + 16, + {7, 7}, + { + 0xF8, 0x1F, 0xFC, 0x3F, 0xFE, 0x7F, 0xDF, 0xFB, 0xCF, 0xF3, 0xC7, + 0xE3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC7, 0xE3, + 0xCF, 0xF3, 0xDF, 0x7B, 0xFE, 0x7F, 0xFC, 0x3F, 0xF8, 0x1F, + }, + { + 0x00, 0x00, 0xF0, 0x0F, 0x8C, 0x31, 0x84, 0x21, 0x82, 0x41, 0x82, + 0x41, 0x82, 0x41, 0xFE, 0x7F, 0xFE, 0x7F, 0x82, 0x41, 0x82, 0x41, + 0x82, 0x41, 0x84, 0x21, 0x8C, 0x31, 0xF0, 0x0F, 0x00, 0x00, + }}; Cursordata arrowdata = { - 16, - {1, 1}, - {0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x03, 0xFF, 0x00, - 0xFF, 0x00, 0xFF, 0x01, 0xFF, 0x03, 0xFF, 0x07, - 0xE7, 0x0F, 0xC7, 0x1F, 0x83, 0x3F, 0x00, 0x7F, - 0x00, 0xFE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10,}, - {0x00, 0x00, 0xFE, 0x03, 0xFE, 0x00, 0x3E, 0x00, - 0x7E, 0x00, 0xFE, 0x00, 0xF6, 0x01, 0xE6, 0x03, - 0xC2, 0x07, 0x82, 0x0F, 0x00, 0x1F, 0x00, 0x3E, - 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00,} -}; + 16, + {1, 1}, + { + 0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x03, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x01, 0xFF, 0x03, 0xFF, 0x07, 0xE7, 0x0F, 0xC7, 0x1F, 0x83, 0x3F, + 0x00, 0x7F, 0x00, 0xFE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10, + }, + { + 0x00, 0x00, 0xFE, 0x03, 0xFE, 0x00, 0x3E, 0x00, 0x7E, 0x00, 0xFE, + 0x00, 0xF6, 0x01, 0xE6, 0x03, 0xC2, 0x07, 0x82, 0x0F, 0x00, 0x1F, + 0x00, 0x3E, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, + }}; Cursordata whitearrow = { - 16, - {0, 0}, - {0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x03, 0xFF, 0x00, - 0xFF, 0x00, 0xFF, 0x01, 0xFF, 0x03, 0xFF, 0x07, - 0xE7, 0x0F, 0xC7, 0x1F, 0x83, 0x3F, 0x00, 0x7F, - 0x00, 0xFE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10,}, - {0xFF, 0x07, 0xFF, 0x07, 0x83, 0x03, 0xC3, 0x00, - 0xC3, 0x00, 0x83, 0x01, 0x1B, 0x03, 0x3F, 0x06, - 0x67, 0x0C, 0xC7, 0x18, 0x83, 0x31, 0x00, 0x63, - 0x00, 0xC6, 0x00, 0x6C, 0x00, 0x38, 0x00, 0x10,} -}; + 16, + {0, 0}, + { + 0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x03, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x01, 0xFF, 0x03, 0xFF, 0x07, 0xE7, 0x0F, 0xC7, 0x1F, 0x83, 0x3F, + 0x00, 0x7F, 0x00, 0xFE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10, + }, + { + 0xFF, 0x07, 0xFF, 0x07, 0x83, 0x03, 0xC3, 0x00, 0xC3, 0x00, 0x83, + 0x01, 0x1B, 0x03, 0x3F, 0x06, 0x67, 0x0C, 0xC7, 0x18, 0x83, 0x31, + 0x00, 0x63, 0x00, 0xC6, 0x00, 0x6C, 0x00, 0x38, 0x00, 0x10, + }}; Cursordata blittarget = { - 18, - {8, 8}, - {0xe0, 0x1f, 0x00, 0xf0, 0x3f, 0x00, 0xf8, 0x7f, 0x00, - 0xfc, 0xff, 0x00, 0xfe, 0xff, 0x01, 0xff, 0xff, 0x03, - 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, - 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, - 0xff, 0xff, 0x03, 0xfe, 0xff, 0x01, 0xfc, 0xff, 0x00, - 0xf8, 0x7f, 0x00, 0xf0, 0x3f, 0x00, 0xe0, 0x1f, 0x00}, - {0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0xf0, 0x3f, 0x00, - 0x38, 0x73, 0x00, 0x8c, 0xc7, 0x00, 0xec, 0xdf, 0x00, - 0x66, 0x9b, 0x01, 0x36, 0xb3, 0x01, 0xfe, 0xff, 0x01, - 0xfe, 0xff, 0x01, 0x36, 0xb3, 0x01, 0x66, 0x9b, 0x01, - 0xec, 0xdf, 0x00, 0x8c, 0xc7, 0x00, 0x38, 0x73, 0x00, - 0xf0, 0x3f, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00} -}; + 18, + {8, 8}, + {0xe0, 0x1f, 0x00, 0xf0, 0x3f, 0x00, 0xf8, 0x7f, 0x00, 0xfc, 0xff, + 0x00, 0xfe, 0xff, 0x01, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, + 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, + 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xfe, 0xff, 0x01, 0xfc, 0xff, + 0x00, 0xf8, 0x7f, 0x00, 0xf0, 0x3f, 0x00, 0xe0, 0x1f, 0x00}, + {0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0xf0, 0x3f, 0x00, 0x38, 0x73, + 0x00, 0x8c, 0xc7, 0x00, 0xec, 0xdf, 0x00, 0x66, 0x9b, 0x01, 0x36, + 0xb3, 0x01, 0xfe, 0xff, 0x01, 0xfe, 0xff, 0x01, 0x36, 0xb3, 0x01, + 0x66, 0x9b, 0x01, 0xec, 0xdf, 0x00, 0x8c, 0xc7, 0x00, 0x38, 0x73, + 0x00, 0xf0, 0x3f, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00}}; Cursordata blitarrow = { - 18, - {1, 1}, - {0xff, 0x0f, 0x00, 0xff, 0x07, 0x00, 0xff, 0x03, 0x00, - 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x01, 0x00, - 0xff, 0x03, 0x00, 0xff, 0x07, 0x00, 0xe7, 0x0f, 0x00, - 0xc7, 0x1f, 0x00, 0x87, 0x3f, 0x00, 0x03, 0x7f, 0x00, - 0x01, 0xfe, 0x00, 0x00, 0xfc, 0x01, 0x00, 0xf8, 0x03, - 0x00, 0xf0, 0x01, 0x00, 0xe0, 0x00, 0x00, 0x40, 0x00}, - {0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0xfe, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0xfe, 0x00, 0x00, - 0xf6, 0x01, 0x00, 0xe6, 0x03, 0x00, 0xc2, 0x07, 0x00, - 0x82, 0x0f, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x3e, 0x00, - 0x00, 0x7c, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf0, 0x01, - 0x00, 0xe0, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00} -}; + 18, + {1, 1}, + {0xff, 0x0f, 0x00, 0xff, 0x07, 0x00, 0xff, 0x03, 0x00, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, 0xff, 0x01, 0x00, 0xff, 0x03, 0x00, 0xff, + 0x07, 0x00, 0xe7, 0x0f, 0x00, 0xc7, 0x1f, 0x00, 0x87, 0x3f, 0x00, + 0x03, 0x7f, 0x00, 0x01, 0xfe, 0x00, 0x00, 0xfc, 0x01, 0x00, 0xf8, + 0x03, 0x00, 0xf0, 0x01, 0x00, 0xe0, 0x00, 0x00, 0x40, 0x00}, + {0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0xfe, 0x00, 0x00, 0x3e, 0x00, + 0x00, 0x7e, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xf6, 0x01, 0x00, 0xe6, + 0x03, 0x00, 0xc2, 0x07, 0x00, 0x82, 0x0f, 0x00, 0x00, 0x1f, 0x00, + 0x00, 0x3e, 0x00, 0x00, 0x7c, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf0, + 0x01, 0x00, 0xe0, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}}; Cursordata blitsweep = { - 18, - {8, 8}, - {0xc4, 0xff, 0x03, 0xce, 0xff, 0x03, 0xdf, 0xff, 0x03, - 0x3e, 0x80, 0x03, 0x7c, 0x83, 0x03, 0xf8, 0x83, 0x03, - 0xf7, 0x83, 0x03, 0xe7, 0x83, 0x03, 0xf7, 0x83, 0x03, - 0xf7, 0x83, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, 0x03, - 0x07, 0x80, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, 0x03, - 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03}, - {0x00, 0x00, 0x00, 0x84, 0xff, 0x01, 0x0e, 0x00, 0x01, - 0x1c, 0x00, 0x01, 0x38, 0x00, 0x01, 0x70, 0x01, 0x01, - 0xe0, 0x01, 0x01, 0xc2, 0x01, 0x01, 0xe2, 0x01, 0x01, - 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, - 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, - 0x02, 0x00, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x00} -}; + 18, + {8, 8}, + {0xc4, 0xff, 0x03, 0xce, 0xff, 0x03, 0xdf, 0xff, 0x03, 0x3e, 0x80, + 0x03, 0x7c, 0x83, 0x03, 0xf8, 0x83, 0x03, 0xf7, 0x83, 0x03, 0xe7, + 0x83, 0x03, 0xf7, 0x83, 0x03, 0xf7, 0x83, 0x03, 0x07, 0x80, 0x03, + 0x07, 0x80, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, + 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03}, + {0x00, 0x00, 0x00, 0x84, 0xff, 0x01, 0x0e, 0x00, 0x01, 0x1c, 0x00, + 0x01, 0x38, 0x00, 0x01, 0x70, 0x01, 0x01, 0xe0, 0x01, 0x01, 0xc2, + 0x01, 0x01, 0xe2, 0x01, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, + 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, + 0x01, 0x02, 0x00, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x00}}; /* * Grey tile pattern for root background @@ -150,232 +137,227 @@ Cursordata blitsweep = { #define grey_width 4 #define grey_height 2 -static char grey_bits[] = { - 0x01, 0x04 -}; +static char grey_bits[] = {0x01, 0x04}; -static XColor bl, wh; +static XColor bl, wh; -Cursor -getcursor(c, s) -Cursordata *c; -ScreenInfo *s; +Cursor getcursor(c, s) Cursordata* c; +ScreenInfo* s; { - Pixmap f, m; + Pixmap f, m; - f = XCreatePixmapFromBitmapData(dpy, s->root, (char *)c->fore, - c->width, c->width, 1, 0, 1); - m = XCreatePixmapFromBitmapData(dpy, s->root, (char *)c->mask, - c->width, c->width, 1, 0, 1); - return XCreatePixmapCursor(dpy, f, m, &bl, &wh, - c->hot[0], c->hot[1]); + f = XCreatePixmapFromBitmapData( + dpy, s->root, (char*)c->fore, c->width, c->width, 1, 0, 1); + m = XCreatePixmapFromBitmapData( + dpy, s->root, (char*)c->mask, c->width, c->width, 1, 0, 1); + return XCreatePixmapCursor(dpy, f, m, &bl, &wh, c->hot[0], c->hot[1]); } -void -initcurs(s) -ScreenInfo *s; +void initcurs(s) ScreenInfo* s; { - XColor dummy; + XColor dummy; - XAllocNamedColor(dpy, DefaultColormap(dpy, s->num), - "black", &bl, &dummy); - XAllocNamedColor(dpy, DefaultColormap(dpy, s->num), - "white", &wh, &dummy); + XAllocNamedColor(dpy, DefaultColormap(dpy, s->num), "black", &bl, &dummy); + XAllocNamedColor(dpy, DefaultColormap(dpy, s->num), "white", &wh, &dummy); - if(nostalgia){ - s->arrow = getcursor(&blitarrow, s); - s->target = getcursor(&blittarget, s); - s->sweep0 = getcursor(&blitsweep, s); - s->boxcurs = getcursor(&blitsweep, s); - } - else { - s->arrow = getcursor(&bigarrow, s); - s->target = getcursor(&sightdata, s); - s->sweep0 = getcursor(&sweep0data, s); - s->boxcurs = getcursor(&boxcursdata, s); - } + if (nostalgia) { + s->arrow = getcursor(&blitarrow, s); + s->target = getcursor(&blittarget, s); + s->sweep0 = getcursor(&blitsweep, s); + s->boxcurs = getcursor(&blitsweep, s); + } else { + s->arrow = getcursor(&bigarrow, s); + s->target = getcursor(&sightdata, s); + s->sweep0 = getcursor(&sweep0data, s); + s->boxcurs = getcursor(&boxcursdata, s); + } - s->root_pixmap = XCreatePixmapFromBitmapData(dpy, - s->root, grey_bits, grey_width, grey_height, - s->black, s->white, s->depth); - - s->bordcurs[BorderN] = XCreateFontCursor(dpy, 138); - s->bordcurs[BorderNNE] = XCreateFontCursor(dpy, 136); - s->bordcurs[BorderENE] = s->bordcurs[BorderNNE] ; - s->bordcurs[BorderE] = XCreateFontCursor(dpy, 96); - s->bordcurs[BorderESE] = XCreateFontCursor(dpy, 14); - s->bordcurs[BorderSSE] = s->bordcurs[BorderESE]; - s->bordcurs[BorderS] = XCreateFontCursor(dpy, 16); - s->bordcurs[BorderSSW] = XCreateFontCursor(dpy, 12); - s->bordcurs[BorderWSW] = s->bordcurs[BorderSSW]; - s->bordcurs[BorderW] = XCreateFontCursor(dpy, 70); - s->bordcurs[BorderWNW] = XCreateFontCursor(dpy, 134); - s->bordcurs[BorderNNW] = s->bordcurs[BorderWNW]; + s->root_pixmap = XCreatePixmapFromBitmapData( + dpy, + s->root, + grey_bits, + grey_width, + grey_height, + s->black, + s->white, + s->depth); + + s->bordcurs[BorderN] = XCreateFontCursor(dpy, 138); + s->bordcurs[BorderNNE] = XCreateFontCursor(dpy, 136); + s->bordcurs[BorderENE] = s->bordcurs[BorderNNE]; + s->bordcurs[BorderE] = XCreateFontCursor(dpy, 96); + s->bordcurs[BorderESE] = XCreateFontCursor(dpy, 14); + s->bordcurs[BorderSSE] = s->bordcurs[BorderESE]; + s->bordcurs[BorderS] = XCreateFontCursor(dpy, 16); + s->bordcurs[BorderSSW] = XCreateFontCursor(dpy, 12); + s->bordcurs[BorderWSW] = s->bordcurs[BorderSSW]; + s->bordcurs[BorderW] = XCreateFontCursor(dpy, 70); + s->bordcurs[BorderWNW] = XCreateFontCursor(dpy, 134); + s->bordcurs[BorderNNW] = s->bordcurs[BorderWNW]; } - /* RIO Cursor crosscursor = { - {-7, -7}, - {0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, - 0x03, 0xC0, 0x03, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xC0, 0x03, 0xC0, - 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, }, - {0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, - 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x7F, 0xFE, - 0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, - 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, } + {-7, -7}, + {0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, + 0x03, 0xC0, 0x03, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xC0, 0x03, 0xC0, + 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, }, + {0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, + 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x7F, 0xFE, + 0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, + 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, } }; Cursor boxcursor = { - {-7, -7}, - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, - 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }, - {0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, - 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, - 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, - 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00, } + {-7, -7}, + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, + 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }, + {0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, + 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, + 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, + 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00, } }; Cursor sightcursor = { - {-7, -7}, - {0x1F, 0xF8, 0x3F, 0xFC, 0x7F, 0xFE, 0xFB, 0xDF, - 0xF3, 0xCF, 0xE3, 0xC7, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0xC7, 0xF3, 0xCF, - 0x7B, 0xDF, 0x7F, 0xFE, 0x3F, 0xFC, 0x1F, 0xF8, }, - {0x00, 0x00, 0x0F, 0xF0, 0x31, 0x8C, 0x21, 0x84, - 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x7F, 0xFE, - 0x7F, 0xFE, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, - 0x21, 0x84, 0x31, 0x8C, 0x0F, 0xF0, 0x00, 0x00, } + {-7, -7}, + {0x1F, 0xF8, 0x3F, 0xFC, 0x7F, 0xFE, 0xFB, 0xDF, + 0xF3, 0xCF, 0xE3, 0xC7, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0xC7, 0xF3, 0xCF, + 0x7B, 0xDF, 0x7F, 0xFE, 0x3F, 0xFC, 0x1F, 0xF8, }, + {0x00, 0x00, 0x0F, 0xF0, 0x31, 0x8C, 0x21, 0x84, + 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x7F, 0xFE, + 0x7F, 0xFE, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, + 0x21, 0x84, 0x31, 0x8C, 0x0F, 0xF0, 0x00, 0x00, } }; Cursor whitearrow = { - {0, 0}, - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFC, - 0xFF, 0xF0, 0xFF, 0xF0, 0xFF, 0xF8, 0xFF, 0xFC, - 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFC, - 0xF3, 0xF8, 0xF1, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, }, - {0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x06, 0xC0, 0x1C, - 0xC0, 0x30, 0xC0, 0x30, 0xC0, 0x38, 0xC0, 0x1C, - 0xC0, 0x0E, 0xC0, 0x07, 0xCE, 0x0E, 0xDF, 0x1C, - 0xD3, 0xB8, 0xF1, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, } + {0, 0}, + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFC, + 0xFF, 0xF0, 0xFF, 0xF0, 0xFF, 0xF8, 0xFF, 0xFC, + 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFC, + 0xF3, 0xF8, 0xF1, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, }, + {0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x06, 0xC0, 0x1C, + 0xC0, 0x30, 0xC0, 0x30, 0xC0, 0x38, 0xC0, 0x1C, + 0xC0, 0x0E, 0xC0, 0x07, 0xCE, 0x0E, 0xDF, 0x1C, + 0xD3, 0xB8, 0xF1, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, } }; Cursor query = { - {-7,-7}, - {0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe, - 0x7c, 0x7e, 0x78, 0x7e, 0x00, 0xfc, 0x01, 0xf8, - 0x03, 0xf0, 0x07, 0xe0, 0x07, 0xc0, 0x07, 0xc0, - 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, }, - {0x00, 0x00, 0x0f, 0xf0, 0x1f, 0xf8, 0x3c, 0x3c, - 0x38, 0x1c, 0x00, 0x3c, 0x00, 0x78, 0x00, 0xf0, - 0x01, 0xe0, 0x03, 0xc0, 0x03, 0x80, 0x03, 0x80, - 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, } + {-7,-7}, + {0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe, + 0x7c, 0x7e, 0x78, 0x7e, 0x00, 0xfc, 0x01, 0xf8, + 0x03, 0xf0, 0x07, 0xe0, 0x07, 0xc0, 0x07, 0xc0, + 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, }, + {0x00, 0x00, 0x0f, 0xf0, 0x1f, 0xf8, 0x3c, 0x3c, + 0x38, 0x1c, 0x00, 0x3c, 0x00, 0x78, 0x00, 0xf0, + 0x01, 0xe0, 0x03, 0xc0, 0x03, 0x80, 0x03, 0x80, + 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, } }; Cursor tl = { - {-4, -4}, - {0xfe, 0x00, 0x82, 0x00, 0x8c, 0x00, 0x87, 0xff, - 0xa0, 0x01, 0xb0, 0x01, 0xd0, 0x01, 0x11, 0xff, - 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, - 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x1f, 0x00, }, - {0x00, 0x00, 0x7c, 0x00, 0x70, 0x00, 0x78, 0x00, - 0x5f, 0xfe, 0x4f, 0xfe, 0x0f, 0xfe, 0x0e, 0x00, - 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, - 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x00, 0x00, } + {-4, -4}, + {0xfe, 0x00, 0x82, 0x00, 0x8c, 0x00, 0x87, 0xff, + 0xa0, 0x01, 0xb0, 0x01, 0xd0, 0x01, 0x11, 0xff, + 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, + 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x1f, 0x00, }, + {0x00, 0x00, 0x7c, 0x00, 0x70, 0x00, 0x78, 0x00, + 0x5f, 0xfe, 0x4f, 0xfe, 0x0f, 0xfe, 0x0e, 0x00, + 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, + 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x00, 0x00, } }; Cursor t = { - {-7, -8}, - {0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x06, 0xc0, - 0x1c, 0x70, 0x10, 0x10, 0x0c, 0x60, 0xfc, 0x7f, - 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x03, 0x80, 0x0f, 0xe0, 0x03, 0x80, 0x03, 0x80, - 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } + {-7, -8}, + {0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x06, 0xc0, + 0x1c, 0x70, 0x10, 0x10, 0x0c, 0x60, 0xfc, 0x7f, + 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x03, 0x80, 0x0f, 0xe0, 0x03, 0x80, 0x03, 0x80, + 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } }; Cursor tr = { - {-11, -4}, - {0x00, 0x7f, 0x00, 0x41, 0x00, 0x31, 0xff, 0xe1, - 0x80, 0x05, 0x80, 0x0d, 0x80, 0x0b, 0xff, 0x88, - 0x00, 0x88, 0x0, 0x88, 0x00, 0x88, 0x00, 0x88, - 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0xf8, }, - {0x00, 0x00, 0x00, 0x3e, 0x00, 0x0e, 0x00, 0x1e, - 0x7f, 0xfa, 0x7f, 0xf2, 0x7f, 0xf0, 0x00, 0x70, - 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, - 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x00, } + {-11, -4}, + {0x00, 0x7f, 0x00, 0x41, 0x00, 0x31, 0xff, 0xe1, + 0x80, 0x05, 0x80, 0x0d, 0x80, 0x0b, 0xff, 0x88, + 0x00, 0x88, 0x0, 0x88, 0x00, 0x88, 0x00, 0x88, + 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0xf8, }, + {0x00, 0x00, 0x00, 0x3e, 0x00, 0x0e, 0x00, 0x1e, + 0x7f, 0xfa, 0x7f, 0xf2, 0x7f, 0xf0, 0x00, 0x70, + 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, + 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x00, } }; Cursor r = { - {-8, -7}, - {0x07, 0xc0, 0x04, 0x40, 0x04, 0x40, 0x04, 0x58, - 0x04, 0x68, 0x04, 0x6c, 0x04, 0x06, 0x04, 0x02, - 0x04, 0x06, 0x04, 0x6c, 0x04, 0x68, 0x04, 0x58, - 0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0x07, 0xc0, }, - {0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, - 0x03, 0x90, 0x03, 0x90, 0x03, 0xf8, 0x03, 0xfc, - 0x03, 0xf8, 0x03, 0x90, 0x03, 0x90, 0x03, 0x80, - 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, } + {-8, -7}, + {0x07, 0xc0, 0x04, 0x40, 0x04, 0x40, 0x04, 0x58, + 0x04, 0x68, 0x04, 0x6c, 0x04, 0x06, 0x04, 0x02, + 0x04, 0x06, 0x04, 0x6c, 0x04, 0x68, 0x04, 0x58, + 0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0x07, 0xc0, }, + {0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, + 0x03, 0x90, 0x03, 0x90, 0x03, 0xf8, 0x03, 0xfc, + 0x03, 0xf8, 0x03, 0x90, 0x03, 0x90, 0x03, 0x80, + 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, } }; Cursor br = { - {-11, -11}, - {0x00, 0xf8, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, - 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, - 0xff, 0x88, 0x80, 0x0b, 0x80, 0x0d, 0x80, 0x05, - 0xff, 0xe1, 0x00, 0x31, 0x00, 0x41, 0x00, 0x7f, }, - {0x00, 0x00, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, - 0x0, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, - 0x00, 0x70, 0x7f, 0xf0, 0x7f, 0xf2, 0x7f, 0xfa, - 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x3e, 0x00, 0x00, } + {-11, -11}, + {0x00, 0xf8, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, + 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, + 0xff, 0x88, 0x80, 0x0b, 0x80, 0x0d, 0x80, 0x05, + 0xff, 0xe1, 0x00, 0x31, 0x00, 0x41, 0x00, 0x7f, }, + {0x00, 0x00, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, + 0x0, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, + 0x00, 0x70, 0x7f, 0xf0, 0x7f, 0xf2, 0x7f, 0xfa, + 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x3e, 0x00, 0x00, } }; Cursor b = { - {-7, -7}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, - 0xfc, 0x7f, 0x0c, 0x60, 0x10, 0x10, 0x1c, 0x70, - 0x06, 0xc0, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, }, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, - 0x03, 0x80, 0x03, 0x80, 0x0f, 0xe0, 0x03, 0x80, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } + {-7, -7}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, + 0xfc, 0x7f, 0x0c, 0x60, 0x10, 0x10, 0x1c, 0x70, + 0x06, 0xc0, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, }, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, + 0x03, 0x80, 0x03, 0x80, 0x0f, 0xe0, 0x03, 0x80, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } }; Cursor bl = { - {-4, -11}, - {0x1f, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, - 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, - 0x11, 0xff, 0xd0, 0x01, 0xb0, 0x01, 0xa0, 0x01, - 0x87, 0xff, 0x8c, 0x00, 0x82, 0x00, 0xfe, 0x00, }, - {0x00, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, - 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, - 0x0e, 0x00, 0x0f, 0xfe, 0x4f, 0xfe, 0x5f, 0xfe, - 0x78, 0x00, 0x70, 0x00, 0x7c, 0x00, 0x00, 0x0, } + {-4, -11}, + {0x1f, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, + 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, + 0x11, 0xff, 0xd0, 0x01, 0xb0, 0x01, 0xa0, 0x01, + 0x87, 0xff, 0x8c, 0x00, 0x82, 0x00, 0xfe, 0x00, }, + {0x00, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, + 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, + 0x0e, 0x00, 0x0f, 0xfe, 0x4f, 0xfe, 0x5f, 0xfe, + 0x78, 0x00, 0x70, 0x00, 0x7c, 0x00, 0x00, 0x0, } }; Cursor l = { - {-7, -7}, - {0x03, 0xe0, 0x02, 0x20, 0x02, 0x20, 0x1a, 0x20, - 0x16, 0x20, 0x36, 0x20, 0x60, 0x20, 0x40, 0x20, - 0x60, 0x20, 0x36, 0x20, 0x16, 0x20, 0x1a, 0x20, - 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x03, 0xe0, }, - {0x00, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, - 0x09, 0xc0, 0x09, 0xc0, 0x1f, 0xc0, 0x3f, 0xc0, - 0x1f, 0xc0, 0x09, 0xc0, 0x09, 0xc0, 0x01, 0xc0, - 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, } + {-7, -7}, + {0x03, 0xe0, 0x02, 0x20, 0x02, 0x20, 0x1a, 0x20, + 0x16, 0x20, 0x36, 0x20, 0x60, 0x20, 0x40, 0x20, + 0x60, 0x20, 0x36, 0x20, 0x16, 0x20, 0x1a, 0x20, + 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x03, 0xe0, }, + {0x00, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, + 0x09, 0xc0, 0x09, 0xc0, 0x1f, 0xc0, 0x3f, 0xc0, + 0x1f, 0xc0, 0x09, 0xc0, 0x09, 0xc0, 0x01, 0xc0, + 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, } }; Cursor *corners[9] = { - &tl, &t, &tr, - &l, nil, &r, - &bl, &b, &br + &tl, &t, &tr, + &l, nil, &r, + &bl, &b, &br }; */ diff --git a/dat.h b/dat.h old mode 100755 new mode 100644 index 4702ab2..cd41513 --- a/dat.h +++ b/dat.h @@ -1,28 +1,28 @@ /* Copyright (c) 1994-1996 David Hogan, see README for licence details */ #ifndef BORDER -#define BORDER _border +#define BORDER _border #endif -#define CORNER _corner -#define INSET _inset -#define MAXHIDDEN 128 +#define CORNER _corner +#define INSET _inset +#define MAXHIDDEN 128 #ifdef SHOWSTICK -#define B3FIXED 6 +#define B3FIXED 6 #else -#define B3FIXED 5 +#define B3FIXED 5 #endif -#define NUMVIRTUALS 12 +#define NUMVIRTUALS 12 -#define AllButtonMask (Button1Mask|Button2Mask|Button3Mask \ - |Button4Mask|Button5Mask) -#define ButtonMask (ButtonPressMask|ButtonReleaseMask) -#define MenuMask (ButtonMask|ButtonMotionMask|ExposureMask) -#define MenuGrabMask (ButtonMask|ButtonMotionMask|StructureNotifyMask) +#define AllButtonMask \ + (Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask) +#define ButtonMask (ButtonPressMask | ButtonReleaseMask) +#define MenuMask (ButtonMask | ButtonMotionMask | ExposureMask) +#define MenuGrabMask (ButtonMask | ButtonMotionMask | StructureNotifyMask) -#ifdef Plan9 -#define DEFSHELL "/bin/rc" +#ifdef Plan9 +#define DEFSHELL "/bin/rc" #else -#define DEFSHELL "/bin/sh" +#define DEFSHELL "/bin/sh" #endif typedef struct Client Client; @@ -30,166 +30,166 @@ typedef struct Menu Menu; typedef struct ScreenInfo ScreenInfo; struct Client { - Window window; - Window parent; - Window trans; - Client *next; - Client *revert; + Window window; + Window parent; + Window trans; + Client* next; + Client* revert; - int x; - int y; - int dx; - int dy; - int border; + int x; + int y; + int dx; + int dy; + int border; - XSizeHints size; - int min_dx; - int min_dy; + XSizeHints size; + int min_dx; + int min_dy; - int state; - int init; - int reparenting; - int is9term; - int hold; - int proto; - int virt; + int state; + int init; + int reparenting; + int is9term; + int hold; + int proto; + int virt; - char *label; - char *instance; - char *class; - char *name; - char *iconname; + char* label; + char* instance; + char* class; + char* name; + char* iconname; - Colormap cmap; - int ncmapwins; - Window *cmapwins; - Colormap *wmcmaps; - ScreenInfo *screen; + Colormap cmap; + int ncmapwins; + Window* cmapwins; + Colormap* wmcmaps; + ScreenInfo* screen; }; -#define hidden(c) ((c)->state == IconicState) -#define withdrawn(c) ((c)->state == WithdrawnState) -#define normal(c) ((c)->state == NormalState) +#define hidden(c) ((c)->state == IconicState) +#define withdrawn(c) ((c)->state == WithdrawnState) +#define normal(c) ((c)->state == NormalState) /* c->proto */ -#define Pdelete 1 -#define Ptakefocus 2 -#define Plosefocus 4 +#define Pdelete 1 +#define Ptakefocus 2 +#define Plosefocus 4 struct Menu { - char **item; - char *(*gen)(); - int lasthit; + char** item; + char* (*gen)(); + int lasthit; }; enum BorderOrient { - BorderUnknown = 0, /* we depend on this!*/ - BorderN, - BorderNNE, - BorderENE, - BorderE, - BorderESE, - BorderSSE, - BorderS, - BorderSSW, - BorderWSW, - BorderW, - BorderWNW, - BorderNNW, - NBorder + BorderUnknown = 0, /* we depend on this!*/ + BorderN, + BorderNNE, + BorderENE, + BorderE, + BorderESE, + BorderSSE, + BorderS, + BorderSSW, + BorderWSW, + BorderW, + BorderWNW, + BorderNNW, + NBorder }; typedef enum BorderOrient BorderOrient; struct ScreenInfo { - int num; - int depth; - Visual *vis; - int width; - int height; - Window root; - Window menuwin; - Window sweepwin; - Colormap def_cmap; - GC gc; - GC gccopy; - GC gcred; - GC gcsweep; - GC gcmenubg; - GC gcmenubgs; - GC gcmenufg; - GC gcmenufgs; - unsigned long black; - unsigned long white; - unsigned long activeholdborder; - unsigned long inactiveholdborder; - unsigned long activeborder; - unsigned long inactiveborder; - unsigned long red; - Pixmap bkup[2]; - int min_cmaps; - Cursor target; - Cursor sweep0; - Cursor boxcurs; - Cursor arrow; - Cursor bordcurs[NBorder]; - Pixmap root_pixmap; - char display[256]; /* arbitrary limit */ + int num; + int depth; + Visual* vis; + int width; + int height; + Window root; + Window menuwin; + Window sweepwin; + Colormap def_cmap; + GC gc; + GC gccopy; + GC gcred; + GC gcsweep; + GC gcmenubg; + GC gcmenubgs; + GC gcmenufg; + GC gcmenufgs; + unsigned long black; + unsigned long white; + unsigned long activeholdborder; + unsigned long inactiveholdborder; + unsigned long activeborder; + unsigned long inactiveborder; + unsigned long red; + Pixmap bkup[2]; + int min_cmaps; + Cursor target; + Cursor sweep0; + Cursor boxcurs; + Cursor arrow; + Cursor bordcurs[NBorder]; + Pixmap root_pixmap; + char display[256]; /* arbitrary limit */ }; /* main.c */ -extern Display *dpy; -extern ScreenInfo *screens; -extern int num_screens; -extern int initting; -extern XFontStruct *font; -extern int nostalgia; -extern char **myargv; -extern Bool shape; -extern char *termprog; -extern char *shell; -extern char *version[]; -extern int _border; -extern int _corner; -extern int _inset; -extern int curtime; -extern int debug; -extern int solidsweep; -extern int numvirtuals; -extern int scrolling; -extern int ffm; /* focus follows mouse */ +extern Display* dpy; +extern ScreenInfo* screens; +extern int num_screens; +extern int initting; +extern XFontStruct* font; +extern int nostalgia; +extern char** myargv; +extern Bool shape; +extern char* termprog; +extern char* shell; +extern char* version[]; +extern int _border; +extern int _corner; +extern int _inset; +extern int curtime; +extern int debug; +extern int solidsweep; +extern int numvirtuals; +extern int scrolling; +extern int ffm; /* focus follows mouse */ -extern Atom exit_rio; -extern Atom restart_rio; -extern Atom wm_state; -extern Atom wm_change_state; -extern Atom _rio_hold_mode; -extern Atom wm_protocols; -extern Atom wm_delete; -extern Atom wm_take_focus; -extern Atom wm_lose_focus; -extern Atom wm_colormaps; -extern Atom wm_state_fullscreen; -extern Atom wm_state; +extern Atom exit_rio; +extern Atom restart_rio; +extern Atom wm_state; +extern Atom wm_change_state; +extern Atom _rio_hold_mode; +extern Atom wm_protocols; +extern Atom wm_delete; +extern Atom wm_take_focus; +extern Atom wm_lose_focus; +extern Atom wm_colormaps; +extern Atom wm_state_fullscreen; +extern Atom wm_state; /* client.c */ -extern Client *clients; -extern Client *current; -extern Client *currents[]; +extern Client* clients; +extern Client* current; +extern Client* currents[]; /* menu.c */ -extern Client *hiddenc[]; -extern int numhidden; -extern char *b2items[]; -extern Menu b2menu; -extern char *b3items[]; -extern Menu b3menu; -extern int virt; +extern Client* hiddenc[]; +extern int numhidden; +extern char* b2items[]; +extern Menu b2menu; +extern char* b3items[]; +extern Menu b3menu; +extern int virt; /* manage.c */ -extern int isNew; +extern int isNew; /* error.c */ -extern int ignore_badwindow; +extern int ignore_badwindow; /* key.c and event.c share this */ -extern int kbLaunch; +extern int kbLaunch; diff --git a/error.c b/error.c old mode 100755 new mode 100644 index 51a4a49..c326242 --- a/error.c +++ b/error.c @@ -8,95 +8,93 @@ #include "dat.h" #include "fns.h" -int ignore_badwindow; +int ignore_badwindow; void -fatal(char *s) -{ - fprintf(stderr, "ryudo: "); - perror(s); - fprintf(stderr, "\n"); - exit(1); +fatal(char* s) { + fprintf(stderr, "ryudo: "); + perror(s); + fprintf(stderr, "\n"); + exit(1); } int -handler(Display *d, XErrorEvent *e) -{ - char msg[80], req[80], number[80]; +handler(Display* d, XErrorEvent* e) { + char msg[80], req[80], number[80]; - if(initting && (e->request_code == X_ChangeWindowAttributes) && (e->error_code == BadAccess)){ - fprintf(stderr, "ryudo: it looks like there's already a window manager running; ryudo not started\n"); - exit(1); - } + if ( + initting && (e->request_code == X_ChangeWindowAttributes) && + (e->error_code == BadAccess)) { + fprintf( + stderr, + "ryudo: it looks like there's already a window manager running; ryudo " + "not started\n"); + exit(1); + } - if(ignore_badwindow && (e->error_code == BadWindow || e->error_code == BadColor)) - return 0; + if ( + ignore_badwindow && + (e->error_code == BadWindow || e->error_code == BadColor)) + return 0; - XGetErrorText(d, e->error_code, msg, sizeof(msg)); - sprintf(number, "%d", e->request_code); - XGetErrorDatabaseText(d, "XRequest", number, "", req, sizeof(req)); - if(req[0] == '\0') - sprintf(req, "", (int)e->request_code); + XGetErrorText(d, e->error_code, msg, sizeof(msg)); + sprintf(number, "%d", e->request_code); + XGetErrorDatabaseText(d, "XRequest", number, "", req, sizeof(req)); + if (req[0] == '\0') sprintf(req, "", (int)e->request_code); - fprintf(stderr, "ryudo: %s(0x%x): %s\n", req, (int)e->resourceid, msg); + fprintf(stderr, "ryudo: %s(0x%x): %s\n", req, (int)e->resourceid, msg); - if(initting){ - fprintf(stderr, "ryudo: failure during initialisation; aborting\n"); - exit(1); - } - return 0; + if (initting) { + fprintf(stderr, "ryudo: failure during initialisation; aborting\n"); + exit(1); + } + return 0; } void -graberror(char *f, int err) -{ -#ifdef DEBUG /* sick of "bug" reports; grab errors "just happen" */ - char *s; +graberror(char* f, int err) { +#ifdef DEBUG /* sick of "bug" reports; grab errors "just happen" */ + char* s; - switch (err){ - case GrabNotViewable: - s = "not viewable"; - break; - case AlreadyGrabbed: - s = "already grabbed"; - break; - case GrabFrozen: - s = "grab frozen"; - break; - case GrabInvalidTime: - s = "invalid time"; - break; - case GrabSuccess: - return; - default: - fprintf(stderr, "ryudo: %s: grab error: %d\n", f, err); - return; - } - fprintf(stderr, "ryudo: %s: grab error: %s\n", f, s); + switch (err) { + case GrabNotViewable: s = "not viewable"; break; + case AlreadyGrabbed: s = "already grabbed"; break; + case GrabFrozen: s = "grab frozen"; break; + case GrabInvalidTime: s = "invalid time"; break; + case GrabSuccess: return; + default: fprintf(stderr, "ryudo: %s: grab error: %d\n", f, err); return; + } + fprintf(stderr, "ryudo: %s: grab error: %s\n", f, s); #endif } -#ifdef DEBUG_EV +#ifdef DEBUG_EV #include "showevent/ShowEvent.c" #endif -#ifdef DEBUG +#ifdef DEBUG void -dotrace(char *s, Client *c, XEvent *e) -{ - if(debug == 0) - return; -setbuf(stdout, 0); - fprintf(stderr, "ryudo: %s: c=%p", s, (void*)c); - if(c) - fprintf(stderr, " x %d y %d dx %d dy %d w 0x%x parent 0x%x", c->x, c->y, c->dx, c->dy, (int)c->window, (int)c->parent); -#ifdef DEBUG_EV - if(e){ - fprintf(stderr, "\n\t"); - ShowEvent(e); - } +dotrace(char* s, Client* c, XEvent* e) { + if (debug == 0) return; + setbuf(stdout, 0); + fprintf(stderr, "ryudo: %s: c=%p", s, (void*)c); + if (c) + fprintf( + stderr, + " x %d y %d dx %d dy %d w 0x%x parent 0x%x", + c->x, + c->y, + c->dx, + c->dy, + (int)c->window, + (int)c->parent); +#ifdef DEBUG_EV + if (e) { + fprintf(stderr, "\n\t"); + ShowEvent(e); + } #endif - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); } #endif diff --git a/event.c b/event.c old mode 100755 new mode 100644 index 7533b63..5532a10 --- a/event.c +++ b/event.c @@ -18,613 +18,533 @@ #include "config.h" void -mainloop(int shape_event) -{ - XEvent ev; +mainloop(int shape_event) { + XEvent ev; - for(;;){ - getevent(&ev); -#ifdef DEBUG_EV - if(debug){ - ShowEvent(&ev); - printf("\n"); - } + for (;;) { + getevent(&ev); +#ifdef DEBUG_EV + if (debug) { + ShowEvent(&ev); + printf("\n"); + } #endif - switch (ev.type){ - default: -#ifdef SHAPE - if(shape && ev.type == shape_event) - shapenotify((XShapeEvent *)&ev); - else + switch (ev.type) { + default: +#ifdef SHAPE + if (shape && ev.type == shape_event) + shapenotify((XShapeEvent*)&ev); + else #endif - fprintf(stderr, "ryudo: unknown ev.type %d\n", ev.type); - break; - case KeyPress: - keypress(&ev.xkey); - break; - case KeyRelease: - keyrelease(&ev.xkey); - break; - case ButtonPress: - button(&ev.xbutton); - break; - case ButtonRelease: - break; - case MapRequest: - mapreq(&ev.xmaprequest); - break; - case ConfigureRequest: - configurereq(&ev.xconfigurerequest); - break; - case CirculateRequest: - circulatereq(&ev.xcirculaterequest); - break; - case UnmapNotify: - unmap(&ev.xunmap); - break; - case CreateNotify: - newwindow(&ev.xcreatewindow); - break; - case DestroyNotify: - destroy(ev.xdestroywindow.window); - break; - case ClientMessage: - clientmesg(&ev.xclient); - break; - case ColormapNotify: - cmap(&ev.xcolormap); - break; - case PropertyNotify: - property(&ev.xproperty); - break; - case SelectionClear: - fprintf(stderr, "ryudo: SelectionClear (this should not happen)\n"); - break; - case SelectionNotify: - fprintf(stderr, "ryudo: SelectionNotify (this should not happen)\n"); - break; - case SelectionRequest: - fprintf(stderr, "ryudo: SelectionRequest (this should not happen)\n"); - break; - case EnterNotify: - enter(&ev.xcrossing); - break; - case LeaveNotify: - leave(&ev.xcrossing); - break; - case ReparentNotify: - reparent(&ev.xreparent); - break; - case FocusIn: - focusin(&ev.xfocus); - break; - case MotionNotify: - motionnotify(&ev.xmotion); - break; - case Expose: - case NoExpose: - case FocusOut: - case ConfigureNotify: - case MapNotify: - case MappingNotify: - case GraphicsExpose: - /* not interested */ - trace("ignore", 0, &ev); - break; - } - } -} - - -void -configurereq(XConfigureRequestEvent *e) -{ - XWindowChanges wc; - Client *c; - - /* we don't set curtime as nothing here uses it */ - c = getclient(e->window, 0); - trace("configurereq", c, e); - - e->value_mask &= ~CWSibling; - - if(c){ - if(e->value_mask & CWX) - c->x = e->x; - if(e->value_mask & CWY) - c->y = e->y; - if(e->value_mask & CWWidth) - c->dx = e->width; - if(e->value_mask & CWHeight) - c->dy = e->height; - if(e->value_mask & CWBorderWidth) - c->border = e->border_width; - - if(c->dx >= c->screen->width && c->dy >= c->screen->height) - c->border = 0; - else - c->border = BORDER; - - if(e->value_mask & CWStackMode){ - if(e->detail == Above) - top(c); - else - e->value_mask &= ~CWStackMode; - } - e->value_mask |= CWX|CWY|CWHeight|CWWidth; - - if(c->parent != c->screen->root && c->window == e->window){ - wc.x = c->x - c->border; - wc.y = c->y - c->border; - wc.width = c->dx+c->border+c->border; - wc.height = c->dy+c->border+c->border; - wc.border_width = 1; - wc.sibling = None; - wc.stack_mode = e->detail; - XConfigureWindow(dpy, c->parent, e->value_mask, &wc); - - if(e->value_mask & CWStackMode){ - top(c); - active(c); - } - } - } - - if(c && c->parent != c->screen->root){ - wc.x = c->border; - wc.y = c->border; - }else { - wc.x = c->x; - wc.y = c->y; - } - wc.width = c->dx; - wc.height = c->dy; - wc.border_width = 0; - wc.sibling = None; - wc.stack_mode = Above; - e->value_mask &= ~CWStackMode; - e->value_mask |= CWBorderWidth; - XConfigureWindow(dpy, c->window, e->value_mask, &wc); + fprintf(stderr, "ryudo: unknown ev.type %d\n", ev.type); + break; + case KeyPress: keypress(&ev.xkey); break; + case KeyRelease: keyrelease(&ev.xkey); break; + case ButtonPress: button(&ev.xbutton); break; + case ButtonRelease: break; + case MapRequest: mapreq(&ev.xmaprequest); break; + case ConfigureRequest: configurereq(&ev.xconfigurerequest); break; + case CirculateRequest: circulatereq(&ev.xcirculaterequest); break; + case UnmapNotify: unmap(&ev.xunmap); break; + case CreateNotify: newwindow(&ev.xcreatewindow); break; + case DestroyNotify: destroy(ev.xdestroywindow.window); break; + case ClientMessage: clientmesg(&ev.xclient); break; + case ColormapNotify: cmap(&ev.xcolormap); break; + case PropertyNotify: property(&ev.xproperty); break; + case SelectionClear: + fprintf(stderr, "ryudo: SelectionClear (this should not happen)\n"); + break; + case SelectionNotify: + fprintf(stderr, "ryudo: SelectionNotify (this should not happen)\n"); + break; + case SelectionRequest: + fprintf(stderr, "ryudo: SelectionRequest (this should not happen)\n"); + break; + case EnterNotify: enter(&ev.xcrossing); break; + case LeaveNotify: leave(&ev.xcrossing); break; + case ReparentNotify: reparent(&ev.xreparent); break; + case FocusIn: focusin(&ev.xfocus); break; + case MotionNotify: motionnotify(&ev.xmotion); break; + case Expose: + case NoExpose: + case FocusOut: + case ConfigureNotify: + case MapNotify: + case MappingNotify: + case GraphicsExpose: + /* not interested */ + trace("ignore", 0, &ev); + break; + } + } } void -mapreq(XMapRequestEvent *e) -{ - Client *c; - int i; +configurereq(XConfigureRequestEvent* e) { + XWindowChanges wc; + Client* c; - curtime = CurrentTime; - c = getclient(e->window, 0); - trace("mapreq", c, e); + /* we don't set curtime as nothing here uses it */ + c = getclient(e->window, 0); + trace("configurereq", c, e); - if(c == 0 || c->window != e->window){ - /* workaround for stupid NCDware */ - fprintf(stderr, "ryudo: bad mapreq c %p w %x, rescanning\n", - (void*)c, (int)e->window); - for(i = 0; i < num_screens; i++) - scanwins(&screens[i]); - c = getclient(e->window, 0); - if(c == 0 || c->window != e->window){ - fprintf(stderr, "ryudo: window not found after rescan\n"); - return; - } - } + e->value_mask &= ~CWSibling; - switch (c->state){ - case WithdrawnState: - if(c->parent == c->screen->root){ - if(!manage(c, 0)) - return; - break; - } - XReparentWindow(dpy, c->window, c->parent, BORDER-1, BORDER-1); - XAddToSaveSet(dpy, c->window); - /* fall through... */ - case NormalState: - XMapWindow(dpy, c->window); - XMapRaised(dpy, c->parent); - top(c); - setstate(c, NormalState); - if(c->trans != None && current && c->trans == current->window) - active(c); - break; - case IconicState: - unhidec(c, 1); - break; - } + if (c) { + if (e->value_mask & CWX) c->x = e->x; + if (e->value_mask & CWY) c->y = e->y; + if (e->value_mask & CWWidth) c->dx = e->width; + if (e->value_mask & CWHeight) c->dy = e->height; + if (e->value_mask & CWBorderWidth) c->border = e->border_width; + + if (c->dx >= c->screen->width && c->dy >= c->screen->height) + c->border = 0; + else + c->border = BORDER; + + if (e->value_mask & CWStackMode) { + if (e->detail == Above) + top(c); + else + e->value_mask &= ~CWStackMode; + } + e->value_mask |= CWX | CWY | CWHeight | CWWidth; + + if (c->parent != c->screen->root && c->window == e->window) { + wc.x = c->x - c->border; + wc.y = c->y - c->border; + wc.width = c->dx + c->border + c->border; + wc.height = c->dy + c->border + c->border; + wc.border_width = 1; + wc.sibling = None; + wc.stack_mode = e->detail; + XConfigureWindow(dpy, c->parent, e->value_mask, &wc); + + if (e->value_mask & CWStackMode) { + top(c); + active(c); + } + } + } + + if (c && c->parent != c->screen->root) { + wc.x = c->border; + wc.y = c->border; + } else { + wc.x = c->x; + wc.y = c->y; + } + wc.width = c->dx; + wc.height = c->dy; + wc.border_width = 0; + wc.sibling = None; + wc.stack_mode = Above; + e->value_mask &= ~CWStackMode; + e->value_mask |= CWBorderWidth; + XConfigureWindow(dpy, c->window, e->value_mask, &wc); } void -unmap(XUnmapEvent *e) -{ - Client *c; +mapreq(XMapRequestEvent* e) { + Client* c; + int i; - curtime = CurrentTime; - c = getclient(e->window, 0); - if(c){ - switch (c->state){ - case IconicState: - if(e->send_event){ - unhidec(c, 0); - withdraw(c); - } - break; - case NormalState: - if(c == current) - nofocus(); - if(!c->reparenting) - withdraw(c); - break; - } - c->reparenting = 0; - } + curtime = CurrentTime; + c = getclient(e->window, 0); + trace("mapreq", c, e); + + if (c == 0 || c->window != e->window) { + /* workaround for stupid NCDware */ + fprintf( + stderr, + "ryudo: bad mapreq c %p w %x, rescanning\n", + (void*)c, + (int)e->window); + for (i = 0; i < num_screens; i++) scanwins(&screens[i]); + c = getclient(e->window, 0); + if (c == 0 || c->window != e->window) { + fprintf(stderr, "ryudo: window not found after rescan\n"); + return; + } + } + + switch (c->state) { + case WithdrawnState: + if (c->parent == c->screen->root) { + if (!manage(c, 0)) return; + break; + } + XReparentWindow(dpy, c->window, c->parent, BORDER - 1, BORDER - 1); + XAddToSaveSet(dpy, c->window); + /* fall through... */ + case NormalState: + XMapWindow(dpy, c->window); + XMapRaised(dpy, c->parent); + top(c); + setstate(c, NormalState); + if (c->trans != None && current && c->trans == current->window) active(c); + break; + case IconicState: unhidec(c, 1); break; + } } void -circulatereq(XCirculateRequestEvent *e) -{ - fprintf(stderr, "It must be the warlock Krill!\n"); /* ☺ */ +unmap(XUnmapEvent* e) { + Client* c; + + curtime = CurrentTime; + c = getclient(e->window, 0); + if (c) { + switch (c->state) { + case IconicState: + if (e->send_event) { + unhidec(c, 0); + withdraw(c); + } + break; + case NormalState: + if (c == current) nofocus(); + if (!c->reparenting) withdraw(c); + break; + } + c->reparenting = 0; + } } void -newwindow(XCreateWindowEvent *e) -{ - Client *c; - ScreenInfo *s; - static XWindowAttributes ra; - XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra); - - - /* we don't set curtime as nothing here uses it */ - if(e->override_redirect) - return; - c = getclient(e->window, 1); - if(c && c->window == e->window && (s = getscreen(e->parent))){ - c->x = e->x; - c->y = e->y; - c->dx = e->width; - c->dy = e->height; - c->border = e->border_width; - c->screen = s; - if(c->parent == None) - c->parent = c->screen->root; - } - if (kbLaunch) - { - usleep(100000); - quickreshape(c, ra.width/6, GAPSZ, 2*ra.width/3, ra.height - 2*GAPSZ); - kbLaunch = 0; - } +circulatereq(XCirculateRequestEvent* e) { + fprintf(stderr, "It must be the warlock Krill!\n"); /* ☺ */ } void -destroy(Window w) -{ - int i; - Client *c; +newwindow(XCreateWindowEvent* e) { + Client* c; + ScreenInfo* s; + static XWindowAttributes ra; + XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra); - curtime = CurrentTime; - c = getclient(w, 0); - if(c == 0) - return; - - if(numvirtuals > 1) - for(i=0; ioverride_redirect) return; + c = getclient(e->window, 1); + if (c && c->window == e->window && (s = getscreen(e->parent))) { + c->x = e->x; + c->y = e->y; + c->dx = e->width; + c->dy = e->height; + c->border = e->border_width; + c->screen = s; + if (c->parent == None) c->parent = c->screen->root; + } + if (kbLaunch) { + usleep(100000); + quickreshape( + c, ra.width / 6, GAPSZ, 2 * ra.width / 3, ra.height - 2 * GAPSZ); + kbLaunch = 0; + } } void -clientmesg(XClientMessageEvent *e) -{ - Client *c; +destroy(Window w) { + int i; + Client* c; - curtime = CurrentTime; - if(e->message_type == exit_rio){ - cleanup(); - exit(0); - } - if(e->message_type == restart_rio){ - fprintf(stderr, "*** rio restarting ***\n"); - cleanup(); - execvp(myargv[0], myargv); - perror("ryudo: exec failed"); - exit(1); - } - if(e->message_type == wm_protocols) - return; - if(e->message_type == wm_change_state){ - c = getclient(e->window, 0); - if(e->format == 32 && e->data.l[0] == IconicState && c != 0){ - if(normal(c)) - hide(c); - } - else - fprintf(stderr, "ryudo: WM_CHANGE_STATE: format %d data %d w 0x%x\n", - (int)e->format, (int)e->data.l[0], (int)e->window); - return; - } - if(e->message_type == wm_state){ -// c = getclient(e->window, 0); -// if(e->format == 32 && e->data.l[1] == wm_state_fullscreen){ -// }else - fprintf(stderr, "ryudo: WM_STATE: format %d data %d %d w 0x%x\n", - (int)e->format, (int)e->data.l[0], (int)e->data.l[1], - (int)e->window); - return; - } - fprintf(stderr, "ryudo: strange ClientMessage, type 0x%x window 0x%x\n", - (int)e->message_type, (int)e->window); + curtime = CurrentTime; + c = getclient(w, 0); + if (c == 0) return; + + if (numvirtuals > 1) + for (i = 0; i < numvirtuals; i++) + if (currents[i] == c) currents[i] = 0; + + rmclient(c); + + /* flush any errors generated by the window's sudden demise */ + ignore_badwindow = 1; + XSync(dpy, False); + ignore_badwindow = 0; } void -cmap(XColormapEvent *e) -{ - Client *c; - int i; +clientmesg(XClientMessageEvent* e) { + Client* c; - /* we don't set curtime as nothing here uses it */ - if(e->new){ - c = getclient(e->window, 0); - if(c){ - c->cmap = e->colormap; - if(c == current) - cmapfocus(c); - } - else - for(c = clients; c; c = c->next){ - for(i = 0; i < c->ncmapwins; i++) - if(c->cmapwins[i] == e->window){ - c->wmcmaps[i] = e->colormap; - if(c == current) - cmapfocus(c); - return; - } - } - } + curtime = CurrentTime; + if (e->message_type == exit_rio) { + cleanup(); + exit(0); + } + if (e->message_type == restart_rio) { + fprintf(stderr, "*** rio restarting ***\n"); + cleanup(); + execvp(myargv[0], myargv); + perror("ryudo: exec failed"); + exit(1); + } + if (e->message_type == wm_protocols) return; + if (e->message_type == wm_change_state) { + c = getclient(e->window, 0); + if (e->format == 32 && e->data.l[0] == IconicState && c != 0) { + if (normal(c)) hide(c); + } else + fprintf( + stderr, + "ryudo: WM_CHANGE_STATE: format %d data %d w 0x%x\n", + (int)e->format, + (int)e->data.l[0], + (int)e->window); + return; + } + if (e->message_type == wm_state) { + // c = getclient(e->window, 0); + // if(e->format == 32 && e->data.l[1] == wm_state_fullscreen){ + // }else + fprintf( + stderr, + "ryudo: WM_STATE: format %d data %d %d w 0x%x\n", + (int)e->format, + (int)e->data.l[0], + (int)e->data.l[1], + (int)e->window); + return; + } + fprintf( + stderr, + "ryudo: strange ClientMessage, type 0x%x window 0x%x\n", + (int)e->message_type, + (int)e->window); } void -property(XPropertyEvent *e) -{ - Atom a; - int delete; - Client *c; - long msize; +cmap(XColormapEvent* e) { + Client* c; + int i; - /* we don't set curtime as nothing here uses it */ - a = e->atom; - delete = (e->state == PropertyDelete); - c = getclient(e->window, 0); - if(c == 0) - return; - - switch (a){ - case XA_WM_ICON_NAME: - if(c->iconname != 0) - XFree((char*) c->iconname); - c->iconname = delete ? 0 : getprop(c->window, a); - setlabel(c); - renamec(c, c->label); - return; - case XA_WM_NAME: - if(c->name != 0) - XFree((char*) c->name); - c->name = delete ? 0 : getprop(c->window, a); - setlabel(c); - renamec(c, c->label); - return; - case XA_WM_TRANSIENT_FOR: - gettrans(c); - return; - case XA_WM_HINTS: - case XA_WM_SIZE_HINTS: - case XA_WM_ZOOM_HINTS: - /* placeholders to not forget. ignore for now. -Axel */ - return; - case XA_WM_NORMAL_HINTS: - if(XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || c->size.flags == 0) - c->size.flags = PSize; /* not specified - punt */ - return; - } - if(a == _rio_hold_mode){ - c->hold = getiprop(c->window, _rio_hold_mode); - if(c == current) - draw_border(c, 1); - } - else if(a == wm_colormaps){ - getcmaps(c); - if(c == current) - cmapfocus(c); - } + /* we don't set curtime as nothing here uses it */ + if (e->new) { + c = getclient(e->window, 0); + if (c) { + c->cmap = e->colormap; + if (c == current) cmapfocus(c); + } else + for (c = clients; c; c = c->next) { + for (i = 0; i < c->ncmapwins; i++) + if (c->cmapwins[i] == e->window) { + c->wmcmaps[i] = e->colormap; + if (c == current) cmapfocus(c); + return; + } + } + } } void -reparent(XReparentEvent *e) -{ - Client *c; - XWindowAttributes attr; - ScreenInfo *s; +property(XPropertyEvent* e) { + Atom a; + int delete; + Client* c; + long msize; - /* we don't set curtime as nothing here uses it */ - if(!getscreen(e->event) || e->override_redirect) - return; - if((s = getscreen(e->parent)) != 0){ - c = getclient(e->window, 1); - if(c != 0 && (c->dx == 0 || c->dy == 0)){ - /* flush any errors */ - ignore_badwindow = 1; - XGetWindowAttributes(dpy, c->window, &attr); - XSync(dpy, False); - ignore_badwindow = 0; + /* we don't set curtime as nothing here uses it */ + a = e->atom; + delete = (e->state == PropertyDelete); + c = getclient(e->window, 0); + if (c == 0) return; - c->x = attr.x; - c->y = attr.y; - c->dx = attr.width; - c->dy = attr.height; - c->border = attr.border_width; - c->screen = s; - if(c->parent == None) - c->parent = c->screen->root; - } - } - else { - c = getclient(e->window, 0); - if(c != 0 && (c->parent == c->screen->root || withdrawn(c))) - rmclient(c); - } + switch (a) { + case XA_WM_ICON_NAME: + if (c->iconname != 0) XFree((char*)c->iconname); + c->iconname = delete ? 0 : getprop(c->window, a); + setlabel(c); + renamec(c, c->label); + return; + case XA_WM_NAME: + if (c->name != 0) XFree((char*)c->name); + c->name = delete ? 0 : getprop(c->window, a); + setlabel(c); + renamec(c, c->label); + return; + case XA_WM_TRANSIENT_FOR: gettrans(c); return; + case XA_WM_HINTS: + case XA_WM_SIZE_HINTS: + case XA_WM_ZOOM_HINTS: + /* placeholders to not forget. ignore for now. -Axel */ + return; + case XA_WM_NORMAL_HINTS: + if ( + XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || + c->size.flags == 0) + c->size.flags = PSize; /* not specified - punt */ + return; + } + if (a == _rio_hold_mode) { + c->hold = getiprop(c->window, _rio_hold_mode); + if (c == current) draw_border(c, 1); + } else if (a == wm_colormaps) { + getcmaps(c); + if (c == current) cmapfocus(c); + } } -#ifdef SHAPE void -shapenotify(XShapeEvent *e) -{ - Client *c; +reparent(XReparentEvent* e) { + Client* c; + XWindowAttributes attr; + ScreenInfo* s; - /* we don't set curtime as nothing here uses it */ - c = getclient(e->window, 0); - if(c == 0) - return; + /* we don't set curtime as nothing here uses it */ + if (!getscreen(e->event) || e->override_redirect) return; + if ((s = getscreen(e->parent)) != 0) { + c = getclient(e->window, 1); + if (c != 0 && (c->dx == 0 || c->dy == 0)) { + /* flush any errors */ + ignore_badwindow = 1; + XGetWindowAttributes(dpy, c->window, &attr); + XSync(dpy, False); + ignore_badwindow = 0; - setshape(c); + c->x = attr.x; + c->y = attr.y; + c->dx = attr.width; + c->dy = attr.height; + c->border = attr.border_width; + c->screen = s; + if (c->parent == None) c->parent = c->screen->root; + } + } else { + c = getclient(e->window, 0); + if (c != 0 && (c->parent == c->screen->root || withdrawn(c))) rmclient(c); + } +} + +#ifdef SHAPE +void +shapenotify(XShapeEvent* e) { + Client* c; + + /* we don't set curtime as nothing here uses it */ + c = getclient(e->window, 0); + if (c == 0) return; + + setshape(c); } #endif void -enter(XCrossingEvent *e) -{ - Client *c; +enter(XCrossingEvent* e) { + Client* c; - curtime = e->time; - if(!ffm) - if(e->mode != NotifyGrab || e->detail != NotifyNonlinearVirtual) - return; - c = getclient(e->window, 0); - if(c != 0 && c != current){ - /* someone grabbed the pointer; make them current */ - if(!ffm) - XMapRaised(dpy, c->parent); - top(c); - active(c); - } + curtime = e->time; + if (!ffm) + if (e->mode != NotifyGrab || e->detail != NotifyNonlinearVirtual) return; + c = getclient(e->window, 0); + if (c != 0 && c != current) { + /* someone grabbed the pointer; make them current */ + if (!ffm) XMapRaised(dpy, c->parent); + top(c); + active(c); + } } void -leave(XCrossingEvent *e) -{ - Client *c; +leave(XCrossingEvent* e) { + Client* c; - c = getclient(e->window, 0); - if(c) - XUndefineCursor(dpy, c->parent); -/* XDefineCursor(dpy, c->parent, c->screen->arrow); */ + c = getclient(e->window, 0); + if (c) XUndefineCursor(dpy, c->parent); + /* XDefineCursor(dpy, c->parent, c->screen->arrow); */ } void -focusin(XFocusChangeEvent *e) -{ - Client *c; +focusin(XFocusChangeEvent* e) { + Client* c; - curtime = CurrentTime; - if(e->detail != NotifyNonlinearVirtual) - return; - c = getclient(e->window, 0); - if(c != 0 && c->window == e->window && c != current){ + curtime = CurrentTime; + if (e->detail != NotifyNonlinearVirtual) return; + c = getclient(e->window, 0); + if (c != 0 && c->window == e->window && c != current) { #ifdef AUTOSTICK - if (isautostick(c)){ -#endif - /* someone grabbed keyboard or seized focus; make them current */ - XMapRaised(dpy, c->parent); - top(c); - active(c); + if (isautostick(c)) { +#endif + /* someone grabbed keyboard or seized focus; make them current */ + XMapRaised(dpy, c->parent); + top(c); + active(c); #ifdef AUTOSTICK } #endif - } + } } BorderOrient -borderorient(Client *c, int x, int y) -{ - if(x <= BORDER){ - if(y <= CORNER){ - if(debug) fprintf(stderr, "topleft\n"); - return BorderWNW; - } - if(y >= (c->dy + 2*BORDER) - CORNER){ - if(debug) fprintf(stderr, "botleft\n"); - return BorderWSW; - } - if(y > CORNER && - y < (c->dy + 2*BORDER) - CORNER){ - if(debug) fprintf(stderr, "left\n"); - return BorderW; - } - } else if(x <= CORNER){ - if(y <= BORDER){ - if(debug) fprintf(stderr, "topleft\n"); - return BorderNNW; - } - if (y >= (c->dy + BORDER)){ - if(debug) fprintf(stderr, "botleft\n"); - return BorderSSW; - } - } else if(x >= (c->dx + BORDER)){ - if(y <= CORNER){ - if(debug) fprintf(stderr, "topright\n"); - return BorderENE; - } - if(y >= (c->dy + 2*BORDER) - CORNER){ - if(debug) fprintf(stderr, "botright\n"); - return BorderESE; - } - if(y > CORNER && - y < (c->dy + 2*BORDER) - CORNER){ - if(debug) fprintf(stderr, "right\n"); - return BorderE; - } - } else if(x >= (c->dx + 2*BORDER) - CORNER){ - if(y <= BORDER){ - if(debug) fprintf(stderr, "topright\n"); - return BorderNNE; - } - if (y >= (c->dy + BORDER)){ - if(debug) fprintf(stderr, "botright\n"); - return BorderSSE; - } - } else if(x > CORNER && - x < (c->dx + 2*BORDER) - CORNER){ - if(y <= BORDER){ - if(debug) fprintf(stderr, "top\n"); - return BorderN; - } - if(y >= (c->dy + BORDER)){ - if(debug) fprintf(stderr, "bot\n"); - return BorderS; - } - } - return BorderUnknown; +borderorient(Client* c, int x, int y) { + if (x <= BORDER) { + if (y <= CORNER) { + if (debug) fprintf(stderr, "topleft\n"); + return BorderWNW; + } + if (y >= (c->dy + 2 * BORDER) - CORNER) { + if (debug) fprintf(stderr, "botleft\n"); + return BorderWSW; + } + if (y > CORNER && y < (c->dy + 2 * BORDER) - CORNER) { + if (debug) fprintf(stderr, "left\n"); + return BorderW; + } + } else if (x <= CORNER) { + if (y <= BORDER) { + if (debug) fprintf(stderr, "topleft\n"); + return BorderNNW; + } + if (y >= (c->dy + BORDER)) { + if (debug) fprintf(stderr, "botleft\n"); + return BorderSSW; + } + } else if (x >= (c->dx + BORDER)) { + if (y <= CORNER) { + if (debug) fprintf(stderr, "topright\n"); + return BorderENE; + } + if (y >= (c->dy + 2 * BORDER) - CORNER) { + if (debug) fprintf(stderr, "botright\n"); + return BorderESE; + } + if (y > CORNER && y < (c->dy + 2 * BORDER) - CORNER) { + if (debug) fprintf(stderr, "right\n"); + return BorderE; + } + } else if (x >= (c->dx + 2 * BORDER) - CORNER) { + if (y <= BORDER) { + if (debug) fprintf(stderr, "topright\n"); + return BorderNNE; + } + if (y >= (c->dy + BORDER)) { + if (debug) fprintf(stderr, "botright\n"); + return BorderSSE; + } + } else if (x > CORNER && x < (c->dx + 2 * BORDER) - CORNER) { + if (y <= BORDER) { + if (debug) fprintf(stderr, "top\n"); + return BorderN; + } + if (y >= (c->dy + BORDER)) { + if (debug) fprintf(stderr, "bot\n"); + return BorderS; + } + } + return BorderUnknown; } void -motionnotify(XMotionEvent *e) -{ - Client *c; - BorderOrient bl; +motionnotify(XMotionEvent* e) { + Client* c; + BorderOrient bl; - c = getclient(e->window, 0); - if(c){ - bl = borderorient(c, e->x, e->y); - if(bl == BorderUnknown) - XUndefineCursor(dpy, c->parent); - else - XDefineCursor(dpy, c->parent, c->screen->bordcurs[bl]); - } + c = getclient(e->window, 0); + if (c) { + bl = borderorient(c, e->x, e->y); + if (bl == BorderUnknown) + XUndefineCursor(dpy, c->parent); + else + XDefineCursor(dpy, c->parent, c->screen->bordcurs[bl]); + } } diff --git a/fns.h b/fns.h old mode 100755 new mode 100644 index 2dcf5ca..8c72117 --- a/fns.h +++ b/fns.h @@ -1,121 +1,120 @@ /* Copyright (c) 1994-1996 David Hogan, see README for licence details */ -#ifdef DEBUG -#define trace(s, c, e) dotrace((s), (c), (e)) +#ifdef DEBUG +#define trace(s, c, e) dotrace((s), (c), (e)) #else -#define trace(s, c, e) +#define trace(s, c, e) #endif #define setstate setstaterio - /* color.c */ -unsigned long colorpixel(Display*, ScreenInfo*, int, unsigned long, unsigned long); +unsigned long +colorpixel(Display*, ScreenInfo*, int, unsigned long, unsigned long); /* main.c */ -void usage(); -void initscreen(); -ScreenInfo *getscreen(); -Time timestamp(); -void sendcmessage(); -void sendconfig(); -void sighandler(); -void getevent(); -void cleanup(); +void usage(); +void initscreen(); +ScreenInfo* getscreen(); +Time timestamp(); +void sendcmessage(); +void sendconfig(); +void sighandler(); +void getevent(); +void cleanup(); /* event.c */ -void mainloop(); -void configurereq(); -void mapreq(); -void circulatereq(); -void unmap(); -void newwindow(); -void destroy(); -void clientmesg(); -void cmap(); -void property(); -void shapenotify(); -void enter(); -void leave(); -void focusin(); -void reparent(); -void motionnotify(); +void mainloop(); +void configurereq(); +void mapreq(); +void circulatereq(); +void unmap(); +void newwindow(); +void destroy(); +void clientmesg(); +void cmap(); +void property(); +void shapenotify(); +void enter(); +void leave(); +void focusin(); +void reparent(); +void motionnotify(); BorderOrient borderorient(); /* manage.c */ -int manage(); -void scanwins(); -void setshape(); -void withdraw(); -void gravitate(); -void cmapfocus(); -void cmapnofocus(); -void getcmaps(); -int _getprop(); -char *getprop(); -Window getwprop(); -int getiprop(); -int getstate(); -void setstate(); -void setlabel(); -void getproto(); -void gettrans(); +int manage(); +void scanwins(); +void setshape(); +void withdraw(); +void gravitate(); +void cmapfocus(); +void cmapnofocus(); +void getcmaps(); +int _getprop(); +char* getprop(); +Window getwprop(); +int getiprop(); +int getstate(); +void setstate(); +void setlabel(); +void getproto(); +void gettrans(); /* key.c */ void keypress(); void keyrelease(); void keysetup(); -void quickreshape(Client *c, int x, int y, int dx, int dy); +void quickreshape(Client* c, int x, int y, int dx, int dy); void stickystack(int); void centercurrent(XWindowAttributes ra); /* menu.c */ -void button(); -void spawn(); -void reshape(); -void move(); -void delete(); -void hide(); -void unhide(); -void unhidec(); -void renamec(); -void button2(); -void initb2menu(); -void switch_to(); -void switch_to_c(); -void stick(); - +void button(); +void spawn(); +void reshape(); +void move(); +void delete (); +void hide(); +void unhide(); +void unhidec(); +void renamec(); +void button2(); +void initb2menu(); +void switch_to(); +void switch_to_c(); +void stick(); /* client.c */ -void setactive(); -void draw_border(); -void active(); -void nofocus(); -void top(); -Client *getclient(); -void rmclient(); -void dump_revert(); -void dump_clients(); +void setactive(); +void draw_border(); +void active(); +void nofocus(); +void top(); +Client* getclient(); +void rmclient(); +void dump_revert(); +void dump_clients(); void shuffle(int); int isautostick(Client* c); /* grab.c */ -int menuhit(); -Client *selectwin(); -int sweep(); -int drag(); -int pull(); -void getmouse(); -void setmouse(); +int menuhit(); +Client* selectwin(); +int sweep(); +int drag(); +int pull(); +void getmouse(); +void setmouse(); /* error.c */ -int handler(); -void fatal(); -void graberror(); -void showhints(); -void dotrace(); +int handler(); +void fatal(); +void graberror(); +void showhints(); +void dotrace(); /* cursor.c */ -void initcurs(); +void initcurs(); void ShowEvent(XEvent*); diff --git a/grab.c b/grab.c old mode 100755 new mode 100644 index 2dd86cd..e5f12d3 --- a/grab.c +++ b/grab.c @@ -8,668 +8,672 @@ #include "fns.h" int -nobuttons(XButtonEvent *e) /* Einstuerzende */ +nobuttons(XButtonEvent* e) /* Einstuerzende */ { - int state; + int state; - state = (e->state & AllButtonMask); - return (e->type == ButtonRelease) && (state & (state - 1)) == 0; + state = (e->state & AllButtonMask); + return (e->type == ButtonRelease) && (state & (state - 1)) == 0; } int -grab(Window w, Window constrain, int mask, Cursor curs, int t) -{ - int status; +grab(Window w, Window constrain, int mask, Cursor curs, int t) { + int status; - if(t == 0) - t = timestamp(); - status = XGrabPointer(dpy, w, False, mask, - GrabModeAsync, GrabModeAsync, constrain, curs, t); - return status; + if (t == 0) t = timestamp(); + status = XGrabPointer( + dpy, w, False, mask, GrabModeAsync, GrabModeAsync, constrain, curs, t); + return status; } void -ungrab(XButtonEvent *e) -{ - XEvent ev; +ungrab(XButtonEvent* e) { + XEvent ev; - if(!nobuttons(e)) - for(;;){ - XMaskEvent(dpy, ButtonMask | ButtonMotionMask, &ev); - if(ev.type == MotionNotify) - continue; - e = &ev.xbutton; - if(nobuttons(e)) - break; - } - XUngrabPointer(dpy, e->time); - curtime = e->time; + if (!nobuttons(e)) + for (;;) { + XMaskEvent(dpy, ButtonMask | ButtonMotionMask, &ev); + if (ev.type == MotionNotify) continue; + e = &ev.xbutton; + if (nobuttons(e)) break; + } + XUngrabPointer(dpy, e->time); + curtime = e->time; } static void -drawstring(Display *dpy, ScreenInfo *s, Menu *m, int wide, int high, int i, int selected) -{ - int tx, ty; +drawstring( + Display* dpy, ScreenInfo* s, Menu* m, int wide, int high, int i, + int selected) { + int tx, ty; - tx = (wide - XTextWidth(font, m->item[i], strlen(m->item[i])))/2; - ty = i*high + font->ascent + 1; - XFillRectangle(dpy, s->menuwin, selected ? s->gcmenubgs : s->gcmenubg, 0, i*high, wide, high); - XDrawString(dpy, s->menuwin, selected ? s->gcmenufgs : s->gcmenufg, tx, ty, m->item[i], strlen(m->item[i])); + tx = (wide - XTextWidth(font, m->item[i], strlen(m->item[i]))) / 2; + ty = i * high + font->ascent + 1; + XFillRectangle( + dpy, + s->menuwin, + selected ? s->gcmenubgs : s->gcmenubg, + 0, + i * high, + wide, + high); + XDrawString( + dpy, + s->menuwin, + selected ? s->gcmenufgs : s->gcmenufg, + tx, + ty, + m->item[i], + strlen(m->item[i])); } int -menuhit(XButtonEvent *e, Menu *m) -{ - XEvent ev; - int i, n, cur, old, wide, high, status, drawn, warp; - int x, y, dx, dy, xmax, ymax; - ScreenInfo *s; +menuhit(XButtonEvent* e, Menu* m) { + XEvent ev; + int i, n, cur, old, wide, high, status, drawn, warp; + int x, y, dx, dy, xmax, ymax; + ScreenInfo* s; - if(font == 0) - return -1; - s = getscreen(e->root); - if(s == 0 || e->window == s->menuwin) /* ugly event mangling */ - return -1; + if (font == 0) return -1; + s = getscreen(e->root); + if (s == 0 || e->window == s->menuwin) /* ugly event mangling */ + return -1; - dx = 0; - for(n = 0; m->item[n]; n++){ - wide = XTextWidth(font, m->item[n], strlen(m->item[n])) + 4; - if(wide > dx) - dx = wide; - } - wide = dx; - cur = m->lasthit; - if(cur >= n) - cur = n - 1; + dx = 0; + for (n = 0; m->item[n]; n++) { + wide = XTextWidth(font, m->item[n], strlen(m->item[n])) + 4; + if (wide > dx) dx = wide; + } + wide = dx; + cur = m->lasthit; + if (cur >= n) cur = n - 1; - high = font->ascent + font->descent + 1; - dy = n*high; - x = e->x - wide/2; - y = e->y - cur*high - high/2; - warp = 0; - xmax = DisplayWidth(dpy, s->num); - ymax = DisplayHeight(dpy, s->num); - if(x < 0){ - e->x -= x; - x = 0; - warp++; - } - if(x+wide >= xmax){ - e->x -= x+wide-xmax; - x = xmax-wide; - warp++; - } - if(y < 0){ - e->y -= y; - y = 0; - warp++; - } - if(y+dy >= ymax){ - e->y -= y+dy-ymax; - y = ymax-dy; - warp++; - } - if(warp) - setmouse(e->x, e->y, s); - XMoveResizeWindow(dpy, s->menuwin, x, y, dx, dy); - XSelectInput(dpy, s->menuwin, MenuMask); - XMapRaised(dpy, s->menuwin); - status = grab(s->menuwin, None, MenuGrabMask, None, e->time); - if(status != GrabSuccess){ - /* graberror("menuhit", status); */ - XUnmapWindow(dpy, s->menuwin); - return -1; - } - drawn = 0; - for(;;){ - XMaskEvent(dpy, MenuMask, &ev); - switch (ev.type){ - default: - fprintf(stderr, "ryudo: menuhit: unknown ev.type %d\n", ev.type); - break; - case ButtonPress: - break; - case ButtonRelease: - if(ev.xbutton.button != e->button) - break; - x = ev.xbutton.x; - y = ev.xbutton.y; - i = y/high; - if(cur >= 0 && y >= cur*high-3 && y < (cur+1)*high+3) - i = cur; - if(x < 0 || x > wide || y < -3) - i = -1; - else if(i < 0 || i >= n) - i = -1; - else - m->lasthit = i; - if(!nobuttons(&ev.xbutton)) - i = -1; - ungrab(&ev.xbutton); - XUnmapWindow(dpy, s->menuwin); - return i; - case MotionNotify: - if(!drawn) - break; - x = ev.xbutton.x; - y = ev.xbutton.y; - old = cur; - cur = y/high; - if(old >= 0 && y >= old*high-3 && y < (old+1)*high+3) - cur = old; - if(x < 0 || x > wide || y < -3) - cur = -1; - else if(cur < 0 || cur >= n) - cur = -1; - if(cur == old) - break; - if(old >= 0 && old < n) - drawstring(dpy, s, m, wide, high, old, 0); - if(cur >= 0 && cur < n) - drawstring(dpy, s, m, wide, high, cur, 1); - break; - case Expose: - XClearWindow(dpy, s->menuwin); - for(i = 0; i < n; i++) - drawstring(dpy, s, m, wide, high, i, cur==i); - drawn = 1; - } - } + high = font->ascent + font->descent + 1; + dy = n * high; + x = e->x - wide / 2; + y = e->y - cur * high - high / 2; + warp = 0; + xmax = DisplayWidth(dpy, s->num); + ymax = DisplayHeight(dpy, s->num); + if (x < 0) { + e->x -= x; + x = 0; + warp++; + } + if (x + wide >= xmax) { + e->x -= x + wide - xmax; + x = xmax - wide; + warp++; + } + if (y < 0) { + e->y -= y; + y = 0; + warp++; + } + if (y + dy >= ymax) { + e->y -= y + dy - ymax; + y = ymax - dy; + warp++; + } + if (warp) setmouse(e->x, e->y, s); + XMoveResizeWindow(dpy, s->menuwin, x, y, dx, dy); + XSelectInput(dpy, s->menuwin, MenuMask); + XMapRaised(dpy, s->menuwin); + status = grab(s->menuwin, None, MenuGrabMask, None, e->time); + if (status != GrabSuccess) { + /* graberror("menuhit", status); */ + XUnmapWindow(dpy, s->menuwin); + return -1; + } + drawn = 0; + for (;;) { + XMaskEvent(dpy, MenuMask, &ev); + switch (ev.type) { + default: + fprintf(stderr, "ryudo: menuhit: unknown ev.type %d\n", ev.type); + break; + case ButtonPress: break; + case ButtonRelease: + if (ev.xbutton.button != e->button) break; + x = ev.xbutton.x; + y = ev.xbutton.y; + i = y / high; + if (cur >= 0 && y >= cur * high - 3 && y < (cur + 1) * high + 3) + i = cur; + if (x < 0 || x > wide || y < -3) + i = -1; + else if (i < 0 || i >= n) + i = -1; + else + m->lasthit = i; + if (!nobuttons(&ev.xbutton)) i = -1; + ungrab(&ev.xbutton); + XUnmapWindow(dpy, s->menuwin); + return i; + case MotionNotify: + if (!drawn) break; + x = ev.xbutton.x; + y = ev.xbutton.y; + old = cur; + cur = y / high; + if (old >= 0 && y >= old * high - 3 && y < (old + 1) * high + 3) + cur = old; + if (x < 0 || x > wide || y < -3) + cur = -1; + else if (cur < 0 || cur >= n) + cur = -1; + if (cur == old) break; + if (old >= 0 && old < n) drawstring(dpy, s, m, wide, high, old, 0); + if (cur >= 0 && cur < n) drawstring(dpy, s, m, wide, high, cur, 1); + break; + case Expose: + XClearWindow(dpy, s->menuwin); + for (i = 0; i < n; i++) drawstring(dpy, s, m, wide, high, i, cur == i); + drawn = 1; + } + } } -Client * -selectwin(int release, int *shift, ScreenInfo *s) -{ - XEvent ev; - XButtonEvent *e; - int status; - Window w; - Client *c; +Client* +selectwin(int release, int* shift, ScreenInfo* s) { + XEvent ev; + XButtonEvent* e; + int status; + Window w; + Client* c; - status = grab(s->root, s->root, ButtonMask, s->target, 0); - if(status != GrabSuccess){ - graberror("selectwin", status); /* */ - return 0; - } - w = None; - for(;;){ - XMaskEvent(dpy, ButtonMask, &ev); - e = &ev.xbutton; - switch (ev.type){ - case ButtonPress: - if(e->button != Button3){ - ungrab(e); - return 0; - } - w = e->subwindow; - if(!release){ - c = getclient(w, 0); - if(c == 0) - ungrab(e); - if(shift != 0) - *shift = (e->state&ShiftMask) != 0; - return c; - } - break; - case ButtonRelease: - ungrab(e); - if(e->button != Button3 || e->subwindow != w) - return 0; - if(shift != 0) - *shift = (e->state&ShiftMask) != 0; - return getclient(w, 0); - } - } + status = grab(s->root, s->root, ButtonMask, s->target, 0); + if (status != GrabSuccess) { + graberror("selectwin", status); /* */ + return 0; + } + w = None; + for (;;) { + XMaskEvent(dpy, ButtonMask, &ev); + e = &ev.xbutton; + switch (ev.type) { + case ButtonPress: + if (e->button != Button3) { + ungrab(e); + return 0; + } + w = e->subwindow; + if (!release) { + c = getclient(w, 0); + if (c == 0) ungrab(e); + if (shift != 0) *shift = (e->state & ShiftMask) != 0; + return c; + } + break; + case ButtonRelease: + ungrab(e); + if (e->button != Button3 || e->subwindow != w) return 0; + if (shift != 0) *shift = (e->state & ShiftMask) != 0; + return getclient(w, 0); + } + } } int -sweepcalc(Client *c, int x, int y, BorderOrient bl, int ignored) -{ - int dx, dy, sx, sy; +sweepcalc(Client* c, int x, int y, BorderOrient bl, int ignored) { + int dx, dy, sx, sy; - dx = x - c->x; - dy = y - c->y; - sx = sy = 1; - x += dx; - if(dx < 0){ - dx = -dx; - sx = -1; - } - y += dy; - if(dy < 0){ - dy = -dy; - sy = -1; - } + dx = x - c->x; + dy = y - c->y; + sx = sy = 1; + x += dx; + if (dx < 0) { + dx = -dx; + sx = -1; + } + y += dy; + if (dy < 0) { + dy = -dy; + sy = -1; + } - dx -= 2*BORDER; - dy -= 2*BORDER; + dx -= 2 * BORDER; + dy -= 2 * BORDER; - if(!c->is9term){ - if(dx < c->min_dx) - dx = c->min_dx; - if(dy < c->min_dy) - dy = c->min_dy; - } + if (!c->is9term) { + if (dx < c->min_dx) dx = c->min_dx; + if (dy < c->min_dy) dy = c->min_dy; + } - if(c->size.flags & PResizeInc){ - dx = c->min_dx + (dx-c->min_dx)/c->size.width_inc*c->size.width_inc; - dy = c->min_dy + (dy-c->min_dy)/c->size.height_inc*c->size.height_inc; - } + if (c->size.flags & PResizeInc) { + dx = c->min_dx + (dx - c->min_dx) / c->size.width_inc * c->size.width_inc; + dy = c->min_dy + (dy - c->min_dy) / c->size.height_inc * c->size.height_inc; + } - if(c->size.flags & PMaxSize){ - if(dx > c->size.max_width) - dx = c->size.max_width; - if(dy > c->size.max_height) - dy = c->size.max_height; - } - c->dx = sx*(dx + 2*BORDER); - c->dy = sy*(dy + 2*BORDER); + if (c->size.flags & PMaxSize) { + if (dx > c->size.max_width) dx = c->size.max_width; + if (dy > c->size.max_height) dy = c->size.max_height; + } + c->dx = sx * (dx + 2 * BORDER); + c->dy = sy * (dy + 2 * BORDER); - return ignored; + return ignored; } int -dragcalc(Client *c, int x, int y, BorderOrient bl, int ignored) -{ - c->x += x; - c->y += y; +dragcalc(Client* c, int x, int y, BorderOrient bl, int ignored) { + c->x += x; + c->y += y; - return ignored; + return ignored; } int -pullcalc(Client *c, int x, int y, BorderOrient bl, int init) -{ - int dx, dy, sx, sy, px, py, spx, spy, rdx, rdy, xoff, yoff, xcorn, ycorn; +pullcalc(Client* c, int x, int y, BorderOrient bl, int init) { + int dx, dy, sx, sy, px, py, spx, spy, rdx, rdy, xoff, yoff, xcorn, ycorn; - px = c->x; - py = c->y; - dx = c->dx; - dy = c->dy; - sx = sy = 1; - spx = spy = 0; - xoff = yoff = 0; - xcorn = ycorn = 0; + px = c->x; + py = c->y; + dx = c->dx; + dy = c->dy; + sx = sy = 1; + spx = spy = 0; + xoff = yoff = 0; + xcorn = ycorn = 0; - switch(bl){ - case BorderN: - py = y; - dy = (c->y + c->dy) - y; - spy = 1; - yoff = y - c->y; - break; - case BorderS: - dy = y - c->y; - yoff = (c->y + c->dy) - y; - break; - case BorderE: - dx = x - c->x; - xoff = (c->x + c->dx) - x; - break; - case BorderW: - px = x; - dx = (c->x + c->dx) - x; - spx = 1; - xoff = x - c->x; - break; - case BorderNNW: - case BorderWNW: - px = x; - dx = (c->x + c->dx) - x; - spx = 1; - py = y; - dy = (c->y + c->dy) - y; - spy = 1; - xoff = x - c->x; - yoff = y - c->y; - break; - case BorderNNE: - case BorderENE: - dx = x - c->x; - py = y; - dy = (c->y + c->dy) - y; - spy = 1; - xoff = (c->x + c->dx) - x; - yoff = y - c->y; - break; - case BorderSSE: - case BorderESE: - dx = x - c->x; - dy = y - c->y; - xoff = (c->x + c->dx) - x; - yoff = (c->y + c->dy) - y; - break; - case BorderSSW: - case BorderWSW: - px = x; - dx = (c->x + c->dx) - x; - spx = 1; - dy = y - c->y; - xoff = x - c->x; - yoff = (c->y + c->dy) - y; - break; - default: - break; - } - switch(bl){ - case BorderNNW: - case BorderNNE: - case BorderSSW: - case BorderSSE: - xcorn = 1; - break; - case BorderWNW: - case BorderENE: - case BorderWSW: - case BorderESE: - ycorn = 1; - break; - } - if(!init - || xoff < 0 || (xcorn && xoff > CORNER) || (!xcorn && xoff > BORDER) - || yoff < 0 || (ycorn && yoff > CORNER) || (!ycorn && yoff > BORDER)){ - xoff = 0; - yoff = 0; - init = 0; - } + switch (bl) { + case BorderN: + py = y; + dy = (c->y + c->dy) - y; + spy = 1; + yoff = y - c->y; + break; + case BorderS: + dy = y - c->y; + yoff = (c->y + c->dy) - y; + break; + case BorderE: + dx = x - c->x; + xoff = (c->x + c->dx) - x; + break; + case BorderW: + px = x; + dx = (c->x + c->dx) - x; + spx = 1; + xoff = x - c->x; + break; + case BorderNNW: + case BorderWNW: + px = x; + dx = (c->x + c->dx) - x; + spx = 1; + py = y; + dy = (c->y + c->dy) - y; + spy = 1; + xoff = x - c->x; + yoff = y - c->y; + break; + case BorderNNE: + case BorderENE: + dx = x - c->x; + py = y; + dy = (c->y + c->dy) - y; + spy = 1; + xoff = (c->x + c->dx) - x; + yoff = y - c->y; + break; + case BorderSSE: + case BorderESE: + dx = x - c->x; + dy = y - c->y; + xoff = (c->x + c->dx) - x; + yoff = (c->y + c->dy) - y; + break; + case BorderSSW: + case BorderWSW: + px = x; + dx = (c->x + c->dx) - x; + spx = 1; + dy = y - c->y; + xoff = x - c->x; + yoff = (c->y + c->dy) - y; + break; + default: break; + } + switch (bl) { + case BorderNNW: + case BorderNNE: + case BorderSSW: + case BorderSSE: xcorn = 1; break; + case BorderWNW: + case BorderENE: + case BorderWSW: + case BorderESE: ycorn = 1; break; + } + if ( + !init || xoff < 0 || (xcorn && xoff > CORNER) || + (!xcorn && xoff > BORDER) || yoff < 0 || (ycorn && yoff > CORNER) || + (!ycorn && yoff > BORDER)) { + xoff = 0; + yoff = 0; + init = 0; + } - if(debug) fprintf(stderr, "c %dx%d+%d+%d m +%d+%d r %dx%d+%d+%d sp (%d,%d) bl %d\n", - c->dx, c->dy, c->x, c->y, x, y, dx, dy, px, py, spx, spy, bl); - if(dx < 0){ - dx = -dx; - sx = -1; - } - if(dy < 0){ - dy = -dy; - sy = -1; - } + if (debug) + fprintf( + stderr, + "c %dx%d+%d+%d m +%d+%d r %dx%d+%d+%d sp (%d,%d) bl %d\n", + c->dx, + c->dy, + c->x, + c->y, + x, + y, + dx, + dy, + px, + py, + spx, + spy, + bl); + if (dx < 0) { + dx = -dx; + sx = -1; + } + if (dy < 0) { + dy = -dy; + sy = -1; + } - /* remember requested size; - * after applying size hints we may have to correct position - */ - rdx = sx*dx; - rdy = sy*dy; + /* remember requested size; + * after applying size hints we may have to correct position + */ + rdx = sx * dx; + rdy = sy * dy; - /* apply size hints */ - dx -= (2*BORDER - xoff); - dy -= (2*BORDER - yoff); + /* apply size hints */ + dx -= (2 * BORDER - xoff); + dy -= (2 * BORDER - yoff); - if(!c->is9term){ - if(dx < c->min_dx) - dx = c->min_dx; - if(dy < c->min_dy) - dy = c->min_dy; - } + if (!c->is9term) { + if (dx < c->min_dx) dx = c->min_dx; + if (dy < c->min_dy) dy = c->min_dy; + } - if(c->size.flags & PResizeInc){ - dx = c->min_dx + (dx-c->min_dx)/c->size.width_inc*c->size.width_inc; - dy = c->min_dy + (dy-c->min_dy)/c->size.height_inc*c->size.height_inc; - } + if (c->size.flags & PResizeInc) { + dx = c->min_dx + (dx - c->min_dx) / c->size.width_inc * c->size.width_inc; + dy = c->min_dy + (dy - c->min_dy) / c->size.height_inc * c->size.height_inc; + } - if(c->size.flags & PMaxSize){ - if(dx > c->size.max_width) - dx = c->size.max_width; - if(dy > c->size.max_height) - dy = c->size.max_height; - } + if (c->size.flags & PMaxSize) { + if (dx > c->size.max_width) dx = c->size.max_width; + if (dy > c->size.max_height) dy = c->size.max_height; + } - /* set size and position */ - c->dx = sx*(dx + 2*BORDER ); - c->dy = sy*(dy + 2*BORDER ); - c->x = px; - c->y = py; + /* set size and position */ + c->dx = sx * (dx + 2 * BORDER); + c->dy = sy * (dy + 2 * BORDER); + c->x = px; + c->y = py; - /* compensate position for size changed due to size hints */ - if(spx) - c->x -= c->dx - rdx; - if(spy) - c->y -= c->dy - rdy; + /* compensate position for size changed due to size hints */ + if (spx) c->x -= c->dx - rdx; + if (spy) c->y -= c->dy - rdy; - return init; + return init; } static void -xcopy(int fwd, Display *dpy, Drawable src, Drawable dst, GC gc, int x, int y, int dx, int dy, int x1, int y1) -{ - if(fwd) - XCopyArea(dpy, src, dst, gc, x, y, dx, dy, x1, y1); - else - XCopyArea(dpy, dst, src, gc, x1, y1, dx, dy, x, y); +xcopy( + int fwd, Display* dpy, Drawable src, Drawable dst, GC gc, int x, int y, + int dx, int dy, int x1, int y1) { + if (fwd) + XCopyArea(dpy, src, dst, gc, x, y, dx, dy, x1, y1); + else + XCopyArea(dpy, dst, src, gc, x1, y1, dx, dy, x, y); } void -drawbound(Client *c, int drawing) -{ - int x, y, dx, dy; - ScreenInfo *s; +drawbound(Client* c, int drawing) { + int x, y, dx, dy; + ScreenInfo* s; - if(debug) fprintf(stderr, "drawbound %d %dx%d+%d+%d\n", drawing, c->dx, c->dy, c->x, c->y); + if (debug) + fprintf( + stderr, "drawbound %d %dx%d+%d+%d\n", drawing, c->dx, c->dy, c->x, c->y); - s = c->screen; - x = c->x; - y = c->y; - dx = c->dx; - dy = c->dy; - if(dx < 0){ - x += dx; - dx = -dx; - } - if(dy < 0){ - y += dy; - dy = -dy; - } - if(dx <= 2 || dy <= 2) - return; + s = c->screen; + x = c->x; + y = c->y; + dx = c->dx; + dy = c->dy; + if (dx < 0) { + x += dx; + dx = -dx; + } + if (dy < 0) { + y += dy; + dy = -dy; + } + if (dx <= 2 || dy <= 2) return; - if(solidsweep){ - if(drawing == -1){ - XUnmapWindow(dpy, s->sweepwin); - return; - } + if (solidsweep) { + if (drawing == -1) { + XUnmapWindow(dpy, s->sweepwin); + return; + } - x += BORDER; - y += BORDER; - dx -= 2*BORDER; - dy -= 2*BORDER; + x += BORDER; + y += BORDER; + dx -= 2 * BORDER; + dy -= 2 * BORDER; - if(drawing){ - XMoveResizeWindow(dpy, s->sweepwin, x, y, dx, dy); - XSelectInput(dpy, s->sweepwin, MenuMask); - XMapRaised(dpy, s->sweepwin); - } - return; - } + if (drawing) { + XMoveResizeWindow(dpy, s->sweepwin, x, y, dx, dy); + XSelectInput(dpy, s->sweepwin, MenuMask); + XMapRaised(dpy, s->sweepwin); + } + return; + } - if(drawing == -1) - return; + if (drawing == -1) return; - xcopy(drawing, dpy, s->root, s->bkup[0], s->gccopy, x, y, dx, BORDER, 0, 0); - xcopy(drawing, dpy, s->root, s->bkup[0], s->gccopy, x, y+dy-BORDER, dx, BORDER, dx, 0); - xcopy(drawing, dpy, s->root, s->bkup[1], s->gccopy, x, y, BORDER, dy, 0, 0); - xcopy(drawing, dpy, s->root, s->bkup[1], s->gccopy, x+dx-BORDER, y, BORDER, dy, 0, dy); + xcopy(drawing, dpy, s->root, s->bkup[0], s->gccopy, x, y, dx, BORDER, 0, 0); + xcopy( + drawing, + dpy, + s->root, + s->bkup[0], + s->gccopy, + x, + y + dy - BORDER, + dx, + BORDER, + dx, + 0); + xcopy(drawing, dpy, s->root, s->bkup[1], s->gccopy, x, y, BORDER, dy, 0, 0); + xcopy( + drawing, + dpy, + s->root, + s->bkup[1], + s->gccopy, + x + dx - BORDER, + y, + BORDER, + dy, + 0, + dy); - if(drawing){ - XFillRectangle(dpy, s->root, s->gcred, x, y, dx, BORDER); - XFillRectangle(dpy, s->root, s->gcred, x, y+dy-BORDER, dx, BORDER); - XFillRectangle(dpy, s->root, s->gcred, x, y, BORDER, dy); - XFillRectangle(dpy, s->root, s->gcred, x+dx-BORDER, y, BORDER, dy); - } + if (drawing) { + XFillRectangle(dpy, s->root, s->gcred, x, y, dx, BORDER); + XFillRectangle(dpy, s->root, s->gcred, x, y + dy - BORDER, dx, BORDER); + XFillRectangle(dpy, s->root, s->gcred, x, y, BORDER, dy); + XFillRectangle(dpy, s->root, s->gcred, x + dx - BORDER, y, BORDER, dy); + } } void -misleep(int msec) -{ - struct timeval t; +misleep(int msec) { + struct timeval t; - t.tv_sec = msec/1000; - t.tv_usec = (msec%1000)*1000; - select(0, 0, 0, 0, &t); + t.tv_sec = msec / 1000; + t.tv_usec = (msec % 1000) * 1000; + select(0, 0, 0, 0, &t); } int -sweepdrag(Client *c, int but, XButtonEvent *e0, BorderOrient bl, int (*recalc)(Client*, int, int, BorderOrient, int)) -{ - XEvent ev; - int idle; - int cx, cy, rx, ry; - int ox, oy, odx, ody; - XButtonEvent *e; - int notmoved; +sweepdrag( + Client* c, int but, XButtonEvent* e0, BorderOrient bl, + int (*recalc)(Client*, int, int, BorderOrient, int)) { + XEvent ev; + int idle; + int cx, cy, rx, ry; + int ox, oy, odx, ody; + XButtonEvent* e; + int notmoved; - notmoved = 1; - ox = c->x; - oy = c->y; - odx = c->dx; - ody = c->dy; - c->x -= BORDER; - c->y -= BORDER; - c->dx += 2*BORDER; - c->dy += 2*BORDER; - if(bl != BorderUnknown || e0 == 0) - getmouse(&cx, &cy, c->screen); - else - getmouse(&c->x, &c->y, c->screen); - XGrabServer(dpy); - if(bl != BorderUnknown){ - notmoved = recalc(c, cx, cy, bl, notmoved); - } - drawbound(c, 1); - idle = 0; - for(;;){ - if(XCheckMaskEvent(dpy, ButtonMask, &ev) == 0){ - getmouse(&rx, &ry, c->screen); - if(rx != cx || ry != cy || ++idle > 300){ - drawbound(c, 0); - if(rx == cx && ry == cy){ - XUngrabServer(dpy); - XFlush(dpy); - misleep(500); - XGrabServer(dpy); - idle = 0; - } - if(e0 || bl != BorderUnknown) - notmoved = recalc(c, rx, ry, bl, notmoved); - else - notmoved = recalc(c, rx-cx, ry-cy, bl, notmoved); - cx = rx; - cy = ry; - drawbound(c, 1); - XFlush(dpy); - } - misleep(50); - continue; - } - e = &ev.xbutton; - switch (ev.type){ - case ButtonPress: - case ButtonRelease: - drawbound(c, 0); - ungrab(e); - XUngrabServer(dpy); - if(e->button != but && c->init) - goto bad; - if(c->dx < 0){ - c->x += c->dx; - c->dx = -c->dx; - } - if(c->dy < 0){ - c->y += c->dy; - c->dy = -c->dy; - } - c->x += BORDER; - c->y += BORDER; - c->dx -= 2*BORDER; - c->dy -= 2*BORDER; - if(c->dx < 4 || c->dy < 4 || c->dx < c->min_dx || c->dy < c->min_dy) - goto bad; - return 1; - } - } + notmoved = 1; + ox = c->x; + oy = c->y; + odx = c->dx; + ody = c->dy; + c->x -= BORDER; + c->y -= BORDER; + c->dx += 2 * BORDER; + c->dy += 2 * BORDER; + if (bl != BorderUnknown || e0 == 0) + getmouse(&cx, &cy, c->screen); + else + getmouse(&c->x, &c->y, c->screen); + XGrabServer(dpy); + if (bl != BorderUnknown) { notmoved = recalc(c, cx, cy, bl, notmoved); } + drawbound(c, 1); + idle = 0; + for (;;) { + if (XCheckMaskEvent(dpy, ButtonMask, &ev) == 0) { + getmouse(&rx, &ry, c->screen); + if (rx != cx || ry != cy || ++idle > 300) { + drawbound(c, 0); + if (rx == cx && ry == cy) { + XUngrabServer(dpy); + XFlush(dpy); + misleep(500); + XGrabServer(dpy); + idle = 0; + } + if (e0 || bl != BorderUnknown) + notmoved = recalc(c, rx, ry, bl, notmoved); + else + notmoved = recalc(c, rx - cx, ry - cy, bl, notmoved); + cx = rx; + cy = ry; + drawbound(c, 1); + XFlush(dpy); + } + misleep(50); + continue; + } + e = &ev.xbutton; + switch (ev.type) { + case ButtonPress: + case ButtonRelease: + drawbound(c, 0); + ungrab(e); + XUngrabServer(dpy); + if (e->button != but && c->init) goto bad; + if (c->dx < 0) { + c->x += c->dx; + c->dx = -c->dx; + } + if (c->dy < 0) { + c->y += c->dy; + c->dy = -c->dy; + } + c->x += BORDER; + c->y += BORDER; + c->dx -= 2 * BORDER; + c->dy -= 2 * BORDER; + if (c->dx < 4 || c->dy < 4 || c->dx < c->min_dx || c->dy < c->min_dy) + goto bad; + return 1; + } + } bad: - if(debug) fprintf(stderr, "sweepdrag bad\n"); - c->x = ox; - c->y = oy; - c->dx = odx; - c->dy = ody; - drawbound(c, -1); - return 0; + if (debug) fprintf(stderr, "sweepdrag bad\n"); + c->x = ox; + c->y = oy; + c->dx = odx; + c->dy = ody; + drawbound(c, -1); + return 0; } int -sweep(Client *c, int but, XButtonEvent *ignored) -{ - XEvent ev; - int status; - XButtonEvent *e; - ScreenInfo *s; +sweep(Client* c, int but, XButtonEvent* ignored) { + XEvent ev; + int status; + XButtonEvent* e; + ScreenInfo* s; - s = c->screen; - c->dx = 0; - c->dy = 0; - status = grab(s->root, s->root, ButtonMask, s->sweep0, 0); - if(status != GrabSuccess){ - graberror("sweep", status); /* */ - return 0; - } + s = c->screen; + c->dx = 0; + c->dy = 0; + status = grab(s->root, s->root, ButtonMask, s->sweep0, 0); + if (status != GrabSuccess) { + graberror("sweep", status); /* */ + return 0; + } - XMaskEvent(dpy, ButtonMask, &ev); - e = &ev.xbutton; - if(e->button != but){ - ungrab(e); - return 0; - } - XChangeActivePointerGrab(dpy, ButtonMask, s->boxcurs, e->time); - return sweepdrag(c, but, e, BorderUnknown, sweepcalc); + XMaskEvent(dpy, ButtonMask, &ev); + e = &ev.xbutton; + if (e->button != but) { + ungrab(e); + return 0; + } + XChangeActivePointerGrab(dpy, ButtonMask, s->boxcurs, e->time); + return sweepdrag(c, but, e, BorderUnknown, sweepcalc); } int -pull(Client *c, int but, XButtonEvent *e) -{ - int status; - ScreenInfo *s; - BorderOrient bl; +pull(Client* c, int but, XButtonEvent* e) { + int status; + ScreenInfo* s; + BorderOrient bl; - bl = borderorient(c, e->x, e->y); - /* assert(bl > BorderUnknown && bl < NBorder); */ + bl = borderorient(c, e->x, e->y); + /* assert(bl > BorderUnknown && bl < NBorder); */ - s = c->screen; - status = grab(s->root, s->root, ButtonMask, s->bordcurs[bl], 0); - if(status != GrabSuccess){ - graberror("pull", status); /* */ - return 0; - } + s = c->screen; + status = grab(s->root, s->root, ButtonMask, s->bordcurs[bl], 0); + if (status != GrabSuccess) { + graberror("pull", status); /* */ + return 0; + } - return sweepdrag(c, but, 0, bl, pullcalc); + return sweepdrag(c, but, 0, bl, pullcalc); } int -drag(Client *c, int but) -{ - int status; - ScreenInfo *s; +drag(Client* c, int but) { + int status; + ScreenInfo* s; - s = c->screen; - status = grab(s->root, s->root, ButtonMask, s->boxcurs, 0); - if(status != GrabSuccess){ - graberror("drag", status); /* */ - return 0; - } - return sweepdrag(c, but, 0, BorderUnknown, dragcalc); + s = c->screen; + status = grab(s->root, s->root, ButtonMask, s->boxcurs, 0); + if (status != GrabSuccess) { + graberror("drag", status); /* */ + return 0; + } + return sweepdrag(c, but, 0, BorderUnknown, dragcalc); } void -getmouse(int *x, int *y, ScreenInfo *s) -{ - Window dw1, dw2; - int t1, t2; - unsigned int t3; +getmouse(int* x, int* y, ScreenInfo* s) { + Window dw1, dw2; + int t1, t2; + unsigned int t3; - XQueryPointer(dpy, s->root, &dw1, &dw2, x, y, &t1, &t2, &t3); - if(debug) fprintf(stderr, "getmouse: %d %d\n", *x, *y); + XQueryPointer(dpy, s->root, &dw1, &dw2, x, y, &t1, &t2, &t3); + if (debug) fprintf(stderr, "getmouse: %d %d\n", *x, *y); } void -setmouse(int x, int y, ScreenInfo *s) -{ - XWarpPointer(dpy, None, s->root, None, None, None, None, x, y); +setmouse(int x, int y, ScreenInfo* s) { + XWarpPointer(dpy, None, s->root, None, None, None, None, x, y); } diff --git a/key.c b/key.c old mode 100755 new mode 100644 index fe269a4..4fa22e0 --- a/key.c +++ b/key.c @@ -18,11 +18,7 @@ #include "fns.h" #include "patchlevel.h" -enum -{ - GrabAltTab, - GrabAltAny -}; +enum { GrabAltTab, GrabAltAny }; /*static int tabcode = 0x17; */ /*static int altcode = 0x40; */ @@ -32,252 +28,329 @@ enum static void alttab(int shift); void -keysetup(void) -{ - int i; - int tabcode = XKeysymToKeycode(dpy, XK_Tab); - int dcode = XKeysymToKeycode(dpy, DESTROY_KEY); - int icode = XKeysymToKeycode(dpy, ICON_KEY); - int ucode = XKeysymToKeycode(dpy, UNHIDE_KEY); - int mcode = XKeysymToKeycode(dpy, MAX_KEY); - int vcode = XKeysymToKeycode(dpy, MOVE_KEY); - int rcode = XKeysymToKeycode(dpy, RESIZE_KEY); - int scode = XKeysymToKeycode(dpy, STICK_KEY); - int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY); - int lcode = XKeysymToKeycode(dpy, SNAPRIGHT_KEY); - int jcode = XKeysymToKeycode(dpy, SNAPBOTTOM_KEY); - int kcode = XKeysymToKeycode(dpy, SNAPTOP_KEY); - int qcode = XKeysymToKeycode(dpy, SNAPTOPLEFT_KEY); - int wcode = XKeysymToKeycode(dpy, SNAPBOTTOMLEFT_KEY); - int ocode = XKeysymToKeycode(dpy, SNAPBOTTOMRIGHT_KEY); - int pcode = XKeysymToKeycode(dpy, SNAPTOPRIGHT_KEY); - int ccode = XKeysymToKeycode(dpy, SNAPCENTER_KEY); - int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY); - int rightcode = XKeysymToKeycode(dpy, NEXTVIRT_KEY); - int leftcode = XKeysymToKeycode(dpy, PREVVIRT_KEY); +keysetup(void) { + int i; + int tabcode = XKeysymToKeycode(dpy, XK_Tab); + int dcode = XKeysymToKeycode(dpy, DESTROY_KEY); + int icode = XKeysymToKeycode(dpy, ICON_KEY); + int ucode = XKeysymToKeycode(dpy, UNHIDE_KEY); + int mcode = XKeysymToKeycode(dpy, MAX_KEY); + int vcode = XKeysymToKeycode(dpy, MOVE_KEY); + int rcode = XKeysymToKeycode(dpy, RESIZE_KEY); + int scode = XKeysymToKeycode(dpy, STICK_KEY); + int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY); + int lcode = XKeysymToKeycode(dpy, SNAPRIGHT_KEY); + int jcode = XKeysymToKeycode(dpy, SNAPBOTTOM_KEY); + int kcode = XKeysymToKeycode(dpy, SNAPTOP_KEY); + int qcode = XKeysymToKeycode(dpy, SNAPTOPLEFT_KEY); + int wcode = XKeysymToKeycode(dpy, SNAPBOTTOMLEFT_KEY); + int ocode = XKeysymToKeycode(dpy, SNAPBOTTOMRIGHT_KEY); + int pcode = XKeysymToKeycode(dpy, SNAPTOPRIGHT_KEY); + int ccode = XKeysymToKeycode(dpy, SNAPCENTER_KEY); + int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY); + int rightcode = XKeysymToKeycode(dpy, NEXTVIRT_KEY); + int leftcode = XKeysymToKeycode(dpy, PREVVIRT_KEY); #ifdef DEVEL - int tcode = XKeysymToKeycode(dpy, STICKYTOFRONT_KEY); - int bcode = XKeysymToKeycode(dpy, STICKYTOBACK_KEY); + int tcode = XKeysymToKeycode(dpy, STICKYTOFRONT_KEY); + int bcode = XKeysymToKeycode(dpy, STICKYTOBACK_KEY); #endif - for(i=0; ikeycode == tabcode && (e->state&Mod1Mask) == (1<<3)) - alttab(e->state&ShiftMask); - else if(e->keycode == dcode && (e->state&SHORTCUTMOD) == (MODBITS)) - delete(current, 0); - else if (e->keycode == icode && (e->state&SHORTCUTMOD) == (MODBITS)) - hide(current); - else if (e->keycode == ucode && (e->state&SHORTCUTMOD) == (MODBITS)) - unhide(0, 1); - else if (e->keycode == vcode && (e->state&SHORTCUTMOD) == (MODBITS)) - move(current, Button3); - else if (e->keycode == rcode && (e->state&SHORTCUTMOD) == (MODBITS)) - reshape(current, Button3, sweep, 0); - else if (e->keycode == mcode && (e->state&SHORTCUTMOD) == (MODBITS)) - quickreshape(current, -BORDER, -BORDER, ra.width + 2*BORDER, ra.height + 2*BORDER); - else if (e->keycode == scode && (e->state&SHORTCUTMOD) == (MODBITS)) - stick(current); + /* basic wm functionality */ + if (e->keycode == tabcode && (e->state & Mod1Mask) == (1 << 3)) + alttab(e->state & ShiftMask); + else if (e->keycode == dcode && (e->state & SHORTCUTMOD) == (MODBITS)) + delete (current, 0); + else if (e->keycode == icode && (e->state & SHORTCUTMOD) == (MODBITS)) + hide(current); + else if (e->keycode == ucode && (e->state & SHORTCUTMOD) == (MODBITS)) + unhide(0, 1); + else if (e->keycode == vcode && (e->state & SHORTCUTMOD) == (MODBITS)) + move(current, Button3); + else if (e->keycode == rcode && (e->state & SHORTCUTMOD) == (MODBITS)) + reshape(current, Button3, sweep, 0); + else if (e->keycode == mcode && (e->state & SHORTCUTMOD) == (MODBITS)) + quickreshape( + current, -BORDER, -BORDER, ra.width + 2 * BORDER, ra.height + 2 * BORDER); + else if (e->keycode == scode && (e->state & SHORTCUTMOD) == (MODBITS)) + stick(current); -/* half snap */ - else if (e->keycode == hcode && (e->state&SHORTCUTMOD) == (MODBITS)) - quickreshape(current, GAPSZ, GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height - 2*GAPSZ); - else if (e->keycode == lcode && (e->state&SHORTCUTMOD) == (MODBITS)) - quickreshape(current, ra.width/2 + 0.5*GAPSZ, GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height - 2*GAPSZ); - else if (e->keycode == jcode && (e->state&SHORTCUTMOD) == (MODBITS)) - quickreshape(current, GAPSZ, ra.height/2 + 0.5*GAPSZ, ra.width - 2*GAPSZ, ra.height/2 - 1.5*GAPSZ); - else if (e->keycode == kcode && (e->state&SHORTCUTMOD) == (MODBITS)) - quickreshape(current, GAPSZ, GAPSZ, ra.width - 2*GAPSZ, ra.height/2 - 1.5*GAPSZ); + /* half snap */ + else if (e->keycode == hcode && (e->state & SHORTCUTMOD) == (MODBITS)) + quickreshape( + current, GAPSZ, GAPSZ, ra.width / 2 - 1.5 * GAPSZ, ra.height - 2 * GAPSZ); + else if (e->keycode == lcode && (e->state & SHORTCUTMOD) == (MODBITS)) + quickreshape( + current, + ra.width / 2 + 0.5 * GAPSZ, + GAPSZ, + ra.width / 2 - 1.5 * GAPSZ, + ra.height - 2 * GAPSZ); + else if (e->keycode == jcode && (e->state & SHORTCUTMOD) == (MODBITS)) + quickreshape( + current, + GAPSZ, + ra.height / 2 + 0.5 * GAPSZ, + ra.width - 2 * GAPSZ, + ra.height / 2 - 1.5 * GAPSZ); + else if (e->keycode == kcode && (e->state & SHORTCUTMOD) == (MODBITS)) + quickreshape( + current, GAPSZ, GAPSZ, ra.width - 2 * GAPSZ, ra.height / 2 - 1.5 * GAPSZ); -/* quarter snap */ - else if (e->keycode == qcode && (e->state&SHORTCUTMOD) == (MODBITS)) - quickreshape(current, GAPSZ, GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height/2 - 1.5*GAPSZ); - else if (e->keycode == wcode && (e->state&SHORTCUTMOD) == (MODBITS)) - quickreshape(current, GAPSZ, ra.height/2 + 0.5*GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height/2 - 1.5*GAPSZ); - else if (e->keycode == ocode && (e->state&SHORTCUTMOD) == (MODBITS)) - quickreshape(current, ra.width/2 + 0.5*GAPSZ, ra.height/2 + 0.5*GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height/2 - 1.5*GAPSZ); - else if (e->keycode == pcode && (e->state&SHORTCUTMOD) == (MODBITS)) - quickreshape(current, ra.width/2 + 0.5*GAPSZ, GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height/2 - 1.5*GAPSZ); + /* quarter snap */ + else if (e->keycode == qcode && (e->state & SHORTCUTMOD) == (MODBITS)) + quickreshape( + current, + GAPSZ, + GAPSZ, + ra.width / 2 - 1.5 * GAPSZ, + ra.height / 2 - 1.5 * GAPSZ); + else if (e->keycode == wcode && (e->state & SHORTCUTMOD) == (MODBITS)) + quickreshape( + current, + GAPSZ, + ra.height / 2 + 0.5 * GAPSZ, + ra.width / 2 - 1.5 * GAPSZ, + ra.height / 2 - 1.5 * GAPSZ); + else if (e->keycode == ocode && (e->state & SHORTCUTMOD) == (MODBITS)) + quickreshape( + current, + ra.width / 2 + 0.5 * GAPSZ, + ra.height / 2 + 0.5 * GAPSZ, + ra.width / 2 - 1.5 * GAPSZ, + ra.height / 2 - 1.5 * GAPSZ); + else if (e->keycode == pcode && (e->state & SHORTCUTMOD) == (MODBITS)) + quickreshape( + current, + ra.width / 2 + 0.5 * GAPSZ, + GAPSZ, + ra.width / 2 - 1.5 * GAPSZ, + ra.height / 2 - 1.5 * GAPSZ); -/* center snap */ - else if (e->keycode == ccode && (e->state&SHORTCUTMOD) == (MODBITS)){ + /* center snap */ + else if (e->keycode == ccode && (e->state & SHORTCUTMOD) == (MODBITS)) { centercurrent(ra); -} - -#ifdef DEVEL -/* manage autostuck windows */ - if (e->keycode == tcode && (e->state&SHORTCUTMOD) == (MODBITS)) - stickystack(1); - if (e->keycode == bcode && (e->state&SHORTCUTMOD) == (MODBITS)) - stickystack(0); -#endif - - -/* launch */ - if (e->keycode == slcode && (e->state&SHORTCUTMOD) == (MODBITS)){ - kbLaunch = 1; - if(fork() == 0){ - close(ConnectionNumber(dpy)); - if(dpy != '\0') - putenv(dpy); - signal(SIGINT, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGHUP, SIG_DFL); - if(termprog != NULL){ - execl(shell, shell, "-c", termprog, (char*)0); - fprintf(stderr, "ryudo: exec %s", shell); - perror(" failed"); - } - execlp("urxvt", "urxvt", (char*)0); - execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0); - execlp("xterm", "xterm", "-ut", (char*)0); - perror("ryudo: exec urxvt/9term/xterm failed"); - } } -/* switch virts */ - if (e->keycode == rightcode && (e->state&SHORTCUTMOD) == (MODBITS)) - if (numvirtuals > 1) - if (virt < numvirtuals - 1) - switch_to(virt + 1); - else - switch_to(0); +#ifdef DEVEL + /* manage autostuck windows */ + if (e->keycode == tcode && (e->state & SHORTCUTMOD) == (MODBITS)) + stickystack(1); + if (e->keycode == bcode && (e->state & SHORTCUTMOD) == (MODBITS)) + stickystack(0); +#endif - if (e->keycode == leftcode && (e->state&SHORTCUTMOD) == (MODBITS)) - if (numvirtuals >1) - if (virt > 0) - switch_to(virt - 1); - else - switch_to(numvirtuals - 1); + /* launch */ + if (e->keycode == slcode && (e->state & SHORTCUTMOD) == (MODBITS)) { + kbLaunch = 1; + if (fork() == 0) { + close(ConnectionNumber(dpy)); + if (dpy != '\0') putenv(dpy); + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + signal(SIGHUP, SIG_DFL); + if (termprog != NULL) { + execl(shell, shell, "-c", termprog, (char*)0); + fprintf(stderr, "ryudo: exec %s", shell); + perror(" failed"); + } + execlp("urxvt", "urxvt", (char*)0); + execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0); + execlp("xterm", "xterm", "-ut", (char*)0); + perror("ryudo: exec urxvt/9term/xterm failed"); + } + } - XAllowEvents(dpy, SyncKeyboard, e->time); + /* switch virts */ + if (e->keycode == rightcode && (e->state & SHORTCUTMOD) == (MODBITS)) + if (numvirtuals > 1) + if (virt < numvirtuals - 1) + switch_to(virt + 1); + else + switch_to(0); + + if (e->keycode == leftcode && (e->state & SHORTCUTMOD) == (MODBITS)) + if (numvirtuals > 1) + if (virt > 0) + switch_to(virt - 1); + else + switch_to(numvirtuals - 1); + + XAllowEvents(dpy, SyncKeyboard, e->time); } void -keyrelease(XKeyEvent *e) -{ - XAllowEvents(dpy, SyncKeyboard, e->time); +keyrelease(XKeyEvent* e) { + XAllowEvents(dpy, SyncKeyboard, e->time); } void -quickreshape(Client *c, int x, int y, int dx, int dy) -{ - if (c == 0) - return; - XMoveResizeWindow(dpy, c->parent, x,y, dx, dy); - c->x = x + BORDER; - c->y = y + BORDER; - c->dx = dx-2*BORDER; - c->dy = dy-2*BORDER; - XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy); - sendconfig(c); +quickreshape(Client* c, int x, int y, int dx, int dy) { + if (c == 0) return; + XMoveResizeWindow(dpy, c->parent, x, y, dx, dy); + c->x = x + BORDER; + c->y = y + BORDER; + c->dx = dx - 2 * BORDER; + c->dy = dy - 2 * BORDER; + XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy); + sendconfig(c); } void -centercurrent(XWindowAttributes ra) -{ - static int centeroffsetnum = CENTERNUM%2 == 0 ? - CENTERDEN - CENTERNUM : - (CENTERDEN - CENTERNUM)/2; +centercurrent(XWindowAttributes ra) { + static int centeroffsetnum = + CENTERNUM % 2 == 0 ? CENTERDEN - CENTERNUM : (CENTERDEN - CENTERNUM) / 2; - static int centeroffsetden = CENTERNUM%2 == 0 ? - CENTERDEN*2 : - CENTERDEN; + static int centeroffsetden = CENTERNUM % 2 == 0 ? CENTERDEN * 2 : CENTERDEN; - #ifdef CENTERVMAX - quickreshape(current, centeroffsetnum*ra.width/centeroffsetden, GAPSZ, CENTERNUM*ra.width/CENTERDEN, ra.height - 2*GAPSZ); - #else - quickreshape(current, centeroffsetnum*ra.width/centerofsetden, centeroffsetnum*ra.height/centeroffsetden, CENTERNUM*ra.width/CENTERDEN, CENTERNUM*ra.height/CENTERDEN); - #endif +#ifdef CENTERVMAX + quickreshape( + current, + centeroffsetnum * ra.width / centeroffsetden, + GAPSZ, + CENTERNUM * ra.width / CENTERDEN, + ra.height - 2 * GAPSZ); +#else + quickreshape( + current, + centeroffsetnum * ra.width / centerofsetden, + centeroffsetnum * ra.height / centeroffsetden, + CENTERNUM * ra.width / CENTERDEN, + CENTERNUM * ra.height / CENTERDEN); +#endif } static void -alttab(int shift) -{ - shuffle(shift); -/* fprintf(stderr, "%sTab\n", shift ? "Back" : ""); */ +alttab(int shift) { + shuffle(shift); + /* fprintf(stderr, "%sTab\n", shift ? "Back" : ""); */ } #ifdef DEVEL void -stickystack(int toTop) -{ - Client *c; - if(toTop){ - for(c = clients; c->next; c = c->next){ - if(c && isautostick(c)) - top(c); +stickystack(int toTop) { + Client* c; + if (toTop) { + for (c = clients; c->next; c = c->next) { + if (c && isautostick(c)) top(c); } - }else{ - for(c = clients; c->next; c = c->next){ - if(c && !isautostick(c)) - top(c); + } else { + for (c = clients; c->next; c = c->next) { + if (c && !isautostick(c)) top(c); } } } diff --git a/main.c b/main.c old mode 100755 new mode 100644 index dd292a1..da922c9 --- a/main.c +++ b/main.c @@ -17,510 +17,501 @@ #include "fns.h" #include "patchlevel.h" -char *version[] = -{ - "ryudo version 0.4\nCopyright (c) 1994-1996 David Hogan,\n(c) 2004 Russ Cox,\n(c) 2019-2021 Derek Stevens", 0 -}; +char* version[] = { + "ryudo version 0.4\nCopyright (c) 1994-1996 David Hogan,\n(c) 2004 Russ " + "Cox,\n(c) 2019-2021 Derek Stevens", + 0}; -Display *dpy; -ScreenInfo *screens; -int initting; -XFontStruct *font; -int nostalgia; -char **myargv; -char *termprog; -char *shell; -Bool shape; -int _border = 4; -int _corner = 25; -int _inset = 1; -int curtime; -int debug; -int signalled; -int scrolling; -int num_screens; -int solidsweep = 0; -int numvirtuals = 0; -int ffm = 0; -int kbLaunch = 0; +Display* dpy; +ScreenInfo* screens; +int initting; +XFontStruct* font; +int nostalgia; +char** myargv; +char* termprog; +char* shell; +Bool shape; +int _border = 4; +int _corner = 25; +int _inset = 1; +int curtime; +int debug; +int signalled; +int scrolling; +int num_screens; +int solidsweep = 0; +int numvirtuals = 0; +int ffm = 0; +int kbLaunch = 0; -Atom exit_rio; -Atom restart_rio; -Atom wm_state; -Atom wm_change_state; -Atom wm_protocols; -Atom wm_delete; -Atom wm_take_focus; -Atom wm_lose_focus; -Atom wm_colormaps; -Atom _rio_running; -Atom _rio_hold_mode; -Atom wm_state_fullscreen; -Atom wm_state; +Atom exit_rio; +Atom restart_rio; +Atom wm_state; +Atom wm_change_state; +Atom wm_protocols; +Atom wm_delete; +Atom wm_take_focus; +Atom wm_lose_focus; +Atom wm_colormaps; +Atom _rio_running; +Atom _rio_hold_mode; +Atom wm_state_fullscreen; +Atom wm_state; -char *fontlist[] = FONTLIST; +char* fontlist[] = FONTLIST; void -usage(void) -{ - fprintf(stderr, "usage: ryudo [-ffm] [-font fname] [-s] [-term prog] [-version] [-virtuals num] [exit|restart]\n"); - exit(1); +usage(void) { + fprintf( + stderr, + "usage: ryudo [-ffm] [-font fname] [-s] [-term prog] [-version] [-virtuals " + "num] [exit|restart]\n"); + exit(1); } int -main(int argc, char *argv[]) -{ - int i, do_exit, do_restart; - char *fname; - int shape_event; +main(int argc, char* argv[]) { + int i, do_exit, do_restart; + char* fname; + int shape_event; #ifdef SHAPE - int dummy; + int dummy; #endif - shape_event = 0; - myargv = argv; /* for restart */ + shape_event = 0; + myargv = argv; /* for restart */ - do_exit = do_restart = 0; - font = 0; - fname = 0; - for(i = 1; i < argc; i++) - if(strcmp(argv[i], "-nostalgia") == 0) - nostalgia++; - else if(strcmp(argv[i], "-debug") == 0) - debug++; + do_exit = do_restart = 0; + font = 0; + fname = 0; + for (i = 1; i < argc; i++) + if (strcmp(argv[i], "-nostalgia") == 0) + nostalgia++; + else if (strcmp(argv[i], "-debug") == 0) + debug++; - else if(strcmp(argv[i], "-ffm") == 0) - ffm++; + else if (strcmp(argv[i], "-ffm") == 0) + ffm++; - else if(strcmp(argv[i], "-font") == 0 && i+1 12){ - fprintf(stderr, "ryudo: wrong number of virtual displays, defaulting to 4\n"); - numvirtuals = 4; - } - } else if(strcmp(argv[i], "-version") == 0){ - fprintf(stderr, "%s", version[0]); - if(PATCHLEVEL > 0) - fprintf(stderr, "; patch level %d", PATCHLEVEL); - fprintf(stderr, "\n"); - exit(0); - } - else if(strcmp(argv[i], "-s") == 0){ - scrolling = 1; - } - else if(argv[i][0] == '-') - usage(); - else - break; - for(; i < argc; i++) - if(strcmp(argv[i], "exit") == 0) - do_exit++; - else if(strcmp(argv[i], "restart") == 0) - do_restart++; - else - usage(); + else if (strcmp(argv[i], "-font") == 0 && i + 1 < argc) { + i++; + fname = argv[i]; + } else if (strcmp(argv[i], "-term") == 0 && i + 1 < argc) + termprog = argv[++i]; + else if (strcmp(argv[i], "-virtuals") == 0 && i + 1 < argc) { + numvirtuals = atoi(argv[++i]); + if (numvirtuals < 0 || numvirtuals > 12) { + fprintf( + stderr, "ryudo: wrong number of virtual displays, defaulting to 4\n"); + numvirtuals = 4; + } + } else if (strcmp(argv[i], "-version") == 0) { + fprintf(stderr, "%s", version[0]); + if (PATCHLEVEL > 0) fprintf(stderr, "; patch level %d", PATCHLEVEL); + fprintf(stderr, "\n"); + exit(0); + } else if (strcmp(argv[i], "-s") == 0) { + scrolling = 1; + } else if (argv[i][0] == '-') + usage(); + else + break; + for (; i < argc; i++) + if (strcmp(argv[i], "exit") == 0) + do_exit++; + else if (strcmp(argv[i], "restart") == 0) + do_restart++; + else + usage(); - if(do_exit && do_restart) - usage(); + if (do_exit && do_restart) usage(); - shell = (char *)getenv("SHELL"); - if(shell == NULL) - shell = DEFSHELL; + shell = (char*)getenv("SHELL"); + if (shell == NULL) shell = DEFSHELL; - dpy = XOpenDisplay(""); - if(dpy == 0) - fatal("can't open display"); + dpy = XOpenDisplay(""); + if (dpy == 0) fatal("can't open display"); - initting = 1; - XSetErrorHandler(handler); - if(signal(SIGTERM, sighandler) == SIG_IGN) - signal(SIGTERM, SIG_IGN); - if(signal(SIGINT, sighandler) == SIG_IGN) - signal(SIGINT, SIG_IGN); - if(signal(SIGHUP, sighandler) == SIG_IGN) - signal(SIGHUP, SIG_IGN); + initting = 1; + XSetErrorHandler(handler); + if (signal(SIGTERM, sighandler) == SIG_IGN) signal(SIGTERM, SIG_IGN); + if (signal(SIGINT, sighandler) == SIG_IGN) signal(SIGINT, SIG_IGN); + if (signal(SIGHUP, sighandler) == SIG_IGN) signal(SIGHUP, SIG_IGN); - exit_rio = XInternAtom(dpy, "9WM_EXIT", False); - restart_rio = XInternAtom(dpy, "9WM_RESTART", False); + exit_rio = XInternAtom(dpy, "9WM_EXIT", False); + restart_rio = XInternAtom(dpy, "9WM_RESTART", False); - curtime = -1; /* don't care */ - if(do_exit){ - sendcmessage(DefaultRootWindow(dpy), exit_rio, 0L, 1, 1); - XSync(dpy, False); - exit(0); - } - if(do_restart){ - sendcmessage(DefaultRootWindow(dpy), restart_rio, 0L, 1, 1); - XSync(dpy, False); - exit(0); - } + curtime = -1; /* don't care */ + if (do_exit) { + sendcmessage(DefaultRootWindow(dpy), exit_rio, 0L, 1, 1); + XSync(dpy, False); + exit(0); + } + if (do_restart) { + sendcmessage(DefaultRootWindow(dpy), restart_rio, 0L, 1, 1); + XSync(dpy, False); + exit(0); + } - if(0) XSynchronize(dpy, True); + if (0) XSynchronize(dpy, True); - wm_state = XInternAtom(dpy, "WM_STATE", False); - wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False); - wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False); - wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False); - wm_take_focus = XInternAtom(dpy, "WM_TAKE_FOCUS", False); - wm_lose_focus = XInternAtom(dpy, "_9WM_LOSE_FOCUS", False); - wm_colormaps = XInternAtom(dpy, "WM_COLORMAP_WINDOWS", False); - _rio_running = XInternAtom(dpy, "_9WM_RUNNING", False); - _rio_hold_mode = XInternAtom(dpy, "_9WM_HOLD_MODE", False); - wm_state = XInternAtom(dpy, "_NET_WM_STATE", False); - wm_state_fullscreen = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); + wm_state = XInternAtom(dpy, "WM_STATE", False); + wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False); + wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False); + wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + wm_take_focus = XInternAtom(dpy, "WM_TAKE_FOCUS", False); + wm_lose_focus = XInternAtom(dpy, "_9WM_LOSE_FOCUS", False); + wm_colormaps = XInternAtom(dpy, "WM_COLORMAP_WINDOWS", False); + _rio_running = XInternAtom(dpy, "_9WM_RUNNING", False); + _rio_hold_mode = XInternAtom(dpy, "_9WM_HOLD_MODE", False); + wm_state = XInternAtom(dpy, "_NET_WM_STATE", False); + wm_state_fullscreen = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); - if(fname != 0) - if((font = XLoadQueryFont(dpy, fname)) == 0) - fprintf(stderr, "ryudo: warning: can't load font %s\n", fname); + if (fname != 0) + if ((font = XLoadQueryFont(dpy, fname)) == 0) + fprintf(stderr, "ryudo: warning: can't load font %s\n", fname); - if(font == 0){ - i = 0; - for(;;){ - fname = fontlist[i++]; - if(fname == 0){ - fprintf(stderr, "ryudo: warning: can't find a font\n"); - break; - } - font = XLoadQueryFont(dpy, fname); - if(font != 0) - break; - } - } - if(nostalgia){ - _border--; - _inset--; - } + if (font == 0) { + i = 0; + for (;;) { + fname = fontlist[i++]; + if (fname == 0) { + fprintf(stderr, "ryudo: warning: can't find a font\n"); + break; + } + font = XLoadQueryFont(dpy, fname); + if (font != 0) break; + } + } + if (nostalgia) { + _border--; + _inset--; + } -#ifdef SHAPE - shape = XShapeQueryExtension(dpy, &shape_event, &dummy); +#ifdef SHAPE + shape = XShapeQueryExtension(dpy, &shape_event, &dummy); #endif - num_screens = ScreenCount(dpy); - screens = (ScreenInfo *)malloc(sizeof(ScreenInfo) * num_screens); + num_screens = ScreenCount(dpy); + screens = (ScreenInfo*)malloc(sizeof(ScreenInfo) * num_screens); - for(i = 0; i < num_screens; i++) - initscreen(&screens[i], i, 0); + for (i = 0; i < num_screens; i++) initscreen(&screens[i], i, 0); - initb2menu(numvirtuals); + initb2menu(numvirtuals); - /* set selection so that 9term knows we're running */ - curtime = CurrentTime; - XSetSelectionOwner(dpy, _rio_running, screens[0].menuwin, timestamp()); + /* set selection so that 9term knows we're running */ + curtime = CurrentTime; + XSetSelectionOwner(dpy, _rio_running, screens[0].menuwin, timestamp()); - XSync(dpy, False); - initting = 0; + XSync(dpy, False); + initting = 0; - nofocus(); + nofocus(); - for(i = 0; i < num_screens; i++) - scanwins(&screens[i]); + for (i = 0; i < num_screens; i++) scanwins(&screens[i]); - keysetup(); - mainloop(shape_event); - return 0; + keysetup(); + mainloop(shape_event); + return 0; } void -initscreen(ScreenInfo *s, int i, int background) -{ - char *ds, *colon, *dot1; - unsigned long mask; - unsigned long gmask; - XGCValues gv; - XSetWindowAttributes attr; - XVisualInfo xvi; - XSetWindowAttributes attrs; +initscreen(ScreenInfo* s, int i, int background) { + char *ds, *colon, *dot1; + unsigned long mask; + unsigned long gmask; + XGCValues gv; + XSetWindowAttributes attr; + XVisualInfo xvi; + XSetWindowAttributes attrs; - s->num = i; - s->root = RootWindow(dpy, i); - s->def_cmap = DefaultColormap(dpy, i); - s->min_cmaps = MinCmapsOfScreen(ScreenOfDisplay(dpy, i)); - s->depth = DefaultDepth(dpy, i); + s->num = i; + s->root = RootWindow(dpy, i); + s->def_cmap = DefaultColormap(dpy, i); + s->min_cmaps = MinCmapsOfScreen(ScreenOfDisplay(dpy, i)); + s->depth = DefaultDepth(dpy, i); - /* - * Figure out underlying screen format. - */ - if(XMatchVisualInfo(dpy, i, 16, TrueColor, &xvi) - || XMatchVisualInfo(dpy, i, 16, DirectColor, &xvi)){ - s->vis = xvi.visual; - s->depth = 16; - } - else - if(XMatchVisualInfo(dpy, i, 15, TrueColor, &xvi) - || XMatchVisualInfo(dpy, i, 15, DirectColor, &xvi)){ - s->vis = xvi.visual; - s->depth = 15; - } - else - if(XMatchVisualInfo(dpy, i, 24, TrueColor, &xvi) - || XMatchVisualInfo(dpy, i, 24, DirectColor, &xvi)){ - s->vis = xvi.visual; - s->depth = 24; - } - else - if(XMatchVisualInfo(dpy, i, 8, PseudoColor, &xvi) - || XMatchVisualInfo(dpy, i, 8, StaticColor, &xvi)){ - s->vis = xvi.visual; - s->depth = 8; - } - else{ - s->depth = DefaultDepth(dpy, i); - if(s->depth != 8){ - fprintf(stderr, "can't understand depth %d screen", s->depth); - exit(1); - } - s->vis = DefaultVisual(dpy, i); - } - if(DefaultDepth(dpy, i) != s->depth){ - s->def_cmap = XCreateColormap(dpy, s->root, s->vis, AllocNone); - } + /* + * Figure out underlying screen format. + */ + if ( + XMatchVisualInfo(dpy, i, 16, TrueColor, &xvi) || + XMatchVisualInfo(dpy, i, 16, DirectColor, &xvi)) { + s->vis = xvi.visual; + s->depth = 16; + } else if ( + XMatchVisualInfo(dpy, i, 15, TrueColor, &xvi) || + XMatchVisualInfo(dpy, i, 15, DirectColor, &xvi)) { + s->vis = xvi.visual; + s->depth = 15; + } else if ( + XMatchVisualInfo(dpy, i, 24, TrueColor, &xvi) || + XMatchVisualInfo(dpy, i, 24, DirectColor, &xvi)) { + s->vis = xvi.visual; + s->depth = 24; + } else if ( + XMatchVisualInfo(dpy, i, 8, PseudoColor, &xvi) || + XMatchVisualInfo(dpy, i, 8, StaticColor, &xvi)) { + s->vis = xvi.visual; + s->depth = 8; + } else { + s->depth = DefaultDepth(dpy, i); + if (s->depth != 8) { + fprintf(stderr, "can't understand depth %d screen", s->depth); + exit(1); + } + s->vis = DefaultVisual(dpy, i); + } + if (DefaultDepth(dpy, i) != s->depth) { + s->def_cmap = XCreateColormap(dpy, s->root, s->vis, AllocNone); + } - ds = DisplayString(dpy); - colon = rindex(ds, ':'); - if(colon && num_screens > 1){ - strcpy(s->display, "DISPLAY="); - strcat(s->display, ds); - colon = s->display + 8 + (colon - ds); /* use version in buf */ - dot1 = index(colon, '.'); /* first period after colon */ - if(!dot1) - dot1 = colon + strlen(colon); /* if not there, append */ - sprintf(dot1, ".%d", i); - } - else - s->display[0] = '\0'; + ds = DisplayString(dpy); + colon = rindex(ds, ':'); + if (colon && num_screens > 1) { + strcpy(s->display, "DISPLAY="); + strcat(s->display, ds); + colon = s->display + 8 + (colon - ds); /* use version in buf */ + dot1 = index(colon, '.'); /* first period after colon */ + if (!dot1) dot1 = colon + strlen(colon); /* if not there, append */ + sprintf(dot1, ".%d", i); + } else + s->display[0] = '\0'; - s->black = BlackPixel(dpy, i); - s->white = WhitePixel(dpy, i); - s->activeholdborder = colorpixel(dpy, s, s->depth, SHOLDCOL, s->white); - s->inactiveholdborder = colorpixel(dpy, s, s->depth, HOLDCOL, s->black); - s->activeborder = colorpixel(dpy, s, s->depth, SBORDERCOL, s->black); - s->inactiveborder = colorpixel(dpy, s, s->depth, BORDERCOL, s->white); - s->red = colorpixel(dpy, s, s->depth, GHOSTCOL, s->white); - s->width = WidthOfScreen(ScreenOfDisplay(dpy, i)); - s->height = HeightOfScreen(ScreenOfDisplay(dpy, i)); - s->bkup[0] = XCreatePixmap(dpy, s->root, 2*s->width, BORDER, DefaultDepth(dpy, i)); - s->bkup[1] = XCreatePixmap(dpy, s->root, BORDER, 2*s->height, DefaultDepth(dpy, i)); + s->black = BlackPixel(dpy, i); + s->white = WhitePixel(dpy, i); + s->activeholdborder = colorpixel(dpy, s, s->depth, SHOLDCOL, s->white); + s->inactiveholdborder = colorpixel(dpy, s, s->depth, HOLDCOL, s->black); + s->activeborder = colorpixel(dpy, s, s->depth, SBORDERCOL, s->black); + s->inactiveborder = colorpixel(dpy, s, s->depth, BORDERCOL, s->white); + s->red = colorpixel(dpy, s, s->depth, GHOSTCOL, s->white); + s->width = WidthOfScreen(ScreenOfDisplay(dpy, i)); + s->height = HeightOfScreen(ScreenOfDisplay(dpy, i)); + s->bkup[0] = + XCreatePixmap(dpy, s->root, 2 * s->width, BORDER, DefaultDepth(dpy, i)); + s->bkup[1] = + XCreatePixmap(dpy, s->root, BORDER, 2 * s->height, DefaultDepth(dpy, i)); - gv.foreground = s->black^s->white; - gv.background = s->white; - gv.function = GXxor; - gv.line_width = 0; - gv.subwindow_mode = IncludeInferiors; - gmask = GCForeground | GCBackground | GCFunction | GCLineWidth - | GCSubwindowMode; - if(font != 0){ - gv.font = font->fid; - gmask |= GCFont; - } - s->gc = XCreateGC(dpy, s->root, gmask, &gv); + gv.foreground = s->black ^ s->white; + gv.background = s->white; + gv.function = GXxor; + gv.line_width = 0; + gv.subwindow_mode = IncludeInferiors; + gmask = + GCForeground | GCBackground | GCFunction | GCLineWidth | GCSubwindowMode; + if (font != 0) { + gv.font = font->fid; + gmask |= GCFont; + } + s->gc = XCreateGC(dpy, s->root, gmask, &gv); - gv.function = GXcopy; - s->gccopy = XCreateGC(dpy, s->root, gmask, &gv); + gv.function = GXcopy; + s->gccopy = XCreateGC(dpy, s->root, gmask, &gv); - gv.foreground = s->red; - s->gcred = XCreateGC(dpy, s->root, gmask, &gv); + gv.foreground = s->red; + s->gcred = XCreateGC(dpy, s->root, gmask, &gv); - gv.foreground = colorpixel(dpy, s, s->depth, 0xEEEEEE, s->black); - s->gcsweep = XCreateGC(dpy, s->root, gmask, &gv); + gv.foreground = colorpixel(dpy, s, s->depth, 0xEEEEEE, s->black); + s->gcsweep = XCreateGC(dpy, s->root, gmask, &gv); - initcurs(s); + initcurs(s); - attr.cursor = s->arrow; - attr.event_mask = SubstructureRedirectMask - | SubstructureNotifyMask | ColormapChangeMask - | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask - | KeyPressMask | EnterWindowMask; - mask = CWCursor|CWEventMask; - XChangeWindowAttributes(dpy, s->root, mask, &attr); - XSync(dpy, False); + attr.cursor = s->arrow; + attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | + ColormapChangeMask | ButtonPressMask | ButtonReleaseMask | + PropertyChangeMask | KeyPressMask | EnterWindowMask; + mask = CWCursor | CWEventMask; + XChangeWindowAttributes(dpy, s->root, mask, &attr); + XSync(dpy, False); - attrs.border_pixel = colorpixel(dpy, s, s->depth, MBORDERCOL, s->black); - attrs.background_pixel = colorpixel(dpy, s, s->depth, MENUBGCOL, s->white); - attrs.colormap = s->def_cmap; + attrs.border_pixel = colorpixel(dpy, s, s->depth, MBORDERCOL, s->black); + attrs.background_pixel = colorpixel(dpy, s, s->depth, MENUBGCOL, s->white); + attrs.colormap = s->def_cmap; - s->menuwin = XCreateWindow(dpy, s->root, 0, 0, 1, 1, MENUBORDER, - s->depth, - CopyFromParent, - s->vis, - CWBackPixel | CWBorderPixel | CWColormap, - &attrs - ); + s->menuwin = XCreateWindow( + dpy, + s->root, + 0, + 0, + 1, + 1, + MENUBORDER, + s->depth, + CopyFromParent, + s->vis, + CWBackPixel | CWBorderPixel | CWColormap, + &attrs); + gv.foreground = colorpixel(dpy, s, s->depth, MENUBGCOL, s->black); + s->gcmenubg = XCreateGC(dpy, s->menuwin, gmask, &gv); - gv.foreground = colorpixel(dpy, s, s->depth, MENUBGCOL, s->black); - s->gcmenubg = XCreateGC(dpy, s->menuwin, gmask, &gv); + gv.foreground = colorpixel(dpy, s, s->depth, SMENUBGCOL, s->white); + s->gcmenubgs = XCreateGC(dpy, s->menuwin, gmask, &gv); - gv.foreground = colorpixel(dpy, s, s->depth, SMENUBGCOL, s->white); - s->gcmenubgs = XCreateGC(dpy, s->menuwin, gmask, &gv); + gv.foreground = colorpixel(dpy, s, s->depth, MENUFGCOL, s->white); + gv.background = colorpixel(dpy, s, s->depth, MENUBGCOL, s->black); + s->gcmenufg = XCreateGC(dpy, s->menuwin, gmask, &gv); - gv.foreground = colorpixel(dpy, s, s->depth, MENUFGCOL, s->white); - gv.background = colorpixel(dpy, s, s->depth, MENUBGCOL, s->black); - s->gcmenufg = XCreateGC(dpy, s->menuwin, gmask, &gv); + gv.foreground = colorpixel(dpy, s, s->depth, SMENUFGCOL, s->white); + gv.background = colorpixel(dpy, s, s->depth, SMENUBGCOL, s->black); + s->gcmenufgs = XCreateGC(dpy, s->menuwin, gmask, &gv); - gv.foreground = colorpixel(dpy, s, s->depth, SMENUFGCOL, s->white); - gv.background = colorpixel(dpy, s, s->depth, SMENUBGCOL, s->black); - s->gcmenufgs = XCreateGC(dpy, s->menuwin, gmask, &gv); - - attrs.border_pixel = s->red; - attrs.background_pixel = colorpixel(dpy, s, s->depth, 0xEEEEEE, s->black); - attrs.colormap = s->def_cmap; - s->sweepwin = XCreateWindow(dpy, s->root, 0, 0, 1, 1, 4, - s->depth, - CopyFromParent, - s->vis, - CWBackPixel | CWBorderPixel | CWColormap, - &attrs - ); + attrs.border_pixel = s->red; + attrs.background_pixel = colorpixel(dpy, s, s->depth, 0xEEEEEE, s->black); + attrs.colormap = s->def_cmap; + s->sweepwin = XCreateWindow( + dpy, + s->root, + 0, + 0, + 1, + 1, + 4, + s->depth, + CopyFromParent, + s->vis, + CWBackPixel | CWBorderPixel | CWColormap, + &attrs); } ScreenInfo* -getscreen(Window w) -{ - int i; +getscreen(Window w) { + int i; - for(i = 0; i < num_screens; i++) - if(screens[i].root == w) - return &screens[i]; + for (i = 0; i < num_screens; i++) + if (screens[i].root == w) return &screens[i]; - return 0; + return 0; } Time -timestamp(void) -{ - XEvent ev; +timestamp(void) { + XEvent ev; - if(curtime == CurrentTime){ - XChangeProperty(dpy, screens[0].root, _rio_running, _rio_running, 8, - PropModeAppend, (unsigned char *)"", 0); - XMaskEvent(dpy, PropertyChangeMask, &ev); - curtime = ev.xproperty.time; - } - return curtime; + if (curtime == CurrentTime) { + XChangeProperty( + dpy, + screens[0].root, + _rio_running, + _rio_running, + 8, + PropModeAppend, + (unsigned char*)"", + 0); + XMaskEvent(dpy, PropertyChangeMask, &ev); + curtime = ev.xproperty.time; + } + return curtime; } void -sendcmessage(Window w, Atom a, long x, int isroot, int usemask) -{ - XEvent ev; - int status; - long mask; +sendcmessage(Window w, Atom a, long x, int isroot, int usemask) { + XEvent ev; + int status; + long mask; - memset(&ev, 0, sizeof(ev)); - ev.xclient.type = ClientMessage; - ev.xclient.window = w; - ev.xclient.message_type = a; - ev.xclient.format = 32; - ev.xclient.data.l[0] = x; - ev.xclient.data.l[1] = timestamp(); - mask = 0; - if(usemask){ - mask |= KeyPressMask; /* seems to be necessary */ - if(isroot) - mask |= SubstructureRedirectMask; /* magic! */ - else - mask |= ExposureMask; /* not really correct but so be it */ - } - status = XSendEvent(dpy, w, False, mask, &ev); - if(status == 0) - fprintf(stderr, "ryudo: sendcmessage failed\n"); + memset(&ev, 0, sizeof(ev)); + ev.xclient.type = ClientMessage; + ev.xclient.window = w; + ev.xclient.message_type = a; + ev.xclient.format = 32; + ev.xclient.data.l[0] = x; + ev.xclient.data.l[1] = timestamp(); + mask = 0; + if (usemask) { + mask |= KeyPressMask; /* seems to be necessary */ + if (isroot) + mask |= SubstructureRedirectMask; /* magic! */ + else + mask |= ExposureMask; /* not really correct but so be it */ + } + status = XSendEvent(dpy, w, False, mask, &ev); + if (status == 0) fprintf(stderr, "ryudo: sendcmessage failed\n"); } void -sendconfig(Client *c) -{ - XConfigureEvent ce; +sendconfig(Client* c) { + XConfigureEvent ce; - ce.type = ConfigureNotify; - ce.event = c->window; - ce.window = c->window; - ce.x = c->x; - ce.y = c->y; - ce.width = c->dx; - ce.height = c->dy; - ce.border_width = c->border; - ce.above = None; - ce.override_redirect = 0; - XSendEvent(dpy, c->window, False, StructureNotifyMask, (XEvent*)&ce); + ce.type = ConfigureNotify; + ce.event = c->window; + ce.window = c->window; + ce.x = c->x; + ce.y = c->y; + ce.width = c->dx; + ce.height = c->dy; + ce.border_width = c->border; + ce.above = None; + ce.override_redirect = 0; + XSendEvent(dpy, c->window, False, StructureNotifyMask, (XEvent*)&ce); } void -sighandler(void) -{ - signalled = 1; +sighandler(void) { + signalled = 1; } void -getevent(XEvent *e) -{ - int fd; - fd_set rfds; - struct timeval t; +getevent(XEvent* e) { + int fd; + fd_set rfds; + struct timeval t; - if(!signalled){ - if(QLength(dpy) > 0){ - XNextEvent(dpy, e); - return; - } - fd = ConnectionNumber(dpy); - FD_ZERO(&rfds); - FD_SET(fd, &rfds); - t.tv_sec = t.tv_usec = 0; - if(select(fd+1, &rfds, NULL, NULL, &t) == 1){ - XNextEvent(dpy, e); - return; - } - XFlush(dpy); - FD_SET(fd, &rfds); - if(select(fd+1, &rfds, NULL, NULL, NULL) == 1){ - XNextEvent(dpy, e); - return; - } - if(errno != EINTR || !signalled){ - perror("ryudo: select failed"); - exit(1); - } - } - fprintf(stderr, "ryudo: exiting on signal\n"); - cleanup(); - exit(1); + if (!signalled) { + if (QLength(dpy) > 0) { + XNextEvent(dpy, e); + return; + } + fd = ConnectionNumber(dpy); + FD_ZERO(&rfds); + FD_SET(fd, &rfds); + t.tv_sec = t.tv_usec = 0; + if (select(fd + 1, &rfds, NULL, NULL, &t) == 1) { + XNextEvent(dpy, e); + return; + } + XFlush(dpy); + FD_SET(fd, &rfds); + if (select(fd + 1, &rfds, NULL, NULL, NULL) == 1) { + XNextEvent(dpy, e); + return; + } + if (errno != EINTR || !signalled) { + perror("ryudo: select failed"); + exit(1); + } + } + fprintf(stderr, "ryudo: exiting on signal\n"); + cleanup(); + exit(1); } void -cleanup(void) -{ - Client *c, *cc[2], *next; - XWindowChanges wc; - int i; +cleanup(void) { + Client *c, *cc[2], *next; + XWindowChanges wc; + int i; - /* order of un-reparenting determines final stacking order... */ - cc[0] = cc[1] = 0; - for(c = clients; c; c = next){ - next = c->next; - i = normal(c); - c->next = cc[i]; - cc[i] = c; - } + /* order of un-reparenting determines final stacking order... */ + cc[0] = cc[1] = 0; + for (c = clients; c; c = next) { + next = c->next; + i = normal(c); + c->next = cc[i]; + cc[i] = c; + } - for(i = 0; i < 2; i++){ - for(c = cc[i]; c; c = c->next){ - if(!withdrawn(c)){ - XReparentWindow(dpy, c->window, c->screen->root, - c->x, c->y); - } - wc.border_width = c->border; - XConfigureWindow(dpy, c->window, CWBorderWidth, &wc); - } - } + for (i = 0; i < 2; i++) { + for (c = cc[i]; c; c = c->next) { + if (!withdrawn(c)) { + XReparentWindow(dpy, c->window, c->screen->root, c->x, c->y); + } + wc.border_width = c->border; + XConfigureWindow(dpy, c->window, CWBorderWidth, &wc); + } + } - XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, timestamp()); - for(i = 0; i < num_screens; i++) - cmapnofocus(&screens[i]); - XCloseDisplay(dpy); + XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, timestamp()); + for (i = 0; i < num_screens; i++) cmapnofocus(&screens[i]); + XCloseDisplay(dpy); } diff --git a/manage.c b/manage.c old mode 100755 new mode 100644 index 698bac2..fa55da5 --- a/manage.c +++ b/manage.c @@ -23,497 +23,504 @@ int isNew; int -manage(Client *c, int mapped) -{ - int fixsize, dohide, doreshape, state; - long msize; - XClassHint class; - XWMHints *hints; - XSetWindowAttributes attrs; +manage(Client* c, int mapped) { + int fixsize, dohide, doreshape, state; + long msize; + XClassHint class; + XWMHints* hints; + XSetWindowAttributes attrs; - - static XWindowAttributes ra; - XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra); - - trace("manage", c, 0); - XSelectInput(dpy, c->window, ColormapChangeMask | EnterWindowMask | PropertyChangeMask | FocusChangeMask | KeyPressMask); + static XWindowAttributes ra; + XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra); - /* Get loads of hints */ + trace("manage", c, 0); + XSelectInput( + dpy, + c->window, + ColormapChangeMask | EnterWindowMask | PropertyChangeMask | + FocusChangeMask | KeyPressMask); - if(XGetClassHint(dpy, c->window, &class) != 0){ /* ``Success'' */ - c->instance = class.res_name; - c->class = class.res_class; - c->is9term = 0; - if(isNew){ - c->is9term = strstr(c->class, "term") || strstr(c->class, "Term") - || strstr(c->class, "urxvt") || strstr(c->class, "URxvt") - || strstr(c->class, "onsole") || strstr(c->class, "Alacritty"); - isNew = 0; - } - printf("%s: is9term = %d", c->class, c->is9term); - } - else { - c->instance = 0; - c->class = 0; - c->is9term = 0; - } - c->iconname = getprop(c->window, XA_WM_ICON_NAME); - c->name = getprop(c->window, XA_WM_NAME); - setlabel(c); + /* Get loads of hints */ - hints = XGetWMHints(dpy, c->window); - if(XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || c->size.flags == 0) - c->size.flags = PSize; /* not specified - punt */ + if (XGetClassHint(dpy, c->window, &class) != 0) { /* ``Success'' */ + c->instance = class.res_name; + c->class = class.res_class; + c->is9term = 0; + if (isNew) { + c->is9term = strstr(c->class, "term") || strstr(c->class, "Term") || + strstr(c->class, "urxvt") || strstr(c->class, "URxvt") || + strstr(c->class, "onsole") || strstr(c->class, "Alacritty"); + isNew = 0; + } + printf("%s: is9term = %d", c->class, c->is9term); + } else { + c->instance = 0; + c->class = 0; + c->is9term = 0; + } + c->iconname = getprop(c->window, XA_WM_ICON_NAME); + c->name = getprop(c->window, XA_WM_NAME); + setlabel(c); - getcmaps(c); - getproto(c); - gettrans(c); - if(c->is9term) - c->hold = getiprop(c->window, _rio_hold_mode); + hints = XGetWMHints(dpy, c->window); + if ( + XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || + c->size.flags == 0) + c->size.flags = PSize; /* not specified - punt */ - /* Figure out what to do with the window from hints */ + getcmaps(c); + getproto(c); + gettrans(c); + if (c->is9term) c->hold = getiprop(c->window, _rio_hold_mode); - if(!getstate(c->window, &state)) - state = hints ? hints->initial_state : NormalState; - dohide = (state == IconicState); + /* Figure out what to do with the window from hints */ - fixsize = 0; - if((c->size.flags & (USSize|PSize))) - fixsize = 1; - if((c->size.flags & (PMinSize|PMaxSize)) == (PMinSize|PMaxSize) && c->size.min_width == c->size.max_width && c->size.min_height == c->size.max_height) - fixsize = 1; - doreshape = !mapped; - if(fixsize){ - if(c->size.flags & USPosition) - doreshape = 0; - if(dohide && (c->size.flags & PPosition)) - doreshape = 0; - if(c->trans != None) - doreshape = 0; - } - if(c->is9term) - fixsize = 0; - if(c->size.flags & PBaseSize){ - c->min_dx = c->size.base_width; - c->min_dy = c->size.base_height; - } - else if(c->size.flags & PMinSize){ - c->min_dx = c->size.min_width; - c->min_dy = c->size.min_height; - } - else if(c->is9term){ - c->min_dx = 100; - c->min_dy = 50; - } - else - c->min_dx = c->min_dy = 0; + if (!getstate(c->window, &state)) + state = hints ? hints->initial_state : NormalState; + dohide = (state == IconicState); - if(hints) - XFree(hints); + fixsize = 0; + if ((c->size.flags & (USSize | PSize))) fixsize = 1; + if ( + (c->size.flags & (PMinSize | PMaxSize)) == (PMinSize | PMaxSize) && + c->size.min_width == c->size.max_width && + c->size.min_height == c->size.max_height) + fixsize = 1; + doreshape = !mapped; + if (fixsize) { + if (c->size.flags & USPosition) doreshape = 0; + if (dohide && (c->size.flags & PPosition)) doreshape = 0; + if (c->trans != None) doreshape = 0; + } + if (c->is9term) fixsize = 0; + if (c->size.flags & PBaseSize) { + c->min_dx = c->size.base_width; + c->min_dy = c->size.base_height; + } else if (c->size.flags & PMinSize) { + c->min_dx = c->size.min_width; + c->min_dy = c->size.min_height; + } else if (c->is9term) { + c->min_dx = 100; + c->min_dy = 50; + } else + c->min_dx = c->min_dy = 0; - /* Now do it!!! */ + if (hints) XFree(hints); - if(doreshape){ - if(0) fprintf(stderr, "in doreshape is9term=%d fixsize=%d, x=%d, y=%d, min_dx=%d, min_dy=%d, dx=%d, dy=%d\n", - c->is9term, fixsize, c->x, c->y, c->min_dx, c->min_dy, c->dx, c->dy); - if(current && current->screen == c->screen) - cmapnofocus(c->screen); - if(!c->is9term && c->x==0 && c->y==0){ - static int nwin; + /* Now do it!!! */ - c->x = 20*nwin+BORDER; - c->y = 20*nwin+BORDER; - nwin++; - nwin %= 10; - } + if (doreshape) { + if (0) + fprintf( + stderr, + "in doreshape is9term=%d fixsize=%d, x=%d, y=%d, min_dx=%d, min_dy=%d, " + "dx=%d, dy=%d\n", + c->is9term, + fixsize, + c->x, + c->y, + c->min_dx, + c->min_dy, + c->dx, + c->dy); + if (current && current->screen == c->screen) cmapnofocus(c->screen); + if (!c->is9term && c->x == 0 && c->y == 0) { + static int nwin; - if(c->is9term && !(fixsize ? drag(c, Button3) : sweep(c, Button3))){ - XKillClient(dpy, c->window); - rmclient(c); - if(current && current->screen == c->screen) - cmapfocus(current); - return 0; - } - } + c->x = 20 * nwin + BORDER; + c->y = 20 * nwin + BORDER; + nwin++; + nwin %= 10; + } - attrs.border_pixel = c->screen->black; - attrs.background_pixel = c->screen->white; - attrs.colormap = c->screen->def_cmap; - c->parent = XCreateWindow(dpy, c->screen->root, - c->x - BORDER, c->y - BORDER, - c->dx + 2*BORDER, c->dy + 2*BORDER, - 0, - c->screen->depth, - CopyFromParent, - c->screen->vis, - CWBackPixel | CWBorderPixel | CWColormap, - &attrs); + if (c->is9term && !(fixsize ? drag(c, Button3) : sweep(c, Button3))) { + XKillClient(dpy, c->window); + rmclient(c); + if (current && current->screen == c->screen) cmapfocus(current); + return 0; + } + } - XSelectInput(dpy, c->parent, SubstructureRedirectMask | SubstructureNotifyMask|ButtonPressMask| PointerMotionMask|LeaveWindowMask|KeyPressMask); - if(mapped) - c->reparenting = 1; - if(doreshape && !fixsize) - XResizeWindow(dpy, c->window, c->dx, c->dy); - XSetWindowBorderWidth(dpy, c->window, 0); + attrs.border_pixel = c->screen->black; + attrs.background_pixel = c->screen->white; + attrs.colormap = c->screen->def_cmap; + c->parent = XCreateWindow( + dpy, + c->screen->root, + c->x - BORDER, + c->y - BORDER, + c->dx + 2 * BORDER, + c->dy + 2 * BORDER, + 0, + c->screen->depth, + CopyFromParent, + c->screen->vis, + CWBackPixel | CWBorderPixel | CWColormap, + &attrs); - /* - * To have something more than only a big white or black border - * XXX should replace this by a pattern in the white or black - * such that we can see the border also if all our - * windows are black and/or white - * (black (or white) border around black (or white) window - * is not very helpful. - */ - if(c->screen->depth <= 8){ - XSetWindowBorderWidth(dpy, c->parent, 1); - } + XSelectInput( + dpy, + c->parent, + SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask | + PointerMotionMask | LeaveWindowMask | KeyPressMask); + if (mapped) c->reparenting = 1; + if (doreshape && !fixsize) XResizeWindow(dpy, c->window, c->dx, c->dy); + XSetWindowBorderWidth(dpy, c->window, 0); - XReparentWindow(dpy, c->window, c->parent, BORDER, BORDER); -#ifdef SHAPE - if(shape){ - XShapeSelectInput(dpy, c->window, ShapeNotifyMask); - ignore_badwindow = 1; /* magic */ - setshape(c); - ignore_badwindow = 0; - } + /* + * To have something more than only a big white or black border + * XXX should replace this by a pattern in the white or black + * such that we can see the border also if all our + * windows are black and/or white + * (black (or white) border around black (or white) window + * is not very helpful. + */ + if (c->screen->depth <= 8) { XSetWindowBorderWidth(dpy, c->parent, 1); } + + XReparentWindow(dpy, c->window, c->parent, BORDER, BORDER); +#ifdef SHAPE + if (shape) { + XShapeSelectInput(dpy, c->window, ShapeNotifyMask); + ignore_badwindow = 1; /* magic */ + setshape(c); + ignore_badwindow = 0; + } #endif - XAddToSaveSet(dpy, c->window); - if(dohide) - hide(c); - else { - XMapWindow(dpy, c->window); - XMapWindow(dpy, c->parent); - XUnmapWindow(dpy, c->screen->sweepwin); + XAddToSaveSet(dpy, c->window); + if (dohide) + hide(c); + else { + XMapWindow(dpy, c->window); + XMapWindow(dpy, c->parent); + XUnmapWindow(dpy, c->screen->sweepwin); #ifdef AUTOSTICK - if(!isautostick(c)) + if (!isautostick(c)) #endif - active(c); - /*else if(c->trans != None && current && current->window == c->trans) - active(c);*/ - else - setactive(c, 0); - setstate(c, NormalState); - } - if(current && (current != c)) - cmapfocus(current); - c->init = 1; + active(c); + /*else if(c->trans != None && current && current->window == c->trans) + active(c);*/ + else + setactive(c, 0); + setstate(c, NormalState); + } + if (current && (current != c)) cmapfocus(current); + c->init = 1; /* If the window is out of bounds of the screen, try to wrangle it */ /* If it's bigger than the screen, try to set it maximized */ - if (c->dx >= ra.width || c->dy >= ra.width){ + if (c->dx >= ra.width || c->dy >= ra.width) { if (c->dx >= ra.width) - quickreshape(c, -BORDER, c->y - BORDER, ra.width + 2*BORDER, c->dy + 2*BORDER); + quickreshape( + c, -BORDER, c->y - BORDER, ra.width + 2 * BORDER, c->dy + 2 * BORDER); if (c->dy >= ra.height) - quickreshape(c, c->x - BORDER, -BORDER, c->dx + 2*BORDER, ra.height + 2*BORDER); - - /* and if it's got an edge out of bounds, nudge it into bounds */ + quickreshape( + c, c->x - BORDER, -BORDER, c->dx + 2 * BORDER, ra.height + 2 * BORDER); + + /* and if it's got an edge out of bounds, nudge it into bounds */ } else { - if (c->x < BORDER){ - quickreshape(c, 0, c->y - BORDER, c->dx + 2*BORDER, c->dy + 2*BORDER); - } - if (c->y < BORDER){ - quickreshape(c, c->x - BORDER, 0, c->dx + 2*BORDER, c->dy + 2*BORDER); - } - if (c->x + c->dx + BORDER > ra.width){ - quickreshape(c, ra.width - (c->dx + 2*BORDER), c->y - BORDER, c->dx + 2*BORDER, c->dy + 2*BORDER); - } - if (c->y + c->dy + BORDER > ra.height){ - quickreshape(c, c->x - BORDER, ra.height - (c->dy + 2*BORDER), c->dx + 2*BORDER, c->dy + 2*BORDER); - } + if (c->x < BORDER) { + quickreshape(c, 0, c->y - BORDER, c->dx + 2 * BORDER, c->dy + 2 * BORDER); + } + if (c->y < BORDER) { + quickreshape(c, c->x - BORDER, 0, c->dx + 2 * BORDER, c->dy + 2 * BORDER); + } + if (c->x + c->dx + BORDER > ra.width) { + quickreshape( + c, + ra.width - (c->dx + 2 * BORDER), + c->y - BORDER, + c->dx + 2 * BORDER, + c->dy + 2 * BORDER); + } + if (c->y + c->dy + BORDER > ra.height) { + quickreshape( + c, + c->x - BORDER, + ra.height - (c->dy + 2 * BORDER), + c->dx + 2 * BORDER, + c->dy + 2 * BORDER); + } } - /* - * If we swept the window, let's send a resize event to the - * guy who just got resized. It's not clear whether the apps - * should notice their new size via other means. Try as I might, - * I can't find a way to have them notice during initdraw, so - * I solve the problem this way instead. -rsc - */ - if(c->is9term) - sendconfig(c); - return 1; + /* + * If we swept the window, let's send a resize event to the + * guy who just got resized. It's not clear whether the apps + * should notice their new size via other means. Try as I might, + * I can't find a way to have them notice during initdraw, so + * I solve the problem this way instead. -rsc + */ + if (c->is9term) sendconfig(c); + return 1; } void -scanwins(ScreenInfo *s) -{ - unsigned int i, nwins; - Client *c; - Window dw1, dw2, *wins; - XWindowAttributes attr; +scanwins(ScreenInfo* s) { + unsigned int i, nwins; + Client* c; + Window dw1, dw2, *wins; + XWindowAttributes attr; - XQueryTree(dpy, s->root, &dw1, &dw2, &wins, &nwins); - for(i = 0; i < nwins; i++){ - XGetWindowAttributes(dpy, wins[i], &attr); - if(attr.override_redirect || wins[i] == s->menuwin) - continue; - c = getclient(wins[i], 1); - if(c != 0 && c->window == wins[i] && !c->init){ - c->x = attr.x; - c->y = attr.y; - c->dx = attr.width; - c->dy = attr.height; - c->border = attr.border_width; - c->screen = s; - c->parent = s->root; - if(attr.map_state == IsViewable) - manage(c, 1); - } - } - XFree((void *) wins); /* cast is to shut stoopid compiler up */ + XQueryTree(dpy, s->root, &dw1, &dw2, &wins, &nwins); + for (i = 0; i < nwins; i++) { + XGetWindowAttributes(dpy, wins[i], &attr); + if (attr.override_redirect || wins[i] == s->menuwin) continue; + c = getclient(wins[i], 1); + if (c != 0 && c->window == wins[i] && !c->init) { + c->x = attr.x; + c->y = attr.y; + c->dx = attr.width; + c->dy = attr.height; + c->border = attr.border_width; + c->screen = s; + c->parent = s->root; + if (attr.map_state == IsViewable) manage(c, 1); + } + } + XFree((void*)wins); /* cast is to shut stoopid compiler up */ } void -gettrans(Client *c) -{ - Window trans; +gettrans(Client* c) { + Window trans; - trans = None; - if(XGetTransientForHint(dpy, c->window, &trans) != 0) - c->trans = trans; - else - c->trans = None; + trans = None; + if (XGetTransientForHint(dpy, c->window, &trans) != 0) + c->trans = trans; + else + c->trans = None; } void -withdraw(Client *c) -{ - XUnmapWindow(dpy, c->parent); - XReparentWindow(dpy, c->window, c->screen->root, c->x, c->y); - XRemoveFromSaveSet(dpy, c->window); - setstate(c, WithdrawnState); +withdraw(Client* c) { + XUnmapWindow(dpy, c->parent); + XReparentWindow(dpy, c->window, c->screen->root, c->x, c->y); + XRemoveFromSaveSet(dpy, c->window); + setstate(c, WithdrawnState); - /* flush any errors */ - ignore_badwindow = 1; - XSync(dpy, False); - ignore_badwindow = 0; + /* flush any errors */ + ignore_badwindow = 1; + XSync(dpy, False); + ignore_badwindow = 0; } static void -installcmap(ScreenInfo *s, Colormap cmap) -{ - if(cmap == None) - XInstallColormap(dpy, s->def_cmap); - else - XInstallColormap(dpy, cmap); +installcmap(ScreenInfo* s, Colormap cmap) { + if (cmap == None) + XInstallColormap(dpy, s->def_cmap); + else + XInstallColormap(dpy, cmap); } void -cmapfocus(Client *c) -{ - int i, found; - Client *cc; +cmapfocus(Client* c) { + int i, found; + Client* cc; - if(c == 0) - return; - else if(c->ncmapwins != 0){ - found = 0; - for(i = c->ncmapwins-1; i >= 0; i--){ - installcmap(c->screen, c->wmcmaps[i]); - if(c->cmapwins[i] == c->window) - found++; - } - if(!found) - installcmap(c->screen, c->cmap); - } - else if(c->trans != None && (cc = getclient(c->trans, 0)) != 0 && cc->ncmapwins != 0) - cmapfocus(cc); - else - installcmap(c->screen, c->cmap); + if (c == 0) + return; + else if (c->ncmapwins != 0) { + found = 0; + for (i = c->ncmapwins - 1; i >= 0; i--) { + installcmap(c->screen, c->wmcmaps[i]); + if (c->cmapwins[i] == c->window) found++; + } + if (!found) installcmap(c->screen, c->cmap); + } else if ( + c->trans != None && (cc = getclient(c->trans, 0)) != 0 && + cc->ncmapwins != 0) + cmapfocus(cc); + else + installcmap(c->screen, c->cmap); } void -cmapnofocus(ScreenInfo *s) -{ - installcmap(s, None); +cmapnofocus(ScreenInfo* s) { + installcmap(s, None); } void -getcmaps(Client *c) -{ - int n, i; - Window *cw; - XWindowAttributes attr; +getcmaps(Client* c) { + int n, i; + Window* cw; + XWindowAttributes attr; - if(!c->init){ - ignore_badwindow = 1; - XGetWindowAttributes(dpy, c->window, &attr); - c->cmap = attr.colormap; - XSync(dpy, False); - ignore_badwindow = 0; - } + if (!c->init) { + ignore_badwindow = 1; + XGetWindowAttributes(dpy, c->window, &attr); + c->cmap = attr.colormap; + XSync(dpy, False); + ignore_badwindow = 0; + } - n = _getprop(c->window, wm_colormaps, XA_WINDOW, 100L, (void*)&cw); - if(c->ncmapwins != 0){ - XFree((char *)c->cmapwins); - free((char *)c->wmcmaps); - } - if(n <= 0){ - c->ncmapwins = 0; - return; - } + n = _getprop(c->window, wm_colormaps, XA_WINDOW, 100L, (void*)&cw); + if (c->ncmapwins != 0) { + XFree((char*)c->cmapwins); + free((char*)c->wmcmaps); + } + if (n <= 0) { + c->ncmapwins = 0; + return; + } - c->ncmapwins = n; - c->cmapwins = cw; + c->ncmapwins = n; + c->cmapwins = cw; - c->wmcmaps = (Colormap*)malloc(n*sizeof(Colormap)); - for(i = 0; i < n; i++){ - if(cw[i] == c->window) - c->wmcmaps[i] = c->cmap; - else { - /* flush any errors (e.g., caused by mozilla tabs) */ - ignore_badwindow = 1; - XSelectInput(dpy, cw[i], ColormapChangeMask); - XGetWindowAttributes(dpy, cw[i], &attr); - c->wmcmaps[i] = attr.colormap; - XSync(dpy, False); - ignore_badwindow = 0; - } - } + c->wmcmaps = (Colormap*)malloc(n * sizeof(Colormap)); + for (i = 0; i < n; i++) { + if (cw[i] == c->window) + c->wmcmaps[i] = c->cmap; + else { + /* flush any errors (e.g., caused by mozilla tabs) */ + ignore_badwindow = 1; + XSelectInput(dpy, cw[i], ColormapChangeMask); + XGetWindowAttributes(dpy, cw[i], &attr); + c->wmcmaps[i] = attr.colormap; + XSync(dpy, False); + ignore_badwindow = 0; + } + } } void -setlabel(Client *c) -{ - char *label, *p, *lc; +setlabel(Client* c) { + char *label, *p, *lc; int i; - if(c->iconname != 0) - label = c->iconname; - else if(c->name != 0) - label = c->name; - else if(c->instance != 0) - label = c->instance; - else if(c->class != 0) - label = c->class; - else - label = "no label"; - if((p = index(label, ':')) != 0) - *p = '\0'; - for (i = 0, lc = label; *lc != '\0'; lc++, i++){ - if (i >= 23){ - label[22] = '~'; - label[23] = '\0'; - } - } + if (c->iconname != 0) + label = c->iconname; + else if (c->name != 0) + label = c->name; + else if (c->instance != 0) + label = c->instance; + else if (c->class != 0) + label = c->class; + else + label = "no label"; + if ((p = index(label, ':')) != 0) *p = '\0'; + for (i = 0, lc = label; *lc != '\0'; lc++, i++) { + if (i >= 23) { + label[22] = '~'; + label[23] = '\0'; + } + } - c->label = label; + c->label = label; } -#ifdef SHAPE +#ifdef SHAPE void -setshape(Client *c) -{ - int n, order; - XRectangle *rect; +setshape(Client* c) { + int n, order; + XRectangle* rect; - /* don't try to add a border if the window is non-rectangular */ - rect = XShapeGetRectangles(dpy, c->window, ShapeBounding, &n, &order); - if(n > 1) - XShapeCombineShape(dpy, c->parent, ShapeBounding, BORDER, BORDER, - c->window, ShapeBounding, ShapeSet); - XFree((void*)rect); + /* don't try to add a border if the window is non-rectangular */ + rect = XShapeGetRectangles(dpy, c->window, ShapeBounding, &n, &order); + if (n > 1) + XShapeCombineShape( + dpy, + c->parent, + ShapeBounding, + BORDER, + BORDER, + c->window, + ShapeBounding, + ShapeSet); + XFree((void*)rect); } #endif int -_getprop(Window w, Atom a, Atom type, long len, unsigned char **p) -{ - Atom real_type; - int format; - unsigned long n, extra; - int status; +_getprop(Window w, Atom a, Atom type, long len, unsigned char** p) { + Atom real_type; + int format; + unsigned long n, extra; + int status; - status = XGetWindowProperty(dpy, w, a, 0L, len, False, type, &real_type, &format, &n, &extra, p); - if(status != Success || *p == 0) - return -1; - if(n == 0) - XFree((void*) *p); - /* could check real_type, format, extra here... */ - return n; + status = XGetWindowProperty( + dpy, w, a, 0L, len, False, type, &real_type, &format, &n, &extra, p); + if (status != Success || *p == 0) return -1; + if (n == 0) XFree((void*)*p); + /* could check real_type, format, extra here... */ + return n; } -char * -getprop(Window w, Atom a) -{ - unsigned char *p; +char* +getprop(Window w, Atom a) { + unsigned char* p; - if(_getprop(w, a, XA_STRING, 100L, &p) <= 0) - return 0; - return (char *)p; + if (_getprop(w, a, XA_STRING, 100L, &p) <= 0) return 0; + return (char*)p; } int -get1prop(Window w, Atom a, Atom type) -{ - char **p, *x; +get1prop(Window w, Atom a, Atom type) { + char **p, *x; - if(_getprop(w, a, type, 1L, (void*)&p) <= 0) - return 0; - x = *p; - XFree((void*) p); - return (int)(uintptr_t)x; + if (_getprop(w, a, type, 1L, (void*)&p) <= 0) return 0; + x = *p; + XFree((void*)p); + return (int)(uintptr_t)x; } Window -getwprop(Window w, Atom a) -{ - return get1prop(w, a, XA_WINDOW); +getwprop(Window w, Atom a) { + return get1prop(w, a, XA_WINDOW); } int -getiprop(Window w, Atom a) -{ - return get1prop(w, a, XA_INTEGER); +getiprop(Window w, Atom a) { + return get1prop(w, a, XA_INTEGER); } void -setstate(Client *c, int state) -{ - long data[2]; +setstate(Client* c, int state) { + long data[2]; - data[0] = (long) state; - data[1] = (long) None; + data[0] = (long)state; + data[1] = (long)None; - c->state = state; - XChangeProperty(dpy, c->window, wm_state, wm_state, 32, - PropModeReplace, (unsigned char *)data, 2); + c->state = state; + XChangeProperty( + dpy, + c->window, + wm_state, + wm_state, + 32, + PropModeReplace, + (unsigned char*)data, + 2); } int -getstate(Window w, int *state) -{ - long *p = 0; +getstate(Window w, int* state) { + long* p = 0; - if(_getprop(w, wm_state, wm_state, 2L, (void*)&p) <= 0) - return 0; + if (_getprop(w, wm_state, wm_state, 2L, (void*)&p) <= 0) return 0; - *state = (int) *p; - XFree((char *) p); - return 1; + *state = (int)*p; + XFree((char*)p); + return 1; } void -getproto(Client *c) -{ - Atom *p; - int i; - long n; - Window w; +getproto(Client* c) { + Atom* p; + int i; + long n; + Window w; - w = c->window; - c->proto = 0; - if((n = _getprop(w, wm_protocols, XA_ATOM, 20L, (void*)&p)) <= 0) - return; + w = c->window; + c->proto = 0; + if ((n = _getprop(w, wm_protocols, XA_ATOM, 20L, (void*)&p)) <= 0) return; - for(i = 0; i < n; i++) - if(p[i] == wm_delete) - c->proto |= Pdelete; - else if(p[i] == wm_take_focus) - c->proto |= Ptakefocus; - else if(p[i] == wm_lose_focus) - c->proto |= Plosefocus; + for (i = 0; i < n; i++) + if (p[i] == wm_delete) + c->proto |= Pdelete; + else if (p[i] == wm_take_focus) + c->proto |= Ptakefocus; + else if (p[i] == wm_lose_focus) + c->proto |= Plosefocus; - XFree((char *) p); + XFree((char*)p); } diff --git a/menu.c b/menu.c old mode 100755 new mode 100644 index 53e9e6a..e7ef58f --- a/menu.c +++ b/menu.c @@ -3,7 +3,7 @@ */ /* Copyright (c) 1994-1996 David Hogan, see README for licence details */ -#define _SVID_SOURCE 1 /* putenv in glibc */ +#define _SVID_SOURCE 1 /* putenv in glibc */ #define _DEFAULT_SOURCE 1 #include #include @@ -18,459 +18,405 @@ #include "dat.h" #include "fns.h" -Client *hiddenc[MAXHIDDEN]; +Client* hiddenc[MAXHIDDEN]; -int numhidden; +int numhidden; int virt; int reversehide = 1; -Client * currents[NUMVIRTUALS] = -{ - NULL, NULL, NULL, NULL -}; +Client* currents[NUMVIRTUALS] = {NULL, NULL, NULL, NULL}; -char *b2items[NUMVIRTUALS+1] = -{ - "One", - "Two", - "Three", - "Four", - "Five", - "Six", - "Seven", - "Eight", - "Nine", - "Ten", - "Eleven", - "Twelve", - 0 -}; +char* b2items[NUMVIRTUALS + 1] = { + "One", + "Two", + "Three", + "Four", + "Five", + "Six", + "Seven", + "Eight", + "Nine", + "Ten", + "Eleven", + "Twelve", + 0}; -Menu b2menu = -{ - b2items -}; +Menu b2menu = {b2items}; -char *b3items[B3FIXED+MAXHIDDEN+1] = -{ - "New", - "Reshape", - "Move", - "Delete", - "Hide", +char* b3items[B3FIXED + MAXHIDDEN + 1] = { + "New", + "Reshape", + "Move", + "Delete", + "Hide", #ifdef SHOWSTICK - "Stick", + "Stick", #endif - 0 -}; + 0}; -enum -{ - New, - Reshape, - Move, - Delete, +enum { + New, + Reshape, + Move, + Delete, #ifdef SHOWSTICK - Hide, - Stick + Hide, + Stick #else - Hide + Hide #endif }; -Menu b3menu = -{ - b3items -}; +Menu b3menu = {b3items}; -Menu egg = -{ - version -}; +Menu egg = {version}; void -button(XButtonEvent *e) -{ - int n, shift; - Client *c; - Window dw; - ScreenInfo *s; +button(XButtonEvent* e) { + int n, shift; + Client* c; + Window dw; + ScreenInfo* s; - curtime = e->time; - s = getscreen(e->root); - if(s == 0) - return; - c = getclient(e->window, 0); - if(c){ - if(debug) fprintf(stderr, "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n", - e->x, e->y, c->x, c->y, c->dx, c->dy, BORDER); - if(borderorient(c, e->x, e->y) != BorderUnknown){ - switch (e->button){ - case Button1: - case Button2: - reshape(c, e->button, pull, e); - return; - case Button3: - move(c, Button3); - return; - default: - return; - } - } - e->x += c->x - BORDER; - e->y += c->y - BORDER; - } else if(e->window != e->root){ - if(debug) fprintf(stderr, "but no client: e x=%d y=%d\n", - e->x, e->y); - XTranslateCoordinates(dpy, e->window, s->root, e->x, e->y, - &e->x, &e->y, &dw); - } - switch (e->button){ - case Button1: - fflush(stdout); - if(c){ - if (ffm) - XRaiseWindow(dpy, c->window); - XMapRaised(dpy, c->parent); - top(c); - active(c); - } - return; - case Button2: - if(c){ - XMapRaised(dpy, c->parent); - active(c); - XAllowEvents (dpy, ReplayPointer, curtime); - } else if((e->state&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)){ - menuhit(e, &egg); - } else if(numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1) - button2(n); - return; - case Button3: - break; - case Button4: - /* scroll up changes to previous virtual screen */ - if(!c && e->type == ButtonPress) - if(numvirtuals > 1 && virt > 0) - switch_to(virt - 1); - return; - case Button5: - /* scroll down changes to next virtual screen */ - if(!c && e->type == ButtonPress) - if(numvirtuals > 1 && virt < numvirtuals - 1) - switch_to(virt + 1); - return; - default: - return; - } + curtime = e->time; + s = getscreen(e->root); + if (s == 0) return; + c = getclient(e->window, 0); + if (c) { + if (debug) + fprintf( + stderr, + "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n", + e->x, + e->y, + c->x, + c->y, + c->dx, + c->dy, + BORDER); + if (borderorient(c, e->x, e->y) != BorderUnknown) { + switch (e->button) { + case Button1: + case Button2: reshape(c, e->button, pull, e); return; + case Button3: move(c, Button3); return; + default: return; + } + } + e->x += c->x - BORDER; + e->y += c->y - BORDER; + } else if (e->window != e->root) { + if (debug) fprintf(stderr, "but no client: e x=%d y=%d\n", e->x, e->y); + XTranslateCoordinates( + dpy, e->window, s->root, e->x, e->y, &e->x, &e->y, &dw); + } + switch (e->button) { + case Button1: + fflush(stdout); + if (c) { + if (ffm) XRaiseWindow(dpy, c->window); + XMapRaised(dpy, c->parent); + top(c); + active(c); + } + return; + case Button2: + if (c) { + XMapRaised(dpy, c->parent); + active(c); + XAllowEvents(dpy, ReplayPointer, curtime); + } else if ( + (e->state & (ShiftMask | ControlMask)) == (ShiftMask | ControlMask)) { + menuhit(e, &egg); + } else if (numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1) + button2(n); + return; + case Button3: break; + case Button4: + /* scroll up changes to previous virtual screen */ + if (!c && e->type == ButtonPress) + if (numvirtuals > 1 && virt > 0) switch_to(virt - 1); + return; + case Button5: + /* scroll down changes to next virtual screen */ + if (!c && e->type == ButtonPress) + if (numvirtuals > 1 && virt < numvirtuals - 1) switch_to(virt + 1); + return; + default: return; + } - if(current && current->screen == s) - cmapnofocus(s); - switch (n = menuhit(e, &b3menu)){ - case New: - spawn(s); - break; - case Reshape: - reshape(selectwin(1, 0, s), Button3, sweep, 0); - break; - case Move: - move(selectwin(0, 0, s), Button3); - break; - case Delete: - shift = 0; - c = selectwin(1, &shift, s); - delete(c, shift); - break; - case Hide: - hide(selectwin(1, 0, s)); - break; + if (current && current->screen == s) cmapnofocus(s); + switch (n = menuhit(e, &b3menu)) { + case New: spawn(s); break; + case Reshape: reshape(selectwin(1, 0, s), Button3, sweep, 0); break; + case Move: move(selectwin(0, 0, s), Button3); break; + case Delete: + shift = 0; + c = selectwin(1, &shift, s); + delete (c, shift); + break; + case Hide: hide(selectwin(1, 0, s)); break; #ifdef SHOWSTICK - case Stick: - stick(selectwin(1, 0, s)); - break; + case Stick: stick(selectwin(1, 0, s)); break; #endif - default: /* unhide window */ - unhide(n - B3FIXED, 1); - break; - case -1: /* nothing */ - break; - } - if(current && current->screen == s) - cmapfocus(current); + default: /* unhide window */ unhide(n - B3FIXED, 1); break; + case -1: /* nothing */ break; + } + if (current && current->screen == s) cmapfocus(current); } void -spawn(ScreenInfo *s) -{ - /* - * ugly dance to cause sweeping for terminals. - * the very next window created will require sweeping. - * hope it's created by the program we're about to - * exec! - */ - isNew = 1; - /* - * ugly dance to avoid leaving zombies. Could use SIGCHLD, - * but it's not very portable. - */ - if(fork() == 0){ - if(fork() == 0){ - close(ConnectionNumber(dpy)); - if(s->display[0] != '\0') - putenv(s->display); - signal(SIGINT, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGHUP, SIG_DFL); - if(termprog != NULL){ - execl(shell, shell, "-c", termprog, (char*)0); - fprintf(stderr, "ryudo: exec %s", shell); - perror(" failed"); - } - execlp("urxvt", "urxvt", (char*)0); - execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0); - execlp("xterm", "xterm", "-ut", (char*)0); - perror("ryudo: exec urxvt/9term/xterm failed"); - exit(1); - } - exit(0); - } - wait((int *) 0); +spawn(ScreenInfo* s) { + /* + * ugly dance to cause sweeping for terminals. + * the very next window created will require sweeping. + * hope it's created by the program we're about to + * exec! + */ + isNew = 1; + /* + * ugly dance to avoid leaving zombies. Could use SIGCHLD, + * but it's not very portable. + */ + if (fork() == 0) { + if (fork() == 0) { + close(ConnectionNumber(dpy)); + if (s->display[0] != '\0') putenv(s->display); + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + signal(SIGHUP, SIG_DFL); + if (termprog != NULL) { + execl(shell, shell, "-c", termprog, (char*)0); + fprintf(stderr, "ryudo: exec %s", shell); + perror(" failed"); + } + execlp("urxvt", "urxvt", (char*)0); + execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0); + execlp("xterm", "xterm", "-ut", (char*)0); + perror("ryudo: exec urxvt/9term/xterm failed"); + exit(1); + } + exit(0); + } + wait((int*)0); } void -reshape(Client *c, int but, int (*fn)(Client*, int, XButtonEvent *), XButtonEvent *e) -{ - int odx, ody; +reshape( + Client* c, int but, int (*fn)(Client*, int, XButtonEvent*), XButtonEvent* e) { + int odx, ody; - if(c == 0) - return; - odx = c->dx; - ody = c->dy; - if(fn(c, but, e) == 0) - return; - active(c); - top(c); - XRaiseWindow(dpy, c->parent); - XMoveResizeWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER, - c->dx+2*BORDER, c->dy+2*BORDER); - if(c->dx == odx && c->dy == ody) - sendconfig(c); - else - XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy); + if (c == 0) return; + odx = c->dx; + ody = c->dy; + if (fn(c, but, e) == 0) return; + active(c); + top(c); + XRaiseWindow(dpy, c->parent); + XMoveResizeWindow( + dpy, + c->parent, + c->x - BORDER, + c->y - BORDER, + c->dx + 2 * BORDER, + c->dy + 2 * BORDER); + if (c->dx == odx && c->dy == ody) + sendconfig(c); + else + XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy); } void -move(Client *c, int but) -{ - if(c == 0) - return; - if(drag(c, but) == 0) - return; - active(c); - top(c); - XRaiseWindow(dpy, c->parent); - XMoveWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER); - sendconfig(c); +move(Client* c, int but) { + if (c == 0) return; + if (drag(c, but) == 0) return; + active(c); + top(c); + XRaiseWindow(dpy, c->parent); + XMoveWindow(dpy, c->parent, c->x - BORDER, c->y - BORDER); + sendconfig(c); +} + +void delete (Client* c, int shift) { + if (c == 0) return; + if ((c->proto & Pdelete) && !shift) + sendcmessage(c->window, wm_protocols, wm_delete, 0, 0); + else + XKillClient(dpy, c->window); /* let event clean up */ } void -delete(Client *c, int shift) -{ - if(c == 0) - return; - if((c->proto & Pdelete) && !shift) - sendcmessage(c->window, wm_protocols, wm_delete, 0, 0); - else - XKillClient(dpy, c->window); /* let event clean up */ +hide(Client* c) { + if (c == 0 || numhidden == MAXHIDDEN) return; + if (hidden(c)) { + fprintf(stderr, "ryudo: already hidden: %s\n", c->label); + return; + } + XUnmapWindow(dpy, c->parent); + XUnmapWindow(dpy, c->window); + setstate(c, IconicState); + if (c == current) nofocus(); + if (reversehide) { + memmove(hiddenc + 1, hiddenc, numhidden * sizeof hiddenc[0]); + memmove( + b3items + B3FIXED + 1, b3items + B3FIXED, numhidden * sizeof b3items[0]); + hiddenc[0] = c; + b3items[B3FIXED] = c->label; + } else { + hiddenc[numhidden] = c; + b3items[B3FIXED + numhidden] = c->label; + } + numhidden++; + b3items[B3FIXED + numhidden] = 0; } void -hide(Client *c) -{ - if(c == 0 || numhidden == MAXHIDDEN) - return; - if(hidden(c)){ - fprintf(stderr, "ryudo: already hidden: %s\n", c->label); - return; - } - XUnmapWindow(dpy, c->parent); - XUnmapWindow(dpy, c->window); - setstate(c, IconicState); - if(c == current) - nofocus(); - if(reversehide){ - memmove(hiddenc+1, hiddenc, numhidden*sizeof hiddenc[0]); - memmove(b3items+B3FIXED+1, b3items+B3FIXED, numhidden*sizeof b3items[0]); - hiddenc[0] = c; - b3items[B3FIXED] = c->label; - }else{ - hiddenc[numhidden] = c; - b3items[B3FIXED+numhidden] = c->label; - } - numhidden++; - b3items[B3FIXED+numhidden] = 0; +unhide(int n, int map) { + Client* c; + int i; + + if (n >= numhidden) { + fprintf(stderr, "ryudo: unhide: n %d numhidden %d\n", n, numhidden); + return; + } + c = hiddenc[n]; + if (!hidden(c)) { + fprintf( + stderr, + "ryudo: unhide: not hidden: %s(0x%x)\n", + c->label, + (int)c->window); + return; + } + c->virt = virt; + + if (map) { + XMapWindow(dpy, c->window); + XMapRaised(dpy, c->parent); + setstate(c, NormalState); + active(c); + top(c); + } + + numhidden--; + for (i = n; i < numhidden; i++) { + hiddenc[i] = hiddenc[i + 1]; + b3items[B3FIXED + i] = b3items[B3FIXED + i + 1]; + } + b3items[B3FIXED + numhidden] = 0; } void -unhide(int n, int map) -{ - Client *c; - int i; +unhidec(Client* c, int map) { + int i; - if(n >= numhidden){ - fprintf(stderr, "ryudo: unhide: n %d numhidden %d\n", n, numhidden); - return; - } - c = hiddenc[n]; - if(!hidden(c)){ - fprintf(stderr, "ryudo: unhide: not hidden: %s(0x%x)\n", - c->label, (int)c->window); - return; - } - c->virt = virt; - - if(map){ - XMapWindow(dpy, c->window); - XMapRaised(dpy, c->parent); - setstate(c, NormalState); - active(c); - top(c); - } - - numhidden--; - for(i = n; i < numhidden; i++){ - hiddenc[i] = hiddenc[i+1]; - b3items[B3FIXED+i] = b3items[B3FIXED+i+1]; - } - b3items[B3FIXED+numhidden] = 0; + for (i = 0; i < numhidden; i++) + if (c == hiddenc[i]) { + unhide(i, map); + return; + } + fprintf( + stderr, "ryudo: unhidec: not hidden: %s(0x%x)\n", c->label, (int)c->window); } void -unhidec(Client *c, int map) -{ - int i; - - for(i = 0; i < numhidden; i++) - if(c == hiddenc[i]){ - unhide(i, map); - return; - } - fprintf(stderr, "ryudo: unhidec: not hidden: %s(0x%x)\n", - c->label, (int)c->window); -} - -void -stick(Client *c) -{ - if (numvirtuals > 1 && c->virt >= 0 ) +stick(Client* c) { + if (numvirtuals > 1 && c->virt >= 0) c->virt = -1; - else c->virt = virt; + else + c->virt = virt; } void -renamec(Client *c, char *name) -{ - int i; +renamec(Client* c, char* name) { + int i; - if(name == 0) - name = "???"; - c->label = name; - if(!hidden(c)) - return; - for(i = 0; i < numhidden; i++) - if(c == hiddenc[i]){ - b3items[B3FIXED+i] = name; - return; - } + if (name == 0) name = "???"; + c->label = name; + if (!hidden(c)) return; + for (i = 0; i < numhidden; i++) + if (c == hiddenc[i]) { + b3items[B3FIXED + i] = name; + return; + } } void -button2(int n) -{ - switch_to(n); - if(current) - cmapfocus(current); +button2(int n) { + switch_to(n); + if (current) cmapfocus(current); } void -switch_to_c(int n, Client *c) -{ - if(c == 0) - return; +switch_to_c(int n, Client* c) { + if (c == 0) return; - if(c->next) - switch_to_c(n, c->next); + if (c->next) switch_to_c(n, c->next); - if(c->parent == DefaultRootWindow(dpy)) - return; + if (c->parent == DefaultRootWindow(dpy)) return; #ifdef AUTOSTICK - if(c->virt >= 0 && isautostick(c)){ - stick(c); + if (c->virt >= 0 && isautostick(c)) { stick(c); } +#endif + + if (c->virt != virt && c->state == NormalState && c->virt >= 0) { + XUnmapWindow(dpy, c->parent); + XUnmapWindow(dpy, c->window); + setstate(c, IconicState); + if (c == current) nofocus(); + } else if (c->virt == virt && c->state == IconicState) { + int i; + + for (i = 0; i < numhidden; i++) + if (c == hiddenc[i]) break; + + if (i == numhidden) { + XMapWindow(dpy, c->window); + XMapWindow(dpy, c->parent); + setstate(c, NormalState); + if (currents[virt] == c) active(c); } -#endif - - if(c->virt != virt && c->state == NormalState && c->virt >= 0){ - XUnmapWindow(dpy, c->parent); - XUnmapWindow(dpy, c->window); - setstate(c, IconicState); - if(c == current) - nofocus(); - } else if(c->virt == virt && c->state == IconicState){ - int i; - - for(i = 0; i < numhidden; i++) - if(c == hiddenc[i]) - break; - - if(i == numhidden){ - XMapWindow(dpy, c->window); - XMapWindow(dpy, c->parent); - setstate(c, NormalState); - if(currents[virt] == c) - active(c); - - } - } + } } void -switch_to(int n) -{ +switch_to(int n) { #ifdef VIRTNOTIFY - static char virtmsg[32]; + static char virtmsg[32]; #endif - if(n == virt) - return; - currents[virt] = current; - virt = n; + if (n == virt) return; + currents[virt] = current; + virt = n; - /* redundant when called from a menu switch - * but needed for scroll-button switches - */ - b2menu.lasthit = n; + /* redundant when called from a menu switch + * but needed for scroll-button switches + */ + b2menu.lasthit = n; - switch_to_c(n, clients); - current = currents[virt]; - top(current); - if(fork() == 0) - { - close(ConnectionNumber(dpy)); - if(dpy != '\0') - putenv(dpy); - signal(SIGINT, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGHUP, SIG_DFL); + switch_to_c(n, clients); + current = currents[virt]; + top(current); + if (fork() == 0) { + close(ConnectionNumber(dpy)); + if (dpy != '\0') putenv(dpy); + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + signal(SIGHUP, SIG_DFL); #ifdef VIRTNOTIFY - sprintf(virtmsg, VIRTMSG, b2items[virt]); - execlp("notify-send", "notify-send", "-c", "virtual", VIRTHEADER, virtmsg, (char*)0); + sprintf(virtmsg, VIRTMSG, b2items[virt]); + execlp( + "notify-send", + "notify-send", + "-c", + "virtual", + VIRTHEADER, + virtmsg, + (char*)0); #endif - } + } } void -initb2menu(int n) -{ - b2items[n] = 0; +initb2menu(int n) { + b2items[n] = 0; } diff --git a/printevent.c b/printevent.c old mode 100755 new mode 100644 index 05cc5ad..fea2668 --- a/printevent.c +++ b/printevent.c @@ -20,9 +20,9 @@ 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 +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 @@ -35,12 +35,12 @@ 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 +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 +comments, suggestions, improvements, or if you find any blithering errors you can get it touch with me at the following location: - ken@richsun.UUCP + ken@richsun.UUCP */ #include @@ -56,403 +56,341 @@ static char* sep = " "; /* Returns the string equivalent of a boolean parameter */ static char* -TorF(int bool) -{ - switch (bool) { - case True: - return ("True"); +TorF(int bool) { + switch (bool) { + case True: return ("True"); - case False: - return ("False"); + case False: return ("False"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a property notify state */ static char* -PropertyState(int state) -{ - switch (state) { - case PropertyNewValue: - return ("PropertyNewValue"); +PropertyState(int state) { + switch (state) { + case PropertyNewValue: return ("PropertyNewValue"); - case PropertyDelete: - return ("PropertyDelete"); + case PropertyDelete: return ("PropertyDelete"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a visibility notify state */ static char* -VisibilityState(int state) -{ - switch (state) { - case VisibilityUnobscured: - return ("VisibilityUnobscured"); +VisibilityState(int state) { + switch (state) { + case VisibilityUnobscured: return ("VisibilityUnobscured"); - case VisibilityPartiallyObscured: - return ("VisibilityPartiallyObscured"); + case VisibilityPartiallyObscured: return ("VisibilityPartiallyObscured"); - case VisibilityFullyObscured: - return ("VisibilityFullyObscured"); + case VisibilityFullyObscured: return ("VisibilityFullyObscured"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a timestamp */ static char* -ServerTime(Time time) -{ - unsigned long msec; - unsigned long sec; - unsigned long min; - unsigned long hr; - unsigned long day; - static char buffer[32]; +ServerTime(Time time) { + unsigned long msec; + unsigned long sec; + unsigned long min; + unsigned long hr; + unsigned long day; + static char buffer[32]; - 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); - - sprintf(buffer, "%lud%luh%lum%lu.%03lds", day, hr, min, sec, msec); - return (buffer); + 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); } /* Simple structure to ease the interpretation of masks */ typedef struct MaskType MaskType; -struct MaskType -{ - unsigned int value; - char *string; +struct MaskType { + unsigned int value; + char* string; }; /* Returns the string equivalent of a mask of buttons and/or modifier keys */ static char* -ButtonAndOrModifierState(unsigned int 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; +ButtonAndOrModifierState(unsigned int 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; - buffer[0] = 0; + 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); + 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); } /* Returns the string equivalent of a mask of configure window values */ static char* -ConfigureValueMask(unsigned int 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; +ConfigureValueMask(unsigned int 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; - buffer[0] = 0; + 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); - } + 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 (buffer); } /* Returns the string equivalent of a motion hint */ static char* -IsHint(char is_hint) -{ - switch (is_hint) { - case NotifyNormal: - return ("NotifyNormal"); +IsHint(char is_hint) { + switch (is_hint) { + case NotifyNormal: return ("NotifyNormal"); - case NotifyHint: - return ("NotifyHint"); + case NotifyHint: return ("NotifyHint"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of an id or the value "None" */ static char* -MaybeNone(int value) -{ - static char buffer[16]; +MaybeNone(int value) { + static char buffer[16]; - if (value == None) - return ("None"); - else { - sprintf(buffer, "0x%x", value); - return (buffer); - } + if (value == None) + return ("None"); + else { + sprintf(buffer, "0x%x", value); + return (buffer); + } } /* Returns the string equivalent of a colormap state */ static char* -ColormapState(int state) -{ - switch (state) { - case ColormapInstalled: - return ("ColormapInstalled"); +ColormapState(int state) { + switch (state) { + case ColormapInstalled: return ("ColormapInstalled"); - case ColormapUninstalled: - return ("ColormapUninstalled"); + case ColormapUninstalled: return ("ColormapUninstalled"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a crossing detail */ static char* -CrossingDetail(int detail) -{ - switch (detail) { - case NotifyAncestor: - return ("NotifyAncestor"); +CrossingDetail(int detail) { + switch (detail) { + case NotifyAncestor: return ("NotifyAncestor"); - case NotifyInferior: - return ("NotifyInferior"); + case NotifyInferior: return ("NotifyInferior"); - case NotifyVirtual: - return ("NotifyVirtual"); + case NotifyVirtual: return ("NotifyVirtual"); - case NotifyNonlinear: - return ("NotifyNonlinear"); + case NotifyNonlinear: return ("NotifyNonlinear"); - case NotifyNonlinearVirtual: - return ("NotifyNonlinearVirtual"); + case NotifyNonlinearVirtual: return ("NotifyNonlinearVirtual"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a focus change detail */ static char* -FocusChangeDetail(int detail) -{ - switch (detail) { - case NotifyAncestor: - return ("NotifyAncestor"); +FocusChangeDetail(int detail) { + switch (detail) { + case NotifyAncestor: return ("NotifyAncestor"); - case NotifyInferior: - return ("NotifyInferior"); + case NotifyInferior: return ("NotifyInferior"); - case NotifyVirtual: - return ("NotifyVirtual"); + case NotifyVirtual: return ("NotifyVirtual"); - case NotifyNonlinear: - return ("NotifyNonlinear"); + case NotifyNonlinear: return ("NotifyNonlinear"); - case NotifyNonlinearVirtual: - return ("NotifyNonlinearVirtual"); + case NotifyNonlinearVirtual: return ("NotifyNonlinearVirtual"); - case NotifyPointer: - return ("NotifyPointer"); + case NotifyPointer: return ("NotifyPointer"); - case NotifyPointerRoot: - return ("NotifyPointerRoot"); + case NotifyPointerRoot: return ("NotifyPointerRoot"); - case NotifyDetailNone: - return ("NotifyDetailNone"); + case NotifyDetailNone: return ("NotifyDetailNone"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a configure detail */ static char* -ConfigureDetail(int detail) -{ - switch (detail) { - case Above: - return ("Above"); +ConfigureDetail(int detail) { + switch (detail) { + case Above: return ("Above"); - case Below: - return ("Below"); + case Below: return ("Below"); - case TopIf: - return ("TopIf"); + case TopIf: return ("TopIf"); - case BottomIf: - return ("BottomIf"); + case BottomIf: return ("BottomIf"); - case Opposite: - return ("Opposite"); + case Opposite: return ("Opposite"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a grab mode */ static char* -GrabMode(int mode) -{ - switch (mode) { - case NotifyNormal: - return ("NotifyNormal"); +GrabMode(int mode) { + switch (mode) { + case NotifyNormal: return ("NotifyNormal"); - case NotifyGrab: - return ("NotifyGrab"); + case NotifyGrab: return ("NotifyGrab"); - case NotifyUngrab: - return ("NotifyUngrab"); + case NotifyUngrab: return ("NotifyUngrab"); - case NotifyWhileGrabbed: - return ("NotifyWhileGrabbed"); + case NotifyWhileGrabbed: return ("NotifyWhileGrabbed"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a mapping request */ static char* -MappingRequest(int request) -{ - switch (request) { - case MappingModifier: - return ("MappingModifier"); +MappingRequest(int request) { + switch (request) { + case MappingModifier: return ("MappingModifier"); - case MappingKeyboard: - return ("MappingKeyboard"); + case MappingKeyboard: return ("MappingKeyboard"); - case MappingPointer: - return ("MappingPointer"); + case MappingPointer: return ("MappingPointer"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a stacking order place */ static char* -Place(int place) -{ - switch (place) { - case PlaceOnTop: - return ("PlaceOnTop"); +Place(int place) { + switch (place) { + case PlaceOnTop: return ("PlaceOnTop"); - case PlaceOnBottom: - return ("PlaceOnBottom"); + case PlaceOnBottom: return ("PlaceOnBottom"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a major code */ static char* -MajorCode(int code) -{ - static char buffer[32]; +MajorCode(int code) { + static char buffer[32]; - switch (code) { - case X_CopyArea: - return ("X_CopyArea"); + switch (code) { + case X_CopyArea: return ("X_CopyArea"); - case X_CopyPlane: - return ("X_CopyPlane"); + case X_CopyPlane: return ("X_CopyPlane"); - default: - sprintf(buffer, "0x%x", code); - return (buffer); - } + default: sprintf(buffer, "0x%x", code); return (buffer); + } } /* Returns the string equivalent the keycode contained in the key event */ static char* -Keycode(XKeyEvent *ev) -{ - static char buffer[256]; - KeySym keysym_str; - char *keysym_name; - char string[256]; +Keycode(XKeyEvent* ev) { + static char buffer[256]; + KeySym keysym_str; + char* keysym_name; + char string[256]; - XLookupString(ev, string, 64, &keysym_str, NULL); + XLookupString(ev, string, 64, &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 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); } /* Returns the string equivalent of an atom or "None"*/ static char* -AtomName(Display *dpy, Atom atom) -{ - static char buffer[256]; - char *atom_name; +AtomName(Display* dpy, Atom atom) { + static char buffer[256]; + 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(dpy, atom); + strncpy(buffer, atom_name, 256); + XFree(atom_name); + return (buffer); } /******************************************************************************/ @@ -460,527 +398,400 @@ AtomName(Display *dpy, Atom atom) /******************************************************************************/ static void -VerbMotion(XMotionEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("root=0x%x%s", (int)ev->root, sep); - printf("subwindow=0x%x%s", (int)ev->subwindow, sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); - printf("is_hint=%s%s", IsHint(ev->is_hint), sep); - printf("same_screen=%s\n", TorF(ev->same_screen)); +VerbMotion(XMotionEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("root=0x%x%s", (int)ev->root, sep); + printf("subwindow=0x%x%s", (int)ev->subwindow, sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); + printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); + printf("is_hint=%s%s", IsHint(ev->is_hint), sep); + printf("same_screen=%s\n", TorF(ev->same_screen)); } static void -VerbButton(XButtonEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("root=0x%x%s", (int)ev->root, sep); - printf("subwindow=0x%x%s", (int)ev->subwindow, sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); - printf("button=%s%s", ButtonAndOrModifierState(ev->button), sep); - printf("same_screen=%s\n", TorF(ev->same_screen)); +VerbButton(XButtonEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("root=0x%x%s", (int)ev->root, sep); + printf("subwindow=0x%x%s", (int)ev->subwindow, sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); + printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); + printf("button=%s%s", ButtonAndOrModifierState(ev->button), sep); + printf("same_screen=%s\n", TorF(ev->same_screen)); } static void -VerbColormap(XColormapEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("colormap=%s%s", MaybeNone(ev->colormap), sep); - printf("new=%s%s", TorF(ev->new), sep); - printf("state=%s\n", ColormapState(ev->state)); +VerbColormap(XColormapEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("colormap=%s%s", MaybeNone(ev->colormap), sep); + printf("new=%s%s", TorF(ev->new), sep); + printf("state=%s\n", ColormapState(ev->state)); } static void -VerbCrossing(XCrossingEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("root=0x%x%s", (int)ev->root, sep); - printf("subwindow=0x%x%s", (int)ev->subwindow, sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - printf("mode=%s%s", GrabMode(ev->mode), sep); - printf("detail=%s%s", CrossingDetail(ev->detail), sep); - printf("same_screen=%s%s", TorF(ev->same_screen), sep); - printf("focus=%s%s", TorF(ev->focus), sep); - printf("state=%s\n", ButtonAndOrModifierState(ev->state)); +VerbCrossing(XCrossingEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("root=0x%x%s", (int)ev->root, sep); + printf("subwindow=0x%x%s", (int)ev->subwindow, sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); + printf("mode=%s%s", GrabMode(ev->mode), sep); + printf("detail=%s%s", CrossingDetail(ev->detail), sep); + printf("same_screen=%s%s", TorF(ev->same_screen), sep); + printf("focus=%s%s", TorF(ev->focus), sep); + printf("state=%s\n", ButtonAndOrModifierState(ev->state)); } static void -VerbExpose(XExposeEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("width=%d height=%d%s", ev->width, ev->height, sep); - printf("count=%d\n", ev->count); +VerbExpose(XExposeEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("width=%d height=%d%s", ev->width, ev->height, sep); + printf("count=%d\n", ev->count); } static void -VerbGraphicsExpose(XGraphicsExposeEvent *ev) -{ - printf("drawable=0x%x%s", (int)ev->drawable, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("width=%d height=%d%s", ev->width, ev->height, sep); - printf("major_code=%s%s", MajorCode(ev->major_code), sep); - printf("minor_code=%d\n", ev->minor_code); +VerbGraphicsExpose(XGraphicsExposeEvent* ev) { + printf("drawable=0x%x%s", (int)ev->drawable, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("width=%d height=%d%s", ev->width, ev->height, sep); + printf("major_code=%s%s", MajorCode(ev->major_code), sep); + printf("minor_code=%d\n", ev->minor_code); } static void -VerbNoExpose(XNoExposeEvent *ev) -{ - printf("drawable=0x%x%s", (int)ev->drawable, sep); - printf("major_code=%s%s", MajorCode(ev->major_code), sep); - printf("minor_code=%d\n", ev->minor_code); +VerbNoExpose(XNoExposeEvent* ev) { + printf("drawable=0x%x%s", (int)ev->drawable, sep); + printf("major_code=%s%s", MajorCode(ev->major_code), sep); + printf("minor_code=%d\n", ev->minor_code); } static void -VerbFocus(XFocusChangeEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("mode=%s%s", GrabMode(ev->mode), sep); - printf("detail=%s\n", FocusChangeDetail(ev->detail)); +VerbFocus(XFocusChangeEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("mode=%s%s", GrabMode(ev->mode), sep); + printf("detail=%s\n", FocusChangeDetail(ev->detail)); } static void -VerbKeymap(XKeymapEvent *ev) -{ - int i; +VerbKeymap(XKeymapEvent* ev) { + int i; - printf("window=0x%x%s", (int)ev->window, sep); - printf("key_vector="); - for (i = 0; i < 32; i++) - printf("%02x", ev->key_vector[i]); - printf("\n"); + printf("window=0x%x%s", (int)ev->window, sep); + printf("key_vector="); + for (i = 0; i < 32; i++) printf("%02x", ev->key_vector[i]); + printf("\n"); } static void -VerbKey(XKeyEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("root=0x%x%s", (int)ev->root, sep); - if(ev->subwindow) - printf("subwindow=0x%x%s", (int)ev->subwindow, sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("[%d,%d]%s", ev->x, ev->y, sep); - printf("root=[%d,%d]%s", ev->x_root, ev->y_root, sep); - if(ev->state) - printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); - printf("keycode=%s%s", Keycode(ev), sep); - if(!ev->same_screen) - printf("!same_screen", TorF(ev->same_screen)); - printf("\n"); - return; +VerbKey(XKeyEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("root=0x%x%s", (int)ev->root, sep); + if (ev->subwindow) printf("subwindow=0x%x%s", (int)ev->subwindow, sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("[%d,%d]%s", ev->x, ev->y, sep); + printf("root=[%d,%d]%s", ev->x_root, ev->y_root, sep); + if (ev->state) printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); + printf("keycode=%s%s", Keycode(ev), sep); + if (!ev->same_screen) printf("!same_screen", TorF(ev->same_screen)); + printf("\n"); + return; - printf("window=0x%x%s", (int)ev->window, sep); - printf("root=0x%x%s", (int)ev->root, sep); - printf("subwindow=0x%x%s", (int)ev->subwindow, sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); - printf("keycode=%s%s", Keycode(ev), sep); - printf("same_screen=%s\n", TorF(ev->same_screen)); + printf("window=0x%x%s", (int)ev->window, sep); + printf("root=0x%x%s", (int)ev->root, sep); + printf("subwindow=0x%x%s", (int)ev->subwindow, sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); + printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); + printf("keycode=%s%s", Keycode(ev), sep); + printf("same_screen=%s\n", TorF(ev->same_screen)); } static void -VerbProperty(XPropertyEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("atom=%s%s", AtomName(ev->display, ev->atom), sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("state=%s\n", PropertyState(ev->state)); +VerbProperty(XPropertyEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("atom=%s%s", AtomName(ev->display, ev->atom), sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("state=%s\n", PropertyState(ev->state)); } static void -VerbResizeRequest(XResizeRequestEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("width=%d height=%d\n", ev->width, ev->height); +VerbResizeRequest(XResizeRequestEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("width=%d height=%d\n", ev->width, ev->height); } static void -VerbCirculate(XCirculateEvent *ev) -{ - printf("event=0x%x%s", (int)ev->event, sep); - printf("window=0x%x%s", (int)ev->window, sep); - printf("place=%s\n", Place(ev->place)); +VerbCirculate(XCirculateEvent* ev) { + printf("event=0x%x%s", (int)ev->event, sep); + printf("window=0x%x%s", (int)ev->window, sep); + printf("place=%s\n", Place(ev->place)); } static void -VerbConfigure(XConfigureEvent *ev) -{ - printf("event=0x%x%s", (int)ev->event, sep); - printf("window=0x%x%s", (int)ev->window, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("width=%d height=%d%s", ev->width, ev->height, sep); - printf("border_width=%d%s", ev->border_width, sep); - printf("above=%s%s", MaybeNone(ev->above), sep); - printf("override_redirect=%s\n", TorF(ev->override_redirect)); +VerbConfigure(XConfigureEvent* ev) { + printf("event=0x%x%s", (int)ev->event, sep); + printf("window=0x%x%s", (int)ev->window, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("width=%d height=%d%s", ev->width, ev->height, sep); + printf("border_width=%d%s", ev->border_width, sep); + printf("above=%s%s", MaybeNone(ev->above), sep); + printf("override_redirect=%s\n", TorF(ev->override_redirect)); } static void -VerbCreateWindow(XCreateWindowEvent *ev) -{ - printf("parent=0x%x%s", (int)ev->parent, sep); - printf("window=0x%x%s", (int)ev->window, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("width=%d height=%d%s", ev->width, ev->height, sep); - printf("border_width=%d%s", ev->border_width, sep); - printf("override_redirect=%s\n", TorF(ev->override_redirect)); +VerbCreateWindow(XCreateWindowEvent* ev) { + printf("parent=0x%x%s", (int)ev->parent, sep); + printf("window=0x%x%s", (int)ev->window, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("width=%d height=%d%s", ev->width, ev->height, sep); + printf("border_width=%d%s", ev->border_width, sep); + printf("override_redirect=%s\n", TorF(ev->override_redirect)); } static void -VerbDestroyWindow(XDestroyWindowEvent *ev) -{ - printf("event=0x%x%s", (int)ev->event, sep); - printf("window=0x%x\n", (int)ev->window); +VerbDestroyWindow(XDestroyWindowEvent* ev) { + printf("event=0x%x%s", (int)ev->event, sep); + printf("window=0x%x\n", (int)ev->window); } static void -VerbGravity(XGravityEvent *ev) -{ - printf("event=0x%x%s", (int)ev->event, sep); - printf("window=0x%x%s", (int)ev->window, sep); - printf("x=%d y=%d\n", ev->x, ev->y); +VerbGravity(XGravityEvent* ev) { + printf("event=0x%x%s", (int)ev->event, sep); + printf("window=0x%x%s", (int)ev->window, sep); + printf("x=%d y=%d\n", ev->x, ev->y); } static void -VerbMap(XMapEvent *ev) -{ - printf("event=0x%x%s", (int)ev->event, sep); - printf("window=0x%x%s", (int)ev->window, sep); - printf("override_redirect=%s\n", TorF(ev->override_redirect)); +VerbMap(XMapEvent* ev) { + printf("event=0x%x%s", (int)ev->event, sep); + printf("window=0x%x%s", (int)ev->window, sep); + printf("override_redirect=%s\n", TorF(ev->override_redirect)); } static void -VerbReparent(XReparentEvent *ev) -{ - printf("event=0x%x%s", (int)ev->event, sep); - printf("window=0x%x%s", (int)ev->window, sep); - printf("parent=0x%x%s", (int)ev->parent, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("override_redirect=%s\n", TorF(ev->override_redirect)); +VerbReparent(XReparentEvent* ev) { + printf("event=0x%x%s", (int)ev->event, sep); + printf("window=0x%x%s", (int)ev->window, sep); + printf("parent=0x%x%s", (int)ev->parent, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("override_redirect=%s\n", TorF(ev->override_redirect)); } static void -VerbUnmap(XUnmapEvent *ev) -{ - printf("event=0x%x%s", (int)ev->event, sep); - printf("window=0x%x%s", (int)ev->window, sep); - printf("from_configure=%s\n", TorF(ev->from_configure)); +VerbUnmap(XUnmapEvent* ev) { + printf("event=0x%x%s", (int)ev->event, sep); + printf("window=0x%x%s", (int)ev->window, sep); + printf("from_configure=%s\n", TorF(ev->from_configure)); } static void -VerbCirculateRequest(XCirculateRequestEvent *ev) -{ - printf("parent=0x%x%s", (int)ev->parent, sep); - printf("window=0x%x%s", (int)ev->window, sep); - printf("place=%s\n", Place(ev->place)); +VerbCirculateRequest(XCirculateRequestEvent* ev) { + printf("parent=0x%x%s", (int)ev->parent, sep); + printf("window=0x%x%s", (int)ev->window, sep); + printf("place=%s\n", Place(ev->place)); } static void -VerbConfigureRequest(XConfigureRequestEvent *ev) -{ - printf("parent=0x%x%s", (int)ev->parent, sep); - printf("window=0x%x%s", (int)ev->window, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("width=%d height=%d%s", ev->width, ev->height, sep); - printf("border_width=%d%s", ev->border_width, sep); - printf("above=%s%s", MaybeNone(ev->above), sep); - printf("detail=%s%s", ConfigureDetail(ev->detail), sep); - printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask)); +VerbConfigureRequest(XConfigureRequestEvent* ev) { + printf("parent=0x%x%s", (int)ev->parent, sep); + printf("window=0x%x%s", (int)ev->window, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("width=%d height=%d%s", ev->width, ev->height, sep); + printf("border_width=%d%s", ev->border_width, sep); + printf("above=%s%s", MaybeNone(ev->above), sep); + printf("detail=%s%s", ConfigureDetail(ev->detail), sep); + printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask)); } static void -VerbMapRequest(XMapRequestEvent *ev) -{ - printf("parent=0x%x%s", (int)ev->parent, sep); - printf("window=0x%x\n", (int)ev->window); +VerbMapRequest(XMapRequestEvent* ev) { + printf("parent=0x%x%s", (int)ev->parent, sep); + printf("window=0x%x\n", (int)ev->window); } static void -VerbClient(XClientMessageEvent *ev) -{ - int i; +VerbClient(XClientMessageEvent* ev) { + int i; - printf("window=0x%x%s", (int)ev->window, sep); - printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep); - printf("format=%d\n", ev->format); - printf("data (shown as longs)="); - for (i = 0; i < 5; i++) - printf(" 0x%08lx", ev->data.l[i]); - printf("\n"); + printf("window=0x%x%s", (int)ev->window, sep); + printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep); + printf("format=%d\n", ev->format); + printf("data (shown as longs)="); + for (i = 0; i < 5; i++) printf(" 0x%08lx", ev->data.l[i]); + printf("\n"); } static void -VerbMapping(XMappingEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("request=%s%s", MappingRequest(ev->request), sep); - printf("first_keycode=0x%x%s", ev->first_keycode, sep); - printf("count=0x%x\n", ev->count); +VerbMapping(XMappingEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("request=%s%s", MappingRequest(ev->request), sep); + printf("first_keycode=0x%x%s", ev->first_keycode, sep); + printf("count=0x%x\n", ev->count); } static void -VerbSelectionClear(XSelectionClearEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); - printf("time=%s\n", ServerTime(ev->time)); +VerbSelectionClear(XSelectionClearEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); + printf("time=%s\n", ServerTime(ev->time)); } static void -VerbSelection(XSelectionEvent *ev) -{ - printf("requestor=0x%x%s", (int)ev->requestor, sep); - printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); - printf("target=%s%s", AtomName(ev->display, ev->target), sep); - printf("property=%s%s", AtomName(ev->display, ev->property), sep); - printf("time=%s\n", ServerTime(ev->time)); +VerbSelection(XSelectionEvent* ev) { + printf("requestor=0x%x%s", (int)ev->requestor, sep); + printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); + printf("target=%s%s", AtomName(ev->display, ev->target), sep); + printf("property=%s%s", AtomName(ev->display, ev->property), sep); + printf("time=%s\n", ServerTime(ev->time)); } static void -VerbSelectionRequest(XSelectionRequestEvent *ev) -{ - printf("owner=0x%x%s", (int)ev->owner, sep); - printf("requestor=0x%x%s", (int)ev->requestor, sep); - printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); - printf("target=%s%s", AtomName(ev->display, ev->target), sep); - printf("property=%s%s", AtomName(ev->display, ev->property), sep); - printf("time=%s\n", ServerTime(ev->time)); +VerbSelectionRequest(XSelectionRequestEvent* ev) { + printf("owner=0x%x%s", (int)ev->owner, sep); + printf("requestor=0x%x%s", (int)ev->requestor, sep); + printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); + printf("target=%s%s", AtomName(ev->display, ev->target), sep); + printf("property=%s%s", AtomName(ev->display, ev->property), sep); + printf("time=%s\n", ServerTime(ev->time)); } static void -VerbVisibility(XVisibilityEvent *ev) -{ - printf("window=0x%x%s", (int)ev->window, sep); - printf("state=%s\n", VisibilityState(ev->state)); +VerbVisibility(XVisibilityEvent* ev) { + printf("window=0x%x%s", (int)ev->window, sep); + printf("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; +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; } /******************************************************************************/ /**************** Print the values of all fields for any event ****************/ /******************************************************************************/ -void printevent(XEvent *e) -{ - XAnyEvent *ev = (void*)e; +void +printevent(XEvent* e) { + XAnyEvent* ev = (void*)e; - printf("%3ld %-20s ", ev->serial, eventtype(e)); - if(ev->send_event) - printf("(sendevent) "); - if(0){ - printf("type=%s%s", eventtype(e), sep); - printf("serial=%lu%s", ev->serial, sep); - printf("send_event=%s%s", TorF(ev->send_event), sep); - printf("display=0x%p%s", ev->display, sep); - } + printf("%3ld %-20s ", ev->serial, eventtype(e)); + if (ev->send_event) printf("(sendevent) "); + if (0) { + printf("type=%s%s", eventtype(e), sep); + printf("serial=%lu%s", ev->serial, sep); + printf("send_event=%s%s", TorF(ev->send_event), sep); + printf("display=0x%p%s", ev->display, sep); + } - switch (ev->type) { - case MotionNotify: - VerbMotion((void*)ev); - break; + switch (ev->type) { + case MotionNotify: VerbMotion((void*)ev); break; case ButtonPress: - case ButtonRelease: - VerbButton((void*)ev); - break; + case ButtonRelease: VerbButton((void*)ev); break; - case ColormapNotify: - VerbColormap((void*)ev); - break; + case ColormapNotify: VerbColormap((void*)ev); break; case EnterNotify: - case LeaveNotify: - VerbCrossing((void*)ev); - break; + case LeaveNotify: VerbCrossing((void*)ev); break; - case Expose: - VerbExpose((void*)ev); - break; + case Expose: VerbExpose((void*)ev); break; - case GraphicsExpose: - VerbGraphicsExpose((void*)ev); - break; + case GraphicsExpose: VerbGraphicsExpose((void*)ev); break; - case NoExpose: - VerbNoExpose((void*)ev); - break; + case NoExpose: VerbNoExpose((void*)ev); break; case FocusIn: - case FocusOut: - VerbFocus((void*)ev); - break; + case FocusOut: VerbFocus((void*)ev); break; - case KeymapNotify: - VerbKeymap((void*)ev); - break; + case KeymapNotify: VerbKeymap((void*)ev); break; case KeyPress: - case KeyRelease: - VerbKey((void*)ev); - break; + case KeyRelease: VerbKey((void*)ev); break; - case PropertyNotify: - VerbProperty((void*)ev); - break; + case PropertyNotify: VerbProperty((void*)ev); break; - case ResizeRequest: - VerbResizeRequest((void*)ev); - break; + case ResizeRequest: VerbResizeRequest((void*)ev); break; - case CirculateNotify: - VerbCirculate((void*)ev); - break; + case CirculateNotify: VerbCirculate((void*)ev); break; - case ConfigureNotify: - VerbConfigure((void*)ev); - break; + case ConfigureNotify: VerbConfigure((void*)ev); break; - case CreateNotify: - VerbCreateWindow((void*)ev); - break; + case CreateNotify: VerbCreateWindow((void*)ev); break; - case DestroyNotify: - VerbDestroyWindow((void*)ev); - break; + case DestroyNotify: VerbDestroyWindow((void*)ev); break; - case GravityNotify: - VerbGravity((void*)ev); - break; + case GravityNotify: VerbGravity((void*)ev); break; - case MapNotify: - VerbMap((void*)ev); - break; + case MapNotify: VerbMap((void*)ev); break; - case ReparentNotify: - VerbReparent((void*)ev); - break; + case ReparentNotify: VerbReparent((void*)ev); break; - case UnmapNotify: - VerbUnmap((void*)ev); - break; + case UnmapNotify: VerbUnmap((void*)ev); break; - case CirculateRequest: - VerbCirculateRequest((void*)ev); - break; + case CirculateRequest: VerbCirculateRequest((void*)ev); break; - case ConfigureRequest: - VerbConfigureRequest((void*)ev); - break; + case ConfigureRequest: VerbConfigureRequest((void*)ev); break; - case MapRequest: - VerbMapRequest((void*)ev); - break; + case MapRequest: VerbMapRequest((void*)ev); break; - case ClientMessage: - VerbClient((void*)ev); - break; + case ClientMessage: VerbClient((void*)ev); break; - case MappingNotify: - VerbMapping((void*)ev); - break; + case MappingNotify: VerbMapping((void*)ev); break; - case SelectionClear: - VerbSelectionClear((void*)ev); - break; + case SelectionClear: VerbSelectionClear((void*)ev); break; - case SelectionNotify: - VerbSelection((void*)ev); - break; + case SelectionNotify: VerbSelection((void*)ev); break; - case SelectionRequest: - VerbSelectionRequest((void*)ev); - break; + case SelectionRequest: VerbSelectionRequest((void*)ev); break; - case VisibilityNotify: - VerbVisibility((void*)ev); - break; - } + case VisibilityNotify: VerbVisibility((void*)ev); break; + } } - diff --git a/printevent.h b/printevent.h old mode 100755 new mode 100644 index 0a41936..ebb2e62 --- a/printevent.h +++ b/printevent.h @@ -1,2 +1,2 @@ -char *eventtype(XEvent*); +char* eventtype(XEvent*); void printevent(XEvent*); diff --git a/showevent/ShowEvent.c b/showevent/ShowEvent.c old mode 100755 new mode 100644 index 56f620d..39a4e5c --- a/showevent/ShowEvent.c +++ b/showevent/ShowEvent.c @@ -2,887 +2,732 @@ #include Boolean use_separate_lines = True; -static char *sep; +static char* sep; /******************************************************************************/ /**** Miscellaneous routines to convert values to their string equivalents ****/ /******************************************************************************/ /* Returns the string equivalent of a boolean parameter */ -static char *TorF(bool) -int bool; +static char* TorF(bool) int bool; { - switch (bool) { - case True: - return ("True"); + switch (bool) { + case True: return ("True"); - case False: - return ("False"); + case False: return ("False"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a property notify state */ -static char *PropertyState(state) -int state; +static char* PropertyState(state) int state; { - switch (state) { - case PropertyNewValue: - return ("PropertyNewValue"); + switch (state) { + case PropertyNewValue: return ("PropertyNewValue"); - case PropertyDelete: - return ("PropertyDelete"); + case PropertyDelete: return ("PropertyDelete"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a visibility notify state */ -static char *VisibilityState(state) -int state; +static char* VisibilityState(state) int state; { - switch (state) { - case VisibilityUnobscured: - return ("VisibilityUnobscured"); + switch (state) { + case VisibilityUnobscured: return ("VisibilityUnobscured"); - case VisibilityPartiallyObscured: - return ("VisibilityPartiallyObscured"); + case VisibilityPartiallyObscured: return ("VisibilityPartiallyObscured"); - case VisibilityFullyObscured: - return ("VisibilityFullyObscured"); + case VisibilityFullyObscured: return ("VisibilityFullyObscured"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a timestamp */ -static char *ServerTime(time) -Time time; +static char* ServerTime(time) Time time; { - unsigned long msec; - unsigned long sec; - unsigned long min; - unsigned long hr; - unsigned long day; - static char buffer[32]; + unsigned long msec; + unsigned long sec; + unsigned long min; + unsigned long hr; + unsigned long day; + static char buffer[32]; - 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; - sprintf(buffer, "%ld day%s %02ld:%02ld:%02ld.%03ld", - day, day == 1 ? "" : "(s)", hr, min, sec, msec); - return (buffer); + sprintf( + buffer, + "%ld day%s %02ld:%02ld:%02ld.%03ld", + day, + day == 1 ? "" : "(s)", + hr, + min, + sec, + msec); + return (buffer); } /* Simple structure to ease the interpretation of masks */ typedef struct _MaskType { - unsigned int value; - char *string; + unsigned int value; + char* string; } MaskType; /* Returns the string equivalent of a mask of buttons and/or modifier keys */ -static char *ButtonAndOrModifierState(state) -unsigned int state; +static char* ButtonAndOrModifierState(state) unsigned int 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 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; - buffer[0] = 0; + 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); + 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); } /* Returns the string equivalent of a mask of configure window values */ -static char *ConfigureValueMask(valuemask) -unsigned int valuemask; +static char* ConfigureValueMask(valuemask) unsigned int 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 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; - buffer[0] = 0; + 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); - } + 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 (buffer); } /* Returns the string equivalent of a motion hint */ -static char *IsHint(is_hint) -char is_hint; +static char* IsHint(is_hint) char is_hint; { - switch (is_hint) { - case NotifyNormal: - return ("NotifyNormal"); + switch (is_hint) { + case NotifyNormal: return ("NotifyNormal"); - case NotifyHint: - return ("NotifyHint"); + case NotifyHint: return ("NotifyHint"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of an id or the value "None" */ -static char *MaybeNone(value) -int value; +static char* MaybeNone(value) int value; { - static char buffer[16]; + static char buffer[16]; - if (value == None) - return ("None"); - else { - sprintf(buffer, "0x%x", value); - return (buffer); - } + if (value == None) + return ("None"); + else { + sprintf(buffer, "0x%x", value); + return (buffer); + } } /* Returns the string equivalent of a colormap state */ -static char *ColormapState(state) -int state; +static char* ColormapState(state) int state; { - switch (state) { - case ColormapInstalled: - return ("ColormapInstalled"); + switch (state) { + case ColormapInstalled: return ("ColormapInstalled"); - case ColormapUninstalled: - return ("ColormapUninstalled"); + case ColormapUninstalled: return ("ColormapUninstalled"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a crossing detail */ -static char *CrossingDetail(detail) -int detail; +static char* CrossingDetail(detail) int detail; { - switch (detail) { - case NotifyAncestor: - return ("NotifyAncestor"); + switch (detail) { + case NotifyAncestor: return ("NotifyAncestor"); - case NotifyInferior: - return ("NotifyInferior"); + case NotifyInferior: return ("NotifyInferior"); - case NotifyVirtual: - return ("NotifyVirtual"); + case NotifyVirtual: return ("NotifyVirtual"); - case NotifyNonlinear: - return ("NotifyNonlinear"); + case NotifyNonlinear: return ("NotifyNonlinear"); - case NotifyNonlinearVirtual: - return ("NotifyNonlinearVirtual"); + case NotifyNonlinearVirtual: return ("NotifyNonlinearVirtual"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a focus change detail */ -static char *FocusChangeDetail(detail) -int detail; +static char* FocusChangeDetail(detail) int detail; { - switch (detail) { - case NotifyAncestor: - return ("NotifyAncestor"); + switch (detail) { + case NotifyAncestor: return ("NotifyAncestor"); - case NotifyInferior: - return ("NotifyInferior"); + case NotifyInferior: return ("NotifyInferior"); - case NotifyVirtual: - return ("NotifyVirtual"); + case NotifyVirtual: return ("NotifyVirtual"); - case NotifyNonlinear: - return ("NotifyNonlinear"); + case NotifyNonlinear: return ("NotifyNonlinear"); - case NotifyNonlinearVirtual: - return ("NotifyNonlinearVirtual"); + case NotifyNonlinearVirtual: return ("NotifyNonlinearVirtual"); - case NotifyPointer: - return ("NotifyPointer"); + case NotifyPointer: return ("NotifyPointer"); - case NotifyPointerRoot: - return ("NotifyPointerRoot"); + case NotifyPointerRoot: return ("NotifyPointerRoot"); - case NotifyDetailNone: - return ("NotifyDetailNone"); + case NotifyDetailNone: return ("NotifyDetailNone"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a configure detail */ -static char *ConfigureDetail(detail) -int detail; +static char* ConfigureDetail(detail) int detail; { - switch (detail) { - case Above: - return ("Above"); + switch (detail) { + case Above: return ("Above"); - case Below: - return ("Below"); + case Below: return ("Below"); - case TopIf: - return ("TopIf"); + case TopIf: return ("TopIf"); - case BottomIf: - return ("BottomIf"); + case BottomIf: return ("BottomIf"); - case Opposite: - return ("Opposite"); + case Opposite: return ("Opposite"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a grab mode */ -static char *GrabMode(mode) -int mode; +static char* GrabMode(mode) int mode; { - switch (mode) { - case NotifyNormal: - return ("NotifyNormal"); + switch (mode) { + case NotifyNormal: return ("NotifyNormal"); - case NotifyGrab: - return ("NotifyGrab"); + case NotifyGrab: return ("NotifyGrab"); - case NotifyUngrab: - return ("NotifyUngrab"); + case NotifyUngrab: return ("NotifyUngrab"); - case NotifyWhileGrabbed: - return ("NotifyWhileGrabbed"); + case NotifyWhileGrabbed: return ("NotifyWhileGrabbed"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a mapping request */ -static char *MappingRequest(request) -int request; +static char* MappingRequest(request) int request; { - switch (request) { - case MappingModifier: - return ("MappingModifier"); + switch (request) { + case MappingModifier: return ("MappingModifier"); - case MappingKeyboard: - return ("MappingKeyboard"); + case MappingKeyboard: return ("MappingKeyboard"); - case MappingPointer: - return ("MappingPointer"); + case MappingPointer: return ("MappingPointer"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a stacking order place */ -static char *Place(place) -int place; +static char* Place(place) int place; { - switch (place) { - case PlaceOnTop: - return ("PlaceOnTop"); + switch (place) { + case PlaceOnTop: return ("PlaceOnTop"); - case PlaceOnBottom: - return ("PlaceOnBottom"); + case PlaceOnBottom: return ("PlaceOnBottom"); - default: - return ("?"); - } + default: return ("?"); + } } /* Returns the string equivalent of a major code */ -static char *MajorCode(code) -int code; +static char* MajorCode(code) int code; { - static char buffer[32]; + static char buffer[32]; - switch (code) { - case X_CopyArea: - return ("X_CopyArea"); + switch (code) { + case X_CopyArea: return ("X_CopyArea"); - case X_CopyPlane: - return ("X_CopyPlane"); + case X_CopyPlane: return ("X_CopyPlane"); - default: - sprintf(buffer, "0x%x", code); - return (buffer); - } + default: sprintf(buffer, "0x%x", code); return (buffer); + } } /* Returns the string equivalent the keycode contained in the key event */ -static char *Keycode(ev) -XKeyEvent *ev; +static char* Keycode(ev) XKeyEvent* ev; { - static char buffer[256]; - KeySym keysym_str; - char *keysym_name; - char string[256]; + static char buffer[256]; + KeySym keysym_str; + char* keysym_name; + char string[256]; - XLookupString(ev, string, 64, &keysym_str, NULL); + XLookupString(ev, string, 64, &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\")", - ev->keycode, (unsigned)keysym_str, keysym_name); - return (buffer); + 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\")", + ev->keycode, + (unsigned)keysym_str, + keysym_name); + return (buffer); } /* Returns the string equivalent of an atom or "None"*/ -static char *AtomName(Display *dpy, Atom atom) -{ - static char buffer[256]; - char *atom_name; +static char* +AtomName(Display* dpy, Atom atom) { + static char buffer[256]; + 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(dpy, atom); + strncpy(buffer, atom_name, 256); + XFree(atom_name); + return (buffer); } /******************************************************************************/ /**** Routines to print out readable values for the field of various events ***/ /******************************************************************************/ -static void VerbMotion(XMotionEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("root=0x%x%s", (unsigned)ev->root, sep); - printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); - printf("is_hint=%s%s", IsHint(ev->is_hint), sep); - printf("same_screen=%s\n", TorF(ev->same_screen)); +static void +VerbMotion(XMotionEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("root=0x%x%s", (unsigned)ev->root, sep); + printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); + printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); + printf("is_hint=%s%s", IsHint(ev->is_hint), sep); + printf("same_screen=%s\n", TorF(ev->same_screen)); } -static void VerbButton(XButtonEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("root=0x%x%s", (unsigned)ev->root, sep); - printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); - printf("button=%s%s", ButtonAndOrModifierState(ev->button), sep); - printf("same_screen=%s\n", TorF(ev->same_screen)); +static void +VerbButton(XButtonEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("root=0x%x%s", (unsigned)ev->root, sep); + printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); + printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); + printf("button=%s%s", ButtonAndOrModifierState(ev->button), sep); + printf("same_screen=%s\n", TorF(ev->same_screen)); } -static void VerbColormap(XColormapEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("colormap=%s%s", MaybeNone(ev->colormap), sep); - printf("new=%s%s", TorF(ev->new), sep); - printf("state=%s\n", ColormapState(ev->state)); +static void +VerbColormap(XColormapEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("colormap=%s%s", MaybeNone(ev->colormap), sep); + printf("new=%s%s", TorF(ev->new), sep); + printf("state=%s\n", ColormapState(ev->state)); } -static void VerbCrossing(XCrossingEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("root=0x%x%s", (unsigned)ev->root, sep); - printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - printf("mode=%s%s", GrabMode(ev->mode), sep); - printf("detail=%s%s", CrossingDetail(ev->detail), sep); - printf("same_screen=%s%s", TorF(ev->same_screen), sep); - printf("focus=%s%s", TorF(ev->focus), sep); - printf("state=%s\n", ButtonAndOrModifierState(ev->state)); +static void +VerbCrossing(XCrossingEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("root=0x%x%s", (unsigned)ev->root, sep); + printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); + printf("mode=%s%s", GrabMode(ev->mode), sep); + printf("detail=%s%s", CrossingDetail(ev->detail), sep); + printf("same_screen=%s%s", TorF(ev->same_screen), sep); + printf("focus=%s%s", TorF(ev->focus), sep); + printf("state=%s\n", ButtonAndOrModifierState(ev->state)); } -static void VerbExpose(XExposeEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("width=%d height=%d%s", ev->width, ev->height, sep); - printf("count=%d\n", ev->count); +static void +VerbExpose(XExposeEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("width=%d height=%d%s", ev->width, ev->height, sep); + printf("count=%d\n", ev->count); } -static void VerbGraphicsExpose(XGraphicsExposeEvent *ev) -{ - printf("drawable=0x%x%s", (unsigned)ev->drawable, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("width=%d height=%d%s", ev->width, ev->height, sep); - printf("major_code=%s%s", MajorCode(ev->major_code), sep); - printf("minor_code=%d\n", ev->minor_code); +static void +VerbGraphicsExpose(XGraphicsExposeEvent* ev) { + printf("drawable=0x%x%s", (unsigned)ev->drawable, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("width=%d height=%d%s", ev->width, ev->height, sep); + printf("major_code=%s%s", MajorCode(ev->major_code), sep); + printf("minor_code=%d\n", ev->minor_code); } -static void VerbNoExpose(XNoExposeEvent *ev) -{ - printf("drawable=0x%x%s", (unsigned)ev->drawable, sep); - printf("major_code=%s%s", MajorCode(ev->major_code), sep); - printf("minor_code=%d\n", ev->minor_code); +static void +VerbNoExpose(XNoExposeEvent* ev) { + printf("drawable=0x%x%s", (unsigned)ev->drawable, sep); + printf("major_code=%s%s", MajorCode(ev->major_code), sep); + printf("minor_code=%d\n", ev->minor_code); } -static void VerbFocus(XFocusChangeEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("mode=%s%s", GrabMode(ev->mode), sep); - printf("detail=%s\n", FocusChangeDetail(ev->detail)); +static void +VerbFocus(XFocusChangeEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("mode=%s%s", GrabMode(ev->mode), sep); + printf("detail=%s\n", FocusChangeDetail(ev->detail)); } -static void VerbKeymap(XKeymapEvent *ev) -{ - int i; +static void +VerbKeymap(XKeymapEvent* ev) { + int i; - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("key_vector="); - for (i = 0; i < 32; i++) - printf("%02x", ev->key_vector[i]); - printf("\n"); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("key_vector="); + for (i = 0; i < 32; i++) printf("%02x", ev->key_vector[i]); + printf("\n"); } -static void VerbKey(XKeyEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("root=0x%x%s", (unsigned)ev->root, sep); - printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); - printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); - printf("keycode=%s%s", Keycode(ev), sep); - printf("same_screen=%s\n", TorF(ev->same_screen)); +static void +VerbKey(XKeyEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("root=0x%x%s", (unsigned)ev->root, sep); + printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("x_root=%d y_root=%d%s", ev->x_root, ev->y_root, sep); + printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep); + printf("keycode=%s%s", Keycode(ev), sep); + printf("same_screen=%s\n", TorF(ev->same_screen)); } -static void VerbProperty(XPropertyEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("atom=%s%s", AtomName(ev->display, ev->atom), sep); - printf("time=%s%s", ServerTime(ev->time), sep); - printf("state=%s\n", PropertyState(ev->state)); +static void +VerbProperty(XPropertyEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("atom=%s%s", AtomName(ev->display, ev->atom), sep); + printf("time=%s%s", ServerTime(ev->time), sep); + printf("state=%s\n", PropertyState(ev->state)); } -static void VerbResizeRequest(XResizeRequestEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("width=%d height=%d\n", ev->width, ev->height); +static void +VerbResizeRequest(XResizeRequestEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("width=%d height=%d\n", ev->width, ev->height); } -static void VerbCirculate(XCirculateEvent *ev) -{ - printf("event=0x%x%s", (unsigned)ev->event, sep); - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("place=%s\n", Place(ev->place)); +static void +VerbCirculate(XCirculateEvent* ev) { + printf("event=0x%x%s", (unsigned)ev->event, sep); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("place=%s\n", Place(ev->place)); } -static void VerbConfigure(XConfigureEvent *ev) -{ - printf("event=0x%x%s", (unsigned)ev->event, sep); - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("width=%d height=%d%s", ev->width, ev->height, sep); - printf("border_width=%d%s", ev->border_width, sep); - printf("above=%s%s", MaybeNone(ev->above), sep); - printf("override_redirect=%s\n", TorF(ev->override_redirect)); +static void +VerbConfigure(XConfigureEvent* ev) { + printf("event=0x%x%s", (unsigned)ev->event, sep); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("width=%d height=%d%s", ev->width, ev->height, sep); + printf("border_width=%d%s", ev->border_width, sep); + printf("above=%s%s", MaybeNone(ev->above), sep); + printf("override_redirect=%s\n", TorF(ev->override_redirect)); } -static void VerbCreateWindow(XCreateWindowEvent *ev) -{ - printf("parent=0x%x%s", (unsigned)ev->parent, sep); - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("width=%d height=%d%s", ev->width, ev->height, sep); - printf("border_width=%d%s", ev->border_width, sep); - printf("override_redirect=%s\n", TorF(ev->override_redirect)); +static void +VerbCreateWindow(XCreateWindowEvent* ev) { + printf("parent=0x%x%s", (unsigned)ev->parent, sep); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("width=%d height=%d%s", ev->width, ev->height, sep); + printf("border_width=%d%s", ev->border_width, sep); + printf("override_redirect=%s\n", TorF(ev->override_redirect)); } -static void VerbDestroyWindow(XDestroyWindowEvent *ev) -{ - printf("event=0x%x%s", (unsigned)ev->event, sep); - printf("window=0x%x\n", (unsigned)ev->window); +static void +VerbDestroyWindow(XDestroyWindowEvent* ev) { + printf("event=0x%x%s", (unsigned)ev->event, sep); + printf("window=0x%x\n", (unsigned)ev->window); } -static void VerbGravity(XGravityEvent *ev) -{ - printf("event=0x%x%s", (unsigned)ev->event, sep); - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("x=%d y=%d\n", ev->x, ev->y); +static void +VerbGravity(XGravityEvent* ev) { + printf("event=0x%x%s", (unsigned)ev->event, sep); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("x=%d y=%d\n", ev->x, ev->y); } -static void VerbMap(XMapEvent *ev) -{ - printf("event=0x%x%s", (unsigned)ev->event, sep); - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("override_redirect=%s\n", TorF(ev->override_redirect)); +static void +VerbMap(XMapEvent* ev) { + printf("event=0x%x%s", (unsigned)ev->event, sep); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("override_redirect=%s\n", TorF(ev->override_redirect)); } -static void VerbReparent(XReparentEvent *ev) -{ - printf("event=0x%x%s", (unsigned)ev->event, sep); - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("parent=0x%x%s", (unsigned)ev->parent, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("override_redirect=%s\n", TorF(ev->override_redirect)); +static void +VerbReparent(XReparentEvent* ev) { + printf("event=0x%x%s", (unsigned)ev->event, sep); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("parent=0x%x%s", (unsigned)ev->parent, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("override_redirect=%s\n", TorF(ev->override_redirect)); } -static void VerbUnmap(XUnmapEvent *ev) -{ - printf("event=0x%x%s", (unsigned)ev->event, sep); - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("from_configure=%s\n", TorF(ev->from_configure)); +static void +VerbUnmap(XUnmapEvent* ev) { + printf("event=0x%x%s", (unsigned)ev->event, sep); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("from_configure=%s\n", TorF(ev->from_configure)); } -static void VerbCirculateRequest(XCirculateRequestEvent *ev) -{ - printf("parent=0x%x%s", (unsigned)ev->parent, sep); - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("place=%s\n", Place(ev->place)); +static void +VerbCirculateRequest(XCirculateRequestEvent* ev) { + printf("parent=0x%x%s", (unsigned)ev->parent, sep); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("place=%s\n", Place(ev->place)); } -static void VerbConfigureRequest(XConfigureRequestEvent *ev) -{ - printf("parent=0x%x%s", (unsigned)ev->parent, sep); - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("x=%d y=%d%s", ev->x, ev->y, sep); - printf("width=%d height=%d%s", ev->width, ev->height, sep); - printf("border_width=%d%s", ev->border_width, sep); - printf("above=%s%s", MaybeNone(ev->above), sep); - printf("detail=%s%s", ConfigureDetail(ev->detail), sep); - printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask)); +static void +VerbConfigureRequest(XConfigureRequestEvent* ev) { + printf("parent=0x%x%s", (unsigned)ev->parent, sep); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("x=%d y=%d%s", ev->x, ev->y, sep); + printf("width=%d height=%d%s", ev->width, ev->height, sep); + printf("border_width=%d%s", ev->border_width, sep); + printf("above=%s%s", MaybeNone(ev->above), sep); + printf("detail=%s%s", ConfigureDetail(ev->detail), sep); + printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask)); } -static void VerbMapRequest(XMapRequestEvent *ev) -{ - printf("parent=0x%x%s", (unsigned)ev->parent, sep); - printf("window=0x%x\n", (unsigned)ev->window); +static void +VerbMapRequest(XMapRequestEvent* ev) { + printf("parent=0x%x%s", (unsigned)ev->parent, sep); + printf("window=0x%x\n", (unsigned)ev->window); } -static void VerbClient(XClientMessageEvent *ev) -{ - int i; +static void +VerbClient(XClientMessageEvent* ev) { + int i; - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep); - printf("format=%d\n", ev->format); - printf("data (shown as longs)="); - for (i = 0; i < 5; i++) - printf(" 0x%08lx", ev->data.l[i]); - printf("\n"); + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep); + printf("format=%d\n", ev->format); + printf("data (shown as longs)="); + for (i = 0; i < 5; i++) printf(" 0x%08lx", ev->data.l[i]); + printf("\n"); } -static void VerbMapping(XMappingEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("request=%s%s", MappingRequest(ev->request), sep); - printf("first_keycode=0x%x%s", ev->first_keycode, sep); - printf("count=0x%x\n", ev->count); +static void +VerbMapping(XMappingEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("request=%s%s", MappingRequest(ev->request), sep); + printf("first_keycode=0x%x%s", ev->first_keycode, sep); + printf("count=0x%x\n", ev->count); } -static void VerbSelectionClear(XSelectionClearEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); - printf("time=%s\n", ServerTime(ev->time)); +static void +VerbSelectionClear(XSelectionClearEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); + printf("time=%s\n", ServerTime(ev->time)); } -static void VerbSelection(XSelectionEvent *ev) -{ - printf("requestor=0x%x%s", (unsigned)ev->requestor, sep); - printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); - printf("target=%s%s", AtomName(ev->display, ev->target), sep); - printf("property=%s%s", AtomName(ev->display, ev->property), sep); - printf("time=%s\n", ServerTime(ev->time)); +static void +VerbSelection(XSelectionEvent* ev) { + printf("requestor=0x%x%s", (unsigned)ev->requestor, sep); + printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); + printf("target=%s%s", AtomName(ev->display, ev->target), sep); + printf("property=%s%s", AtomName(ev->display, ev->property), sep); + printf("time=%s\n", ServerTime(ev->time)); } -static void VerbSelectionRequest(XSelectionRequestEvent *ev) -{ - printf("owner=0x%x%s", (unsigned)ev->owner, sep); - printf("requestor=0x%x%s", (unsigned)ev->requestor, sep); - printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); - printf("target=%s%s", AtomName(ev->display, ev->target), sep); - printf("property=%s%s", AtomName(ev->display, ev->property), sep); - printf("time=%s\n", ServerTime(ev->time)); +static void +VerbSelectionRequest(XSelectionRequestEvent* ev) { + printf("owner=0x%x%s", (unsigned)ev->owner, sep); + printf("requestor=0x%x%s", (unsigned)ev->requestor, sep); + printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); + printf("target=%s%s", AtomName(ev->display, ev->target), sep); + printf("property=%s%s", AtomName(ev->display, ev->property), sep); + printf("time=%s\n", ServerTime(ev->time)); } -static void VerbVisibility(XVisibilityEvent *ev) -{ - printf("window=0x%x%s", (unsigned)ev->window, sep); - printf("state=%s\n", VisibilityState(ev->state)); +static void +VerbVisibility(XVisibilityEvent* ev) { + printf("window=0x%x%s", (unsigned)ev->window, sep); + printf("state=%s\n", VisibilityState(ev->state)); } /******************************************************************************/ /************ Return the string representation for type of an event ***********/ /******************************************************************************/ -char *GetType(ev) -XEvent *ev; +char* GetType(ev) XEvent* ev; { - 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"); - } - return "???"; + 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"); + } + return "???"; } /******************************************************************************/ /**************** Print the values of all fields for any event ****************/ /******************************************************************************/ -void ShowEvent(XEvent *eev) -{ - XAnyEvent *ev = (XAnyEvent*)eev; - /* determine which field separator to use */ - if (use_separate_lines) - sep = "\n"; - else - sep = " "; +void +ShowEvent(XEvent* eev) { + XAnyEvent* ev = (XAnyEvent*)eev; + /* determine which field separator to use */ + if (use_separate_lines) + sep = "\n"; + else + sep = " "; - printf("type=%s%s", GetType((XEvent*)ev), sep); - printf("serial=%ld%s", ev->serial, sep); - printf("send_event=%s%s", TorF(ev->send_event), sep); - printf("display=0x%p%s", ev->display, sep); + printf("type=%s%s", GetType((XEvent*)ev), sep); + printf("serial=%ld%s", ev->serial, sep); + printf("send_event=%s%s", TorF(ev->send_event), sep); + printf("display=0x%p%s", ev->display, sep); - switch (ev->type) { - case MotionNotify: - VerbMotion((void*)ev); - break; + switch (ev->type) { + case MotionNotify: VerbMotion((void*)ev); break; - case ButtonPress: - case ButtonRelease: - VerbButton((void*)ev); - break; + case ButtonPress: + case ButtonRelease: VerbButton((void*)ev); break; - case ColormapNotify: - VerbColormap((void*)ev); - break; + case ColormapNotify: VerbColormap((void*)ev); break; - case EnterNotify: - case LeaveNotify: - VerbCrossing((void*)ev); - break; + case EnterNotify: + case LeaveNotify: VerbCrossing((void*)ev); break; - case Expose: - VerbExpose((void*)ev); - break; + case Expose: VerbExpose((void*)ev); break; - case GraphicsExpose: - VerbGraphicsExpose((void*)ev); - break; + case GraphicsExpose: VerbGraphicsExpose((void*)ev); break; - case NoExpose: - VerbNoExpose((void*)ev); - break; + case NoExpose: VerbNoExpose((void*)ev); break; - case FocusIn: - case FocusOut: - VerbFocus((void*)ev); - break; + case FocusIn: + case FocusOut: VerbFocus((void*)ev); break; - case KeymapNotify: - VerbKeymap((void*)ev); - break; + case KeymapNotify: VerbKeymap((void*)ev); break; - case KeyPress: - case KeyRelease: - VerbKey((void*)ev); - break; + case KeyPress: + case KeyRelease: VerbKey((void*)ev); break; - case PropertyNotify: - VerbProperty((void*)ev); - break; + case PropertyNotify: VerbProperty((void*)ev); break; - case ResizeRequest: - VerbResizeRequest((void*)ev); - break; + case ResizeRequest: VerbResizeRequest((void*)ev); break; - case CirculateNotify: - VerbCirculate((void*)ev); - break; + case CirculateNotify: VerbCirculate((void*)ev); break; - case ConfigureNotify: - VerbConfigure((void*)ev); - break; + case ConfigureNotify: VerbConfigure((void*)ev); break; - case CreateNotify: - VerbCreateWindow((void*)ev); - break; + case CreateNotify: VerbCreateWindow((void*)ev); break; - case DestroyNotify: - VerbDestroyWindow((void*)ev); - break; + case DestroyNotify: VerbDestroyWindow((void*)ev); break; - case GravityNotify: - VerbGravity((void*)ev); - break; + case GravityNotify: VerbGravity((void*)ev); break; - case MapNotify: - VerbMap((void*)ev); - break; + case MapNotify: VerbMap((void*)ev); break; - case ReparentNotify: - VerbReparent((void*)ev); - break; + case ReparentNotify: VerbReparent((void*)ev); break; - case UnmapNotify: - VerbUnmap((void*)ev); - break; + case UnmapNotify: VerbUnmap((void*)ev); break; - case CirculateRequest: - VerbCirculateRequest((void*)ev); - break; + case CirculateRequest: VerbCirculateRequest((void*)ev); break; - case ConfigureRequest: - VerbConfigureRequest((void*)ev); - break; + case ConfigureRequest: VerbConfigureRequest((void*)ev); break; - case MapRequest: - VerbMapRequest((void*)ev); - break; + case MapRequest: VerbMapRequest((void*)ev); break; - case ClientMessage: - VerbClient((void*)ev); - break; + case ClientMessage: VerbClient((void*)ev); break; - case MappingNotify: - VerbMapping((void*)ev); - break; + case MappingNotify: VerbMapping((void*)ev); break; - case SelectionClear: - VerbSelectionClear((void*)ev); - break; + case SelectionClear: VerbSelectionClear((void*)ev); break; - case SelectionNotify: - VerbSelection((void*)ev); - break; + case SelectionNotify: VerbSelection((void*)ev); break; - case SelectionRequest: - VerbSelectionRequest((void*)ev); - break; + case SelectionRequest: VerbSelectionRequest((void*)ev); break; - case VisibilityNotify: - VerbVisibility((void*)ev); - break; - - } + case VisibilityNotify: VerbVisibility((void*)ev); break; + } } diff --git a/showevent/sample.c b/showevent/sample.c old mode 100755 new mode 100644 index 7b22e97..c4078f1 --- a/showevent/sample.c +++ b/showevent/sample.c @@ -5,44 +5,53 @@ * "Quick-n-Dirty", plain, vanilla, "No ups, No extras" piece of code. */ -main(argc, argv) -int argc; -char **argv; +main(argc, argv) int argc; +char** argv; { - Display *dpy; - int screen; - Window window; - XEvent event; - extern Boolean use_separate_lines; + Display* dpy; + int screen; + Window window; + XEvent event; + extern Boolean use_separate_lines; - if (!(dpy = XOpenDisplay(""))) { - printf("Failed to open display...\n"); - exit(1); - } - screen = DefaultScreen(dpy); + if (!(dpy = XOpenDisplay(""))) { + printf("Failed to open display...\n"); + exit(1); + } + screen = DefaultScreen(dpy); - window = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 100, 100, - 300, 200, 2, BlackPixel(dpy, screen), WhitePixel(dpy, screen)); + window = XCreateSimpleWindow( + dpy, + RootWindow(dpy, screen), + 100, + 100, + 300, + 200, + 2, + BlackPixel(dpy, screen), + WhitePixel(dpy, screen)); - XSelectInput(dpy, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | - ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | - PointerMotionMask | PointerMotionHintMask | Button1MotionMask | - Button2MotionMask | Button3MotionMask | Button4MotionMask | - Button5MotionMask | ButtonMotionMask | KeymapStateMask | - ExposureMask | VisibilityChangeMask | StructureNotifyMask | - SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask | - PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask); + XSelectInput( + dpy, + window, + KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | + EnterWindowMask | LeaveWindowMask | PointerMotionMask | + PointerMotionHintMask | Button1MotionMask | Button2MotionMask | + Button3MotionMask | Button4MotionMask | Button5MotionMask | + ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask | + StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask | + FocusChangeMask | PropertyChangeMask | ColormapChangeMask | + OwnerGrabButtonMask); - XMapWindow(dpy, window); + XMapWindow(dpy, window); - /* set this to false to make ShowEvent take up less vertival space */ - use_separate_lines = True; + /* set this to false to make ShowEvent take up less vertival space */ + use_separate_lines = True; - while (1) { - XNextEvent(dpy, &event); - printf("Detail of %s event:\n", GetType(&event)); - ShowEvent(&event); - printf("\n\n"); - } + while (1) { + XNextEvent(dpy, &event); + printf("Detail of %s event:\n", GetType(&event)); + ShowEvent(&event); + printf("\n\n"); + } } - diff --git a/xevents.c b/xevents.c old mode 100755 new mode 100644 index d42ddba..8d37c37 --- a/xevents.c +++ b/xevents.c @@ -9,37 +9,46 @@ #include "printevent.h" int -main(int argc, char **argv) -{ - int screen; - Display *dpy; - Window window; - XEvent event; - - if (!(dpy = XOpenDisplay(""))) { - printf("Failed to open display...\n"); - exit(1); - } - - screen = DefaultScreen(dpy); +main(int argc, char** argv) { + int screen; + Display* dpy; + Window window; + XEvent event; - window = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 100, 100, - 300, 200, 2, BlackPixel(dpy, screen), WhitePixel(dpy, screen)); + if (!(dpy = XOpenDisplay(""))) { + printf("Failed to open display...\n"); + exit(1); + } - XSelectInput(dpy, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | - ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | - PointerMotionMask | PointerMotionHintMask | Button1MotionMask | - Button2MotionMask | Button3MotionMask | Button4MotionMask | - Button5MotionMask | ButtonMotionMask | KeymapStateMask | - ExposureMask | VisibilityChangeMask | StructureNotifyMask | - SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask | - PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask); + screen = DefaultScreen(dpy); - XMapWindow(dpy, window); + window = XCreateSimpleWindow( + dpy, + RootWindow(dpy, screen), + 100, + 100, + 300, + 200, + 2, + BlackPixel(dpy, screen), + WhitePixel(dpy, screen)); - for(;;){ - XNextEvent(dpy, &event); - printevent(&event); - } + XSelectInput( + dpy, + window, + KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | + EnterWindowMask | LeaveWindowMask | PointerMotionMask | + PointerMotionHintMask | Button1MotionMask | Button2MotionMask | + Button3MotionMask | Button4MotionMask | Button5MotionMask | + ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask | + StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask | + FocusChangeMask | PropertyChangeMask | ColormapChangeMask | + OwnerGrabButtonMask); + + XMapWindow(dpy, window); + + for (;;) { + XNextEvent(dpy, &event); + printevent(&event); + } } - diff --git a/xshove.c b/xshove.c old mode 100755 new mode 100644 index 180eada..27d3c10 --- a/xshove.c +++ b/xshove.c @@ -9,34 +9,32 @@ AUTOLIB(X11); typedef struct Rectangle Rectangle; -struct Rectangle -{ - struct { - int x; - int y; - } min, max; +struct Rectangle { + struct { + int x; + int y; + } min, max; }; #define Dx(r) ((r).max.x - (r).min.x) #define Dy(r) ((r).max.y - (r).min.y) typedef struct Win Win; -struct Win -{ - Window xw; - int x; - int y; - int dx; - int dy; - char *class; - char *instance; - char *name; - char *iconname; +struct Win { + Window xw; + int x; + int y; + int dx; + int dy; + char* class; + char* instance; + char* name; + char* iconname; }; -Display *dpy; +Display* dpy; Window root; -Win *w; +Win* w; int nw; void getinfo(void); @@ -45,274 +43,243 @@ int parsewinsize(char*, Rectangle*, int*, int*, int*); void shove(char*, char*); void -usage(void) -{ - fprint(2, "usage: xshove [window rectangle]\n"); - exits("usage"); +usage(void) { + fprint(2, "usage: xshove [window rectangle]\n"); + exits("usage"); } void -main(int argc, char **argv) -{ - int screen; - - screen = 0; - ARGBEGIN{ - case 's': - screen = atoi(EARGF(usage())); - break; - default: - usage(); - break; - }ARGEND - - dpy = XOpenDisplay(""); - if(dpy == nil) - sysfatal("open display: %r"); +main(int argc, char** argv) { + int screen; - root = RootWindow(dpy, screen); - getinfo(); + screen = 0; + ARGBEGIN { + case 's': screen = atoi(EARGF(usage())); break; + default: usage(); break; + } + ARGEND - if(argc == 0){ - listwindows(); - exits(0); - } - if(argc != 2) - usage(); - shove(argv[0], argv[1]); - exits(0); + dpy = XOpenDisplay(""); + if (dpy == nil) sysfatal("open display: %r"); + + root = RootWindow(dpy, screen); + getinfo(); + + if (argc == 0) { + listwindows(); + exits(0); + } + if (argc != 2) usage(); + shove(argv[0], argv[1]); + exits(0); } char* -getproperty(Window w, Atom a) -{ - uchar *p; - int fmt; - Atom type; - ulong n, dummy; +getproperty(Window w, Atom a) { + uchar* p; + int fmt; + Atom type; + ulong n, dummy; - n = 100; - p = nil; - XGetWindowProperty(dpy, w, a, 0, 100L, 0, - AnyPropertyType, &type, &fmt, - &n, &dummy, &p); - if(p == nil || *p == 0) - return nil; - return strdup((char*)p); + n = 100; + p = nil; + XGetWindowProperty( + dpy, w, a, 0, 100L, 0, AnyPropertyType, &type, &fmt, &n, &dummy, &p); + if (p == nil || *p == 0) return nil; + return strdup((char*)p); } Window -findname(Window w) -{ - int i; - uint nxwin; - Window dw1, dw2, *xwin; +findname(Window w) { + int i; + uint nxwin; + Window dw1, dw2, *xwin; - if(getproperty(w, XA_WM_NAME)) - return w; - if(!XQueryTree(dpy, w, &dw1, &dw2, &xwin, &nxwin)) - return 0; - for(i=0; ixw = xwin[i]; - ww->x = attr.x; - ww->y = attr.y; - ww->dx = attr.width; - ww->dy = attr.height; - XTranslateCoordinates(dpy, ww->xw, root, 0, 0, &ww->x, &ww->y, &dw1); - if(XGetClassHint(dpy, ww->xw, &class)){ - ww->class = strdup(class.res_class); - ww->instance = strdup(class.res_name); - } - ww->iconname = getproperty(ww->xw, XA_WM_ICON_NAME); - ww->name = getproperty(ww->xw, XA_WM_NAME); - ww++; - } - nw = ww - w; -} + if (!XQueryTree(dpy, root, &dw1, &dw2, &xwin, &nxwin)) return; + w = mallocz(nxwin * sizeof w[0], 1); + if (w == 0) sysfatal("malloc: %r"); -void -listwindows(void) -{ - int i; - - for(i=0; ix, ww->y, ww->x+ww->dx, ww->y+ww->dy); - print("%08x %-20s %-10s %s\n", - (uint)ww->xw, - rect, - ww->instance, - ww->class); - } + Win* ww = w; + for (i = 0; i < nxwin; i++) { + memset(&attr, 0, sizeof attr); + xwin[i] = findname(xwin[i]); + if (xwin[i] == 0) continue; + XGetWindowAttributes(dpy, xwin[i], &attr); + if ( + attr.width <= 0 || attr.override_redirect || attr.map_state != IsViewable) + continue; + ww->xw = xwin[i]; + ww->x = attr.x; + ww->y = attr.y; + ww->dx = attr.width; + ww->dy = attr.height; + XTranslateCoordinates(dpy, ww->xw, root, 0, 0, &ww->x, &ww->y, &dw1); + if (XGetClassHint(dpy, ww->xw, &class)) { + ww->class = strdup(class.res_class); + ww->instance = strdup(class.res_name); + } + ww->iconname = getproperty(ww->xw, XA_WM_ICON_NAME); + ww->name = getproperty(ww->xw, XA_WM_NAME); + ww++; + } + nw = ww - w; } void -shove(char *name, char *geom) -{ - int i; - int isdelta, havemin, havesize; - int old, new; - Rectangle r; +listwindows(void) { + int i; - if(parsewinsize(geom, &r, &isdelta, &havemin, &havesize) < 0) - sysfatal("bad window spec: %s", name); + for (i = 0; i < nw; i++) { + Win* ww = &w[i]; + char rect[50]; + snprint( + rect, + sizeof rect, + "%d,%d,%d,%d", + ww->x, + ww->y, + ww->x + ww->dx, + ww->y + ww->dy); + print("%08x %-20s %-10s %s\n", (uint)ww->xw, rect, ww->instance, ww->class); + } +} - old = 0; - new = 1; - if(isdelta){ - old = 1; - new = isdelta; - } - for(i=0; iinstance && strstr(ww->instance, name) - || ww->class && strstr(ww->class, name)){ - int value_mask; - XWindowChanges e; +void +shove(char* name, char* geom) { + int i; + int isdelta, havemin, havesize; + int old, new; + Rectangle r; - memset(&e, 0, sizeof e); - if(havemin){ - e.x = old*ww->x + new*r.min.x; - e.y = old*ww->y + new*r.min.y; - }else{ - e.x = ww->x; - e.y = ww->y; - } - if(havesize){ - e.width = old*ww->dx + new*Dx(r); - e.height = old*ww->dy + new*Dy(r); - }else{ - e.width = ww->dx; - e.height = ww->dy; - } - value_mask = CWX | CWY | CWWidth | CWHeight; - XConfigureWindow(dpy, ww->xw, value_mask, &e); - XFlush(dpy); - } - } + if (parsewinsize(geom, &r, &isdelta, &havemin, &havesize) < 0) + sysfatal("bad window spec: %s", name); + + old = 0; + new = 1; + if (isdelta) { + old = 1; + new = isdelta; + } + for (i = 0; i < nw; i++) { + Win* ww = &w[i]; + if ( + ww->instance && strstr(ww->instance, name) || + ww->class && strstr(ww->class, name)) { + int value_mask; + XWindowChanges e; + + memset(&e, 0, sizeof e); + if (havemin) { + e.x = old * ww->x + new* r.min.x; + e.y = old * ww->y + new* r.min.y; + } else { + e.x = ww->x; + e.y = ww->y; + } + if (havesize) { + e.width = old * ww->dx + new* Dx(r); + e.height = old * ww->dy + new* Dy(r); + } else { + e.width = ww->dx; + e.height = ww->dy; + } + value_mask = CWX | CWY | CWWidth | CWHeight; + XConfigureWindow(dpy, ww->xw, value_mask, &e); + XFlush(dpy); + } + } } int -parsewinsize(char *s, Rectangle *r, int *isdelta, int *havemin, int *havesize) -{ - char c, *os; - int i, j, k, l; +parsewinsize(char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) { + char c, *os; + int i, j, k, l; - os = s; - if(*s == '-'){ - s++; - *isdelta = -1; - }else if(*s == '+'){ - s++; - *isdelta = 1; - }else - *isdelta = 0; - *havemin = 0; - *havesize = 0; - memset(r, 0, sizeof *r); - if(!isdigit((uchar)*s)) - goto oops; - i = strtol(s, &s, 0); - if(*s == 'x'){ - s++; - if(!isdigit((uchar)*s)) - goto oops; - j = strtol(s, &s, 0); - r->max.x = i; - r->max.y = j; - *havesize = 1; - if(*s == 0) - return 0; - if(*s != '@') - goto oops; + os = s; + if (*s == '-') { + s++; + *isdelta = -1; + } else if (*s == '+') { + s++; + *isdelta = 1; + } else + *isdelta = 0; + *havemin = 0; + *havesize = 0; + memset(r, 0, sizeof *r); + if (!isdigit((uchar)*s)) goto oops; + i = strtol(s, &s, 0); + if (*s == 'x') { + s++; + if (!isdigit((uchar)*s)) goto oops; + j = strtol(s, &s, 0); + r->max.x = i; + r->max.y = j; + *havesize = 1; + if (*s == 0) return 0; + if (*s != '@') goto oops; - s++; - if(!isdigit((uchar)*s)) - goto oops; - i = strtol(s, &s, 0); - if(*s != ',' && *s != ' ') - goto oops; - s++; - if(!isdigit((uchar)*s)) - goto oops; - j = strtol(s, &s, 0); - if(*s != 0) - goto oops; - r->min.x += i; - r->max.x += i; - r->min.y += j; - r->max.y += j; - *havesize = 1; - *havemin = 1; - return 0; - } + s++; + if (!isdigit((uchar)*s)) goto oops; + i = strtol(s, &s, 0); + if (*s != ',' && *s != ' ') goto oops; + s++; + if (!isdigit((uchar)*s)) goto oops; + j = strtol(s, &s, 0); + if (*s != 0) goto oops; + r->min.x += i; + r->max.x += i; + r->min.y += j; + r->max.y += j; + *havesize = 1; + *havemin = 1; + return 0; + } - c = *s; - if(c != ' ' && c != ',') - goto oops; - s++; - if(!isdigit((uchar)*s)) - goto oops; - j = strtol(s, &s, 0); - if(*s == 0){ - r->min.x = i; - r->min.y = j; - *havemin = 1; - return 0; - } - if(*s != c) - goto oops; - s++; - if(!isdigit((uchar)*s)) - goto oops; - k = strtol(s, &s, 0); - if(*s != c) - goto oops; - s++; - if(!isdigit((uchar)*s)) - goto oops; - l = strtol(s, &s, 0); - if(*s != 0) - goto oops; - r->min.x = i; - r->min.y = j; - r->max.x = k; - r->max.y = l; - *havemin = 1; - *havesize = 1; - return 0; + c = *s; + if (c != ' ' && c != ',') goto oops; + s++; + if (!isdigit((uchar)*s)) goto oops; + j = strtol(s, &s, 0); + if (*s == 0) { + r->min.x = i; + r->min.y = j; + *havemin = 1; + return 0; + } + if (*s != c) goto oops; + s++; + if (!isdigit((uchar)*s)) goto oops; + k = strtol(s, &s, 0); + if (*s != c) goto oops; + s++; + if (!isdigit((uchar)*s)) goto oops; + l = strtol(s, &s, 0); + if (*s != 0) goto oops; + r->min.x = i; + r->min.y = j; + r->max.x = k; + r->max.y = l; + *havemin = 1; + *havesize = 1; + return 0; oops: - werrstr("bad syntax in window size '%s'", os); - return -1; + werrstr("bad syntax in window size '%s'", os); + return -1; }