Configuration file for DWM on MacBook Air
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

323 lines
7.1 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*
  2. * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * See LICENSE file for license details.
  4. */
  5. #include <errno.h>
  6. #include <stdarg.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <unistd.h>
  11. #include <X11/cursorfont.h>
  12. #include <X11/Xatom.h>
  13. #include <X11/Xproto.h>
  14. #include "dwm.h"
  15. /********** CUSTOMIZE **********/
  16. char *tags[TLast] = {
  17. [Tscratch] = "scratch",
  18. [Tdev] = "dev",
  19. [Twww] = "www",
  20. [Twork] = "work",
  21. };
  22. /********** CUSTOMIZE **********/
  23. /* X structs */
  24. Display *dpy;
  25. Window root, barwin;
  26. Atom wm_atom[WMLast], net_atom[NetLast];
  27. Cursor cursor[CurLast];
  28. Bool running = True;
  29. Bool issel;
  30. int tsel = Tdev; /* default tag */
  31. int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
  32. char stext[1024];
  33. DC dc = {0};
  34. Client *clients = NULL;
  35. Client *sel = NULL;
  36. static Bool other_wm_running;
  37. static const char version[] =
  38. "dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
  39. static int (*x_error_handler) (Display *, XErrorEvent *);
  40. static void
  41. usage() { error("usage: dwm [-v]\n"); }
  42. static void
  43. scan_wins()
  44. {
  45. unsigned int i, num;
  46. Window *wins;
  47. XWindowAttributes wa;
  48. Window d1, d2;
  49. if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
  50. for(i = 0; i < num; i++) {
  51. if(!XGetWindowAttributes(dpy, wins[i], &wa))
  52. continue;
  53. if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
  54. continue;
  55. if(wa.map_state == IsViewable)
  56. manage(wins[i], &wa);
  57. }
  58. }
  59. if(wins)
  60. XFree(wins);
  61. }
  62. static int
  63. win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
  64. {
  65. Atom real;
  66. int format;
  67. unsigned long res, extra;
  68. int status;
  69. status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
  70. &res, &extra, prop);
  71. if(status != Success || *prop == 0) {
  72. return 0;
  73. }
  74. if(res == 0) {
  75. free((void *) *prop);
  76. }
  77. return res;
  78. }
  79. int
  80. win_proto(Window w)
  81. {
  82. unsigned char *protocols;
  83. long res;
  84. int protos = 0;
  85. int i;
  86. res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, &protocols);
  87. if(res <= 0) {
  88. return protos;
  89. }
  90. for(i = 0; i < res; i++) {
  91. if(protocols[i] == wm_atom[WMDelete])
  92. protos |= WM_PROTOCOL_DELWIN;
  93. }
  94. free((char *) protocols);
  95. return protos;
  96. }
  97. void
  98. send_message(Window w, Atom a, long value)
  99. {
  100. XEvent e;
  101. e.type = ClientMessage;
  102. e.xclient.window = w;
  103. e.xclient.message_type = a;
  104. e.xclient.format = 32;
  105. e.xclient.data.l[0] = value;
  106. e.xclient.data.l[1] = CurrentTime;
  107. XSendEvent(dpy, w, False, NoEventMask, &e);
  108. XFlush(dpy);
  109. }
  110. /*
  111. * There's no way to check accesses to destroyed windows, thus
  112. * those cases are ignored (especially on UnmapNotify's).
  113. * Other types of errors call Xlib's default error handler, which
  114. * calls exit().
  115. */
  116. int
  117. error_handler(Display *dpy, XErrorEvent *error)
  118. {
  119. if(error->error_code == BadWindow
  120. || (error->request_code == X_SetInputFocus
  121. && error->error_code == BadMatch)
  122. || (error->request_code == X_PolyText8
  123. && error->error_code == BadDrawable)
  124. || (error->request_code == X_PolyFillRectangle
  125. && error->error_code == BadDrawable)
  126. || (error->request_code == X_PolySegment
  127. && error->error_code == BadDrawable)
  128. || (error->request_code == X_ConfigureWindow
  129. && error->error_code == BadMatch)
  130. || (error->request_code == X_GrabKey
  131. && error->error_code == BadAccess))
  132. return 0;
  133. fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
  134. error->request_code, error->error_code);
  135. return x_error_handler(dpy, error); /* may call exit() */
  136. }
  137. /*
  138. * Startup Error handler to check if another window manager
  139. * is already running.
  140. */
  141. static int
  142. startup_error_handler(Display *dpy, XErrorEvent *error)
  143. {
  144. other_wm_running = True;
  145. return -1;
  146. }
  147. static void
  148. cleanup()
  149. {
  150. while(sel) {
  151. resize(sel, True);
  152. unmanage(sel);
  153. }
  154. XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
  155. }
  156. void
  157. quit(Arg *arg)
  158. {
  159. running = False;
  160. }
  161. int
  162. main(int argc, char *argv[])
  163. {
  164. int i, n;
  165. fd_set rd;
  166. XSetWindowAttributes wa;
  167. unsigned int mask;
  168. Window w;
  169. XEvent ev;
  170. for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
  171. switch (argv[i][1]) {
  172. case 'v':
  173. fprintf(stdout, "%s", version);
  174. exit(0);
  175. break;
  176. default:
  177. usage();
  178. break;
  179. }
  180. }
  181. dpy = XOpenDisplay(0);
  182. if(!dpy)
  183. error("dwm: cannot connect X server\n");
  184. screen = DefaultScreen(dpy);
  185. root = RootWindow(dpy, screen);
  186. /* check if another WM is already running */
  187. other_wm_running = False;
  188. XSetErrorHandler(startup_error_handler);
  189. /* this causes an error if some other WM is running */
  190. XSelectInput(dpy, root, SubstructureRedirectMask);
  191. XFlush(dpy);
  192. if(other_wm_running)
  193. error("dwm: another window manager is already running\n");
  194. XSetErrorHandler(0);
  195. x_error_handler = XSetErrorHandler(error_handler);
  196. /* init atoms */
  197. wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
  198. wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  199. net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
  200. net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
  201. XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
  202. PropModeReplace, (unsigned char *) net_atom, NetLast);
  203. /* init cursors */
  204. cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
  205. cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
  206. cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
  207. update_keys();
  208. /* style */
  209. dc.bg = initcolor(BGCOLOR);
  210. dc.fg = initcolor(FGCOLOR);
  211. dc.border = initcolor(BORDERCOLOR);
  212. initfont(FONT);
  213. sx = sy = 0;
  214. sw = DisplayWidth(dpy, screen);
  215. sh = DisplayHeight(dpy, screen);
  216. mw = (sw * MASTERW) / 100;
  217. wa.override_redirect = 1;
  218. wa.background_pixmap = ParentRelative;
  219. wa.event_mask = ButtonPressMask | ExposureMask;
  220. bx = by = 0;
  221. bw = sw;
  222. dc.h = bh = dc.font.height + 4;
  223. barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
  224. CopyFromParent, DefaultVisual(dpy, screen),
  225. CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
  226. XDefineCursor(dpy, barwin, cursor[CurNormal]);
  227. XMapRaised(dpy, barwin);
  228. dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
  229. dc.gc = XCreateGC(dpy, root, 0, 0);
  230. draw_bar();
  231. issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
  232. wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
  233. | LeaveWindowMask;
  234. wa.cursor = cursor[CurNormal];
  235. XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
  236. strcpy(stext, "dwm-"VERSION);
  237. scan_wins();
  238. /* main event loop, reads status text from stdin as well */
  239. Mainloop:
  240. while(running) {
  241. FD_ZERO(&rd);
  242. FD_SET(STDIN_FILENO, &rd);
  243. FD_SET(ConnectionNumber(dpy), &rd);
  244. i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0);
  245. if(i == -1 && errno == EINTR)
  246. continue;
  247. if(i < 0)
  248. error("select failed\n");
  249. else if(i > 0) {
  250. if(FD_ISSET(ConnectionNumber(dpy), &rd)) {
  251. while(XPending(dpy)) {
  252. XNextEvent(dpy, &ev);
  253. if(handler[ev.type])
  254. (handler[ev.type])(&ev); /* call handler */
  255. }
  256. }
  257. if(FD_ISSET(STDIN_FILENO, &rd)) {
  258. i = n = 0;
  259. for(;;) {
  260. if((i = getchar()) == EOF) {
  261. stext[0] = 0;
  262. goto Mainloop;
  263. }
  264. if(i == '\n' || n >= sizeof(stext) - 1)
  265. break;
  266. stext[n++] = i;
  267. }
  268. stext[n] = 0;
  269. draw_bar();
  270. }
  271. }
  272. }
  273. cleanup();
  274. XCloseDisplay(dpy);
  275. return 0;
  276. }