diff options
author | bernd | 2007-04-27 18:08:14 +0000 |
---|---|---|
committer | bernd | 2007-04-27 18:08:14 +0000 |
commit | 7c8043d99252ee1f16a0c00c2712ed543d44cba1 (patch) | |
tree | 39d7c908b0bc8678cfa4708aef75550c9ddeee36 /grab.c | |
parent | e350df9a3778c6cb7c7ed92e108fc2c98958b798 (diff) | |
download | cwm-7c8043d99252ee1f16a0c00c2712ed543d44cba1.tar.gz |
Apply cwm-3-exec.diff from http://aon.iki.fi/cwm/. Document the new
key binding.
Diffstat (limited to '')
-rw-r--r-- | grab.c | 81 |
1 files changed, 80 insertions, 1 deletions
@@ -4,7 +4,7 @@ * Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org> * All rights reserved. * - * $Id: grab.c,v 1.1.1.1 2007/04/27 17:58:48 bernd Exp $ + * $Id: grab.c,v 1.2 2007/04/27 18:08:14 bernd Exp $ */ #include "headers.h" @@ -430,6 +430,85 @@ grab_label(struct client_ctx *cc) XUnmapWindow(G_dpy, sc->searchwin); } +#define ExecMask (KeyPressMask|ExposureMask) + +void +grab_exec(void) +{ + int x, y, dx, dy, fontheight, focusrevert, len; + char cmdstr[MAXPATHLEN]; + char dispstr[MAXPATHLEN + sizeof("exec>") - 1]; + char chr, str[2]; + enum ctltype ctl; + struct fontdesc *font = DefaultFont; + struct screen_ctx *sc = screen_current(); + XEvent e; + Window focuswin; + + cmdstr[0] = '\0'; + + xu_ptr_getpos(sc->rootwin, &x, &y); + + dy = fontheight = font_ascent(font) + font_descent(font) + 1; + dx = font_width(font, "exec>", 5); + + XMoveResizeWindow(G_dpy, sc->searchwin, x, y, dx, dy); + XSelectInput(G_dpy, sc->searchwin, ExecMask); + XMapRaised(G_dpy, sc->searchwin); + + XGetInputFocus(G_dpy, &focuswin, &focusrevert); + XSetInputFocus(G_dpy, sc->searchwin, + RevertToPointerRoot, CurrentTime); + + for (;;) { + XMaskEvent(G_dpy, ExecMask, &e); + + switch (e.type) { + case KeyPress: + if (input_keycodetrans(e.xkey.keycode, e.xkey.state, + &ctl, &chr, 0) < 0) + continue; + + switch (ctl) { + case CTL_ERASEONE: + if ((len = strlen(cmdstr)) > 0) + cmdstr[len - 1] = '\0'; + break; + case CTL_RETURN: + if (strlen(cmdstr) > 0) + u_spawn(cmdstr); + goto out; + break; + case CTL_ABORT: + goto out; + default: + break; + } + + if (chr != '\0') { + str[0] = chr; + str[1] = '\0'; + strlcat(cmdstr, str, sizeof(cmdstr)); + } + case Expose: + snprintf(dispstr, sizeof(dispstr), "exec>%s", cmdstr); + + dx = font_width(font, dispstr, strlen(dispstr)); + dy = fontheight; + + XClearWindow(G_dpy, sc->searchwin); + XResizeWindow(G_dpy, sc->searchwin, dx, dy); + + font_draw(font, dispstr, strlen(dispstr), + sc->searchwin, 0, font_ascent(font) + 1); + break; + } + } + out: + XSetInputFocus(G_dpy, focuswin, focusrevert, CurrentTime); + XUnmapWindow(G_dpy, sc->searchwin); +} + int _sweepcalc(struct client_ctx *cc, int x0, int y0, int motionx, int motiony) { |