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.

151 lines
3.9 KiB

19 years ago
19 years ago
19 years ago
19 years ago
19 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 "dwm.h"
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <unistd.h>
  9. #include <X11/keysym.h>
  10. /********** CUSTOMIZE **********/
  11. const char *term[] = {
  12. "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
  13. "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
  14. };
  15. const char *browse[] = { "firefox", NULL };
  16. const char *xlock[] = { "xlock", NULL };
  17. static Key key[] = {
  18. /* modifier key function arguments */
  19. { Mod1Mask, XK_Return, zoom, { 0 } },
  20. { Mod1Mask, XK_k, prevc, { 0 } },
  21. { Mod1Mask, XK_j, nextc, { 0 } },
  22. { Mod1Mask, XK_m, max, { 0 } },
  23. { Mod1Mask, XK_0, view, { .i = Tscratch } },
  24. { Mod1Mask, XK_1, view, { .i = Tdev } },
  25. { Mod1Mask, XK_2, view, { .i = Twww } },
  26. { Mod1Mask, XK_3, view, { .i = Twork } },
  27. { Mod1Mask, XK_space, tiling, { 0 } },
  28. { Mod1Mask|ShiftMask, XK_space, floating, { 0 } },
  29. { Mod1Mask|ShiftMask, XK_0, ttrunc, { .i = Tscratch } },
  30. { Mod1Mask|ShiftMask, XK_1, ttrunc, { .i = Tdev } },
  31. { Mod1Mask|ShiftMask, XK_2, ttrunc, { .i = Twww } },
  32. { Mod1Mask|ShiftMask, XK_3, ttrunc, { .i = Twork } },
  33. { Mod1Mask|ShiftMask, XK_c, ckill, { 0 } },
  34. { Mod1Mask|ShiftMask, XK_q, quit, { 0 } },
  35. { Mod1Mask|ShiftMask, XK_Return, spawn, { .argv = term } },
  36. { Mod1Mask|ShiftMask, XK_w, spawn, { .argv = browse } },
  37. { Mod1Mask|ShiftMask, XK_l, spawn, { .argv = xlock } },
  38. { ControlMask, XK_0, tappend, { .i = Tscratch } },
  39. { ControlMask, XK_1, tappend, { .i = Tdev } },
  40. { ControlMask, XK_2, tappend, { .i = Twww } },
  41. { ControlMask, XK_3, tappend, { .i = Twork } },
  42. };
  43. /********** CUSTOMIZE **********/
  44. void
  45. update_keys(void)
  46. {
  47. static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
  48. unsigned int i;
  49. KeyCode code;
  50. for(i = 0; i < len; i++) {
  51. code = XKeysymToKeycode(dpy, key[i].keysym);
  52. XUngrabKey(dpy, code, key[i].mod, root);
  53. XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
  54. }
  55. }
  56. void
  57. keypress(XEvent *e)
  58. {
  59. XKeyEvent *ev = &e->xkey;
  60. static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
  61. unsigned int i;
  62. KeySym keysym;
  63. keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
  64. for(i = 0; i < len; i++)
  65. if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
  66. if(key[i].func)
  67. key[i].func(&key[i].arg);
  68. return;
  69. }
  70. }
  71. #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
  72. #define MouseMask (ButtonMask | PointerMotionMask)
  73. void
  74. mresize(Client *c)
  75. {
  76. XEvent ev;
  77. int ocx, ocy;
  78. ocx = c->x;
  79. ocy = c->y;
  80. if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
  81. None, cursor[CurResize], CurrentTime) != GrabSuccess)
  82. return;
  83. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
  84. for(;;) {
  85. XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
  86. switch(ev.type) {
  87. default: break;
  88. case Expose:
  89. handler[Expose](&ev);
  90. break;
  91. case MotionNotify:
  92. XFlush(dpy);
  93. c->w = abs(ocx - ev.xmotion.x);
  94. c->h = abs(ocy - ev.xmotion.y);
  95. c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
  96. c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
  97. resize(c, True);
  98. break;
  99. case ButtonRelease:
  100. XUngrabPointer(dpy, CurrentTime);
  101. return;
  102. }
  103. }
  104. }
  105. void
  106. mmove(Client *c)
  107. {
  108. XEvent ev;
  109. int x1, y1, ocx, ocy, di;
  110. unsigned int dui;
  111. Window dummy;
  112. ocx = c->x;
  113. ocy = c->y;
  114. if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
  115. None, cursor[CurMove], CurrentTime) != GrabSuccess)
  116. return;
  117. XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
  118. for(;;) {
  119. XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
  120. switch (ev.type) {
  121. default: break;
  122. case Expose:
  123. handler[Expose](&ev);
  124. break;
  125. case MotionNotify:
  126. XFlush(dpy);
  127. c->x = ocx + (ev.xmotion.x - x1);
  128. c->y = ocy + (ev.xmotion.y - y1);
  129. resize(c, False);
  130. break;
  131. case ButtonRelease:
  132. XUngrabPointer(dpy, CurrentTime);
  133. return;
  134. }
  135. }
  136. }