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.

154 lines
4.1 KiB

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