added some comments
281f0981
2 file(s) · +72 −75
| 19 | 19 | } |
|
| 20 | 20 | ||
| 21 | 21 | static void |
|
| 22 | - | grabbuttons(Client *c, Bool focus) |
|
| 22 | + | grabbuttons(Client *c, Bool focused) |
|
| 23 | 23 | { |
|
| 24 | 24 | XUngrabButton(dpy, AnyButton, AnyModifier, c->win); |
|
| 25 | 25 | ||
| 26 | - | if(focus) { |
|
| 26 | + | if(focused) { |
|
| 27 | 27 | XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK, |
|
| 28 | 28 | GrabModeAsync, GrabModeSync, None, None); |
|
| 29 | 29 | XGrabButton(dpy, Button1, MODKEY | LockMask, c->win, False, BUTTONMASK, |
|
| 304 | 304 | wc.border_width = 0; |
|
| 305 | 305 | else |
|
| 306 | 306 | wc.border_width = 1; |
|
| 307 | - | XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); |
|
| 307 | + | XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc); |
|
| 308 | 308 | XSync(dpy, False); |
|
| 309 | 309 | } |
|
| 310 | 310 | ||
| 11 | 11 | #define MOUSEMASK (BUTTONMASK | PointerMotionMask) |
|
| 12 | 12 | #define PROTODELWIN 1 |
|
| 13 | 13 | ||
| 14 | + | enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
|
| 15 | + | enum { WMProtocols, WMDelete, WMLast }; /* default atoms */ |
|
| 16 | + | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
|
| 17 | + | enum { ColFG, ColBG, ColLast }; /* color */ |
|
| 18 | + | ||
| 19 | + | typedef enum { |
|
| 20 | + | TopLeft, TopRight, BotLeft, BotRight |
|
| 21 | + | } Corner; /* window corners */ |
|
| 22 | + | ||
| 14 | 23 | typedef union { |
|
| 15 | 24 | const char *cmd; |
|
| 16 | 25 | int i; |
|
| 17 | - | } Arg; |
|
| 18 | - | ||
| 19 | - | /* atoms */ |
|
| 20 | - | enum { NetSupported, NetWMName, NetLast }; |
|
| 21 | - | enum { WMProtocols, WMDelete, WMLast }; |
|
| 22 | - | ||
| 23 | - | /* cursor */ |
|
| 24 | - | enum { CurNormal, CurResize, CurMove, CurLast }; |
|
| 25 | - | ||
| 26 | - | /* color */ |
|
| 27 | - | enum { ColFG, ColBG, ColLast }; |
|
| 28 | - | ||
| 29 | - | /* window corners */ |
|
| 30 | - | typedef enum { TopLeft, TopRight, BotLeft, BotRight } Corner; |
|
| 26 | + | } Arg; /* argument type */ |
|
| 31 | 27 | ||
| 32 | 28 | typedef struct { |
|
| 33 | 29 | int ascent; |
|
| 37 | 33 | XFontStruct *xfont; |
|
| 38 | 34 | } Fnt; |
|
| 39 | 35 | ||
| 40 | - | typedef struct { /* draw context */ |
|
| 36 | + | typedef struct { |
|
| 41 | 37 | int x, y, w, h; |
|
| 42 | 38 | unsigned long norm[ColLast]; |
|
| 43 | 39 | unsigned long sel[ColLast]; |
|
| 45 | 41 | Drawable drawable; |
|
| 46 | 42 | Fnt font; |
|
| 47 | 43 | GC gc; |
|
| 48 | - | } DC; |
|
| 44 | + | } DC; /* draw context */ |
|
| 49 | 45 | ||
| 50 | 46 | typedef struct Client Client; |
|
| 51 | 47 | struct Client { |
|
| 66 | 62 | Window twin; |
|
| 67 | 63 | }; |
|
| 68 | 64 | ||
| 69 | - | extern const char *tags[]; |
|
| 70 | - | extern char stext[1024]; |
|
| 71 | - | extern int bx, by, bw, bh, bmw, mw, screen, sx, sy, sw, sh; |
|
| 72 | - | extern unsigned int ntags, numlockmask; |
|
| 73 | - | extern void (*handler[LASTEvent])(XEvent *); |
|
| 74 | - | extern void (*arrange)(Arg *); |
|
| 65 | + | extern const char *tags[]; /* all tags */ |
|
| 66 | + | extern char stext[1024]; /* status text */ |
|
| 67 | + | extern int bx, by, bw, bh, bmw; /* bar geometry, bar mode label width */ |
|
| 68 | + | extern int mw, screen, sx, sy, sw, sh; /* screen geometry, master width */ |
|
| 69 | + | extern unsigned int ntags, numlockmask; /* number of tags, and dynamic lock mask */ |
|
| 70 | + | extern void (*handler[LASTEvent])(XEvent *); /* event handler */ |
|
| 71 | + | extern void (*arrange)(Arg *); /* arrange function, indicates mode */ |
|
| 75 | 72 | extern Atom wmatom[WMLast], netatom[NetLast]; |
|
| 76 | - | extern Bool running, issel, maximized, *seltag; |
|
| 77 | - | extern Client *clients, *sel, *stack; |
|
| 73 | + | extern Bool running, issel, maximized, *seltag; /* seltag is array of Bool */ |
|
| 74 | + | extern Client *clients, *sel, *stack; /* Client containers */ |
|
| 78 | 75 | extern Cursor cursor[CurLast]; |
|
| 79 | - | extern DC dc; |
|
| 76 | + | extern DC dc; /* draw context for everything */ |
|
| 80 | 77 | extern Display *dpy; |
|
| 81 | 78 | extern Window root, barwin; |
|
| 82 | 79 | ||
| 83 | 80 | /* client.c */ |
|
| 84 | - | extern void ban(Client *c); |
|
| 85 | - | extern void focus(Client *c); |
|
| 86 | - | extern Client *getclient(Window w); |
|
| 87 | - | extern Client *getctitle(Window w); |
|
| 88 | - | extern void gravitate(Client *c, Bool invert); |
|
| 89 | - | extern void killclient(Arg *arg); |
|
| 90 | - | extern void manage(Window w, XWindowAttributes *wa); |
|
| 91 | - | extern void resize(Client *c, Bool sizehints, Corner sticky); |
|
| 92 | - | extern void setsize(Client *c); |
|
| 93 | - | extern void settitle(Client *c); |
|
| 94 | - | extern void togglemax(Arg *arg); |
|
| 95 | - | extern void unmanage(Client *c); |
|
| 81 | + | extern void ban(Client *c); /* ban client from screen */ |
|
| 82 | + | extern void focus(Client *c); /* focus c, c may be NULL */ |
|
| 83 | + | extern Client *getclient(Window w); /* return client of w */ |
|
| 84 | + | extern Client *getctitle(Window w); /* return client of title window */ |
|
| 85 | + | extern void gravitate(Client *c, Bool invert); /* gravitate c */ |
|
| 86 | + | extern void killclient(Arg *arg); /* kill c nicely */ |
|
| 87 | + | extern void manage(Window w, XWindowAttributes *wa); /* manage new client */ |
|
| 88 | + | extern void resize(Client *c, Bool sizehints, Corner sticky); /* resize c*/ |
|
| 89 | + | extern void setsize(Client *c); /* set the size structs of c */ |
|
| 90 | + | extern void settitle(Client *c); /* set the name of c */ |
|
| 91 | + | extern void togglemax(Arg *arg); /* (un)maximize c */ |
|
| 92 | + | extern void unmanage(Client *c); /* destroy c */ |
|
| 96 | 93 | ||
| 97 | 94 | /* draw.c */ |
|
| 98 | - | extern void drawall(); |
|
| 99 | - | extern void drawstatus(); |
|
| 100 | - | extern void drawtitle(Client *c); |
|
| 101 | - | extern unsigned long getcolor(const char *colstr); |
|
| 102 | - | extern void setfont(const char *fontstr); |
|
| 103 | - | extern unsigned int textw(const char *text); |
|
| 95 | + | extern void drawall(); /* draw all visible client titles and the bar */ |
|
| 96 | + | extern void drawstatus(); /* draw the bar */ |
|
| 97 | + | extern void drawtitle(Client *c); /* draw title of c */ |
|
| 98 | + | extern unsigned long getcolor(const char *colstr); /* return color of colstr */ |
|
| 99 | + | extern void setfont(const char *fontstr); /* set the font for DC */ |
|
| 100 | + | extern unsigned int textw(const char *text); /* return the text width of text */ |
|
| 104 | 101 | ||
| 105 | 102 | /* event.c */ |
|
| 106 | - | extern void grabkeys(); |
|
| 107 | - | extern void procevent(); |
|
| 103 | + | extern void grabkeys(); /* grab all keys defined in config.h */ |
|
| 104 | + | extern void procevent(); /* process pending X events */ |
|
| 108 | 105 | ||
| 109 | 106 | /* main.c */ |
|
| 110 | - | extern int getproto(Window w); |
|
| 111 | - | extern void quit(Arg *arg); |
|
| 112 | - | extern void sendevent(Window w, Atom a, long value); |
|
| 113 | - | extern int xerror(Display *dsply, XErrorEvent *ee); |
|
| 107 | + | extern int getproto(Window w); /* return protocol mask of WMProtocols property of w */ |
|
| 108 | + | extern void quit(Arg *arg); /* quit dwm nicely */ |
|
| 109 | + | extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ |
|
| 110 | + | extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ |
|
| 114 | 111 | ||
| 115 | 112 | /* tag.c */ |
|
| 116 | - | extern void initrregs(); |
|
| 117 | - | extern Client *getnext(Client *c); |
|
| 118 | - | extern Client *getprev(Client *c); |
|
| 119 | - | extern void settags(Client *c, Client *trans); |
|
| 120 | - | extern void tag(Arg *arg); |
|
| 121 | - | extern void toggletag(Arg *arg); |
|
| 113 | + | extern void initrregs(); /* initialize regexps of rules defined in config.h */ |
|
| 114 | + | extern Client *getnext(Client *c); /* returns next visible client */ |
|
| 115 | + | extern Client *getprev(Client *c); /* returns previous visible client */ |
|
| 116 | + | extern void settags(Client *c, Client *trans); /* updates tags of c */ |
|
| 117 | + | extern void tag(Arg *arg); /* tags c accordingly to arg's index */ |
|
| 118 | + | extern void toggletag(Arg *arg); /* toggles c tags accordingly to arg's index */ |
|
| 122 | 119 | ||
| 123 | 120 | /* util.c */ |
|
| 124 | - | extern void *emallocz(unsigned int size); |
|
| 125 | - | extern void eprint(const char *errstr, ...); |
|
| 126 | - | extern void *erealloc(void *ptr, unsigned int size); |
|
| 127 | - | extern void spawn(Arg *arg); |
|
| 121 | + | extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ |
|
| 122 | + | extern void eprint(const char *errstr, ...); /* prints error string and exits with return code 1 */ |
|
| 123 | + | extern void *erealloc(void *ptr, unsigned int size); /* reallocates memory, exits on error */ |
|
| 124 | + | extern void spawn(Arg *arg) /* forks a new subprocess accordingly to arg's cmd */ |
|
| 128 | 125 | ||
| 129 | 126 | /* view.c */ |
|
| 130 | - | extern void detach(Client *c); |
|
| 131 | - | extern void dofloat(Arg *arg); |
|
| 132 | - | extern void dotile(Arg *arg); |
|
| 133 | - | extern void focusnext(Arg *arg); |
|
| 134 | - | extern void focusprev(Arg *arg); |
|
| 135 | - | extern Bool isvisible(Client *c); |
|
| 136 | - | extern void resizecol(Arg *arg); |
|
| 137 | - | extern void restack(); |
|
| 138 | - | extern void togglemode(Arg *arg); |
|
| 139 | - | extern void toggleview(Arg *arg); |
|
| 140 | - | extern void view(Arg *arg); |
|
| 141 | - | extern void viewall(Arg *arg); |
|
| 142 | - | extern void zoom(Arg *arg); |
|
| 127 | + | extern void detach(Client *c); /* detaches c from global client list */ |
|
| 128 | + | extern void dofloat(Arg *arg); /* arranges all windows in a floating way, arg is ignored */ |
|
| 129 | + | extern void dotile(Arg *arg); /* arranges all windows in a tiled way, arg is ignored */ |
|
| 130 | + | extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ |
|
| 131 | + | extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ |
|
| 132 | + | extern Bool isvisible(Client *c); /* returns True if client is visible */ |
|
| 133 | + | extern void resizecol(Arg *arg); /* resizes the master width accordingly to arg's index value */ |
|
| 134 | + | extern void restack(); /* restores z layers of all clients */ |
|
| 135 | + | extern void togglemode(Arg *arg); /* toggles global arrange mode (between dotile and dofloat) */ |
|
| 136 | + | extern void toggleview(Arg *arg); /* makes the tag accordingly to arg's index (in)visible */ |
|
| 137 | + | extern void view(Arg *arg); /* makes the tag accordingly to arg's index visible */ |
|
| 138 | + | extern void viewall(Arg *arg); /* makes all tags visible, arg is ignored */ |
|
| 139 | + | extern void zoom(Arg *arg); /* zooms the focused client to master column, arg is ignored */ |
|