From c4a8f44931713f32f250264ca00520aae30fc0e3 Mon Sep 17 00:00:00 2001 From: oga Date: Tue, 20 May 2008 14:50:51 +0000 Subject: Pull out the behaviour in grab_label and search_start into one utility function menu_filter(). The plan is to eventually merge in grab_menu too. Shrinks the code a fair bit. Also, change XMaskEvent for XWindowEvent to prevent getting exposes for other windows. This is particuarly noticable on slow machines with a LOT of xterms (todd, you're an odd man). ok okan@, todd@. --- grab.c | 99 +----------------------------------------------------------------- 1 file changed, 1 insertion(+), 98 deletions(-) (limited to 'grab.c') diff --git a/grab.c b/grab.c index 90f23b2..d4abc87 100644 --- a/grab.c +++ b/grab.c @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $Id: grab.c,v 1.12 2008/05/19 18:07:53 okan Exp $ + * $Id: grab.c,v 1.13 2008/05/20 14:50:51 oga Exp $ */ #include "headers.h" @@ -171,11 +171,6 @@ grab_menu(XButtonEvent *e, struct menu_q *menuq) no++; } - if (!sc->maxinitialised) { - sc->xmax = DisplayWidth(X_Dpy, sc->which); - sc->ymax = DisplayHeight(X_Dpy, sc->which); - } - height = font_ascent(font) + font_descent(font) + 1; tothigh = height * no; @@ -261,98 +256,6 @@ grab_menuinit(struct screen_ctx *sc) 1, 1, 1, sc->blackpixl, sc->whitepixl); } -#define LABEL_MAXLEN 256 -#define LabelMask (KeyPressMask|ExposureMask) - -void -grab_label(struct client_ctx *cc) -{ - struct screen_ctx *sc = screen_current(); - int x, y, dx, dy, fontheight, focusrevert; - XEvent e; - char labelstr[LABEL_MAXLEN]; - char dispstr[LABEL_MAXLEN + sizeof("label>") - 1]; - Window focuswin; - char chr; - enum ctltype ctl; - size_t len; - struct fontdesc *font = DefaultFont; - - if (cc->label != NULL) - strlcpy(labelstr, cc->label, sizeof(labelstr)); - else - labelstr[0] = '\0'; - - xu_ptr_getpos(sc->rootwin, &x, &y); - - dy = fontheight = font_ascent(font) + font_descent(font) + 1; - dx = font_width(font, "label>", 6); - - XMoveResizeWindow(X_Dpy, sc->searchwin, x, y, dx, dy); - XSelectInput(X_Dpy, sc->searchwin, LabelMask); - XMapRaised(X_Dpy, sc->searchwin); - - XGetInputFocus(X_Dpy, &focuswin, &focusrevert); - XSetInputFocus(X_Dpy, sc->searchwin, RevertToPointerRoot, CurrentTime); - - for (;;) { - XMaskEvent(X_Dpy, LabelMask, &e); - - switch (e.type) { - case KeyPress: - if (input_keycodetrans(e.xkey.keycode, e.xkey.state, - &ctl, &chr) < 0) - continue; - - switch (ctl) { - case CTL_ERASEONE: - if ((len = strlen(labelstr)) > 0) - labelstr[len - 1] = '\0'; - break; - case CTL_RETURN: - /* Done */ - if (strlen(labelstr) == 0) - goto out; - - if (cc->label != NULL) - xfree(cc->label); - - cc->label = xstrdup(labelstr); - /* FALLTHROUGH */ - case CTL_ABORT: - goto out; - default: - break; - } - - if (chr != '\0') { - char str[2]; - - str[0] = chr; - str[1] = '\0'; - strlcat(labelstr, str, sizeof(labelstr)); - } - - case Expose: - snprintf(dispstr, sizeof(dispstr), "label>%s", - labelstr); - dx = font_width(font, dispstr, strlen(dispstr)); - dy = fontheight; - - XClearWindow(X_Dpy, sc->searchwin); - XResizeWindow(X_Dpy, sc->searchwin, dx, dy); - - font_draw(font, dispstr, strlen(dispstr), - sc->searchwin, 0, font_ascent(font) + 1); - break; - } - } - -out: - XSetInputFocus(X_Dpy, focuswin, focusrevert, CurrentTime); - XUnmapWindow(X_Dpy, sc->searchwin); -} - static int _sweepcalc(struct client_ctx *cc, int x0, int y0, int motionx, int motiony) { -- cgit v1.2.3-2-gb3c3