sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 42336d93ac329154f018ae34ae13b0df69fba60a
parent 6e43c894a451dcc9282687fd30a89b8190c997e0
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Wed, 17 Apr 2013 17:13:06 +0200

dmenu: add patch which adds basic mouse support

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Atools.suckless.org/dmenu/patches/dmenu-4.5-mouse-support.diff | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/dmenu/patches/mouse-support.md | 31+++++++++++++++++++++++++++++++
2 files changed, 173 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/dmenu/patches/dmenu-4.5-mouse-support.diff b/tools.suckless.org/dmenu/patches/dmenu-4.5-mouse-support.diff @@ -0,0 +1,142 @@ +diff --git a/dmenu.c b/dmenu.c +index 3962801..a75bf80 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -25,6 +25,7 @@ struct Item { + }; + + static void appenditem(Item *item, Item **list, Item **last); ++static void buttonpress(XEvent *e); + static void calcoffsets(void); + static char *cistrstr(const char *s, const char *sub); + static void drawmenu(void); +@@ -389,6 +390,109 @@ keypress(XKeyEvent *ev) { + } + + void ++buttonpress(XEvent *e) { ++ int curpos; ++ Item *item; ++ XButtonPressedEvent *ev = &e->xbutton; ++ ++ if(ev->window != win) ++ return; ++ ++ /* right-click: exit */ ++ if(ev->button == Button3) ++ exit(EXIT_FAILURE); ++ ++ dc->x = 0; ++ dc->y = 0; ++ dc->h = bh; ++ ++ if(prompt && *prompt) { ++ dc->w = promptw; ++ dc->x = dc->w; ++ } ++ /* input field */ ++ dc->w = (lines > 0 || !matches) ? mw - dc->x : inputw; ++ if((curpos = textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w); ++ ++ /* left-click on input: clear input, ++ * NOTE: if there is no left-arrow the space for < is reserved so ++ * add that to the input width */ ++ if(ev->button == Button1 && ++ ((lines <= 0 && ev->x >= 0 && ev->x <= dc->x + dc->w + ++ ((!prev || !curr->left) ? textw(dc, "<") : 0)) || ++ (lines > 0 && ev->y >= dc->y && ev->y <= dc->y + dc->h))) { ++ insert(NULL, 0 - cursor); ++ drawmenu(); ++ return; ++ } ++ /* middle-mouse click: paste selection */ ++ if(ev->button == Button2) { ++ XConvertSelection(dc->dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, ++ utf8, utf8, win, CurrentTime); ++ drawmenu(); ++ return; ++ } ++ /* scroll up */ ++ if(ev->button == Button4 && prev) { ++ sel = curr = prev; ++ calcoffsets(); ++ drawmenu(); ++ return; ++ } ++ /* scroll down */ ++ if(ev->button == Button5 && next) { ++ sel = curr = next; ++ calcoffsets(); ++ drawmenu(); ++ return; ++ } ++ if(ev->button != Button1) ++ return; ++ if(lines > 0) { ++ /* vertical list: left-click on item */ ++ dc->w = mw - dc->x; ++ for(item = curr; item != next; item = item->right) { ++ dc->y += dc->h; ++ if(ev->y >= dc->y && ev->y <= (dc->y + dc->h)) { ++ puts(item->text); ++ exit(EXIT_SUCCESS); ++ } ++ } ++ } ++ else if(matches) { ++ /* left-click on left arrow */ ++ dc->x += inputw; ++ dc->w = textw(dc, "<"); ++ if(prev && curr->left) { ++ if(ev->x >= dc->x && ev->x <= dc->x + dc->w) { ++ sel = curr = prev; ++ calcoffsets(); ++ drawmenu(); ++ return; ++ } ++ } ++ /* horizontal list: left-click on item */ ++ for(item = curr; item != next; item = item->right) { ++ dc->x += dc->w; ++ dc->w = MIN(textw(dc, item->text), mw - dc->x - textw(dc, ">")); ++ if(ev->x >= dc->x && ev->x <= (dc->x + dc->w)) { ++ puts(item->text); ++ exit(EXIT_SUCCESS); ++ } ++ } ++ /* left-click on right arrow */ ++ dc->w = textw(dc, ">"); ++ dc->x = mw - dc->w; ++ if(next && ev->x >= dc->x && ev->x <= dc->x + dc->w) { ++ sel = curr = next; ++ calcoffsets(); ++ drawmenu(); ++ return; ++ } ++ } ++} ++ ++void + match(void) { + static char **tokv = NULL; + static int tokn = 0; +@@ -497,6 +601,9 @@ run(void) { + if(XFilterEvent(&ev, win)) + continue; + switch(ev.type) { ++ case ButtonPress: ++ buttonpress(&ev); ++ break; + case Expose: + if(ev.xexpose.count == 0) + mapdc(dc, win, mw, mh); +@@ -586,7 +693,8 @@ setup(void) { + /* create menu window */ + swa.override_redirect = True; + swa.background_pixel = normcol[ColBG]; +- swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; ++ swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask | ++ ButtonPressMask; + win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0, + DefaultDepth(dc->dpy, screen), CopyFromParent, + DefaultVisual(dc->dpy, screen), diff --git a/tools.suckless.org/dmenu/patches/mouse-support.md b/tools.suckless.org/dmenu/patches/mouse-support.md @@ -0,0 +1,31 @@ +Mouse support +============= + +With this patch dmenu will have basic mouse support. The following features are supported: + +Mouse actions supported: + +* Left-mouse click: + * On prompt and input field: clear input text and selection. + * In horizontal and vertical mode on item: select and output item (same as pressing enter). + * In horizontal mode on arrows: change items to show left or right. +* Right-mouse click: close. +* Middle-mouse click: + * Paste current selection. + * While holding shift: paste primary selection. +* Scroll up: + * In horizontal mode: same as left-clicking on left arrow. + * In vertical mode: show items above. +* Scroll down: + * In horizontal mode: same as left-clicking on right arrow. + * In vertical mode: show items below. + +The attached patch applies cleanly to latest dmenu 4.5 tip (dec9a28863f388072be105e0950deb72ac719d48). + +Download +-------- +* [dmenu-4.5-mouse-support.diff](dmenu-4.5-mouse-support.diff) + +Author +------ +* Hiltjo Posthuma - <hiltjo@codemadness.org>