diff options
Diffstat (limited to '')
| -rw-r--r-- | key.c (renamed from dev.c) | 169 |
1 files changed, 105 insertions, 64 deletions
| @@ -3,12 +3,23 @@ | |||
| 3 | * See LICENSE file for license details. | 3 | * See LICENSE file for license details. |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #include "dwm.h" | 6 | #include <fcntl.h> |
| 7 | 7 | #include <stdio.h> | |
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| 10 | #include <unistd.h> | 10 | #include <unistd.h> |
| 11 | #include <X11/keysym.h> | 11 | #include <X11/keysym.h> |
| 12 | #include <X11/Xatom.h> | ||
| 13 | |||
| 14 | #include "dwm.h" | ||
| 15 | |||
| 16 | static void ckill(Arg *arg); | ||
| 17 | static void nextc(Arg *arg); | ||
| 18 | static void prevc(Arg *arg); | ||
| 19 | static void max(Arg *arg); | ||
| 20 | static void ttrunc(Arg *arg); | ||
| 21 | static void tappend(Arg *arg); | ||
| 22 | static void zoom(Arg *arg); | ||
| 12 | 23 | ||
| 13 | /********** CUSTOMIZE **********/ | 24 | /********** CUSTOMIZE **********/ |
| 14 | 25 | ||
| @@ -19,7 +30,7 @@ const char *term[] = { | |||
| 19 | const char *browse[] = { "firefox", NULL }; | 30 | const char *browse[] = { "firefox", NULL }; |
| 20 | const char *xlock[] = { "xlock", NULL }; | 31 | const char *xlock[] = { "xlock", NULL }; |
| 21 | 32 | ||
| 22 | static Key key[] = { | 33 | Key key[] = { |
| 23 | /* modifier key function arguments */ | 34 | /* modifier key function arguments */ |
| 24 | { Mod1Mask, XK_Return, zoom, { 0 } }, | 35 | { Mod1Mask, XK_Return, zoom, { 0 } }, |
| 25 | { Mod1Mask, XK_k, prevc, { 0 } }, | 36 | { Mod1Mask, XK_k, prevc, { 0 } }, |
| @@ -49,7 +60,7 @@ static Key key[] = { | |||
| 49 | /********** CUSTOMIZE **********/ | 60 | /********** CUSTOMIZE **********/ |
| 50 | 61 | ||
| 51 | void | 62 | void |
| 52 | update_keys(void) | 63 | grabkeys() |
| 53 | { | 64 | { |
| 54 | static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; | 65 | static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; |
| 55 | unsigned int i; | 66 | unsigned int i; |
| @@ -58,7 +69,8 @@ update_keys(void) | |||
| 58 | for(i = 0; i < len; i++) { | 69 | for(i = 0; i < len; i++) { |
| 59 | code = XKeysymToKeycode(dpy, key[i].keysym); | 70 | code = XKeysymToKeycode(dpy, key[i].keysym); |
| 60 | XUngrabKey(dpy, code, key[i].mod, root); | 71 | XUngrabKey(dpy, code, key[i].mod, root); |
| 61 | XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync); | 72 | XGrabKey(dpy, code, key[i].mod, root, True, |
| 73 | GrabModeAsync, GrabModeAsync); | ||
| 62 | } | 74 | } |
| 63 | } | 75 | } |
| 64 | 76 | ||
| @@ -79,73 +91,102 @@ keypress(XEvent *e) | |||
| 79 | } | 91 | } |
| 80 | } | 92 | } |
| 81 | 93 | ||
| 82 | #define ButtonMask (ButtonPressMask | ButtonReleaseMask) | 94 | static void |
| 83 | #define MouseMask (ButtonMask | PointerMotionMask) | 95 | zoom(Arg *arg) |
| 96 | { | ||
| 97 | Client **l, *c; | ||
| 84 | 98 | ||
| 85 | void | 99 | if(!sel) |
| 86 | mresize(Client *c) | 100 | return; |
| 101 | |||
| 102 | if(sel == next(clients) && sel->next) { | ||
| 103 | if((c = next(sel->next))) | ||
| 104 | sel = c; | ||
| 105 | } | ||
| 106 | |||
| 107 | for(l = &clients; *l && *l != sel; l = &(*l)->next); | ||
| 108 | *l = sel->next; | ||
| 109 | |||
| 110 | sel->next = clients; /* pop */ | ||
| 111 | clients = sel; | ||
| 112 | arrange(NULL); | ||
| 113 | focus(sel); | ||
| 114 | } | ||
| 115 | |||
| 116 | static void | ||
| 117 | max(Arg *arg) | ||
| 87 | { | 118 | { |
| 88 | XEvent ev; | 119 | if(!sel) |
| 89 | int ocx, ocy; | 120 | return; |
| 121 | sel->x = sx; | ||
| 122 | sel->y = sy + bh; | ||
| 123 | sel->w = sw - 2 * sel->border; | ||
| 124 | sel->h = sh - 2 * sel->border - bh; | ||
| 125 | craise(sel); | ||
| 126 | resize(sel, False); | ||
| 127 | } | ||
| 90 | 128 | ||
| 91 | ocx = c->x; | 129 | static void |
| 92 | ocy = c->y; | 130 | tappend(Arg *arg) |
| 93 | if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, | 131 | { |
| 94 | None, cursor[CurResize], CurrentTime) != GrabSuccess) | 132 | if(!sel) |
| 95 | return; | 133 | return; |
| 96 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); | 134 | |
| 97 | for(;;) { | 135 | sel->tags[arg->i] = tags[arg->i]; |
| 98 | XMaskEvent(dpy, MouseMask | ExposureMask, &ev); | 136 | arrange(NULL); |
| 99 | switch(ev.type) { | 137 | } |
| 100 | default: break; | 138 | |
| 101 | case Expose: | 139 | static void |
| 102 | handler[Expose](&ev); | 140 | ttrunc(Arg *arg) |
| 103 | break; | 141 | { |
| 104 | case MotionNotify: | 142 | int i; |
| 105 | XFlush(dpy); | 143 | if(!sel) |
| 106 | c->w = abs(ocx - ev.xmotion.x); | 144 | return; |
| 107 | c->h = abs(ocy - ev.xmotion.y); | 145 | |
| 108 | c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; | 146 | for(i = 0; i < TLast; i++) |
| 109 | c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; | 147 | sel->tags[i] = NULL; |
| 110 | resize(c, True); | 148 | tappend(arg); |
| 111 | break; | 149 | } |
| 112 | case ButtonRelease: | 150 | |
| 113 | XUngrabPointer(dpy, CurrentTime); | 151 | static void |
| 114 | return; | 152 | prevc(Arg *arg) |
| 115 | } | 153 | { |
| 154 | Client *c; | ||
| 155 | |||
| 156 | if(!sel) | ||
| 157 | return; | ||
| 158 | |||
| 159 | if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) { | ||
| 160 | craise(c); | ||
| 161 | focus(c); | ||
| 116 | } | 162 | } |
| 117 | } | 163 | } |
| 118 | 164 | ||
| 119 | void | 165 | static void |
| 120 | mmove(Client *c) | 166 | nextc(Arg *arg) |
| 121 | { | 167 | { |
| 122 | XEvent ev; | 168 | Client *c; |
| 123 | int x1, y1, ocx, ocy, di; | 169 | |
| 124 | unsigned int dui; | 170 | if(!sel) |
| 125 | Window dummy; | ||
| 126 | |||
| 127 | ocx = c->x; | ||
| 128 | ocy = c->y; | ||
| 129 | if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, | ||
| 130 | None, cursor[CurMove], CurrentTime) != GrabSuccess) | ||
| 131 | return; | 171 | return; |
| 132 | XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); | 172 | |
| 133 | for(;;) { | 173 | if(!(c = next(sel->next))) |
| 134 | XMaskEvent(dpy, MouseMask | ExposureMask, &ev); | 174 | c = next(clients); |
| 135 | switch (ev.type) { | 175 | if(c) { |
| 136 | default: break; | 176 | craise(c); |
| 137 | case Expose: | 177 | c->revert = sel; |
| 138 | handler[Expose](&ev); | 178 | focus(c); |
| 139 | break; | ||
| 140 | case MotionNotify: | ||
| 141 | XFlush(dpy); | ||
| 142 | c->x = ocx + (ev.xmotion.x - x1); | ||
| 143 | c->y = ocy + (ev.xmotion.y - y1); | ||
| 144 | resize(c, False); | ||
| 145 | break; | ||
| 146 | case ButtonRelease: | ||
| 147 | XUngrabPointer(dpy, CurrentTime); | ||
| 148 | return; | ||
| 149 | } | ||
| 150 | } | 179 | } |
| 151 | } | 180 | } |
| 181 | |||
| 182 | static void | ||
| 183 | ckill(Arg *arg) | ||
| 184 | { | ||
| 185 | if(!sel) | ||
| 186 | return; | ||
| 187 | if(sel->proto & WM_PROTOCOL_DELWIN) | ||
| 188 | send_message(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]); | ||
| 189 | else | ||
| 190 | XKillClient(dpy, sel->win); | ||
| 191 | } | ||
| 192 | |||
