From 779cf04f0557baa2f94ab788e0a1c36cd3a613c5 Mon Sep 17 00:00:00 2001 From: oga Date: Wed, 21 May 2008 14:11:19 +0000 Subject: Make menu_filter handle mouse movement too. This enables the keyboard search dialogues to be manipulated with the mouse, too. It also allows me to shrink the codebase further by killing grab_menu(). One known issue with highlighting the first entry in a search dialogue, that'll be fixed soonish. ok okan@, tested by Edd Barrett and todd@. --- grab.c | 111 ----------------------------------------------------------------- 1 file changed, 111 deletions(-) (limited to 'grab.c') diff --git a/grab.c b/grab.c index e27eb28..8a901c0 100644 --- a/grab.c +++ b/grab.c @@ -145,117 +145,6 @@ grab_drag(struct client_ctx *cc) /* NOTREACHED */ } -#define MenuMask (ButtonMask|ButtonMotionMask|ExposureMask) -#define MenuGrabMask (ButtonMask|ButtonMotionMask|StructureNotifyMask) -#define AllButtonMask (Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask) - -void * -grab_menu(XButtonEvent *e, struct menu_q *menuq) -{ - struct screen_ctx *sc; - struct menu *mi; - XEvent event; - struct fontdesc *font = DefaultFont; - int x, y, width, height, tothigh, i, no, entry, prev; - int fx, fy; - - no = i = width = 0; - - if ((sc = screen_fromroot(e->root)) == NULL || e->window == sc->menuwin) - return (NULL); - - TAILQ_FOREACH(mi, menuq, entry) { - i = font_width(font, mi->text, strlen(mi->text)) + 4; - if (i > width) - width = i; - no++; - } - - height = font_ascent(font) + font_descent(font) + 1; - tothigh = height * no; - - x = e->x - width/2; - y = e->y - height/2; - - /* does it fit on the screen? */ - if (x < 0) - x = 0; - else if (x+width >= sc->xmax) - x = sc->xmax - width; - - if (y < 0) - y = 0; - else if (y+tothigh >= sc->ymax) - y = sc->ymax - tothigh; - - xu_ptr_setpos(e->root, x + width/2, y + height/2); - - XMoveResizeWindow(X_Dpy, sc->menuwin, x, y, width, tothigh); - XSelectInput(X_Dpy, sc->menuwin, MenuMask); - XMapRaised(X_Dpy, sc->menuwin); - - if (xu_ptr_grab(sc->menuwin, MenuGrabMask, Cursor_select) < 0) { - XUnmapWindow(X_Dpy, sc->menuwin); - return (NULL); - } - - entry = prev = -1; - - for (;;) { - XMaskEvent(X_Dpy, MenuMask, &event); - switch (event.type) { - case Expose: - XClearWindow(X_Dpy, sc->menuwin); - i = 0; - TAILQ_FOREACH(mi, menuq, entry) { - fx = (width - font_width(font, mi->text, - strlen(mi->text)))/2; - fy = height*i + font_ascent(font) + 1; - font_draw(font, mi->text, strlen(mi->text), - sc->menuwin, fx, fy); - i++; - } - /* FALLTHROUGH */ - case MotionNotify: - prev = entry; - entry = menu_calc_entry(event.xbutton.x, - event.xbutton.y, width, height, no); - if (prev != -1) - XFillRectangle(X_Dpy, sc->menuwin, sc->hlgc, - 0, height*prev, width, height); - if (entry != -1) { - xu_ptr_regrab(MenuGrabMask, Cursor_select); - XFillRectangle(X_Dpy, sc->menuwin, sc->hlgc, - 0, height*entry, width, height); - } else - xu_ptr_regrab(MenuGrabMask, Cursor_default); - break; - case ButtonRelease: - if (event.xbutton.button != e->button) - break; - entry = menu_calc_entry(event.xbutton.x, - event.xbutton.y, width, height, no); - xu_ptr_ungrab(); - XUnmapWindow(X_Dpy, sc->menuwin); - - i = 0; - TAILQ_FOREACH(mi, menuq, entry) - if (entry == i++) - break; - return (mi); - default: - break; - } - } -} - -void -grab_menuinit(struct screen_ctx *sc) -{ - sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, - 1, 1, 1, sc->blackpixl, sc->whitepixl); -} - static int _sweepcalc(struct client_ctx *cc, int x0, int y0, int motionx, int motiony) { -- cgit 1.4.1