Great! Something I've been waiting for a ling time!
It would be nice on the wiki!

Le 00:57:33 le 17 oct. 2011 , Connor Lane Smith a écrit :
> Hey all,
> 
> In case anyone's interested, here's a patch which adds some basic
> mouse support to dmenu.
> 
> You can click things, click the paginators ("<" and ">"), and scroll.
> 
> cls

> diff -r 6e962f2337c2 dmenu.c
> --- a/dmenu.c Sun Oct 16 18:26:11 2011 +0100
> +++ b/dmenu.c Mon Oct 17 00:55:51 2011 +0100
> @@ -24,6 +24,7 @@
>  };
>  
>  static void appenditem(Item *item, Item **list, Item **last);
> +static void buttonrelease(XButtonEvent *ev);
>  static void calcoffsets(void);
>  static char *cistrstr(const char *s, const char *sub);
>  static void drawmenu(void);
> @@ -131,6 +132,62 @@
>  }
>  
>  void
> +buttonrelease(XButtonEvent *ev)
> +{
> +     int i;
> +     Item *item = curr;
> +
> +     switch(ev->button) {
> +     case Button1:
> +             if(ev->y > bh || (ev->x > promptw + inputw + textw(dc, "<") && 
> ev->x < mw - textw(dc, ">"))) {
> +                     if(lines == 0) {
> +                             i = promptw + inputw + textw(dc, "<");
> +                             while(item && (i += textw(dc, item->text)) < 
> ev->x)
> +                                     item = item->right;
> +                     }
> +                     else
> +                             for(i = 1; item && i < ev->y / bh; i++)
> +                                     item = item->right;
> +                     if(!item || item == next)
> +                             return;
> +                     if(item == sel) {
> +                             puts(sel->text);
> +                             exit(EXIT_SUCCESS);
> +                     }
> +                     else
> +                             sel = item;
> +             }
> +             else if(lines == 0 && ev->x > promptw + inputw) {
> +                     if(ev->x < mw - textw(dc, "<")) {
> +                             if(!prev)
> +                                     return;
> +                             sel = curr = prev;
> +                     }
> +                     else {
> +                             if(!next)
> +                                     return;
> +                             sel = curr = next;
> +                     }
> +                     calcoffsets();
> +             }
> +             break;
> +     case Button4: /* scroll up */
> +             if(sel && sel->left && (sel = sel->left)->right == curr) {
> +                     curr = prev;
> +                     calcoffsets();
> +             }
> +             break;
> +     case Button5: /* scroll down */
> +             if(sel && sel->right && (sel = sel->right) == next) {
> +                     curr = next;
> +                     calcoffsets();
> +             }
> +             break;
> +     }
> +     drawmenu();
> +}
> +
> +void
>  calcoffsets(void) {
>       int i, n;
>  
> @@ -463,6 +520,9 @@
>  
>       while(!XNextEvent(dc->dpy, &ev))
>               switch(ev.type) {
> +             case ButtonRelease:
> +                     buttonrelease(&ev.xbutton);
> +                     break;
>               case Expose:
>                       if(ev.xexpose.count == 0)
>                               mapdc(dc, win, mw, mh);
> @@ -536,7 +596,7 @@
>       /* menu window */
>       swa.override_redirect = True;
>       swa.background_pixmap = ParentRelative;
> -     swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
> +     swa.event_mask = ButtonPressMask | ButtonReleaseMask | ExposureMask | 
> KeyPressMask | VisibilityChangeMask;
>       win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
>                           DefaultDepth(dc->dpy, screen), CopyFromParent,
>                           DefaultVisual(dc->dpy, screen),


-- 
 ,--.   Xavier Cartron                           ,   /(
: /` )  M1 MEFPC                        o     **}=\\,\(,,  
| `-'   Debian user                    <0--        (___(_\\
 \_     jabber : thu...@jabber.fr      / >        ,)   ,/ ``==>

Reply via email to