diff options
| -rw-r--r-- | config.def.h | 84 | ||||
| -rw-r--r-- | dwm.c | 101 |
2 files changed, 111 insertions, 74 deletions
diff --git a/config.def.h b/config.def.h index 1733681..fe97061 100644 --- a/config.def.h +++ b/config.def.h | |||
| @@ -39,10 +39,10 @@ static Layout layouts[] = { | |||
| 39 | /* key definitions */ | 39 | /* key definitions */ |
| 40 | #define MODKEY Mod1Mask | 40 | #define MODKEY Mod1Mask |
| 41 | #define TAGKEYS(KEY,TAG) \ | 41 | #define TAGKEYS(KEY,TAG) \ |
| 42 | { MODKEY, KEY, view, TAG }, \ | 42 | { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ |
| 43 | { MODKEY|ControlMask, KEY, toggleview, TAG }, \ | 43 | { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ |
| 44 | { MODKEY|ShiftMask, KEY, tag, TAG }, \ | 44 | { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ |
| 45 | { MODKEY|ControlMask|ShiftMask, KEY, toggletag, TAG }, | 45 | { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, |
| 46 | 46 | ||
| 47 | /* helper for spawning shell commands */ | 47 | /* helper for spawning shell commands */ |
| 48 | #define SHCMD(cmd) { .v = (char*[]){ "/bin/sh", "-c", cmd, NULL } } | 48 | #define SHCMD(cmd) { .v = (char*[]){ "/bin/sh", "-c", cmd, NULL } } |
| @@ -51,27 +51,61 @@ static Key keys[] = { | |||
| 51 | /* modifier key function argument */ | 51 | /* modifier key function argument */ |
| 52 | { MODKEY, XK_p, spawn, {.v = (char *[]){"dmenu_run", "-fn", FONT, "-nb", NORMBGCOLOR, "-nf", NORMFGCOLOR, "-sb", SELBGCOLOR, "-sf", SELFGCOLOR, NULL}} }, | 52 | { MODKEY, XK_p, spawn, {.v = (char *[]){"dmenu_run", "-fn", FONT, "-nb", NORMBGCOLOR, "-nf", NORMFGCOLOR, "-sb", SELBGCOLOR, "-sf", SELFGCOLOR, NULL}} }, |
| 53 | { MODKEY|ShiftMask, XK_Return, spawn, {.v = (char *[]){"uxterm", NULL}} }, | 53 | { MODKEY|ShiftMask, XK_Return, spawn, {.v = (char *[]){"uxterm", NULL}} }, |
| 54 | { MODKEY, XK_b, togglebar, {0}}, | 54 | { MODKEY, XK_b, togglebar, {0} }, |
| 55 | { MODKEY, XK_j, focusstack, {.i = +1 }}, | 55 | { MODKEY, XK_j, focusstack, {.i = +1 } }, |
| 56 | { MODKEY, XK_k, focusstack, {.i = -1 }}, | 56 | { MODKEY, XK_k, focusstack, {.i = -1 } }, |
| 57 | { MODKEY, XK_h, setmfact, {.f = -0.05}}, | 57 | { MODKEY, XK_h, setmfact, {.f = -0.05} }, |
| 58 | { MODKEY, XK_l, setmfact, {.f = +0.05}}, | 58 | { MODKEY, XK_l, setmfact, {.f = +0.05} }, |
| 59 | { MODKEY, XK_m, togglemax, {0}}, | 59 | { MODKEY, XK_m, togglemax, {0} }, |
| 60 | { MODKEY, XK_Return, zoom, {0}}, | 60 | { MODKEY, XK_Return, zoom, {0} }, |
| 61 | { MODKEY, XK_Tab, view, {0}}, | 61 | { MODKEY, XK_Tab, view, {0} }, |
| 62 | { MODKEY|ShiftMask, XK_c, killclient, {0}}, | 62 | { MODKEY|ShiftMask, XK_c, killclient, {0} }, |
| 63 | { MODKEY, XK_space, togglelayout, {0}}, | 63 | { MODKEY, XK_space, togglelayout, {0} }, |
| 64 | { MODKEY|ShiftMask, XK_space, togglefloating, {0}}, | 64 | { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, |
| 65 | { MODKEY, XK_0, view, {.ui = ~0 } }, | 65 | { MODKEY, XK_0, view, {.ui = ~0 } }, |
| 66 | { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, | 66 | { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, |
| 67 | TAGKEYS( XK_1, {.ui = 1 << 0} ) | 67 | TAGKEYS( XK_1, 0) |
| 68 | TAGKEYS( XK_2, {.ui = 1 << 1} ) | 68 | TAGKEYS( XK_2, 1) |
| 69 | TAGKEYS( XK_3, {.ui = 1 << 2} ) | 69 | TAGKEYS( XK_3, 2) |
| 70 | TAGKEYS( XK_4, {.ui = 1 << 3} ) | 70 | TAGKEYS( XK_4, 3) |
| 71 | TAGKEYS( XK_5, {.ui = 1 << 4} ) | 71 | TAGKEYS( XK_5, 4) |
| 72 | TAGKEYS( XK_6, {.ui = 1 << 5} ) | 72 | TAGKEYS( XK_6, 5) |
| 73 | TAGKEYS( XK_7, {.ui = 1 << 6} ) | 73 | TAGKEYS( XK_7, 6) |
| 74 | TAGKEYS( XK_8, {.ui = 1 << 7} ) | 74 | TAGKEYS( XK_8, 7) |
| 75 | TAGKEYS( XK_9, {.ui = 1 << 8} ) | 75 | TAGKEYS( XK_9, 8) |
| 76 | { MODKEY|ShiftMask, XK_q, quit, {0}}, | 76 | { MODKEY|ShiftMask, XK_q, quit, {0} }, |
| 77 | }; | 77 | }; |
| 78 | |||
| 79 | /* button definitions */ | ||
| 80 | #define TAGBUTTONS(TAG) \ | ||
| 81 | { TAG, 0, Button1, view, {.ui = 1 << TAG} }, \ | ||
| 82 | { TAG, 0, Button3, toggleview, {.ui = 1 << TAG} }, \ | ||
| 83 | { TAG, MODKEY, Button1, tag, {.ui = 1 << TAG} }, \ | ||
| 84 | { TAG, MODKEY, Button3, toggletag, {.ui = 1 << TAG} }, | ||
| 85 | |||
| 86 | /* click can be a tag number (starting at 0), | ||
| 87 | * ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ | ||
| 88 | static Button buttons[] = { | ||
| 89 | /* click event mask button function argument */ | ||
| 90 | { ClkLtSymbol, 0, Button1, togglelayout, {0} }, | ||
| 91 | { ClkLtSymbol, 0, Button3, togglemax, {0} }, | ||
| 92 | { ClkWinTitle, 0, Button1, movemouse, {0} }, | ||
| 93 | { ClkWinTitle, 0, Button2, zoom, {0} }, | ||
| 94 | { ClkWinTitle, 0, Button3, resizemouse, {0} }, | ||
| 95 | { ClkWinTitle, 0, Button4, focusstack, {.i = +1 } }, | ||
| 96 | { ClkWinTitle, 0, Button5, focusstack, {.i = -1 } }, | ||
| 97 | { ClkClientWin, MODKEY, Button1, movemouse, {0} }, | ||
| 98 | { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, | ||
| 99 | { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, | ||
| 100 | { ClkRootWin, Button1Mask, Button3, spawn, {.v = (char *[]){"uxterm", NULL}} }, | ||
| 101 | TAGBUTTONS(0) | ||
| 102 | TAGBUTTONS(1) | ||
| 103 | TAGBUTTONS(2) | ||
| 104 | TAGBUTTONS(3) | ||
| 105 | TAGBUTTONS(4) | ||
| 106 | TAGBUTTONS(5) | ||
| 107 | TAGBUTTONS(6) | ||
| 108 | TAGBUTTONS(7) | ||
| 109 | TAGBUTTONS(8) | ||
| 110 | }; | ||
| 111 | |||
| @@ -59,10 +59,28 @@ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ | |||
| 59 | enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ | 59 | enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
| 60 | enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ | 60 | enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
| 61 | enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ | 61 | enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ |
| 62 | enum { ClkLtSymbol = -1, ClkStatusText = -2, ClkWinTitle = -3, | ||
| 63 | ClkClientWin = -4, ClkRootWin = -5, ClkLast = -6};/* clicks */ | ||
| 62 | 64 | ||
| 63 | /* typedefs */ | 65 | /* typedefs */ |
| 64 | typedef unsigned int uint; | 66 | typedef unsigned int uint; |
| 65 | typedef unsigned long ulong; | 67 | typedef unsigned long ulong; |
| 68 | |||
| 69 | typedef union { | ||
| 70 | int i; | ||
| 71 | uint ui; | ||
| 72 | float f; | ||
| 73 | void *v; | ||
| 74 | } Arg; | ||
| 75 | |||
| 76 | typedef struct { | ||
| 77 | uint click; | ||
| 78 | uint mask; | ||
| 79 | uint button; | ||
| 80 | void (*func)(const Arg *arg); | ||
| 81 | const Arg arg; | ||
| 82 | } Button; | ||
| 83 | |||
| 66 | typedef struct Client Client; | 84 | typedef struct Client Client; |
| 67 | struct Client { | 85 | struct Client { |
| 68 | char name[256]; | 86 | char name[256]; |
| @@ -92,13 +110,6 @@ typedef struct { | |||
| 92 | } font; | 110 | } font; |
| 93 | } DC; /* draw context */ | 111 | } DC; /* draw context */ |
| 94 | 112 | ||
| 95 | typedef union { | ||
| 96 | int i; | ||
| 97 | uint ui; | ||
| 98 | float f; | ||
| 99 | void *v; | ||
| 100 | } Arg; | ||
| 101 | |||
| 102 | typedef struct { | 113 | typedef struct { |
| 103 | uint mod; | 114 | uint mod; |
| 104 | KeySym keysym; | 115 | KeySym keysym; |
| @@ -157,12 +168,12 @@ static void killclient(const Arg *arg); | |||
| 157 | static void manage(Window w, XWindowAttributes *wa); | 168 | static void manage(Window w, XWindowAttributes *wa); |
| 158 | static void mappingnotify(XEvent *e); | 169 | static void mappingnotify(XEvent *e); |
| 159 | static void maprequest(XEvent *e); | 170 | static void maprequest(XEvent *e); |
| 160 | static void movemouse(Client *c); | 171 | static void movemouse(const Arg *arg); |
| 161 | static Client *nexttiled(Client *c); | 172 | static Client *nexttiled(Client *c); |
| 162 | static void propertynotify(XEvent *e); | 173 | static void propertynotify(XEvent *e); |
| 163 | static void quit(const Arg *arg); | 174 | static void quit(const Arg *arg); |
| 164 | static void resize(Client *c, int x, int y, int w, int h, Bool sizehints); | 175 | static void resize(Client *c, int x, int y, int w, int h, Bool sizehints); |
| 165 | static void resizemouse(Client *c); | 176 | static void resizemouse(const Arg *arg); |
| 166 | static void restack(void); | 177 | static void restack(void); |
| 167 | static void run(void); | 178 | static void run(void); |
| 168 | static void scan(void); | 179 | static void scan(void); |
| @@ -297,50 +308,31 @@ attachstack(Client *c) { | |||
| 297 | 308 | ||
| 298 | void | 309 | void |
| 299 | buttonpress(XEvent *e) { | 310 | buttonpress(XEvent *e) { |
| 300 | uint i, mask; | 311 | uint i, x, click; |
| 301 | int x; | ||
| 302 | Client *c; | 312 | Client *c; |
| 303 | XButtonPressedEvent *ev = &e->xbutton; | 313 | XButtonPressedEvent *ev = &e->xbutton; |
| 304 | 314 | ||
| 315 | click = ClkRootWin; | ||
| 305 | if(ev->window == barwin) { | 316 | if(ev->window == barwin) { |
| 306 | x = 0; | 317 | x = 0; |
| 307 | for(i = 0; i < LENGTH(tags); i++) { | 318 | for(i = 0; i < LENGTH(tags) && ev->x >= x; i++) { |
| 308 | x += TEXTW(tags[i]); | 319 | x += TEXTW(tags[i]); |
| 309 | if(ev->x < x) { | 320 | if(i < LENGTH(tags) || ev->x <= x) |
| 310 | mask = 1 << i; | 321 | click = i - 1; |
| 311 | if(ev->button == Button1) { | 322 | else if(ev->x < x + blw) |
| 312 | if(ev->state & MODKEY) | 323 | click = ClkLtSymbol; |
| 313 | tag((Arg*)&mask); | 324 | else if(ev->x > wx + ww - TEXTW(stext)) |
| 314 | else | 325 | click = ClkStatusText; |
| 315 | view((Arg*)&mask); | 326 | else |
| 316 | } | 327 | click = ClkWinTitle; |
| 317 | else if(ev->button == Button3) { | ||
| 318 | if(ev->state & MODKEY) | ||
| 319 | toggletag((Arg*)&mask); | ||
| 320 | else | ||
| 321 | toggleview((Arg*)&mask); | ||
| 322 | } | ||
| 323 | return; | ||
| 324 | } | ||
| 325 | } | ||
| 326 | if(ev->x < x + blw) { | ||
| 327 | if(ev->button == Button1) | ||
| 328 | togglelayout(NULL); | ||
| 329 | else if(ev->button == Button3) | ||
| 330 | togglemax(NULL); | ||
| 331 | } | 328 | } |
| 332 | } | 329 | } |
| 333 | else if((c = getclient(ev->window))) { | 330 | else if((c = getclient(ev->window))) |
| 334 | focus(c); | 331 | click = ClkClientWin; |
| 335 | if(CLEANMASK(ev->state) != MODKEY || (ismax && !c->isfixed)) | 332 | |
| 336 | return; | 333 | for(i = 0; i < LENGTH(buttons); i++) |
| 337 | if(ev->button == Button1) | 334 | if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) |
| 338 | movemouse(c); | 335 | buttons[i].func(&buttons[i].arg); |
| 339 | else if(ev->button == Button2) | ||
| 340 | togglefloating(NULL); | ||
| 341 | else if(ev->button == Button3 && !c->isfixed) | ||
| 342 | resizemouse(c); | ||
| 343 | } | ||
| 344 | } | 336 | } |
| 345 | 337 | ||
| 346 | void | 338 | void |
| @@ -971,12 +963,15 @@ maprequest(XEvent *e) { | |||
| 971 | } | 963 | } |
| 972 | 964 | ||
| 973 | void | 965 | void |
| 974 | movemouse(Client *c) { | 966 | movemouse(const Arg *arg) { |
| 975 | int x1, y1, ocx, ocy, di, nx, ny; | 967 | int x1, y1, ocx, ocy, di, nx, ny; |
| 976 | uint dui; | 968 | uint dui; |
| 969 | Client *c; | ||
| 977 | Window dummy; | 970 | Window dummy; |
| 978 | XEvent ev; | 971 | XEvent ev; |
| 979 | 972 | ||
| 973 | if(!(c = sel)) | ||
| 974 | return; | ||
| 980 | restack(); | 975 | restack(); |
| 981 | ocx = nx = c->x; | 976 | ocx = nx = c->x; |
| 982 | ocy = ny = c->y; | 977 | ocy = ny = c->y; |
| @@ -984,6 +979,11 @@ movemouse(Client *c) { | |||
| 984 | None, cursor[CurMove], CurrentTime) != GrabSuccess) | 979 | None, cursor[CurMove], CurrentTime) != GrabSuccess) |
| 985 | return; | 980 | return; |
| 986 | XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); | 981 | XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); |
| 982 | if(x1 < c->x || x1 > c->x + c->w || y1 < c->y || y1 > c->y + c->h) { | ||
| 983 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, 0, 0); | ||
| 984 | x1 = c->x + 1; | ||
| 985 | y1 = c->y + 1; | ||
| 986 | } | ||
| 987 | for(;;) { | 987 | for(;;) { |
| 988 | XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); | 988 | XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); |
| 989 | switch (ev.type) { | 989 | switch (ev.type) { |
| @@ -1131,11 +1131,14 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { | |||
| 1131 | } | 1131 | } |
| 1132 | 1132 | ||
| 1133 | void | 1133 | void |
| 1134 | resizemouse(Client *c) { | 1134 | resizemouse(const Arg *arg) { |
| 1135 | int ocx, ocy; | 1135 | int ocx, ocy; |
| 1136 | int nw, nh; | 1136 | int nw, nh; |
| 1137 | Client *c; | ||
| 1137 | XEvent ev; | 1138 | XEvent ev; |
| 1138 | 1139 | ||
| 1140 | if(!(c = sel)) | ||
| 1141 | return; | ||
| 1139 | restack(); | 1142 | restack(); |
| 1140 | ocx = c->x; | 1143 | ocx = c->x; |
| 1141 | ocy = c->y; | 1144 | ocy = c->y; |
| @@ -1377,7 +1380,7 @@ setup(void) { | |||
| 1377 | PropModeReplace, (unsigned char *) netatom, NetLast); | 1380 | PropModeReplace, (unsigned char *) netatom, NetLast); |
| 1378 | 1381 | ||
| 1379 | /* select for events */ | 1382 | /* select for events */ |
| 1380 | wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask | 1383 | wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask |
| 1381 | |EnterWindowMask|LeaveWindowMask|StructureNotifyMask; | 1384 | |EnterWindowMask|LeaveWindowMask|StructureNotifyMask; |
| 1382 | XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); | 1385 | XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); |
| 1383 | XSelectInput(dpy, root, wa.event_mask); | 1386 | XSelectInput(dpy, root, wa.event_mask); |
| @@ -1643,7 +1646,7 @@ updatewmhints(Client *c) { | |||
| 1643 | void | 1646 | void |
| 1644 | view(const Arg *arg) { | 1647 | view(const Arg *arg) { |
| 1645 | seltags ^= 1; /* toggle sel tagset */ | 1648 | seltags ^= 1; /* toggle sel tagset */ |
| 1646 | if(arg && (arg->ui & TAGMASK)) | 1649 | if(arg && (arg->ui & TAGMASK) && (arg->ui & TAGMASK) != tagset[seltags ^ 1]) |
| 1647 | tagset[seltags] = arg->i & TAGMASK; | 1650 | tagset[seltags] = arg->i & TAGMASK; |
| 1648 | arrange(); | 1651 | arrange(); |
| 1649 | } | 1652 | } |
