diff options
author | oga | 2008-05-21 14:11:19 +0000 |
---|---|---|
committer | oga | 2008-05-21 14:11:19 +0000 |
commit | 70508fca2af57f5b3b025a45f7b5a6a66e31d4cb (patch) | |
tree | 2f68ba9395dbae3a11e6d2401bc09b62e09783ad /grab.c | |
parent | c4a8f44931713f32f250264ca00520aae30fc0e3 (diff) | |
download | cwm-70508fca2af57f5b3b025a45f7b5a6a66e31d4cb.tar.gz |
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@.
Diffstat (limited to 'grab.c')
-rw-r--r-- | grab.c | 113 |
1 files changed, 1 insertions, 112 deletions
@@ -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.13 2008/05/20 14:50:51 oga Exp $ + * $Id: grab.c,v 1.14 2008/05/21 14:11:19 oga Exp $ */ #include "headers.h" @@ -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) { |