recent changes, introduced togglebar, changed some defines into variable declarations where possible
54972686
3 file(s) · +53 −33
| 1 | 1 | /* See LICENSE file for copyright and license details. */ |
|
| 2 | 2 | ||
| 3 | 3 | /* appearance */ |
|
| 4 | - | #define BORDERPX 1 |
|
| 5 | 4 | #define FONT "-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*" |
|
| 6 | 5 | #define NORMBORDERCOLOR "#cccccc" |
|
| 7 | 6 | #define NORMBGCOLOR "#cccccc" |
|
| 9 | 8 | #define SELBORDERCOLOR "#0066ff" |
|
| 10 | 9 | #define SELBGCOLOR "#0066ff" |
|
| 11 | 10 | #define SELFGCOLOR "#ffffff" |
|
| 12 | - | #define SNAP 32 /* snap pixel */ |
|
| 11 | + | unsigned int borderpx = 1; /* border pixel of windows */ |
|
| 12 | + | unsigned int snap = 32; /* snap pixel */ |
|
| 13 | + | Bool showbar = True; /* False means no bar */ |
|
| 14 | + | Bool topbar = True; /* False means bottom bar */ |
|
| 13 | 15 | ||
| 14 | 16 | /* tagging */ |
|
| 15 | 17 | const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; |
|
| 20 | 22 | }; |
|
| 21 | 23 | ||
| 22 | 24 | /* layout(s) */ |
|
| 23 | - | #define RESIZEHINTS True /* False - respect size hints in tiled resizals */ |
|
| 24 | - | #define MFACT 0.55 /* master factor [0.1 .. 0.9] */ |
|
| 25 | + | double mfact = 0.55; |
|
| 26 | + | Bool resizehints = True; /* False means respect size hints in tiled resizals */ |
|
| 27 | + | ||
| 25 | 28 | #include "tile.c" |
|
| 29 | + | ||
| 26 | 30 | Layout layouts[] = { |
|
| 27 | 31 | /* symbol arrange geom */ |
|
| 28 | 32 | { "[]=", tile, updatetilegeom }, /* first entry is default */ |
|
| 35 | 39 | /* modifier key function argument */ |
|
| 36 | 40 | { MODKEY, XK_p, spawn, "exec dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"' -sb '"SELBGCOLOR"' -sf '"SELFGCOLOR"'" }, |
|
| 37 | 41 | { MODKEY|ShiftMask, XK_Return, spawn, "exec uxterm" }, |
|
| 42 | + | { MODKEY, XK_b, togglebar, NULL }, |
|
| 38 | 43 | { MODKEY, XK_j, focusnext, NULL }, |
|
| 39 | 44 | { MODKEY, XK_k, focusprev, NULL }, |
|
| 40 | 45 | { MODKEY, XK_h, setmfact, "-0.05" }, |
|
| 41 | 41 | #include <X11/Xutil.h> |
|
| 42 | 42 | ||
| 43 | 43 | /* macros */ |
|
| 44 | - | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
|
| 45 | - | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
|
| 46 | - | #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) |
|
| 47 | - | #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask)) |
|
| 48 | - | #define LENGTH(x) (sizeof x / sizeof x[0]) |
|
| 49 | - | #define MAXTAGLEN 16 |
|
| 50 | - | #define MOUSEMASK (BUTTONMASK|PointerMotionMask) |
|
| 44 | + | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
|
| 45 | + | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
|
| 46 | + | #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) |
|
| 47 | + | #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask)) |
|
| 48 | + | #define LENGTH(x) (sizeof x / sizeof x[0]) |
|
| 49 | + | #define MAXTAGLEN 16 |
|
| 50 | + | #define MOUSEMASK (BUTTONMASK|PointerMotionMask) |
|
| 51 | 51 | ||
| 52 | 52 | /* enums */ |
|
| 53 | - | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
|
| 54 | - | enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
|
| 55 | - | enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
|
| 53 | + | enum { BarTop, BarBot, BarOff, BarLast }; /* bar appearance */ |
|
| 54 | + | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
|
| 55 | + | enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
|
| 56 | + | enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
|
| 56 | 57 | enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ |
|
| 57 | 58 | ||
| 58 | 59 | /* typedefs */ |
|
| 166 | 167 | void tag(const char *arg); |
|
| 167 | 168 | unsigned int textnw(const char *text, unsigned int len); |
|
| 168 | 169 | unsigned int textw(const char *text); |
|
| 170 | + | void togglebar(const char *arg); |
|
| 169 | 171 | void togglefloating(const char *arg); |
|
| 170 | 172 | void togglelayout(const char *arg); |
|
| 171 | 173 | void toggletag(const char *arg); |
|
| 179 | 181 | void updatetitle(Client *c); |
|
| 180 | 182 | void updatewmhints(Client *c); |
|
| 181 | 183 | void view(const char *arg); |
|
| 182 | - | void viewprevtag(const char *arg); /* views previous selected tags */ |
|
| 184 | + | void viewprevtag(const char *arg); |
|
| 183 | 185 | int xerror(Display *dpy, XErrorEvent *ee); |
|
| 184 | 186 | int xerrordummy(Display *dpy, XErrorEvent *ee); |
|
| 185 | 187 | int xerrorstart(Display *dpy, XErrorEvent *ee); |
|
| 188 | 190 | /* variables */ |
|
| 189 | 191 | char stext[256]; |
|
| 190 | 192 | int screen, sx, sy, sw, sh; |
|
| 191 | - | int (*xerrorxlib)(Display *, XErrorEvent *); |
|
| 192 | 193 | int bx, by, bw, bh, blw, wx, wy, ww, wh; |
|
| 193 | 194 | int seltags = 0; |
|
| 195 | + | int (*xerrorxlib)(Display *, XErrorEvent *); |
|
| 194 | 196 | unsigned int numlockmask = 0; |
|
| 195 | 197 | void (*handler[LASTEvent]) (XEvent *) = { |
|
| 196 | 198 | [ButtonPress] = buttonpress, |
|
| 959 | 961 | c->y = wy + wh - c->h - 2 * c->bw; |
|
| 960 | 962 | c->x = MAX(c->x, wx); |
|
| 961 | 963 | c->y = MAX(c->y, wy); |
|
| 962 | - | c->bw = BORDERPX; |
|
| 964 | + | c->bw = borderpx; |
|
| 963 | 965 | } |
|
| 964 | 966 | ||
| 965 | 967 | wc.border_width = c->bw; |
|
| 1037 | 1039 | XSync(dpy, False); |
|
| 1038 | 1040 | nx = ocx + (ev.xmotion.x - x1); |
|
| 1039 | 1041 | ny = ocy + (ev.xmotion.y - y1); |
|
| 1040 | - | if(abs(wx - nx) < SNAP) |
|
| 1042 | + | if(abs(wx - nx) < snap) |
|
| 1041 | 1043 | nx = wx; |
|
| 1042 | - | else if(abs((wx + ww) - (nx + c->w + 2 * c->bw)) < SNAP) |
|
| 1044 | + | else if(abs((wx + ww) - (nx + c->w + 2 * c->bw)) < snap) |
|
| 1043 | 1045 | nx = wx + ww - c->w - 2 * c->bw; |
|
| 1044 | - | if(abs(wy - ny) < SNAP) |
|
| 1046 | + | if(abs(wy - ny) < snap) |
|
| 1045 | 1047 | ny = wy; |
|
| 1046 | - | else if(abs((wy + wh) - (ny + c->h + 2 * c->bw)) < SNAP) |
|
| 1048 | + | else if(abs((wy + wh) - (ny + c->h + 2 * c->bw)) < snap) |
|
| 1047 | 1049 | ny = wy + wh - c->h - 2 * c->bw; |
|
| 1048 | - | if(!c->isfloating && lt->arrange && (abs(nx - c->x) > SNAP || abs(ny - c->y) > SNAP)) |
|
| 1050 | + | if(!c->isfloating && lt->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) |
|
| 1049 | 1051 | togglefloating(NULL); |
|
| 1050 | 1052 | if(!lt->arrange || c->isfloating) |
|
| 1051 | 1053 | resize(c, nx, ny, c->w, c->h, False); |
|
| 1191 | 1193 | XSync(dpy, False); |
|
| 1192 | 1194 | nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); |
|
| 1193 | 1195 | nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); |
|
| 1194 | - | if(!c->isfloating && lt->arrange && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP)) { |
|
| 1196 | + | if(!c->isfloating && lt->arrange && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) { |
|
| 1195 | 1197 | togglefloating(NULL); |
|
| 1196 | 1198 | } |
|
| 1197 | 1199 | if(!lt->arrange || c->isfloating) |
|
| 1455 | 1457 | } |
|
| 1456 | 1458 | ||
| 1457 | 1459 | void |
|
| 1460 | + | togglebar(const char *arg) { |
|
| 1461 | + | showbar = !showbar; |
|
| 1462 | + | updategeom(); |
|
| 1463 | + | updatebar(); |
|
| 1464 | + | arrange(); |
|
| 1465 | + | } |
|
| 1466 | + | ||
| 1467 | + | void |
|
| 1458 | 1468 | togglefloating(const char *arg) { |
|
| 1459 | 1469 | if(!sel) |
|
| 1460 | 1470 | return; |
|
| 1564 | 1574 | updategeom(void) { |
|
| 1565 | 1575 | unsigned int i; |
|
| 1566 | 1576 | ||
| 1567 | - | /* bar geometry */ |
|
| 1577 | + | #ifdef DEFGEOM /* define your own if you are Xinerama user */ |
|
| 1578 | + | DEFGEOM |
|
| 1579 | + | #else |
|
| 1580 | + | /* bar geometry*/ |
|
| 1568 | 1581 | bx = 0; |
|
| 1569 | - | by = 0; |
|
| 1582 | + | by = showbar ? (topbar ? 0 : sh - bh) : -bh; |
|
| 1570 | 1583 | bw = sw; |
|
| 1571 | 1584 | ||
| 1572 | 1585 | /* window area geometry */ |
|
| 1573 | 1586 | wx = sx; |
|
| 1574 | - | wy = sy + bh; |
|
| 1587 | + | wy = showbar && topbar ? sy + bh : sy; |
|
| 1575 | 1588 | ww = sw; |
|
| 1576 | - | wh = sh - bh; |
|
| 1589 | + | wh = showbar ? sh - bh : sh; |
|
| 1590 | + | #endif |
|
| 1577 | 1591 | ||
| 1578 | 1592 | /* update layout geometries */ |
|
| 1579 | 1593 | for(i = 0; i < LENGTH(layouts); i++) |
|
| 1 | 1 | /* See LICENSE file for copyright and license details. */ |
|
| 2 | - | double mfact = MFACT; |
|
| 3 | 2 | int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh; |
|
| 4 | 3 | ||
| 5 | 4 | void setmfact(const char *arg); |
|
| 11 | 10 | setmfact(const char *arg) { |
|
| 12 | 11 | double d; |
|
| 13 | 12 | ||
| 14 | - | if(lt->arrange != tile) |
|
| 13 | + | if(!arg || lt->arrange != tile) |
|
| 15 | 14 | return; |
|
| 16 | - | if(!arg) |
|
| 17 | - | mfact = MFACT; |
|
| 18 | 15 | else { |
|
| 19 | 16 | d = strtod(arg, NULL); |
|
| 20 | 17 | if(arg[0] == '-' || arg[0] == '+') |
|
| 66 | 63 | ||
| 67 | 64 | void |
|
| 68 | 65 | tileresize(Client *c, int x, int y, int w, int h) { |
|
| 69 | - | resize(c, x, y, w, h, RESIZEHINTS); |
|
| 70 | - | if((RESIZEHINTS) && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w))) |
|
| 66 | + | resize(c, x, y, w, h, resizehints); |
|
| 67 | + | if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w))) |
|
| 71 | 68 | /* client doesn't accept size constraints */ |
|
| 72 | 69 | resize(c, x, y, w, h, False); |
|
| 73 | 70 | } |
|
| 89 | 86 | ||
| 90 | 87 | void |
|
| 91 | 88 | updatetilegeom(void) { |
|
| 89 | + | #ifdef TILEGEOM /* define your own if you are Xinerama user */ |
|
| 90 | + | TILEGEOM |
|
| 91 | + | #else |
|
| 92 | 92 | /* master area geometry */ |
|
| 93 | 93 | mx = wx; |
|
| 94 | 94 | my = wy; |
|
| 100 | 100 | ty = wy; |
|
| 101 | 101 | tw = ww - mw; |
|
| 102 | 102 | th = wh; |
|
| 103 | + | #endif |
|
| 103 | 104 | } |
|