From b0fb6654c8d361fe5ca98d486cad7317f6c6f8e3 Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Fri, 26 Feb 2021 14:50:23 -0500 Subject: [PATCH] tweak formatting --- .clang-format | 13 +- client.c | 124 +++++++----- color.c | 3 +- cursor.c | 18 +- error.c | 41 ++-- event.c | 265 ++++++++++++++++--------- grab.c | 189 +++++++++++------- key.c | 205 +++++++++++++++---- main.c | 84 ++++---- manage.c | 161 ++++++++------- menu.c | 185 ++++++++++------- printevent.c | 540 ++++++++++++++++++++++++++++++-------------------- xevents.c | 3 +- xshove.c | 118 +++++++---- 14 files changed, 1214 insertions(+), 735 deletions(-) diff --git a/.clang-format b/.clang-format index 1b47f11..a699815 100644 --- a/.clang-format +++ b/.clang-format @@ -3,11 +3,12 @@ IndentWidth: 2 ContinuationIndentWidth: 2 UseTab: Never AllowShortBlocksOnASingleLine: Always -AllowShortCaseLabelsOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false AllowShortEnumsOnASingleLine: true -AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterDefinitionReturnType: TopLevel +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +PenaltyReturnTypeOnItsOwnLine: 255 IndentCaseLabels: true SpaceBeforeParens: ControlStatements AlignAfterOpenBracket: AlwaysBreak @@ -16,3 +17,7 @@ BinPackArguments: false PointerAlignment: Left BreakBeforeBraces: Attach SortIncludes: false +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AlignEscapedNewlines: Left + diff --git a/client.c b/client.c index a5718a7..378005d 100644 --- a/client.c +++ b/client.c @@ -13,11 +13,11 @@ Client* clients; Client* current; -void -setactive(Client* c, int on) { +void 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); @@ -43,8 +43,7 @@ setactive(Client* c, int on) { draw_border(c, on); } -void -draw_border(Client* c, int active) { +void draw_border(Client* c, int active) { unsigned long pixel; if (active) { @@ -71,35 +70,39 @@ draw_border(Client* c, int active) { XClearWindow(dpy, c->parent); } -void -active(Client* c) { +void active(Client* c) { Client* cc; if (c == 0) { fprintf(stderr, "ryudo: active(c==0)\n"); return; } - if (c == current) 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); + 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; + if (cc->revert == c) + cc->revert = c->revert; c->revert = current; - while (c->revert && !normal(c->revert)) c->revert = c->revert->revert; + while (c->revert && !normal(c->revert)) + c->revert = c->revert->revert; current = c; #ifdef DEBUG - if (debug) dump_revert(); + if (debug) + dump_revert(); #endif } -void -nofocus(void) { +void nofocus(void) { static Window w = 0; int mask; XSetWindowAttributes attr; @@ -138,8 +141,7 @@ nofocus(void) { XSetInputFocus(dpy, w, RevertToPointerRoot, timestamp()); } -void -top(Client* c) { +void top(Client* c) { Client **l, *cc; l = &clients; @@ -155,16 +157,18 @@ top(Client* c) { fprintf(stderr, "rio: %p not on client list in top()\n", (void*)c); } -Client* -getclient(Window w, int create) { +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; + 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)); @@ -188,20 +192,24 @@ getclient(Window w, int create) { return c; } -void -rmclient(Client* c) { +void rmclient(Client* c) { Client* cc; for (cc = current; cc && cc->revert; cc = cc->revert) - if (cc->revert == c) cc->revert = cc->revert->revert; + if (cc->revert == c) + cc->revert = cc->revert->revert; - if (c == clients) clients = c->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 (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) { @@ -209,7 +217,8 @@ rmclient(Client* c) { if (current == 0) nofocus(); else { - if (current->screen != c->screen) cmapnofocus(c->screen); + if (current->screen != c->screen) + cmapnofocus(c->screen); setactive(current, 1); } } @@ -217,33 +226,42 @@ rmclient(Client* c) { 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); + 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 -void -dump_revert(void) { +void 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, " -> "); + 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"); + if (current == 0) + fprintf(stderr, "empty"); fprintf(stderr, "\n"); } -void -dump_clients(void) { +void dump_clients(void) { Client* c; for (c = clients; c; c = c->next) @@ -257,22 +275,25 @@ dump_clients(void) { } #endif -void -shuffle(int up) { +void shuffle(int up) { Client **l, *c; - if (clients == 0 || clients->next == 0) return; + 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; + if (c == 0) + return; XMapRaised(dpy, c->parent); top(c); active(c); @@ -291,13 +312,14 @@ shuffle(int up) { } #ifdef AUTOSTICK -int -isautostick(Client* c) { +int isautostick(Client* c) { static char* autostick[] = AUTOSTICK; char** a = autostick; while (*a) { - if (c && c->class && strstr(c->class, *a)) { return 1; } + if (c && c->class && strstr(c->class, *a)) { + return 1; + } ++a; } return 0; diff --git a/color.c b/color.c index 3d8df29..4d41716 100644 --- a/color.c +++ b/color.c @@ -7,8 +7,7 @@ #include "dat.h" #include "fns.h" -unsigned long -colorpixel( +unsigned long colorpixel( Display* dpy, ScreenInfo* s, int depth, unsigned long rgb, unsigned long def) { int r, g, b; diff --git a/cursor.c b/cursor.c index 0d74cac..393959c 100644 --- a/cursor.c +++ b/cursor.c @@ -147,9 +147,23 @@ ScreenInfo* s; Pixmap f, m; f = XCreatePixmapFromBitmapData( - dpy, s->root, (char*)c->fore, c->width, c->width, 1, 0, 1); + 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); + 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]); } diff --git a/error.c b/error.c index c326242..694f080 100644 --- a/error.c +++ b/error.c @@ -10,16 +10,14 @@ int ignore_badwindow; -void -fatal(char* s) { +void fatal(char* s) { fprintf(stderr, "ryudo: "); perror(s); fprintf(stderr, "\n"); exit(1); } -int -handler(Display* d, XErrorEvent* e) { +int handler(Display* d, XErrorEvent* e) { char msg[80], req[80], number[80]; if ( @@ -40,7 +38,8 @@ handler(Display* d, XErrorEvent* e) { 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); + if (req[0] == '\0') + sprintf(req, "", (int)e->request_code); fprintf(stderr, "ryudo: %s(0x%x): %s\n", req, (int)e->resourceid, msg); @@ -51,18 +50,28 @@ handler(Display* d, XErrorEvent* e) { return 0; } -void -graberror(char* f, int err) { +void 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; + 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 @@ -74,9 +83,9 @@ graberror(char* f, int err) { #ifdef DEBUG -void -dotrace(char* s, Client* c, XEvent* e) { - if (debug == 0) return; +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) diff --git a/event.c b/event.c index 5532a10..593457b 100644 --- a/event.c +++ b/event.c @@ -17,8 +17,7 @@ #include "patchlevel.h" #include "config.h" -void -mainloop(int shape_event) { +void mainloop(int shape_event) { XEvent ev; for (;;) { @@ -38,19 +37,44 @@ mainloop(int shape_event) { #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 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; @@ -60,11 +84,21 @@ mainloop(int shape_event) { 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 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: @@ -79,8 +113,7 @@ mainloop(int shape_event) { } } -void -configurereq(XConfigureRequestEvent* e) { +void configurereq(XConfigureRequestEvent* e) { XWindowChanges wc; Client* c; @@ -91,11 +124,16 @@ configurereq(XConfigureRequestEvent* 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 (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; @@ -144,8 +182,7 @@ configurereq(XConfigureRequestEvent* e) { XConfigureWindow(dpy, c->window, e->value_mask, &wc); } -void -mapreq(XMapRequestEvent* e) { +void mapreq(XMapRequestEvent* e) { Client* c; int i; @@ -160,7 +197,8 @@ mapreq(XMapRequestEvent* e) { "ryudo: bad mapreq c %p w %x, rescanning\n", (void*)c, (int)e->window); - for (i = 0; i < num_screens; i++) scanwins(&screens[i]); + 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"); @@ -171,7 +209,8 @@ mapreq(XMapRequestEvent* e) { switch (c->state) { case WithdrawnState: if (c->parent == c->screen->root) { - if (!manage(c, 0)) return; + if (!manage(c, 0)) + return; break; } XReparentWindow(dpy, c->window, c->parent, BORDER - 1, BORDER - 1); @@ -182,14 +221,16 @@ mapreq(XMapRequestEvent* e) { XMapRaised(dpy, c->parent); top(c); setstate(c, NormalState); - if (c->trans != None && current && c->trans == current->window) active(c); + if (c->trans != None && current && c->trans == current->window) + active(c); + break; + case IconicState: + unhidec(c, 1); break; - case IconicState: unhidec(c, 1); break; } } -void -unmap(XUnmapEvent* e) { +void unmap(XUnmapEvent* e) { Client* c; curtime = CurrentTime; @@ -203,28 +244,29 @@ unmap(XUnmapEvent* e) { } break; case NormalState: - if (c == current) nofocus(); - if (!c->reparenting) withdraw(c); + if (c == current) + nofocus(); + if (!c->reparenting) + withdraw(c); break; } c->reparenting = 0; } } -void -circulatereq(XCirculateRequestEvent* e) { +void circulatereq(XCirculateRequestEvent* e) { fprintf(stderr, "It must be the warlock Krill!\n"); /* ☺ */ } -void -newwindow(XCreateWindowEvent* e) { +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; + if (e->override_redirect) + return; c = getclient(e->window, 1); if (c && c->window == e->window && (s = getscreen(e->parent))) { c->x = e->x; @@ -233,28 +275,34 @@ newwindow(XCreateWindowEvent* e) { c->dy = e->height; c->border = e->border_width; c->screen = s; - if (c->parent == None) c->parent = c->screen->root; + 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); + c, + ra.width / 6, + GAPSZ, + 2 * ra.width / 3, + ra.height - 2 * GAPSZ); kbLaunch = 0; } } -void -destroy(Window w) { +void destroy(Window w) { int i; Client* c; curtime = CurrentTime; c = getclient(w, 0); - if (c == 0) return; + if (c == 0) + return; if (numvirtuals > 1) for (i = 0; i < numvirtuals; i++) - if (currents[i] == c) currents[i] = 0; + if (currents[i] == c) + currents[i] = 0; rmclient(c); @@ -264,8 +312,7 @@ destroy(Window w) { ignore_badwindow = 0; } -void -clientmesg(XClientMessageEvent* e) { +void clientmesg(XClientMessageEvent* e) { Client* c; curtime = CurrentTime; @@ -280,11 +327,13 @@ clientmesg(XClientMessageEvent* e) { perror("ryudo: exec failed"); exit(1); } - if (e->message_type == wm_protocols) return; + 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); + if (normal(c)) + hide(c); } else fprintf( stderr, @@ -314,8 +363,7 @@ clientmesg(XClientMessageEvent* e) { (int)e->window); } -void -cmap(XColormapEvent* e) { +void cmap(XColormapEvent* e) { Client* c; int i; @@ -324,21 +372,22 @@ cmap(XColormapEvent* e) { c = getclient(e->window, 0); if (c) { c->cmap = e->colormap; - if (c == current) cmapfocus(c); + 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); + if (c == current) + cmapfocus(c); return; } } } } -void -property(XPropertyEvent* e) { +void property(XPropertyEvent* e) { Atom a; int delete; Client* c; @@ -348,22 +397,27 @@ property(XPropertyEvent* e) { a = e->atom; delete = (e->state == PropertyDelete); c = getclient(e->window, 0); - if (c == 0) return; + if (c == 0) + return; switch (a) { case XA_WM_ICON_NAME: - if (c->iconname != 0) XFree((char*)c->iconname); + 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); + 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_TRANSIENT_FOR: + gettrans(c); + return; case XA_WM_HINTS: case XA_WM_SIZE_HINTS: case XA_WM_ZOOM_HINTS: @@ -378,21 +432,23 @@ property(XPropertyEvent* e) { } if (a == _rio_hold_mode) { c->hold = getiprop(c->window, _rio_hold_mode); - if (c == current) draw_border(c, 1); + if (c == current) + draw_border(c, 1); } else if (a == wm_colormaps) { getcmaps(c); - if (c == current) cmapfocus(c); + if (c == current) + cmapfocus(c); } } -void -reparent(XReparentEvent* e) { +void reparent(XReparentEvent* e) { Client* c; XWindowAttributes attr; ScreenInfo* s; /* we don't set curtime as nothing here uses it */ - if (!getscreen(e->event) || e->override_redirect) return; + 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)) { @@ -408,58 +464,61 @@ reparent(XReparentEvent* e) { c->dy = attr.height; c->border = attr.border_width; c->screen = s; - if (c->parent == None) c->parent = c->screen->root; + 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); + if (c != 0 && (c->parent == c->screen->root || withdrawn(c))) + rmclient(c); } } #ifdef SHAPE -void -shapenotify(XShapeEvent* e) { +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; + if (c == 0) + return; setshape(c); } #endif -void -enter(XCrossingEvent* e) { +void enter(XCrossingEvent* e) { Client* c; curtime = e->time; if (!ffm) - if (e->mode != NotifyGrab || e->detail != NotifyNonlinearVirtual) return; + 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); + if (!ffm) + XMapRaised(dpy, c->parent); top(c); active(c); } } -void -leave(XCrossingEvent* e) { +void leave(XCrossingEvent* e) { Client* c; c = getclient(e->window, 0); - if (c) XUndefineCursor(dpy, c->parent); + if (c) + XUndefineCursor(dpy, c->parent); /* XDefineCursor(dpy, c->parent, c->screen->arrow); */ } -void -focusin(XFocusChangeEvent* e) { +void focusin(XFocusChangeEvent* e) { Client* c; curtime = CurrentTime; - if (e->detail != NotifyNonlinearVirtual) return; + if (e->detail != NotifyNonlinearVirtual) + return; c = getclient(e->window, 0); if (c != 0 && c->window == e->window && c != current) { #ifdef AUTOSTICK @@ -475,67 +534,77 @@ focusin(XFocusChangeEvent* e) { } } -BorderOrient -borderorient(Client* c, int x, int y) { +BorderOrient borderorient(Client* c, int x, int y) { if (x <= BORDER) { if (y <= CORNER) { - if (debug) fprintf(stderr, "topleft\n"); + if (debug) + fprintf(stderr, "topleft\n"); return BorderWNW; } if (y >= (c->dy + 2 * BORDER) - CORNER) { - if (debug) fprintf(stderr, "botleft\n"); + if (debug) + fprintf(stderr, "botleft\n"); return BorderWSW; } if (y > CORNER && y < (c->dy + 2 * BORDER) - CORNER) { - if (debug) fprintf(stderr, "left\n"); + if (debug) + fprintf(stderr, "left\n"); return BorderW; } } else if (x <= CORNER) { if (y <= BORDER) { - if (debug) fprintf(stderr, "topleft\n"); + if (debug) + fprintf(stderr, "topleft\n"); return BorderNNW; } if (y >= (c->dy + BORDER)) { - if (debug) fprintf(stderr, "botleft\n"); + if (debug) + fprintf(stderr, "botleft\n"); return BorderSSW; } } else if (x >= (c->dx + BORDER)) { if (y <= CORNER) { - if (debug) fprintf(stderr, "topright\n"); + if (debug) + fprintf(stderr, "topright\n"); return BorderENE; } if (y >= (c->dy + 2 * BORDER) - CORNER) { - if (debug) fprintf(stderr, "botright\n"); + if (debug) + fprintf(stderr, "botright\n"); return BorderESE; } if (y > CORNER && y < (c->dy + 2 * BORDER) - CORNER) { - if (debug) fprintf(stderr, "right\n"); + 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"); + if (debug) + fprintf(stderr, "topright\n"); return BorderNNE; } if (y >= (c->dy + BORDER)) { - if (debug) fprintf(stderr, "botright\n"); + 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"); + if (debug) + fprintf(stderr, "top\n"); return BorderN; } if (y >= (c->dy + BORDER)) { - if (debug) fprintf(stderr, "bot\n"); + if (debug) + fprintf(stderr, "bot\n"); return BorderS; } } return BorderUnknown; } -void -motionnotify(XMotionEvent* e) { +void motionnotify(XMotionEvent* e) { Client* c; BorderOrient bl; diff --git a/grab.c b/grab.c index e5f12d3..ad16a9d 100644 --- a/grab.c +++ b/grab.c @@ -7,8 +7,7 @@ #include "dat.h" #include "fns.h" -int -nobuttons(XButtonEvent* e) /* Einstuerzende */ +int nobuttons(XButtonEvent* e) /* Einstuerzende */ { int state; @@ -16,33 +15,41 @@ nobuttons(XButtonEvent* e) /* Einstuerzende */ return (e->type == ButtonRelease) && (state & (state - 1)) == 0; } -int -grab(Window w, Window constrain, int mask, Cursor curs, int t) { +int grab(Window w, Window constrain, int mask, Cursor curs, int t) { int status; - if (t == 0) t = timestamp(); + if (t == 0) + t = timestamp(); status = XGrabPointer( - dpy, w, False, mask, GrabModeAsync, GrabModeAsync, constrain, curs, t); + dpy, + w, + False, + mask, + GrabModeAsync, + GrabModeAsync, + constrain, + curs, + t); return status; } -void -ungrab(XButtonEvent* e) { +void ungrab(XButtonEvent* e) { XEvent ev; if (!nobuttons(e)) for (;;) { XMaskEvent(dpy, ButtonMask | ButtonMotionMask, &ev); - if (ev.type == MotionNotify) continue; + if (ev.type == MotionNotify) + continue; e = &ev.xbutton; - if (nobuttons(e)) break; + if (nobuttons(e)) + break; } XUngrabPointer(dpy, e->time); curtime = e->time; } -static void -drawstring( +static void drawstring( Display* dpy, ScreenInfo* s, Menu* m, int wide, int high, int i, int selected) { int tx, ty; @@ -67,14 +74,14 @@ drawstring( strlen(m->item[i])); } -int -menuhit(XButtonEvent* e, Menu* m) { +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; - if (font == 0) return -1; + if (font == 0) + return -1; s = getscreen(e->root); if (s == 0 || e->window == s->menuwin) /* ugly event mangling */ return -1; @@ -82,11 +89,13 @@ menuhit(XButtonEvent* e, Menu* m) { 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; + if (wide > dx) + dx = wide; } wide = dx; cur = m->lasthit; - if (cur >= n) cur = n - 1; + if (cur >= n) + cur = n - 1; high = font->ascent + font->descent + 1; dy = n * high; @@ -115,7 +124,8 @@ menuhit(XButtonEvent* e, Menu* m) { y = ymax - dy; warp++; } - if (warp) setmouse(e->x, e->y, s); + 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); @@ -132,9 +142,11 @@ menuhit(XButtonEvent* e, Menu* m) { default: fprintf(stderr, "ryudo: menuhit: unknown ev.type %d\n", ev.type); break; - case ButtonPress: break; + case ButtonPress: + break; case ButtonRelease: - if (ev.xbutton.button != e->button) break; + if (ev.xbutton.button != e->button) + break; x = ev.xbutton.x; y = ev.xbutton.y; i = y / high; @@ -146,12 +158,14 @@ menuhit(XButtonEvent* e, Menu* m) { i = -1; else m->lasthit = i; - if (!nobuttons(&ev.xbutton)) i = -1; + if (!nobuttons(&ev.xbutton)) + i = -1; ungrab(&ev.xbutton); XUnmapWindow(dpy, s->menuwin); return i; case MotionNotify: - if (!drawn) break; + if (!drawn) + break; x = ev.xbutton.x; y = ev.xbutton.y; old = cur; @@ -162,20 +176,23 @@ menuhit(XButtonEvent* e, Menu* m) { 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); + 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); + 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) { +Client* selectwin(int release, int* shift, ScreenInfo* s) { XEvent ev; XButtonEvent* e; int status; @@ -200,22 +217,25 @@ selectwin(int release, int* shift, ScreenInfo* s) { w = e->subwindow; if (!release) { c = getclient(w, 0); - if (c == 0) ungrab(e); - if (shift != 0) *shift = (e->state & ShiftMask) != 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; + 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 sweepcalc(Client* c, int x, int y, BorderOrient bl, int ignored) { int dx, dy, sx, sy; dx = x - c->x; @@ -236,8 +256,10 @@ sweepcalc(Client* c, int x, int y, BorderOrient bl, int ignored) { 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 (dx < c->min_dx) + dx = c->min_dx; + if (dy < c->min_dy) + dy = c->min_dy; } if (c->size.flags & PResizeInc) { @@ -246,8 +268,10 @@ sweepcalc(Client* c, int x, int y, BorderOrient bl, int ignored) { } 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 (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); @@ -255,16 +279,14 @@ sweepcalc(Client* c, int x, int y, BorderOrient bl, int ignored) { return ignored; } -int -dragcalc(Client* c, int x, int y, BorderOrient bl, int ignored) { +int dragcalc(Client* c, int x, int y, BorderOrient bl, int ignored) { c->x += x; c->y += y; return ignored; } -int -pullcalc(Client* c, int x, int y, BorderOrient bl, int init) { +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; px = c->x; @@ -333,17 +355,22 @@ pullcalc(Client* c, int x, int y, BorderOrient bl, int init) { xoff = x - c->x; yoff = (c->y + c->dy) - y; break; - default: break; + default: + break; } switch (bl) { case BorderNNW: case BorderNNE: case BorderSSW: - case BorderSSE: xcorn = 1; break; + case BorderSSE: + xcorn = 1; + break; case BorderWNW: case BorderENE: case BorderWSW: - case BorderESE: ycorn = 1; break; + case BorderESE: + ycorn = 1; + break; } if ( !init || xoff < 0 || (xcorn && xoff > CORNER) || @@ -391,8 +418,10 @@ pullcalc(Client* c, int x, int y, BorderOrient bl, int init) { 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 (dx < c->min_dx) + dx = c->min_dx; + if (dy < c->min_dy) + dy = c->min_dy; } if (c->size.flags & PResizeInc) { @@ -401,8 +430,10 @@ pullcalc(Client* c, int x, int y, BorderOrient bl, int init) { } 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 (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 */ @@ -412,14 +443,15 @@ pullcalc(Client* c, int x, int y, BorderOrient bl, int init) { 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; + if (spx) + c->x -= c->dx - rdx; + if (spy) + c->y -= c->dy - rdy; return init; } -static void -xcopy( +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) @@ -428,14 +460,19 @@ xcopy( XCopyArea(dpy, dst, src, gc, x1, y1, dx, dy, x, y); } -void -drawbound(Client* c, int drawing) { +void 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); + stderr, + "drawbound %d %dx%d+%d+%d\n", + drawing, + c->dx, + c->dy, + c->x, + c->y); s = c->screen; x = c->x; @@ -450,7 +487,8 @@ drawbound(Client* c, int drawing) { y += dy; dy = -dy; } - if (dx <= 2 || dy <= 2) return; + if (dx <= 2 || dy <= 2) + return; if (solidsweep) { if (drawing == -1) { @@ -471,7 +509,8 @@ drawbound(Client* c, int drawing) { 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( @@ -508,8 +547,7 @@ drawbound(Client* c, int drawing) { } } -void -misleep(int msec) { +void misleep(int msec) { struct timeval t; t.tv_sec = msec / 1000; @@ -517,8 +555,7 @@ misleep(int msec) { select(0, 0, 0, 0, &t); } -int -sweepdrag( +int sweepdrag( Client* c, int but, XButtonEvent* e0, BorderOrient bl, int (*recalc)(Client*, int, int, BorderOrient, int)) { XEvent ev; @@ -542,7 +579,9 @@ sweepdrag( else getmouse(&c->x, &c->y, c->screen); XGrabServer(dpy); - if (bl != BorderUnknown) { notmoved = recalc(c, cx, cy, bl, notmoved); } + if (bl != BorderUnknown) { + notmoved = recalc(c, cx, cy, bl, notmoved); + } drawbound(c, 1); idle = 0; for (;;) { @@ -576,7 +615,8 @@ sweepdrag( drawbound(c, 0); ungrab(e); XUngrabServer(dpy); - if (e->button != but && c->init) goto bad; + if (e->button != but && c->init) + goto bad; if (c->dx < 0) { c->x += c->dx; c->dx = -c->dx; @@ -595,7 +635,8 @@ sweepdrag( } } bad: - if (debug) fprintf(stderr, "sweepdrag bad\n"); + if (debug) + fprintf(stderr, "sweepdrag bad\n"); c->x = ox; c->y = oy; c->dx = odx; @@ -604,8 +645,7 @@ bad: return 0; } -int -sweep(Client* c, int but, XButtonEvent* ignored) { +int sweep(Client* c, int but, XButtonEvent* ignored) { XEvent ev; int status; XButtonEvent* e; @@ -630,8 +670,7 @@ sweep(Client* c, int but, XButtonEvent* ignored) { return sweepdrag(c, but, e, BorderUnknown, sweepcalc); } -int -pull(Client* c, int but, XButtonEvent* e) { +int pull(Client* c, int but, XButtonEvent* e) { int status; ScreenInfo* s; BorderOrient bl; @@ -649,8 +688,7 @@ pull(Client* c, int but, XButtonEvent* e) { return sweepdrag(c, but, 0, bl, pullcalc); } -int -drag(Client* c, int but) { +int drag(Client* c, int but) { int status; ScreenInfo* s; @@ -663,17 +701,16 @@ drag(Client* c, int but) { return sweepdrag(c, but, 0, BorderUnknown, dragcalc); } -void -getmouse(int* x, int* y, ScreenInfo* s) { +void 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); + if (debug) + fprintf(stderr, "getmouse: %d %d\n", *x, *y); } -void -setmouse(int x, int y, ScreenInfo* s) { +void 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 index 4fa22e0..43dda62 100644 --- a/key.c +++ b/key.c @@ -27,8 +27,7 @@ enum { GrabAltTab, GrabAltAny }; static void alttab(int shift); -void -keysetup(void) { +void keysetup(void) { int i; int tabcode = XKeysymToKeycode(dpy, XK_Tab); int dcode = XKeysymToKeycode(dpy, DESTROY_KEY); @@ -57,39 +56,141 @@ keysetup(void) { for (i = 0; i < num_screens; i++) { XGrabKey( - dpy, tabcode, Mod1Mask, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + tabcode, + Mod1Mask, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, dcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + dcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, icode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + icode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, ucode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + ucode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, rcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + rcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, vcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + vcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, mcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + mcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, scode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + scode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, hcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + hcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, lcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + lcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, jcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + jcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, kcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + kcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, qcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + qcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, wcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + wcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, ocode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + ocode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, pcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + pcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, ccode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + ccode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( dpy, leftcode, @@ -124,9 +225,21 @@ keysetup(void) { GrabModeAsync); #ifdef DEVEL XGrabKey( - dpy, tcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + tcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( - dpy, bcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + dpy, + bcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); #endif /* XGrabKey(dpy, pgupcode, Mod1Mask, screens[i].root, 0, GrabModeSync, * GrabModeAsync); */ @@ -137,8 +250,7 @@ keysetup(void) { } } -void -keypress(XKeyEvent* e) { +void keypress(XKeyEvent* e) { /* * process key press here */ @@ -185,14 +297,22 @@ keypress(XKeyEvent* e) { 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); + 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); + current, + GAPSZ, + GAPSZ, + ra.width / 2 - 1.5 * GAPSZ, + ra.height - 2 * GAPSZ); else if (e->keycode == lcode && (e->state & SHORTCUTMOD) == (MODBITS)) quickreshape( current, @@ -209,7 +329,11 @@ keypress(XKeyEvent* e) { 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); + current, + GAPSZ, + GAPSZ, + ra.width - 2 * GAPSZ, + ra.height / 2 - 1.5 * GAPSZ); /* quarter snap */ else if (e->keycode == qcode && (e->state & SHORTCUTMOD) == (MODBITS)) @@ -259,7 +383,8 @@ keypress(XKeyEvent* e) { kbLaunch = 1; if (fork() == 0) { close(ConnectionNumber(dpy)); - if (dpy != '\0') putenv(dpy); + if (dpy != '\0') + putenv(dpy); signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); signal(SIGHUP, SIG_DFL); @@ -293,14 +418,11 @@ keypress(XKeyEvent* e) { XAllowEvents(dpy, SyncKeyboard, e->time); } -void -keyrelease(XKeyEvent* e) { - XAllowEvents(dpy, SyncKeyboard, e->time); -} +void keyrelease(XKeyEvent* e) { XAllowEvents(dpy, SyncKeyboard, e->time); } -void -quickreshape(Client* c, int x, int y, int dx, int dy) { - if (c == 0) return; +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; @@ -310,8 +432,7 @@ quickreshape(Client* c, int x, int y, int dx, int dy) { sendconfig(c); } -void -centercurrent(XWindowAttributes ra) { +void centercurrent(XWindowAttributes ra) { static int centeroffsetnum = CENTERNUM % 2 == 0 ? CENTERDEN - CENTERNUM : (CENTERDEN - CENTERNUM) / 2; @@ -334,23 +455,23 @@ centercurrent(XWindowAttributes ra) { #endif } -static void -alttab(int shift) { +static void alttab(int shift) { shuffle(shift); /* fprintf(stderr, "%sTab\n", shift ? "Back" : ""); */ } #ifdef DEVEL -void -stickystack(int toTop) { +void stickystack(int toTop) { Client* c; if (toTop) { for (c = clients; c->next; c = c->next) { - if (c && isautostick(c)) top(c); + if (c && isautostick(c)) + top(c); } } else { for (c = clients; c->next; c = c->next) { - if (c && !isautostick(c)) top(c); + if (c && !isautostick(c)) + top(c); } } } diff --git a/main.c b/main.c index da922c9..5cf0ae5 100644 --- a/main.c +++ b/main.c @@ -60,8 +60,7 @@ Atom wm_state; char* fontlist[] = FONTLIST; -void -usage(void) { +void usage(void) { fprintf( stderr, "usage: ryudo [-ffm] [-font fname] [-s] [-term prog] [-version] [-virtuals " @@ -69,8 +68,7 @@ usage(void) { exit(1); } -int -main(int argc, char* argv[]) { +int main(int argc, char* argv[]) { int i, do_exit, do_restart; char* fname; int shape_event; @@ -102,12 +100,14 @@ main(int argc, char* argv[]) { numvirtuals = atoi(argv[++i]); if (numvirtuals < 0 || numvirtuals > 12) { fprintf( - stderr, "ryudo: wrong number of virtual displays, defaulting to 4\n"); + 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); + if (PATCHLEVEL > 0) + fprintf(stderr, "; patch level %d", PATCHLEVEL); fprintf(stderr, "\n"); exit(0); } else if (strcmp(argv[i], "-s") == 0) { @@ -124,19 +124,25 @@ main(int argc, char* argv[]) { else usage(); - if (do_exit && do_restart) usage(); + if (do_exit && do_restart) + usage(); shell = (char*)getenv("SHELL"); - if (shell == NULL) shell = DEFSHELL; + if (shell == NULL) + shell = DEFSHELL; dpy = XOpenDisplay(""); - if (dpy == 0) fatal("can't open display"); + 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); + 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); @@ -153,7 +159,8 @@ main(int argc, char* argv[]) { 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); @@ -180,7 +187,8 @@ main(int argc, char* argv[]) { break; } font = XLoadQueryFont(dpy, fname); - if (font != 0) break; + if (font != 0) + break; } } if (nostalgia) { @@ -195,7 +203,8 @@ main(int argc, char* argv[]) { 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); @@ -208,15 +217,15 @@ main(int argc, char* argv[]) { 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; } -void -initscreen(ScreenInfo* s, int i, int background) { +void initscreen(ScreenInfo* s, int i, int background) { char *ds, *colon, *dot1; unsigned long mask; unsigned long gmask; @@ -271,9 +280,10 @@ initscreen(ScreenInfo* s, int i, int background) { 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 */ + 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'; @@ -374,18 +384,17 @@ initscreen(ScreenInfo* s, int i, int background) { &attrs); } -ScreenInfo* -getscreen(Window w) { +ScreenInfo* getscreen(Window w) { int i; for (i = 0; i < num_screens; i++) - if (screens[i].root == w) return &screens[i]; + if (screens[i].root == w) + return &screens[i]; return 0; } -Time -timestamp(void) { +Time timestamp(void) { XEvent ev; if (curtime == CurrentTime) { @@ -404,8 +413,7 @@ timestamp(void) { return curtime; } -void -sendcmessage(Window w, Atom a, long x, int isroot, int usemask) { +void sendcmessage(Window w, Atom a, long x, int isroot, int usemask) { XEvent ev; int status; long mask; @@ -426,11 +434,11 @@ sendcmessage(Window w, Atom a, long x, int isroot, int usemask) { 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"); + if (status == 0) + fprintf(stderr, "ryudo: sendcmessage failed\n"); } -void -sendconfig(Client* c) { +void sendconfig(Client* c) { XConfigureEvent ce; ce.type = ConfigureNotify; @@ -446,13 +454,9 @@ sendconfig(Client* c) { XSendEvent(dpy, c->window, False, StructureNotifyMask, (XEvent*)&ce); } -void -sighandler(void) { - signalled = 1; -} +void sighandler(void) { signalled = 1; } -void -getevent(XEvent* e) { +void getevent(XEvent* e) { int fd; fd_set rfds; struct timeval t; @@ -486,8 +490,7 @@ getevent(XEvent* e) { exit(1); } -void -cleanup(void) { +void cleanup(void) { Client *c, *cc[2], *next; XWindowChanges wc; int i; @@ -512,6 +515,7 @@ cleanup(void) { } XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, timestamp()); - for (i = 0; i < num_screens; i++) cmapnofocus(&screens[i]); + for (i = 0; i < num_screens; i++) + cmapnofocus(&screens[i]); XCloseDisplay(dpy); } diff --git a/manage.c b/manage.c index fa55da5..d710adb 100644 --- a/manage.c +++ b/manage.c @@ -22,8 +22,7 @@ int isNew; -int -manage(Client* c, int mapped) { +int manage(Client* c, int mapped) { int fixsize, dohide, doreshape, state; long msize; XClassHint class; @@ -71,7 +70,8 @@ manage(Client* c, int mapped) { getcmaps(c); getproto(c); gettrans(c); - if (c->is9term) c->hold = getiprop(c->window, _rio_hold_mode); + if (c->is9term) + c->hold = getiprop(c->window, _rio_hold_mode); /* Figure out what to do with the window from hints */ @@ -80,7 +80,8 @@ manage(Client* c, int mapped) { dohide = (state == IconicState); fixsize = 0; - if ((c->size.flags & (USSize | PSize))) fixsize = 1; + if ((c->size.flags & (USSize | PSize))) + fixsize = 1; if ( (c->size.flags & (PMinSize | PMaxSize)) == (PMinSize | PMaxSize) && c->size.min_width == c->size.max_width && @@ -88,11 +89,15 @@ manage(Client* c, int mapped) { 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->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->is9term) + fixsize = 0; if (c->size.flags & PBaseSize) { c->min_dx = c->size.base_width; c->min_dy = c->size.base_height; @@ -105,7 +110,8 @@ manage(Client* c, int mapped) { } else c->min_dx = c->min_dy = 0; - if (hints) XFree(hints); + if (hints) + XFree(hints); /* Now do it!!! */ @@ -123,7 +129,8 @@ manage(Client* c, int mapped) { c->min_dy, c->dx, c->dy); - if (current && current->screen == c->screen) cmapnofocus(c->screen); + if (current && current->screen == c->screen) + cmapnofocus(c->screen); if (!c->is9term && c->x == 0 && c->y == 0) { static int nwin; @@ -136,7 +143,8 @@ manage(Client* c, int mapped) { if (c->is9term && !(fixsize ? drag(c, Button3) : sweep(c, Button3))) { XKillClient(dpy, c->window); rmclient(c); - if (current && current->screen == c->screen) cmapfocus(current); + if (current && current->screen == c->screen) + cmapfocus(current); return 0; } } @@ -163,8 +171,10 @@ manage(Client* c, int mapped) { c->parent, SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask | PointerMotionMask | LeaveWindowMask | KeyPressMask); - if (mapped) c->reparenting = 1; - if (doreshape && !fixsize) XResizeWindow(dpy, c->window, c->dx, c->dy); + if (mapped) + c->reparenting = 1; + if (doreshape && !fixsize) + XResizeWindow(dpy, c->window, c->dx, c->dy); XSetWindowBorderWidth(dpy, c->window, 0); /* @@ -175,7 +185,9 @@ manage(Client* c, int mapped) { * (black (or white) border around black (or white) window * is not very helpful. */ - if (c->screen->depth <= 8) { XSetWindowBorderWidth(dpy, c->parent, 1); } + if (c->screen->depth <= 8) { + XSetWindowBorderWidth(dpy, c->parent, 1); + } XReparentWindow(dpy, c->window, c->parent, BORDER, BORDER); #ifdef SHAPE @@ -203,7 +215,8 @@ manage(Client* c, int mapped) { setactive(c, 0); setstate(c, NormalState); } - if (current && (current != c)) cmapfocus(current); + if (current && (current != c)) + cmapfocus(current); c->init = 1; /* If the window is out of bounds of the screen, try to wrangle it */ @@ -212,10 +225,18 @@ manage(Client* c, int mapped) { 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); + 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); + 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 { @@ -250,12 +271,12 @@ manage(Client* c, int mapped) { * 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); + if (c->is9term) + sendconfig(c); return 1; } -void -scanwins(ScreenInfo* s) { +void scanwins(ScreenInfo* s) { unsigned int i, nwins; Client* c; Window dw1, dw2, *wins; @@ -264,7 +285,8 @@ scanwins(ScreenInfo* s) { 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; + 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; @@ -274,14 +296,14 @@ scanwins(ScreenInfo* s) { c->border = attr.border_width; c->screen = s; c->parent = s->root; - if (attr.map_state == IsViewable) manage(c, 1); + if (attr.map_state == IsViewable) + manage(c, 1); } } XFree((void*)wins); /* cast is to shut stoopid compiler up */ } -void -gettrans(Client* c) { +void gettrans(Client* c) { Window trans; trans = None; @@ -291,8 +313,7 @@ gettrans(Client* c) { c->trans = None; } -void -withdraw(Client* c) { +void withdraw(Client* c) { XUnmapWindow(dpy, c->parent); XReparentWindow(dpy, c->window, c->screen->root, c->x, c->y); XRemoveFromSaveSet(dpy, c->window); @@ -304,16 +325,14 @@ withdraw(Client* c) { ignore_badwindow = 0; } -static void -installcmap(ScreenInfo* s, Colormap cmap) { +static void installcmap(ScreenInfo* s, Colormap cmap) { if (cmap == None) XInstallColormap(dpy, s->def_cmap); else XInstallColormap(dpy, cmap); } -void -cmapfocus(Client* c) { +void cmapfocus(Client* c) { int i, found; Client* cc; @@ -323,9 +342,11 @@ cmapfocus(Client* c) { found = 0; for (i = c->ncmapwins - 1; i >= 0; i--) { installcmap(c->screen, c->wmcmaps[i]); - if (c->cmapwins[i] == c->window) found++; + if (c->cmapwins[i] == c->window) + found++; } - if (!found) installcmap(c->screen, c->cmap); + if (!found) + installcmap(c->screen, c->cmap); } else if ( c->trans != None && (cc = getclient(c->trans, 0)) != 0 && cc->ncmapwins != 0) @@ -334,13 +355,9 @@ cmapfocus(Client* c) { installcmap(c->screen, c->cmap); } -void -cmapnofocus(ScreenInfo* s) { - installcmap(s, None); -} +void cmapnofocus(ScreenInfo* s) { installcmap(s, None); } -void -getcmaps(Client* c) { +void getcmaps(Client* c) { int n, i; Window* cw; XWindowAttributes attr; @@ -382,8 +399,7 @@ getcmaps(Client* c) { } } -void -setlabel(Client* c) { +void setlabel(Client* c) { char *label, *p, *lc; int i; @@ -397,7 +413,8 @@ setlabel(Client* c) { label = c->class; else label = "no label"; - if ((p = index(label, ':')) != 0) *p = '\0'; + if ((p = index(label, ':')) != 0) + *p = '\0'; for (i = 0, lc = label; *lc != '\0'; lc++, i++) { if (i >= 23) { label[22] = '~'; @@ -409,8 +426,7 @@ setlabel(Client* c) { } #ifdef SHAPE -void -setshape(Client* c) { +void setshape(Client* c) { int n, order; XRectangle* rect; @@ -430,51 +446,56 @@ setshape(Client* c) { } #endif -int -_getprop(Window w, Atom a, Atom type, long len, unsigned char** p) { +int _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); + 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) { +char* getprop(Window w, Atom a) { unsigned char* p; - if (_getprop(w, a, XA_STRING, 100L, &p) <= 0) return 0; + if (_getprop(w, a, XA_STRING, 100L, &p) <= 0) + return 0; return (char*)p; } -int -get1prop(Window w, Atom a, Atom type) { +int get1prop(Window w, Atom a, Atom type) { char **p, *x; - if (_getprop(w, a, type, 1L, (void*)&p) <= 0) return 0; + 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); -} +Window getwprop(Window w, Atom a) { return get1prop(w, a, XA_WINDOW); } -int -getiprop(Window w, Atom a) { - return get1prop(w, a, XA_INTEGER); -} +int getiprop(Window w, Atom a) { return get1prop(w, a, XA_INTEGER); } -void -setstate(Client* c, int state) { +void setstate(Client* c, int state) { long data[2]; data[0] = (long)state; @@ -492,19 +513,18 @@ setstate(Client* c, int state) { 2); } -int -getstate(Window w, int* state) { +int 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; } -void -getproto(Client* c) { +void getproto(Client* c) { Atom* p; int i; long n; @@ -512,7 +532,8 @@ getproto(Client* c) { w = c->window; c->proto = 0; - if ((n = _getprop(w, wm_protocols, XA_ATOM, 20L, (void*)&p)) <= 0) return; + if ((n = _getprop(w, wm_protocols, XA_ATOM, 20L, (void*)&p)) <= 0) + return; for (i = 0; i < n; i++) if (p[i] == wm_delete) diff --git a/menu.c b/menu.c index e7ef58f..9dd279c 100644 --- a/menu.c +++ b/menu.c @@ -72,8 +72,7 @@ Menu b3menu = {b3items}; Menu egg = {version}; -void -button(XButtonEvent* e) { +void button(XButtonEvent* e) { int n, shift; Client* c; Window dw; @@ -81,7 +80,8 @@ button(XButtonEvent* e) { curtime = e->time; s = getscreen(e->root); - if (s == 0) return; + if (s == 0) + return; c = getclient(e->window, 0); if (c) { if (debug) @@ -98,23 +98,37 @@ button(XButtonEvent* e) { 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; + 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); + 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); + 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); + if (ffm) + XRaiseWindow(dpy, c->window); XMapRaised(dpy, c->parent); top(c); active(c); @@ -131,42 +145,60 @@ button(XButtonEvent* e) { } else if (numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1) button2(n); return; - case Button3: break; + 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); + 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); + if (numvirtuals > 1 && virt < numvirtuals - 1) + switch_to(virt + 1); + return; + default: return; - default: return; } - if (current && current->screen == s) cmapnofocus(s); + 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 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; + 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; + default: /* unhide window */ + unhide(n - B3FIXED, 1); + break; + case -1: /* nothing */ + break; } - if (current && current->screen == s) cmapfocus(current); + if (current && current->screen == s) + cmapfocus(current); } -void -spawn(ScreenInfo* s) { +void spawn(ScreenInfo* s) { /* * ugly dance to cause sweeping for terminals. * the very next window created will require sweeping. @@ -181,7 +213,8 @@ spawn(ScreenInfo* s) { if (fork() == 0) { if (fork() == 0) { close(ConnectionNumber(dpy)); - if (s->display[0] != '\0') putenv(s->display); + if (s->display[0] != '\0') + putenv(s->display); signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); signal(SIGHUP, SIG_DFL); @@ -201,15 +234,16 @@ spawn(ScreenInfo* s) { wait((int*)0); } -void -reshape( +void reshape( Client* c, int but, int (*fn)(Client*, int, XButtonEvent*), XButtonEvent* e) { int odx, ody; - if (c == 0) return; + if (c == 0) + return; odx = c->dx; ody = c->dy; - if (fn(c, but, e) == 0) return; + if (fn(c, but, e) == 0) + return; active(c); top(c); XRaiseWindow(dpy, c->parent); @@ -226,10 +260,11 @@ reshape( 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; +void move(Client* c, int but) { + if (c == 0) + return; + if (drag(c, but) == 0) + return; active(c); top(c); XRaiseWindow(dpy, c->parent); @@ -238,16 +273,17 @@ move(Client* c, int but) { } void delete (Client* c, int shift) { - if (c == 0) return; + 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 -hide(Client* c) { - if (c == 0 || numhidden == MAXHIDDEN) return; +void hide(Client* c) { + if (c == 0 || numhidden == MAXHIDDEN) + return; if (hidden(c)) { fprintf(stderr, "ryudo: already hidden: %s\n", c->label); return; @@ -255,11 +291,14 @@ hide(Client* c) { XUnmapWindow(dpy, c->parent); XUnmapWindow(dpy, c->window); setstate(c, IconicState); - if (c == current) nofocus(); + if (c == current) + nofocus(); if (reversehide) { memmove(hiddenc + 1, hiddenc, numhidden * sizeof hiddenc[0]); memmove( - b3items + B3FIXED + 1, b3items + B3FIXED, numhidden * sizeof b3items[0]); + b3items + B3FIXED + 1, + b3items + B3FIXED, + numhidden * sizeof b3items[0]); hiddenc[0] = c; b3items[B3FIXED] = c->label; } else { @@ -270,8 +309,7 @@ hide(Client* c) { b3items[B3FIXED + numhidden] = 0; } -void -unhide(int n, int map) { +void unhide(int n, int map) { Client* c; int i; @@ -306,8 +344,7 @@ unhide(int n, int map) { b3items[B3FIXED + numhidden] = 0; } -void -unhidec(Client* c, int map) { +void unhidec(Client* c, int map) { int i; for (i = 0; i < numhidden; i++) @@ -316,24 +353,27 @@ unhidec(Client* c, int map) { return; } fprintf( - stderr, "ryudo: unhidec: not hidden: %s(0x%x)\n", c->label, (int)c->window); + stderr, + "ryudo: unhidec: not hidden: %s(0x%x)\n", + c->label, + (int)c->window); } -void -stick(Client* c) { +void stick(Client* c) { if (numvirtuals > 1 && c->virt >= 0) c->virt = -1; else c->virt = virt; } -void -renamec(Client* c, char* name) { +void renamec(Client* c, char* name) { int i; - if (name == 0) name = "???"; + if (name == 0) + name = "???"; c->label = name; - if (!hidden(c)) return; + if (!hidden(c)) + return; for (i = 0; i < numhidden; i++) if (c == hiddenc[i]) { b3items[B3FIXED + i] = name; @@ -341,50 +381,57 @@ renamec(Client* c, char* name) { } } -void -button2(int n) { +void button2(int n) { switch_to(n); - if (current) cmapfocus(current); + if (current) + cmapfocus(current); } -void -switch_to_c(int n, Client* c) { - if (c == 0) return; +void 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(); + 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 (c == hiddenc[i]) + break; if (i == numhidden) { XMapWindow(dpy, c->window); XMapWindow(dpy, c->parent); setstate(c, NormalState); - if (currents[virt] == c) active(c); + if (currents[virt] == c) + active(c); } } } -void -switch_to(int n) { +void switch_to(int n) { #ifdef VIRTNOTIFY static char virtmsg[32]; #endif - if (n == virt) return; + if (n == virt) + return; currents[virt] = current; virt = n; @@ -398,7 +445,8 @@ switch_to(int n) { top(current); if (fork() == 0) { close(ConnectionNumber(dpy)); - if (dpy != '\0') putenv(dpy); + if (dpy != '\0') + putenv(dpy); signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); signal(SIGHUP, SIG_DFL); @@ -416,7 +464,4 @@ switch_to(int n) { } } -void -initb2menu(int n) { - b2items[n] = 0; -} +void initb2menu(int n) { b2items[n] = 0; } diff --git a/printevent.c b/printevent.c index fea2668..3725b08 100644 --- a/printevent.c +++ b/printevent.c @@ -55,46 +55,52 @@ static char* sep = " "; /******************************************************************************/ /* Returns the string equivalent of a boolean parameter */ -static char* -TorF(int bool) { +static char* TorF(int bool) { switch (bool) { - case True: return ("True"); + 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) { +static char* PropertyState(int state) { switch (state) { - case PropertyNewValue: return ("PropertyNewValue"); + 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) { +static char* VisibilityState(int state) { switch (state) { - case VisibilityUnobscured: return ("VisibilityUnobscured"); + 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) { +static char* ServerTime(Time time) { unsigned long msec; unsigned long sec; unsigned long min; @@ -135,8 +141,7 @@ struct MaskType { }; /* Returns the string equivalent of a mask of buttons and/or modifier keys */ -static char* -ButtonAndOrModifierState(unsigned int state) { +static char* ButtonAndOrModifierState(unsigned int state) { static char buffer[256]; static MaskType masks[] = { {Button1Mask, "Button1Mask"}, @@ -172,8 +177,7 @@ ButtonAndOrModifierState(unsigned int state) { } /* Returns the string equivalent of a mask of configure window values */ -static char* -ConfigureValueMask(unsigned int valuemask) { +static char* ConfigureValueMask(unsigned int valuemask) { static char buffer[256]; static MaskType masks[] = { {CWX, "CWX"}, @@ -204,20 +208,21 @@ ConfigureValueMask(unsigned int valuemask) { } /* Returns the string equivalent of a motion hint */ -static char* -IsHint(char is_hint) { +static char* IsHint(char is_hint) { switch (is_hint) { - case NotifyNormal: return ("NotifyNormal"); + 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* MaybeNone(int value) { static char buffer[16]; if (value == None) @@ -229,136 +234,167 @@ MaybeNone(int value) { } /* Returns the string equivalent of a colormap state */ -static char* -ColormapState(int state) { +static char* ColormapState(int state) { switch (state) { - case ColormapInstalled: return ("ColormapInstalled"); + 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) { +static char* CrossingDetail(int detail) { switch (detail) { - case NotifyAncestor: return ("NotifyAncestor"); + 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) { +static char* FocusChangeDetail(int detail) { switch (detail) { - case NotifyAncestor: return ("NotifyAncestor"); + 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) { +static char* ConfigureDetail(int detail) { switch (detail) { - case Above: return ("Above"); + 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) { +static char* GrabMode(int mode) { switch (mode) { - case NotifyNormal: return ("NotifyNormal"); + 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) { +static char* MappingRequest(int request) { switch (request) { - case MappingModifier: return ("MappingModifier"); + 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) { +static char* Place(int place) { switch (place) { - case PlaceOnTop: return ("PlaceOnTop"); + 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* MajorCode(int code) { static char buffer[32]; switch (code) { - case X_CopyArea: return ("X_CopyArea"); + 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* Keycode(XKeyEvent* ev) { static char buffer[256]; KeySym keysym_str; char* keysym_name; @@ -380,12 +416,12 @@ Keycode(XKeyEvent* ev) { } /* Returns the string equivalent of an atom or "None"*/ -static char* -AtomName(Display* dpy, Atom atom) { +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); @@ -397,8 +433,7 @@ AtomName(Display* dpy, Atom atom) { /**** Routines to print out readable values for the field of various events ***/ /******************************************************************************/ -static void -VerbMotion(XMotionEvent* ev) { +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); @@ -410,8 +445,7 @@ VerbMotion(XMotionEvent* ev) { printf("same_screen=%s\n", TorF(ev->same_screen)); } -static void -VerbButton(XButtonEvent* ev) { +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); @@ -423,16 +457,14 @@ VerbButton(XButtonEvent* ev) { printf("same_screen=%s\n", TorF(ev->same_screen)); } -static void -VerbColormap(XColormapEvent* ev) { +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)); } -static void -VerbCrossing(XCrossingEvent* ev) { +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); @@ -446,16 +478,14 @@ VerbCrossing(XCrossingEvent* ev) { printf("state=%s\n", ButtonAndOrModifierState(ev->state)); } -static void -VerbExpose(XExposeEvent* ev) { +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); } -static void -VerbGraphicsExpose(XGraphicsExposeEvent* ev) { +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); @@ -463,41 +493,41 @@ VerbGraphicsExpose(XGraphicsExposeEvent* ev) { printf("minor_code=%d\n", ev->minor_code); } -static void -VerbNoExpose(XNoExposeEvent* ev) { +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); } -static void -VerbFocus(XFocusChangeEvent* ev) { +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)); } -static void -VerbKeymap(XKeymapEvent* ev) { +static void 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]); + for (i = 0; i < 32; i++) + printf("%02x", ev->key_vector[i]); printf("\n"); } -static void -VerbKey(XKeyEvent* ev) { +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); + 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); + 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)); + if (!ev->same_screen) + printf("!same_screen", TorF(ev->same_screen)); printf("\n"); return; @@ -512,29 +542,25 @@ VerbKey(XKeyEvent* ev) { printf("same_screen=%s\n", TorF(ev->same_screen)); } -static void -VerbProperty(XPropertyEvent* ev) { +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)); } -static void -VerbResizeRequest(XResizeRequestEvent* ev) { +static void 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) { +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)); } -static void -VerbConfigure(XConfigureEvent* ev) { +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); @@ -544,8 +570,7 @@ VerbConfigure(XConfigureEvent* ev) { printf("override_redirect=%s\n", TorF(ev->override_redirect)); } -static void -VerbCreateWindow(XCreateWindowEvent* ev) { +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); @@ -554,28 +579,24 @@ VerbCreateWindow(XCreateWindowEvent* ev) { printf("override_redirect=%s\n", TorF(ev->override_redirect)); } -static void -VerbDestroyWindow(XDestroyWindowEvent* ev) { +static void 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) { +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); } -static void -VerbMap(XMapEvent* ev) { +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)); } -static void -VerbReparent(XReparentEvent* ev) { +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); @@ -583,22 +604,19 @@ VerbReparent(XReparentEvent* ev) { printf("override_redirect=%s\n", TorF(ev->override_redirect)); } -static void -VerbUnmap(XUnmapEvent* ev) { +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)); } -static void -VerbCirculateRequest(XCirculateRequestEvent* ev) { +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)); } -static void -VerbConfigureRequest(XConfigureRequestEvent* ev) { +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); @@ -609,41 +627,37 @@ VerbConfigureRequest(XConfigureRequestEvent* ev) { printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask)); } -static void -VerbMapRequest(XMapRequestEvent* ev) { +static void 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) { +static void 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]); + for (i = 0; i < 5; i++) + printf(" 0x%08lx", ev->data.l[i]); printf("\n"); } -static void -VerbMapping(XMappingEvent* ev) { +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); } -static void -VerbSelectionClear(XSelectionClearEvent* ev) { +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)); } -static void -VerbSelection(XSelectionEvent* ev) { +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); @@ -651,8 +665,7 @@ VerbSelection(XSelectionEvent* ev) { printf("time=%s\n", ServerTime(ev->time)); } -static void -VerbSelectionRequest(XSelectionRequestEvent* ev) { +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); @@ -661,8 +674,7 @@ VerbSelectionRequest(XSelectionRequestEvent* ev) { printf("time=%s\n", ServerTime(ev->time)); } -static void -VerbVisibility(XVisibilityEvent* ev) { +static void VerbVisibility(XVisibilityEvent* ev) { printf("window=0x%x%s", (int)ev->window, sep); printf("state=%s\n", VisibilityState(ev->state)); } @@ -671,44 +683,76 @@ VerbVisibility(XVisibilityEvent* ev) { /************ Return the string representation for type of an event ***********/ /******************************************************************************/ -char* -eventtype(XEvent* ev) { +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"); + 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; @@ -718,12 +762,12 @@ eventtype(XEvent* ev) { /**************** Print the values of all fields for any event ****************/ /******************************************************************************/ -void -printevent(XEvent* e) { +void printevent(XEvent* e) { XAnyEvent* ev = (void*)e; printf("%3ld %-20s ", ev->serial, eventtype(e)); - if (ev->send_event) printf("(sendevent) "); + if (ev->send_event) + printf("(sendevent) "); if (0) { printf("type=%s%s", eventtype(e), sep); printf("serial=%lu%s", ev->serial, sep); @@ -732,66 +776,124 @@ printevent(XEvent* e) { } switch (ev->type) { - case MotionNotify: VerbMotion((void*)ev); break; + 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/xevents.c b/xevents.c index 8d37c37..4c139e9 100644 --- a/xevents.c +++ b/xevents.c @@ -8,8 +8,7 @@ #include #include "printevent.h" -int -main(int argc, char** argv) { +int main(int argc, char** argv) { int screen; Display* dpy; Window window; diff --git a/xshove.c b/xshove.c index 27d3c10..7b0b8fa 100644 --- a/xshove.c +++ b/xshove.c @@ -42,25 +42,28 @@ void listwindows(void); int parsewinsize(char*, Rectangle*, int*, int*, int*); void shove(char*, char*); -void -usage(void) { +void usage(void) { fprint(2, "usage: xshove [window rectangle]\n"); exits("usage"); } -void -main(int argc, char** argv) { +void main(int argc, char** argv) { int screen; screen = 0; ARGBEGIN { - case 's': screen = atoi(EARGF(usage())); break; - default: usage(); break; + case 's': + screen = atoi(EARGF(usage())); + break; + default: + usage(); + break; } ARGEND dpy = XOpenDisplay(""); - if (dpy == nil) sysfatal("open display: %r"); + if (dpy == nil) + sysfatal("open display: %r"); root = RootWindow(dpy, screen); getinfo(); @@ -69,13 +72,13 @@ main(int argc, char** argv) { listwindows(); exits(0); } - if (argc != 2) usage(); + if (argc != 2) + usage(); shove(argv[0], argv[1]); exits(0); } -char* -getproperty(Window w, Atom a) { +char* getproperty(Window w, Atom a) { uchar* p; int fmt; Atom type; @@ -84,41 +87,57 @@ getproperty(Window w, Atom a) { n = 100; p = nil; XGetWindowProperty( - dpy, w, a, 0, 100L, 0, AnyPropertyType, &type, &fmt, &n, &dummy, &p); - if (p == nil || *p == 0) return nil; + 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) { +Window 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; + if (getproperty(w, XA_WM_NAME)) + return w; + if (!XQueryTree(dpy, w, &dw1, &dw2, &xwin, &nxwin)) + return 0; for (i = 0; i < nxwin; i++) - if ((w = findname(xwin[i])) != 0) return w; + if ((w = findname(xwin[i])) != 0) + return w; return 0; } -void -getinfo(void) { +void getinfo(void) { int i; uint nxwin; Window dw1, dw2, *xwin; XClassHint class; XWindowAttributes attr; - if (!XQueryTree(dpy, root, &dw1, &dw2, &xwin, &nxwin)) return; + if (!XQueryTree(dpy, root, &dw1, &dw2, &xwin, &nxwin)) + return; w = mallocz(nxwin * sizeof w[0], 1); - if (w == 0) sysfatal("malloc: %r"); + if (w == 0) + sysfatal("malloc: %r"); Win* ww = w; for (i = 0; i < nxwin; i++) { memset(&attr, 0, sizeof attr); xwin[i] = findname(xwin[i]); - if (xwin[i] == 0) continue; + if (xwin[i] == 0) + continue; XGetWindowAttributes(dpy, xwin[i], &attr); if ( attr.width <= 0 || attr.override_redirect || attr.map_state != IsViewable) @@ -140,8 +159,7 @@ getinfo(void) { nw = ww - w; } -void -listwindows(void) { +void listwindows(void) { int i; for (i = 0; i < nw; i++) { @@ -159,8 +177,7 @@ listwindows(void) { } } -void -shove(char* name, char* geom) { +void shove(char* name, char* geom) { int i; int isdelta, havemin, havesize; int old, new; @@ -205,8 +222,8 @@ shove(char* name, char* geom) { } } -int -parsewinsize(char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) { +int parsewinsize( + char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) { char c, *os; int i, j, k, l; @@ -222,26 +239,34 @@ parsewinsize(char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) { *havemin = 0; *havesize = 0; memset(r, 0, sizeof *r); - if (!isdigit((uchar)*s)) goto oops; + if (!isdigit((uchar)*s)) + goto oops; i = strtol(s, &s, 0); if (*s == 'x') { s++; - if (!isdigit((uchar)*s)) goto oops; + 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; + if (*s == 0) + return 0; + if (*s != '@') + goto oops; s++; - if (!isdigit((uchar)*s)) goto oops; + if (!isdigit((uchar)*s)) + goto oops; i = strtol(s, &s, 0); - if (*s != ',' && *s != ' ') goto oops; + if (*s != ',' && *s != ' ') + goto oops; s++; - if (!isdigit((uchar)*s)) goto oops; + if (!isdigit((uchar)*s)) + goto oops; j = strtol(s, &s, 0); - if (*s != 0) goto oops; + if (*s != 0) + goto oops; r->min.x += i; r->max.x += i; r->min.y += j; @@ -252,9 +277,11 @@ parsewinsize(char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) { } c = *s; - if (c != ' ' && c != ',') goto oops; + if (c != ' ' && c != ',') + goto oops; s++; - if (!isdigit((uchar)*s)) goto oops; + if (!isdigit((uchar)*s)) + goto oops; j = strtol(s, &s, 0); if (*s == 0) { r->min.x = i; @@ -262,15 +289,20 @@ parsewinsize(char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) { *havemin = 1; return 0; } - if (*s != c) goto oops; + if (*s != c) + goto oops; s++; - if (!isdigit((uchar)*s)) goto oops; + if (!isdigit((uchar)*s)) + goto oops; k = strtol(s, &s, 0); - if (*s != c) goto oops; + if (*s != c) + goto oops; s++; - if (!isdigit((uchar)*s)) goto oops; + if (!isdigit((uchar)*s)) + goto oops; l = strtol(s, &s, 0); - if (*s != 0) goto oops; + if (*s != 0) + goto oops; r->min.x = i; r->min.y = j; r->max.x = k;