mirror of
https://github.com/mintycube/dmenu.git
synced 2024-10-22 14:05:48 +02:00
Added patch to highlight an entry when mouse-hovered.
This commit is contained in:
parent
d04595790f
commit
4a8b71c191
@ -28,6 +28,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/YjT2DD6j
|
|||||||
|
|
||||||
### Changelog:
|
### Changelog:
|
||||||
|
|
||||||
|
2024-07-16 - Added the mouse motion support patch
|
||||||
|
|
||||||
2023-06-15 - Added the caret width patch
|
2023-06-15 - Added the caret width patch
|
||||||
|
|
||||||
2022-09-05 - Removed the json patch due to maintenance and compatibility reasons, added the
|
2022-09-05 - Removed the json patch due to maintenance and compatibility reasons, added the
|
||||||
|
8
dmenu.c
8
dmenu.c
@ -1527,6 +1527,11 @@ run(void)
|
|||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
buttonpress(&ev);
|
buttonpress(&ev);
|
||||||
break;
|
break;
|
||||||
|
#if MOTION_SUPPORT_PATCH
|
||||||
|
case MotionNotify:
|
||||||
|
motionevent(&ev.xbutton);
|
||||||
|
break;
|
||||||
|
#endif // MOTION_SUPPORT_PATCH
|
||||||
#endif // MOUSE_SUPPORT_PATCH
|
#endif // MOUSE_SUPPORT_PATCH
|
||||||
case DestroyNotify:
|
case DestroyNotify:
|
||||||
if (ev.xdestroywindow.window != win)
|
if (ev.xdestroywindow.window != win)
|
||||||
@ -1749,6 +1754,9 @@ setup(void)
|
|||||||
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask
|
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask
|
||||||
#if MOUSE_SUPPORT_PATCH
|
#if MOUSE_SUPPORT_PATCH
|
||||||
| ButtonPressMask
|
| ButtonPressMask
|
||||||
|
#if MOTION_SUPPORT_PATCH
|
||||||
|
| PointerMotionMask
|
||||||
|
#endif // MOTION_SUPPORT_PATCH
|
||||||
#endif // MOUSE_SUPPORT_PATCH
|
#endif // MOUSE_SUPPORT_PATCH
|
||||||
;
|
;
|
||||||
win = XCreateWindow(
|
win = XCreateWindow(
|
||||||
|
@ -4,6 +4,9 @@ buttonpress(XEvent *e)
|
|||||||
struct item *item;
|
struct item *item;
|
||||||
XButtonPressedEvent *ev = &e->xbutton;
|
XButtonPressedEvent *ev = &e->xbutton;
|
||||||
int x = 0, y = 0, h = bh, w;
|
int x = 0, y = 0, h = bh, w;
|
||||||
|
#if GRID_PATCH
|
||||||
|
int i, cols;
|
||||||
|
#endif // GRID_PATCH
|
||||||
|
|
||||||
if (ev->window != win)
|
if (ev->window != win)
|
||||||
return;
|
return;
|
||||||
@ -66,8 +69,40 @@ buttonpress(XEvent *e)
|
|||||||
if (ev->state & ~ControlMask)
|
if (ev->state & ~ControlMask)
|
||||||
return;
|
return;
|
||||||
if (lines > 0) {
|
if (lines > 0) {
|
||||||
|
#if GRID_PATCH
|
||||||
|
cols = columns ? columns : 1;
|
||||||
|
for (i = 0, item = curr; item != next; item = item->right, i++) {
|
||||||
|
if (
|
||||||
|
(ev->y >= y + ((i % lines) + 1) * bh) && // line y start
|
||||||
|
(ev->y <= y + ((i % lines) + 2) * bh) && // line y end
|
||||||
|
(ev->x >= x + ((i / lines) * (w / cols))) && // column x start
|
||||||
|
(ev->x <= x + ((i / lines + 1) * (w / cols))) // column x end
|
||||||
|
) {
|
||||||
|
#if !MULTI_SELECTION_PATCH
|
||||||
|
puts(item->text);
|
||||||
|
#endif // MULTI_SELECTION_PATCH
|
||||||
|
if (!(ev->state & ControlMask)) {
|
||||||
|
#if MULTI_SELECTION_PATCH
|
||||||
|
sel = item;
|
||||||
|
selsel();
|
||||||
|
printsel(ev->state);
|
||||||
|
#endif // MULTI_SELECTION_PATCH
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
sel = item;
|
||||||
|
if (sel) {
|
||||||
|
#if MULTI_SELECTION_PATCH
|
||||||
|
selsel();
|
||||||
|
#else
|
||||||
|
sel->out = 1;
|
||||||
|
#endif // MULTI_SELECTION_PATCH
|
||||||
|
drawmenu();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
/* vertical list: (ctrl)left-click on item */
|
/* vertical list: (ctrl)left-click on item */
|
||||||
w = mw - x;
|
|
||||||
for (item = curr; item != next; item = item->right) {
|
for (item = curr; item != next; item = item->right) {
|
||||||
y += h;
|
y += h;
|
||||||
if (ev->y >= y && ev->y <= (y + h)) {
|
if (ev->y >= y && ev->y <= (y + h)) {
|
||||||
@ -94,6 +129,7 @@ buttonpress(XEvent *e)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // GRID_PATCH
|
||||||
} else if (matches) {
|
} else if (matches) {
|
||||||
/* left-click on left arrow */
|
/* left-click on left arrow */
|
||||||
x += inputw;
|
x += inputw;
|
||||||
@ -156,4 +192,80 @@ buttonpress(XEvent *e)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MOTION_SUPPORT_PATCH
|
||||||
|
static void
|
||||||
|
motionevent(XButtonEvent *ev)
|
||||||
|
{
|
||||||
|
struct item *item;
|
||||||
|
int x = 0, y = 0, w;
|
||||||
|
#if GRID_PATCH
|
||||||
|
int i, cols;
|
||||||
|
#endif // GRID_PATCH
|
||||||
|
|
||||||
|
if (ev->window != win || matches == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (prompt && *prompt)
|
||||||
|
x += promptw;
|
||||||
|
|
||||||
|
if (lines > 0) {
|
||||||
|
/* input field */
|
||||||
|
w = mw - x;
|
||||||
|
#if GRID_PATCH
|
||||||
|
cols = columns ? columns : 1;
|
||||||
|
/* grid view or vertical list */
|
||||||
|
for (i = 0, item = curr; item != next; item = item->right, i++) {
|
||||||
|
if (
|
||||||
|
(ev->y >= y + ((i % lines) + 1) * bh) && // line y start
|
||||||
|
(ev->y <= y + ((i % lines) + 2) * bh) && // line y end
|
||||||
|
(ev->x >= x + ((i / lines) * (w / cols))) && // column x start
|
||||||
|
(ev->x <= x + ((i / lines + 1) * (w / cols))) // column x end
|
||||||
|
) {
|
||||||
|
sel = item;
|
||||||
|
calcoffsets();
|
||||||
|
drawmenu();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* vertical list */
|
||||||
|
w = mw - x;
|
||||||
|
for (item = curr; item != next; item = item->right) {
|
||||||
|
y += bh;
|
||||||
|
if (ev->y >= y && ev->y <= (y + bh)) {
|
||||||
|
sel = item;
|
||||||
|
calcoffsets();
|
||||||
|
drawmenu();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // GRID_PATCH
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* left-click on left arrow */
|
||||||
|
x += inputw;
|
||||||
|
#if SYMBOLS_PATCH
|
||||||
|
w = TEXTW(symbol_1);
|
||||||
|
#else
|
||||||
|
w = TEXTW("<");
|
||||||
|
#endif // SYMBOLS_PATCH
|
||||||
|
/* horizontal list */
|
||||||
|
for (item = curr; item != next; item = item->right) {
|
||||||
|
x += w;
|
||||||
|
#if SYMBOLS_PATCH
|
||||||
|
w = MIN(TEXTW(item->text), mw - x - TEXTW(symbol_2));
|
||||||
|
#else
|
||||||
|
w = MIN(TEXTW(item->text), mw - x - TEXTW(">"));
|
||||||
|
#endif // SYMBOLS_PATCH
|
||||||
|
if (ev->x >= x && ev->x <= x + w) {
|
||||||
|
sel = item;
|
||||||
|
calcoffsets();
|
||||||
|
drawmenu();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -141,6 +141,11 @@
|
|||||||
*/
|
*/
|
||||||
#define MOUSE_SUPPORT_PATCH 0
|
#define MOUSE_SUPPORT_PATCH 0
|
||||||
|
|
||||||
|
/* Expands the above to support mouse hovering.
|
||||||
|
* https://tools.suckless.org/dmenu/patches/mouse-support/
|
||||||
|
*/
|
||||||
|
#define MOTION_SUPPORT_PATCH 0
|
||||||
|
|
||||||
/* Without this patch when you press Ctrl+Enter dmenu just outputs current item and it is not
|
/* Without this patch when you press Ctrl+Enter dmenu just outputs current item and it is not
|
||||||
* possible to undo that.
|
* possible to undo that.
|
||||||
* With this patch dmenu will output all selected items only on exit. It is also possible to
|
* With this patch dmenu will output all selected items only on exit. It is also possible to
|
||||||
|
Loading…
Reference in New Issue
Block a user