Mercurial > hg > index.fcgi > keynav-9pba
diff keynav.c @ 1:0d5dc7c29c78
fix tabbing
author | paulo@thepaulopc |
---|---|
date | Thu, 17 Jun 2010 00:50:35 -0700 |
parents | ab8a496afb67 |
children | 640c5e9ea6ad |
line diff
1.1 --- a/keynav.c Tue Sep 08 22:45:57 2009 -0700 1.2 +++ b/keynav.c Thu Jun 17 00:50:35 2010 -0700 1.3 @@ -27,497 +27,497 @@ 1.4 1.5 struct /* undo stack */ 1.6 { 1.7 - int x[N_UNDO]; 1.8 - int y[N_UNDO]; 1.9 - int w[N_UNDO]; 1.10 - int h[N_UNDO]; 1.11 - int ninegrid[N_UNDO]; 1.12 + int x[N_UNDO]; 1.13 + int y[N_UNDO]; 1.14 + int w[N_UNDO]; 1.15 + int h[N_UNDO]; 1.16 + int ninegrid[N_UNDO]; 1.17 } u; 1.18 1.19 void toggleninegrid() { 1.20 - if (ninegrid) 1.21 - ninegrid = 0; 1.22 - else 1.23 - ninegrid = 1; 1.24 + if (ninegrid) 1.25 + ninegrid = 0; 1.26 + else 1.27 + ninegrid = 1; 1.28 } 1.29 1.30 void stats(int hits, int moves) { 1.31 - allhits += hits; 1.32 - allmoves += moves; 1.33 - allclicks++; 1.34 - printf("hits=%d, moves=%d \n", hits, moves); 1.35 - printf("total hits=%d, total moves=%d, total clicks=%d, avg. hit/click=%.2f, avg. moves/click=%.2f \n", allhits, allmoves, allclicks, (float)allhits/(float)allclicks, (float)allmoves/(float)allclicks); 1.36 - fflush(stdout); fflush(stderr); // force buffers to write out 1.37 + allhits += hits; 1.38 + allmoves += moves; 1.39 + allclicks++; 1.40 + printf("hits=%d, moves=%d \n", hits, moves); 1.41 + printf("total hits=%d, total moves=%d, total clicks=%d, avg. hit/click=%.2f, avg. moves/click=%.2f \n", allhits, allmoves, allclicks, (float)allhits/(float)allclicks, (float)allmoves/(float)allclicks); 1.42 + fflush(stdout); fflush(stderr); // force buffers to write out 1.43 } 1.44 1.45 void grab(char *keyname, int mods) { 1.46 - int key; 1.47 - 1.48 - key = XKeysymToKeycode(dpy, XStringToKeysym(keyname)); 1.49 - XGrabKey(dpy, key, mods, root, False, 1.50 - GrabModeAsync, GrabModeAsync); 1.51 - XGrabKey(dpy, key, mods | CAPSLOCKMASK, root, False, 1.52 - GrabModeAsync, GrabModeAsync); 1.53 - XGrabKey(dpy, key, mods | NUMLOCKMASK, root, False, 1.54 - GrabModeAsync, GrabModeAsync); 1.55 - XGrabKey(dpy, key, mods | CAPSLOCKMASK | NUMLOCKMASK, root, False, 1.56 - GrabModeAsync, GrabModeAsync); 1.57 + int key; 1.58 + 1.59 + key = XKeysymToKeycode(dpy, XStringToKeysym(keyname)); 1.60 + XGrabKey(dpy, key, mods, root, False, 1.61 + GrabModeAsync, GrabModeAsync); 1.62 + XGrabKey(dpy, key, mods | CAPSLOCKMASK, root, False, 1.63 + GrabModeAsync, GrabModeAsync); 1.64 + XGrabKey(dpy, key, mods | NUMLOCKMASK, root, False, 1.65 + GrabModeAsync, GrabModeAsync); 1.66 + XGrabKey(dpy, key, mods | CAPSLOCKMASK | NUMLOCKMASK, root, False, 1.67 + GrabModeAsync, GrabModeAsync); 1.68 } 1.69 1.70 void ungrab(char *keyname, int mod) { 1.71 - int key; 1.72 - 1.73 - key = XKeysymToKeycode(dpy, XStringToKeysym(keyname)); 1.74 - XUngrabKey(dpy, key, mod, root); 1.75 - XUngrabKey(dpy, key, mod | CAPSLOCKMASK, root); 1.76 - XUngrabKey(dpy, key, mod | NUMLOCKMASK, root); 1.77 - XUngrabKey(dpy, key, mod | CAPSLOCKMASK | NUMLOCKMASK, root); 1.78 + int key; 1.79 + 1.80 + key = XKeysymToKeycode(dpy, XStringToKeysym(keyname)); 1.81 + XUngrabKey(dpy, key, mod, root); 1.82 + XUngrabKey(dpy, key, mod | CAPSLOCKMASK, root); 1.83 + XUngrabKey(dpy, key, mod | NUMLOCKMASK, root); 1.84 + XUngrabKey(dpy, key, mod | CAPSLOCKMASK | NUMLOCKMASK, root); 1.85 } 1.86 1.87 void buttondown(int i) { 1.88 - XTestFakeButtonEvent(dpy, i, True, 50); 1.89 + XTestFakeButtonEvent(dpy, i, True, 50); 1.90 } 1.91 1.92 void buttonup(int i) { 1.93 - XTestFakeButtonEvent(dpy, i, False, 50); 1.94 + XTestFakeButtonEvent(dpy, i, False, 50); 1.95 } 1.96 1.97 void warppointer(int x, int y, int w, int h) { 1.98 - XWarpPointer(dpy, None, root, 0, 0, 0, 0, x + w/2, y + h/2); 1.99 + XWarpPointer(dpy, None, root, 0, 0, 0, 0, x + w/2, y + h/2); 1.100 } 1.101 1.102 /* operations for undo */ 1.103 void undo_stack_push(int x, int y, int w, int h) { 1.104 - int i; 1.105 + int i; 1.106 1.107 - if (x >= 0 && y >= 0 && w > 0 && h > 0) { 1.108 - fprintf(stderr,"undo_stack_push success: @(%d,%d) #(%d,%d)\n", x, y, w, h); 1.109 - for (i=N_UNDO-1; i>0; i--) { 1.110 - u.x[i] = u.x[i-1]; 1.111 - u.y[i] = u.y[i-1]; 1.112 - u.w[i] = u.w[i-1]; 1.113 - u.h[i] = u.h[i-1]; 1.114 - u.ninegrid[i] = u.ninegrid[i-1]; 1.115 + if (x >= 0 && y >= 0 && w > 0 && h > 0) { 1.116 + fprintf(stderr,"undo_stack_push success: @(%d,%d) #(%d,%d)\n", x, y, w, h); 1.117 + for (i=N_UNDO-1; i>0; i--) { 1.118 + u.x[i] = u.x[i-1]; 1.119 + u.y[i] = u.y[i-1]; 1.120 + u.w[i] = u.w[i-1]; 1.121 + u.h[i] = u.h[i-1]; 1.122 + u.ninegrid[i] = u.ninegrid[i-1]; 1.123 + } 1.124 + u.x[0] = x; 1.125 + u.y[0] = y; 1.126 + u.w[0] = w; 1.127 + u.h[0] = h; 1.128 + u.ninegrid[0] = ninegrid; 1.129 } 1.130 - u.x[0] = x; 1.131 - u.y[0] = y; 1.132 - u.w[0] = w; 1.133 - u.h[0] = h; 1.134 - u.ninegrid[0] = ninegrid; 1.135 - } 1.136 } 1.137 1.138 int undo_stack_pop(int *x, int *y, int *w, int *h, int *ninegrid) { 1.139 - int i; 1.140 - int ret = 0; 1.141 + int i; 1.142 + int ret = 0; 1.143 + 1.144 + int rx = u.x[0]; 1.145 + int ry = u.y[0]; 1.146 + int rw = u.w[0]; 1.147 + int rh = u.h[0]; 1.148 + int rninegrid = u.ninegrid[0]; 1.149 1.150 - int rx = u.x[0]; 1.151 - int ry = u.y[0]; 1.152 - int rw = u.w[0]; 1.153 - int rh = u.h[0]; 1.154 - int rninegrid = u.ninegrid[0]; 1.155 - 1.156 - if (rx >= 0 && ry >= 0 && rw > 0 && rh > 0) { 1.157 - fprintf(stderr,"undo_stack_pop success: @(%d,%d) #(%d,%d)\n", *x, *y, *w, *h); 1.158 - ret = 1; // return success 1.159 - for (i=0; i<N_UNDO-1; i++) { 1.160 - u.x[i] = u.x[i+1]; 1.161 - u.y[i] = u.y[i+1]; 1.162 - u.w[i] = u.w[i+1]; 1.163 - u.h[i] = u.h[i+1]; 1.164 - u.ninegrid[i] = u.ninegrid[i+1]; 1.165 + if (rx >= 0 && ry >= 0 && rw > 0 && rh > 0) { 1.166 + fprintf(stderr,"undo_stack_pop success: @(%d,%d) #(%d,%d)\n", *x, *y, *w, *h); 1.167 + ret = 1; // return success 1.168 + for (i=0; i<N_UNDO-1; i++) { 1.169 + u.x[i] = u.x[i+1]; 1.170 + u.y[i] = u.y[i+1]; 1.171 + u.w[i] = u.w[i+1]; 1.172 + u.h[i] = u.h[i+1]; 1.173 + u.ninegrid[i] = u.ninegrid[i+1]; 1.174 + } 1.175 + u.x[N_UNDO-1] = -1; 1.176 + u.y[N_UNDO-1] = -1; 1.177 + u.w[N_UNDO-1] = -1; 1.178 + u.h[N_UNDO-1] = -1; 1.179 + u.ninegrid[N_UNDO-1] = -1; 1.180 + *x = rx; 1.181 + *y = ry; 1.182 + *w = rw; 1.183 + *h = rh; 1.184 + *ninegrid = rninegrid; 1.185 } 1.186 - u.x[N_UNDO-1] = -1; 1.187 - u.y[N_UNDO-1] = -1; 1.188 - u.w[N_UNDO-1] = -1; 1.189 - u.h[N_UNDO-1] = -1; 1.190 - u.ninegrid[N_UNDO-1] = -1; 1.191 - *x = rx; 1.192 - *y = ry; 1.193 - *w = rw; 1.194 - *h = rh; 1.195 - *ninegrid = rninegrid; 1.196 - } 1.197 - return ret; 1.198 + return ret; 1.199 } 1.200 1.201 void undo_stack_reset() { 1.202 - int i; 1.203 + int i; 1.204 1.205 - for (i=0; i<N_UNDO; i++) { 1.206 - u.x[i] = -1; 1.207 - u.y[i] = -1; 1.208 - u.w[i] = -1; 1.209 - u.h[i] = -1; 1.210 - } 1.211 + for (i=0; i<N_UNDO; i++) { 1.212 + u.x[i] = -1; 1.213 + u.y[i] = -1; 1.214 + u.w[i] = -1; 1.215 + u.h[i] = -1; 1.216 + } 1.217 } 1.218 /* =-=-=-=-=-= */ 1.219 1.220 int chk_keysym(int keysym, char *str) { 1.221 - int ret = 0; 1.222 + int ret = 0; 1.223 1.224 - if (XStringToKeysym(str) == keysym) 1.225 - ret = 1; 1.226 + if (XStringToKeysym(str) == keysym) 1.227 + ret = 1; 1.228 1.229 - return ret; 1.230 + return ret; 1.231 } 1.232 1.233 GC creategc(Window win) { 1.234 - GC gc; 1.235 - XGCValues values; 1.236 - 1.237 - gc = XCreateGC(dpy, win, 0, &values); 1.238 - XSetForeground(dpy, gc, BlackPixel(dpy, 0)); 1.239 - XSetBackground(dpy, gc, WhitePixel(dpy, 0)); 1.240 - XSetLineAttributes(dpy, gc, LINEWIDTH, LineSolid, CapButt, JoinBevel); 1.241 - XSetFillStyle(dpy, gc, FillSolid); 1.242 - 1.243 - return gc; 1.244 + GC gc; 1.245 + XGCValues values; 1.246 + 1.247 + gc = XCreateGC(dpy, win, 0, &values); 1.248 + XSetForeground(dpy, gc, BlackPixel(dpy, 0)); 1.249 + XSetBackground(dpy, gc, WhitePixel(dpy, 0)); 1.250 + XSetLineAttributes(dpy, gc, LINEWIDTH, LineSolid, CapButt, JoinBevel); 1.251 + XSetFillStyle(dpy, gc, FillSolid); 1.252 + 1.253 + return gc; 1.254 } 1.255 1.256 void drawquadrants(Window win, int w, int h) { 1.257 - GC gc; 1.258 - XRectangle clip[20]; 1.259 - int idx = 0; 1.260 - Colormap colormap; 1.261 - XColor color; 1.262 + GC gc; 1.263 + XRectangle clip[20]; 1.264 + int idx = 0; 1.265 + Colormap colormap; 1.266 + XColor color; 1.267 + 1.268 + gc = creategc(win); 1.269 + colormap = DefaultColormap(dpy, 0); 1.270 + 1.271 + if (drag) 1.272 + XAllocNamedColor(dpy, colormap, DRAG_COLOR, &color, &color); 1.273 + else 1.274 + XAllocNamedColor(dpy, colormap, NORM_COLOR, &color, &color); 1.275 + 1.276 + /*left*/ clip[idx].x = 0; clip[idx].y = 0; clip[idx].width = BORDER; clip[idx].height = h; 1.277 + idx++; 1.278 + /*right*/ clip[idx].x = w-BORDER; clip[idx].y = 0; clip[idx].width = BORDER; clip[idx].height = h; 1.279 + idx++; 1.280 + /*top*/ clip[idx].x = 0; clip[idx].y = 0; clip[idx].width = w; clip[idx].height = BORDER; 1.281 + idx++; 1.282 + /*bottom*/ clip[idx].x = 0; clip[idx].y = h-BORDER; clip[idx].width = w; clip[idx].height = BORDER; 1.283 + idx++; 1.284 + 1.285 + if (ninegrid) { 1.286 + /*1st horiz*/ 1.287 + clip[idx].x = 0; clip[idx].y = h/3 - BORDER/2; 1.288 + clip[idx].width = w; clip[idx].height = BORDER; 1.289 + idx++; 1.290 + /*2nd horiz*/ 1.291 + clip[idx].x = 0; clip[idx].y = h*2/3 - BORDER/2; 1.292 + clip[idx].width = w; clip[idx].height = BORDER; 1.293 + idx++; 1.294 + /*1st vert*/ 1.295 + clip[idx].x = w/3 - BORDER/2; clip[idx].y = 0; 1.296 + clip[idx].width = BORDER; clip[idx].height = h; 1.297 + idx++; 1.298 + /*2nd vert*/ 1.299 + clip[idx].x = w*2/3 - BORDER/2; clip[idx].y = 0; 1.300 + clip[idx].width = BORDER; clip[idx].height = h; 1.301 + idx++; 1.302 + } else { 1.303 + /*horiz*/ 1.304 + clip[idx].x = 0; clip[idx].y = h/2 - BORDER/2; 1.305 + clip[idx].width = w; clip[idx].height = BORDER; 1.306 + idx++; 1.307 + /*vert*/ 1.308 + clip[idx].x = w/2 - BORDER/2; clip[idx].y = 0; 1.309 + clip[idx].width = BORDER; clip[idx].height = h; 1.310 + idx++; 1.311 + } 1.312 1.313 - gc = creategc(win); 1.314 - colormap = DefaultColormap(dpy, 0); 1.315 + XShapeCombineRectangles(dpy, win, ShapeBounding, 0, 0, clip, idx, ShapeSet, 0); 1.316 + 1.317 + XFillRectangle(dpy, win, gc, 0, 0, w, h); 1.318 + 1.319 + XSetForeground(dpy, gc, color.pixel); 1.320 + XDrawLine(dpy, win, gc, BORDER - PEN, BORDER - PEN, w - PEN, BORDER - PEN); //top line 1.321 + XDrawLine(dpy, win, gc, BORDER - PEN, h - PEN, w - PEN, h - PEN); //bottom line 1.322 + XDrawLine(dpy, win, gc, BORDER - PEN, BORDER - PEN, BORDER - PEN, h - PEN); //left line 1.323 + XDrawLine(dpy, win, gc, w - PEN, BORDER - PEN, w - PEN, h - PEN); //left line 1.324 1.325 - if (drag) 1.326 - XAllocNamedColor(dpy, colormap, DRAG_COLOR, &color, &color); 1.327 - else 1.328 - XAllocNamedColor(dpy, colormap, NORM_COLOR, &color, &color); 1.329 + if (ninegrid) { 1.330 + XDrawLine(dpy, win, gc, w/3, 0, w/3, h); // 1st vert line 1.331 + XDrawLine(dpy, win, gc, w*2/3, 0, w*2/3, h); // 2nd vert line 1.332 + XDrawLine(dpy, win, gc, 0, h/3, w, h/3); // 1st horiz line 1.333 + XDrawLine(dpy, win, gc, 0, h*2/3, w, h*2/3); // 2nd horiz line 1.334 + } else { 1.335 + XDrawLine(dpy, win, gc, w/2, 0, w/2, h); // vert line 1.336 + XDrawLine(dpy, win, gc, 0, h/2, w, h/2); // horiz line 1.337 + } 1.338 1.339 - /*left*/ clip[idx].x = 0; clip[idx].y = 0; clip[idx].width = BORDER; clip[idx].height = h; 1.340 - idx++; 1.341 - /*right*/ clip[idx].x = w-BORDER; clip[idx].y = 0; clip[idx].width = BORDER; clip[idx].height = h; 1.342 - idx++; 1.343 - /*top*/ clip[idx].x = 0; clip[idx].y = 0; clip[idx].width = w; clip[idx].height = BORDER; 1.344 - idx++; 1.345 - /*bottom*/ clip[idx].x = 0; clip[idx].y = h-BORDER; clip[idx].width = w; clip[idx].height = BORDER; 1.346 - idx++; 1.347 - 1.348 - if (ninegrid) { 1.349 - /*1st horiz*/ 1.350 - clip[idx].x = 0; clip[idx].y = h/3 - BORDER/2; 1.351 - clip[idx].width = w; clip[idx].height = BORDER; 1.352 - idx++; 1.353 - /*2nd horiz*/ 1.354 - clip[idx].x = 0; clip[idx].y = h*2/3 - BORDER/2; 1.355 - clip[idx].width = w; clip[idx].height = BORDER; 1.356 - idx++; 1.357 - /*1st vert*/ 1.358 - clip[idx].x = w/3 - BORDER/2; clip[idx].y = 0; 1.359 - clip[idx].width = BORDER; clip[idx].height = h; 1.360 - idx++; 1.361 - /*2nd vert*/ 1.362 - clip[idx].x = w*2/3 - BORDER/2; clip[idx].y = 0; 1.363 - clip[idx].width = BORDER; clip[idx].height = h; 1.364 - idx++; 1.365 - } else { 1.366 - /*horiz*/ 1.367 - clip[idx].x = 0; clip[idx].y = h/2 - BORDER/2; 1.368 - clip[idx].width = w; clip[idx].height = BORDER; 1.369 - idx++; 1.370 - /*vert*/ 1.371 - clip[idx].x = w/2 - BORDER/2; clip[idx].y = 0; 1.372 - clip[idx].width = BORDER; clip[idx].height = h; 1.373 - idx++; 1.374 - } 1.375 - 1.376 - XShapeCombineRectangles(dpy, win, ShapeBounding, 0, 0, clip, idx, ShapeSet, 0); 1.377 - 1.378 - XFillRectangle(dpy, win, gc, 0, 0, w, h); 1.379 - 1.380 - XSetForeground(dpy, gc, color.pixel); 1.381 - XDrawLine(dpy, win, gc, BORDER - PEN, BORDER - PEN, w - PEN, BORDER - PEN); //top line 1.382 - XDrawLine(dpy, win, gc, BORDER - PEN, h - PEN, w - PEN, h - PEN); //bottom line 1.383 - XDrawLine(dpy, win, gc, BORDER - PEN, BORDER - PEN, BORDER - PEN, h - PEN); //left line 1.384 - XDrawLine(dpy, win, gc, w - PEN, BORDER - PEN, w - PEN, h - PEN); //left line 1.385 - 1.386 - if (ninegrid) { 1.387 - XDrawLine(dpy, win, gc, w/3, 0, w/3, h); // 1st vert line 1.388 - XDrawLine(dpy, win, gc, w*2/3, 0, w*2/3, h); // 2nd vert line 1.389 - XDrawLine(dpy, win, gc, 0, h/3, w, h/3); // 1st horiz line 1.390 - XDrawLine(dpy, win, gc, 0, h*2/3, w, h*2/3); // 2nd horiz line 1.391 - } else { 1.392 - XDrawLine(dpy, win, gc, w/2, 0, w/2, h); // vert line 1.393 - XDrawLine(dpy, win, gc, 0, h/2, w, h/2); // horiz line 1.394 - } 1.395 - 1.396 - XFlush(dpy); 1.397 + XFlush(dpy); 1.398 } 1.399 1.400 int handlekey(int keysym, int mod, int *moves, int *x, int *y, int *w, int *h) { 1.401 - int ret = 1; 1.402 - int ox = *x; 1.403 - int oy = *y; 1.404 - int ow = *w; 1.405 - int oh = *h;; 1.406 + int ret = 1; 1.407 + int ox = *x; 1.408 + int oy = *y; 1.409 + int ow = *w; 1.410 + int oh = *h;; 1.411 1.412 - if (mod & SHIFTMASK || mod & SHIFTMASK & NUMLOCKMASK || mod & SHIFTMASK & CAPSLOCKMASK || mod & SHIFTMASK & CAPSLOCKMASK & NUMLOCKMASK) { 1.413 - if (chk_keysym(keysym, KEY_CENTER)) 1.414 - toggleninegrid(); 1.415 - if (chk_keysym(keysym, KEY_LEFT) || chk_keysym(keysym, KEY_UPLEFT) || chk_keysym(keysym, KEY_DOWNLEFT)) { 1.416 - if (*x > 0) *x -= *w; // shift left 1.417 - } 1.418 - if (chk_keysym(keysym, KEY_DOWN) || chk_keysym(keysym, KEY_DOWNLEFT) || chk_keysym(keysym, KEY_DOWNRIGHT)) { 1.419 - if ((*y + *h) < attr.height) *y += *h; // shift down 1.420 - } 1.421 - if (chk_keysym(keysym, KEY_UP) || chk_keysym(keysym, KEY_UPLEFT) || chk_keysym(keysym, KEY_UPRIGHT)) { 1.422 - if (*y > 0) *y -= *h; // shift up 1.423 - } 1.424 - if (chk_keysym(keysym, KEY_RIGHT) || chk_keysym(keysym, KEY_UPRIGHT) || chk_keysym(keysym, KEY_DOWNRIGHT)) { 1.425 - if ((*x + *w) < attr.width) *x += *w; // shift right 1.426 + if (mod & SHIFTMASK || mod & SHIFTMASK & NUMLOCKMASK || mod & SHIFTMASK & CAPSLOCKMASK || mod & SHIFTMASK & CAPSLOCKMASK & NUMLOCKMASK) { 1.427 + if (chk_keysym(keysym, KEY_CENTER)) 1.428 + toggleninegrid(); 1.429 + if (chk_keysym(keysym, KEY_LEFT) || chk_keysym(keysym, KEY_UPLEFT) || chk_keysym(keysym, KEY_DOWNLEFT)) { 1.430 + if (*x > 0) *x -= *w; // shift left 1.431 + } 1.432 + if (chk_keysym(keysym, KEY_DOWN) || chk_keysym(keysym, KEY_DOWNLEFT) || chk_keysym(keysym, KEY_DOWNRIGHT)) { 1.433 + if ((*y + *h) < attr.height) *y += *h; // shift down 1.434 + } 1.435 + if (chk_keysym(keysym, KEY_UP) || chk_keysym(keysym, KEY_UPLEFT) || chk_keysym(keysym, KEY_UPRIGHT)) { 1.436 + if (*y > 0) *y -= *h; // shift up 1.437 + } 1.438 + if (chk_keysym(keysym, KEY_RIGHT) || chk_keysym(keysym, KEY_UPRIGHT) || chk_keysym(keysym, KEY_DOWNRIGHT)) { 1.439 + if ((*x + *w) < attr.width) *x += *w; // shift right 1.440 + } 1.441 + } else { 1.442 + if (ninegrid) { 1.443 + if (chk_keysym(keysym, KEY_UPLEFT)) { 1.444 + *w /= 3; *h /= 3; // split upper left 1.445 + } else if (chk_keysym(keysym, KEY_UP)) { 1.446 + *w /= 3; *h /= 3; // split up 1.447 + *x += *w; 1.448 + } else if (chk_keysym(keysym, KEY_UPRIGHT)) { 1.449 + *w /= 3; *h /= 3; // split upper right 1.450 + *x += *w * 2; 1.451 + } else if (chk_keysym(keysym, KEY_LEFT)) { 1.452 + *w /= 3; *h /= 3; // split left 1.453 + *y += *h; 1.454 + } else if (chk_keysym(keysym, KEY_CENTER)) { 1.455 + *w /= 3; *h /= 3; // split center 1.456 + *x += *w; *y += *h; 1.457 + } else if (chk_keysym(keysym, KEY_RIGHT)) { 1.458 + *w /= 3; *h /= 3; // split right 1.459 + *x += *w * 2; *y += *h; 1.460 + } else if (chk_keysym(keysym, KEY_DOWNLEFT)) { 1.461 + *w /= 3; *h /= 3; // split bottom left 1.462 + *y += *h * 2; 1.463 + } else if (chk_keysym(keysym, KEY_DOWN)) { 1.464 + *w /= 3; *h /= 3; // split down 1.465 + *x += *w; *y += *h * 2; 1.466 + } else if (chk_keysym(keysym, KEY_DOWNRIGHT)) { 1.467 + *w /= 3; *h /= 3; // split bottom right 1.468 + *x += *w * 2; *y += *h * 2; 1.469 + } 1.470 + } else { 1.471 + if (chk_keysym(keysym, KEY_LEFT) || chk_keysym(keysym, KEY_UPLEFT) || chk_keysym(keysym, KEY_DOWNLEFT)) { 1.472 + *w /= 2; // split left 1.473 + } 1.474 + if (chk_keysym(keysym, KEY_DOWN) || chk_keysym(keysym, KEY_DOWNLEFT) || chk_keysym(keysym, KEY_DOWNRIGHT)) { 1.475 + *h /= 2; // split down 1.476 + *y += *h; 1.477 + } 1.478 + if (chk_keysym(keysym, KEY_UP) || chk_keysym(keysym, KEY_UPLEFT) || chk_keysym(keysym, KEY_UPRIGHT)) { 1.479 + *h /= 2; // split up 1.480 + } 1.481 + if (chk_keysym(keysym, KEY_RIGHT) || chk_keysym(keysym, KEY_UPRIGHT) || chk_keysym(keysym, KEY_DOWNRIGHT)) { 1.482 + *w /= 2; // split right 1.483 + *x += *w; 1.484 + } 1.485 + } 1.486 } 1.487 - } else { 1.488 - if (ninegrid) { 1.489 - if (chk_keysym(keysym, KEY_UPLEFT)) { 1.490 - *w /= 3; *h /= 3; // split upper left 1.491 - } else if (chk_keysym(keysym, KEY_UP)) { 1.492 - *w /= 3; *h /= 3; // split up 1.493 - *x += *w; 1.494 - } else if (chk_keysym(keysym, KEY_UPRIGHT)) { 1.495 - *w /= 3; *h /= 3; // split upper right 1.496 - *x += *w * 2; 1.497 - } else if (chk_keysym(keysym, KEY_LEFT)) { 1.498 - *w /= 3; *h /= 3; // split left 1.499 - *y += *h; 1.500 - } else if (chk_keysym(keysym, KEY_CENTER)) { 1.501 - *w /= 3; *h /= 3; // split center 1.502 - *x += *w; *y += *h; 1.503 - } else if (chk_keysym(keysym, KEY_RIGHT)) { 1.504 - *w /= 3; *h /= 3; // split right 1.505 - *x += *w * 2; *y += *h; 1.506 - } else if (chk_keysym(keysym, KEY_DOWNLEFT)) { 1.507 - *w /= 3; *h /= 3; // split bottom left 1.508 - *y += *h * 2; 1.509 - } else if (chk_keysym(keysym, KEY_DOWN)) { 1.510 - *w /= 3; *h /= 3; // split down 1.511 - *x += *w; *y += *h * 2; 1.512 - } else if (chk_keysym(keysym, KEY_DOWNRIGHT)) { 1.513 - *w /= 3; *h /= 3; // split bottom right 1.514 - *x += *w * 2; *y += *h * 2; 1.515 - } 1.516 - } else { 1.517 - if (chk_keysym(keysym, KEY_LEFT) || chk_keysym(keysym, KEY_UPLEFT) || chk_keysym(keysym, KEY_DOWNLEFT)) { 1.518 - *w /= 2; // split left 1.519 - } 1.520 - if (chk_keysym(keysym, KEY_DOWN) || chk_keysym(keysym, KEY_DOWNLEFT) || chk_keysym(keysym, KEY_DOWNRIGHT)) { 1.521 - *h /= 2; // split down 1.522 - *y += *h; 1.523 - } 1.524 - if (chk_keysym(keysym, KEY_UP) || chk_keysym(keysym, KEY_UPLEFT) || chk_keysym(keysym, KEY_UPRIGHT)) { 1.525 - *h /= 2; // split up 1.526 - } 1.527 - if (chk_keysym(keysym, KEY_RIGHT) || chk_keysym(keysym, KEY_UPRIGHT) || chk_keysym(keysym, KEY_DOWNRIGHT)) { 1.528 - *w /= 2; // split right 1.529 - *x += *w; 1.530 - } 1.531 + 1.532 + if (ox != *x || oy != *y || ow != *w || oh != *h) { 1.533 + undo_stack_push(ox, oy, ow, oh); 1.534 + *moves += 1; 1.535 } 1.536 - } 1.537 + else if (chk_keysym(keysym, KEY_UNDO)) { 1.538 + int i, j; 1.539 1.540 - if (ox != *x || oy != *y || ow != *w || oh != *h) { 1.541 - undo_stack_push(ox, oy, ow, oh); 1.542 - *moves += 1; 1.543 - } 1.544 - else if (chk_keysym(keysym, KEY_UNDO)) { 1.545 - int i, j; 1.546 + if (mod & SHIFTMASK) j = 0; 1.547 + else j = SHIFT_N_UNDO-1; 1.548 1.549 - if (mod & SHIFTMASK) j = 0; 1.550 - else j = SHIFT_N_UNDO-1; 1.551 + for (i=j; i<SHIFT_N_UNDO; i++) { 1.552 + undo_stack_pop(x, y, w, h, &ninegrid); 1.553 + *moves -= 1; 1.554 + } 1.555 + ret = 2; 1.556 + } 1.557 1.558 - for (i=j; i<SHIFT_N_UNDO; i++) { 1.559 - undo_stack_pop(x, y, w, h, &ninegrid); 1.560 - *moves -= 1; 1.561 + if (*w < 1 || *h < 1) { 1.562 + fprintf(stderr,"OOPS. Area too small. Giving up :(\n"); 1.563 + return 0; 1.564 } 1.565 - ret = 2; 1.566 - } 1.567 1.568 - if (*w < 1 || *h < 1) { 1.569 - fprintf(stderr,"OOPS. Area too small. Giving up :(\n"); 1.570 - return 0; 1.571 - } 1.572 - 1.573 - if (drag && !(mod & WARPMASK) || !drag && (mod & WARPMASK)) 1.574 - warppointer(*x, *y, *w, *h); 1.575 - 1.576 - fprintf(stderr,"Box: @(%d,%d) #(%d,%d)\n", *x, *y, *w, *h); 1.577 - 1.578 - return ret; 1.579 + if (drag && !(mod & WARPMASK) || !drag && (mod & WARPMASK)) 1.580 + warppointer(*x, *y, *w, *h); 1.581 + 1.582 + fprintf(stderr,"Box: @(%d,%d) #(%d,%d)\n", *x, *y, *w, *h); 1.583 + 1.584 + return ret; 1.585 } 1.586 1.587 void startmousekey(int from_undo) { 1.588 - int keysym; 1.589 - int done = 0; 1.590 - int x,y,w,h; 1.591 - int warp = 0; 1.592 - int click = 0; 1.593 - int k, hits, moves; 1.594 - int mod; 1.595 + int keysym; 1.596 + int done = 0; 1.597 + int x,y,w,h; 1.598 + int warp = 0; 1.599 + int click = 0; 1.600 + int k, hits, moves; 1.601 + int mod; 1.602 + 1.603 + Window zone; 1.604 + 1.605 + // disable trigger keygrab 1.606 + ungrab(KEY_TRIGGER, TRIGGERMASK); 1.607 + ungrab(KEY_UNDO, TRIGGERMASK); 1.608 + 1.609 + // grab keyboard 1.610 + XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime); 1.611 + 1.612 + // init stuff 1.613 + hits = moves = 0; 1.614 + if (from_undo && undo_stack_pop(&x, &y, &w, &h, &ninegrid)); 1.615 + /* null -- only check for undo_stack_pop success */ 1.616 + else { 1.617 + undo_stack_reset(); 1.618 + if (ninegrid_default) 1.619 + ninegrid = 1; 1.620 + x = y = 0; 1.621 + w = attr.width; 1.622 + h = attr.height; 1.623 + } 1.624 1.625 - Window zone; 1.626 + zone = XCreateSimpleWindow(dpy, root, x, y, w, h, 1, BlackPixel(dpy, 0), WhitePixel(dpy, 0)); 1.627 + 1.628 + { /* Tell the window manager not to manage us */ 1.629 + unsigned long valuemask; 1.630 + XSetWindowAttributes winattr; 1.631 + winattr.override_redirect = 1; 1.632 + XChangeWindowAttributes(dpy, zone, CWOverrideRedirect, &winattr); 1.633 + } 1.634 1.635 - // disable trigger keygrab 1.636 - ungrab(KEY_TRIGGER, TRIGGERMASK); 1.637 - ungrab(KEY_UNDO, TRIGGERMASK); 1.638 - 1.639 - // grab keyboard 1.640 - XGrabKeyboard(dpy, root, False, GrabModeAsync, GrabModeAsync, CurrentTime); 1.641 - 1.642 - // init stuff 1.643 - hits = moves = 0; 1.644 - if (from_undo && undo_stack_pop(&x, &y, &w, &h, &ninegrid)); 1.645 - /* null -- only check for undo_stack_pop success */ 1.646 - else { 1.647 - undo_stack_reset(); 1.648 - if (ninegrid_default) 1.649 - ninegrid = 1; 1.650 - x = y = 0; 1.651 - w = attr.width; 1.652 - h = attr.height; 1.653 - } 1.654 - 1.655 - zone = XCreateSimpleWindow(dpy, root, x, y, w, h, 1, BlackPixel(dpy, 0), WhitePixel(dpy, 0)); 1.656 - 1.657 - { /* Tell the window manager not to manage us */ 1.658 - unsigned long valuemask; 1.659 - XSetWindowAttributes winattr; 1.660 - winattr.override_redirect = 1; 1.661 - XChangeWindowAttributes(dpy, zone, CWOverrideRedirect, &winattr); 1.662 - } 1.663 - 1.664 - drawquadrants(zone, w, h); 1.665 - XMapWindow(dpy, zone); 1.666 - drawquadrants(zone, w, h); 1.667 - 1.668 - fprintf(stderr,"Starting quadrants...\n"); 1.669 - while (!done) { 1.670 - XEvent e; 1.671 - XNextEvent(dpy, &e); 1.672 - if (e.type == KeyPress) { 1.673 - keysym = XKeycodeToKeysym(dpy, e.xkey.keycode, 0); 1.674 - mod = e.xkey.state; 1.675 - if (chk_keysym(keysym, KEY_Q_CLICK)) { 1.676 - done++; 1.677 - click = 1; 1.678 - } else if (chk_keysym(keysym, KEY_Q_RCLICK)) { 1.679 - done++; 1.680 - click = 3; 1.681 - } else if (chk_keysym(keysym, KEY_QW_CLICK)) { 1.682 - done++; 1.683 - warp = 1; 1.684 - click = 1; 1.685 - } else if (chk_keysym(keysym, KEY_Q_MCLICK)) { 1.686 - done++; 1.687 - click = 2; 1.688 - } else if (chk_keysym(keysym, KEY_QW_RCLICK)) { 1.689 - done++; 1.690 - warp = 1; 1.691 - click = 3; 1.692 - } else if (chk_keysym(keysym, KEY_HIDE)) { 1.693 - done++; 1.694 - warp = 1; 1.695 - x = w; y = h; 1.696 - } else if (chk_keysym(keysym, KEY_ESCAPE)) { 1.697 - warp = 0; 1.698 - done++; 1.699 - } else if (!drag && chk_keysym(keysym, KEY_ONE)) { 1.700 - buttondown(1); 1.701 - buttonup(1); 1.702 - } else if (!drag && chk_keysym(keysym, KEY_TWO)) { 1.703 - buttondown(2); 1.704 - buttonup(2); 1.705 - } else if (!drag && chk_keysym(keysym, KEY_THREE)) { 1.706 - buttondown(3); 1.707 - buttonup(3); 1.708 - } else { 1.709 - if (k = handlekey(keysym, mod, &moves, &x, &y, &w, &h)) { 1.710 - if (ninegrid_default && ninegrid_n_switch && k < 2 && moves >= ninegrid_n_switch) 1.711 - ninegrid = 0; 1.712 - hits++; 1.713 - XMoveResizeWindow(dpy, zone, x, y, w, h); 1.714 - drawquadrants(zone, w, h); 1.715 - } else 1.716 - done++; 1.717 + drawquadrants(zone, w, h); 1.718 + XMapWindow(dpy, zone); 1.719 + drawquadrants(zone, w, h); 1.720 + 1.721 + fprintf(stderr,"Starting quadrants...\n"); 1.722 + while (!done) { 1.723 + XEvent e; 1.724 + XNextEvent(dpy, &e); 1.725 + if (e.type == KeyPress) { 1.726 + keysym = XKeycodeToKeysym(dpy, e.xkey.keycode, 0); 1.727 + mod = e.xkey.state; 1.728 + if (chk_keysym(keysym, KEY_Q_CLICK)) { 1.729 + done++; 1.730 + click = 1; 1.731 + } else if (chk_keysym(keysym, KEY_Q_RCLICK)) { 1.732 + done++; 1.733 + click = 3; 1.734 + } else if (chk_keysym(keysym, KEY_QW_CLICK)) { 1.735 + done++; 1.736 + warp = 1; 1.737 + click = 1; 1.738 + } else if (chk_keysym(keysym, KEY_Q_MCLICK)) { 1.739 + done++; 1.740 + click = 2; 1.741 + } else if (chk_keysym(keysym, KEY_QW_RCLICK)) { 1.742 + done++; 1.743 + warp = 1; 1.744 + click = 3; 1.745 + } else if (chk_keysym(keysym, KEY_HIDE)) { 1.746 + done++; 1.747 + warp = 1; 1.748 + x = w; y = h; 1.749 + } else if (chk_keysym(keysym, KEY_ESCAPE)) { 1.750 + warp = 0; 1.751 + done++; 1.752 + } else if (!drag && chk_keysym(keysym, KEY_ONE)) { 1.753 + buttondown(1); 1.754 + buttonup(1); 1.755 + } else if (!drag && chk_keysym(keysym, KEY_TWO)) { 1.756 + buttondown(2); 1.757 + buttonup(2); 1.758 + } else if (!drag && chk_keysym(keysym, KEY_THREE)) { 1.759 + buttondown(3); 1.760 + buttonup(3); 1.761 + } else { 1.762 + if (k = handlekey(keysym, mod, &moves, &x, &y, &w, &h)) { 1.763 + if (ninegrid_default && ninegrid_n_switch && k < 2 && moves >= ninegrid_n_switch) 1.764 + ninegrid = 0; 1.765 + hits++; 1.766 + XMoveResizeWindow(dpy, zone, x, y, w, h); 1.767 + drawquadrants(zone, w, h); 1.768 + } else 1.769 + done++; 1.770 } 1.771 } 1.772 - } 1.773 + } 1.774 1.775 - // end mouse key 1.776 - XUngrabKeyboard(dpy, CurrentTime); 1.777 - XDestroyWindow(dpy, zone); 1.778 - undo_stack_push(x, y, w, h); 1.779 + // end mouse key 1.780 + XUngrabKeyboard(dpy, CurrentTime); 1.781 + XDestroyWindow(dpy, zone); 1.782 + undo_stack_push(x, y, w, h); 1.783 1.784 - if (warp) 1.785 - warppointer(x, y, w, h); 1.786 - if (click == 1) { 1.787 - if (!drag) 1.788 - buttondown(1); 1.789 - if (mod & DRAGMASK && !drag) 1.790 - drag = 1; 1.791 - else if (mod & DRAGMASK) { 1.792 - buttonup(1); 1.793 - buttondown(1); 1.794 - } else { 1.795 - buttonup(1); 1.796 - drag = 0; 1.797 + if (warp) 1.798 + warppointer(x, y, w, h); 1.799 + if (click == 1) { 1.800 + if (!drag) 1.801 + buttondown(1); 1.802 + if (mod & DRAGMASK && !drag) 1.803 + drag = 1; 1.804 + else if (mod & DRAGMASK) { 1.805 + buttonup(1); 1.806 + buttondown(1); 1.807 + } else { 1.808 + buttonup(1); 1.809 + drag = 0; 1.810 + } 1.811 + } else if (click) { 1.812 + buttondown(click); 1.813 + buttonup(click); 1.814 + } 1.815 + 1.816 + if (click) stats(hits, moves); 1.817 + 1.818 + // loop back if in drag mode 1.819 + if (drag) { 1.820 + usleep(50); 1.821 + startmousekey(0); 1.822 } 1.823 - } else if (click) { 1.824 - buttondown(click); 1.825 - buttonup(click); 1.826 - } 1.827 1.828 - if (click) stats(hits, moves); 1.829 - 1.830 - // loop back if in drag mode 1.831 - if (drag) { 1.832 - usleep(50); 1.833 - startmousekey(0); 1.834 - } 1.835 - 1.836 - // re-enable trigger keygrabs 1.837 - grab(KEY_TRIGGER, TRIGGERMASK); 1.838 - grab(KEY_UNDO, TRIGGERMASK); 1.839 + // re-enable trigger keygrabs 1.840 + grab(KEY_TRIGGER, TRIGGERMASK); 1.841 + grab(KEY_UNDO, TRIGGERMASK); 1.842 } 1.843 1.844 int main(int argc, char **argv) { 1.845 - char *pcDisplay; 1.846 - 1.847 - if ((dpy = XOpenDisplay(pcDisplay = getenv("DISPLAY"))) == NULL) { 1.848 + char *pcDisplay; 1.849 + 1.850 + if ((dpy = XOpenDisplay(pcDisplay = getenv("DISPLAY"))) == NULL) { 1.851 fprintf(stderr,"Error: Can't open display: %s", pcDisplay); 1.852 exit(1); 1.853 - } 1.854 - fprintf(stderr,"Display: %s\n", pcDisplay); 1.855 + } 1.856 + fprintf(stderr,"Display: %s\n", pcDisplay); 1.857 1.858 - // parse options 1.859 - if (argc > 1) 1.860 - if (argv[1][0] && argv[1][0] == '-') 1.861 - if (argv[1][1] && argv[1][1] == 'n') { 1.862 - ninegrid_default = 1; 1.863 - fprintf(stderr,"nine-grid default mode \n"); 1.864 - if (argv[2]) { 1.865 - ninegrid_n_switch = atoi(argv[2]); 1.866 - fprintf(stderr,"nine-grid autoswitch num: %d \n", ninegrid_n_switch); 1.867 - } 1.868 - } 1.869 + // parse options 1.870 + if (argc > 1) 1.871 + if (argv[1][0] && argv[1][0] == '-') 1.872 + if (argv[1][1] && argv[1][1] == 'n') { 1.873 + ninegrid_default = 1; 1.874 + fprintf(stderr,"nine-grid default mode \n"); 1.875 + if (argv[2]) { 1.876 + ninegrid_n_switch = atoi(argv[2]); 1.877 + fprintf(stderr,"nine-grid autoswitch num: %d \n", ninegrid_n_switch); 1.878 + } 1.879 + } 1.880 1.881 - root = XDefaultRootWindow(dpy); 1.882 - XGetWindowAttributes(dpy, root, &attr); 1.883 - 1.884 - // these are the trigger keygrabs 1.885 - grab(KEY_TRIGGER, TRIGGERMASK); 1.886 - grab(KEY_UNDO, TRIGGERMASK); 1.887 - 1.888 - while (1) { 1.889 + root = XDefaultRootWindow(dpy); 1.890 + XGetWindowAttributes(dpy, root, &attr); 1.891 + 1.892 + // these are the trigger keygrabs 1.893 + grab(KEY_TRIGGER, TRIGGERMASK); 1.894 + grab(KEY_UNDO, TRIGGERMASK); 1.895 + 1.896 + while (1) { 1.897 XEvent e; 1.898 XNextEvent(dpy, &e); 1.899 if (e.type == KeyPress) 1.900 - if (chk_keysym(XKeycodeToKeysym(dpy, e.xkey.keycode, 0), KEY_UNDO)) 1.901 - startmousekey(1); 1.902 - else 1.903 - startmousekey(0); 1.904 - } 1.905 + if (chk_keysym(XKeycodeToKeysym(dpy, e.xkey.keycode, 0), KEY_UNDO)) 1.906 + startmousekey(1); 1.907 + else 1.908 + startmousekey(0); 1.909 + } 1.910 }