1 diff --git a/dmenu.c b/dmenu.c
2 index d95e6c6..75a79d0 100644
5 @@ -518,6 +518,119 @@ draw:
10 +buttonpress(XEvent *e)
13 + XButtonPressedEvent *ev = &e->xbutton;
14 + int x = 0, y = 0, h = bh, w;
16 + if (ev->window != win)
19 + /* right-click: exit */
20 + if (ev->button == Button3)
23 + if (prompt && *prompt)
27 + w = (lines > 0 || !matches) ? mw - x : inputw;
29 + /* left-click on input: clear input,
30 + * NOTE: if there is no left-arrow the space for < is reserved so
31 + * add that to the input width */
32 + if (ev->button == Button1 &&
33 + ((lines <= 0 && ev->x >= 0 && ev->x <= x + w +
34 + ((!prev || !curr->left) ? TEXTW("<") : 0)) ||
35 + (lines > 0 && ev->y >= y && ev->y <= y + h))) {
36 + insert(NULL, -cursor);
40 + /* middle-mouse click: paste selection */
41 + if (ev->button == Button2) {
42 + XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
43 + utf8, utf8, win, CurrentTime);
48 + if (ev->button == Button4 && prev) {
55 + if (ev->button == Button5 && next) {
61 + if (ev->button != Button1)
63 + if (ev->state & ~ControlMask)
66 + /* vertical list: (ctrl)left-click on item */
68 + for (item = curr; item != next; item = item->right) {
70 + if (ev->y >= y && ev->y <= (y + h)) {
72 + if (!(ev->state & ControlMask))
82 + } else if (matches) {
83 + /* left-click on left arrow */
86 + if (prev && curr->left) {
87 + if (ev->x >= x && ev->x <= x + w) {
94 + /* horizontal list: (ctrl)left-click on item */
95 + for (item = curr; item != next; item = item->right) {
97 + w = MIN(TEXTW(item->text), mw - x - TEXTW(">"));
98 + if (ev->x >= x && ev->x <= x + w) {
100 + if (!(ev->state & ControlMask))
110 + /* left-click on right arrow */
113 + if (next && ev->x >= x && ev->x <= x + w) {
125 @@ -579,6 +692,9 @@ run(void)
133 if (ev.xexpose.count == 0)
134 drw_map(drw, win, 0, 0, mw, mh);
135 @@ -676,7 +792,8 @@ setup(void)
136 /* create menu window */
137 swa.override_redirect = True;
138 swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
139 - swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
140 + swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask |
142 win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
143 CopyFromParent, CopyFromParent, CopyFromParent,
144 CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);