mirror of
https://github.com/CoolnsX/repos_scripts.git
synced 2025-12-20 07:15:20 +05:30
add mouse support in dmenu
This commit is contained in:
29
dmenu-5.0/config.h
Normal file
29
dmenu-5.0/config.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
/* Default settings; can be overriden by command line. */
|
||||||
|
|
||||||
|
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||||
|
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||||
|
static const char *fonts[] = {
|
||||||
|
"Comic Sans MS:size=12"
|
||||||
|
};
|
||||||
|
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||||
|
static const char *colors[SchemeLast][2] = {
|
||||||
|
/* fg bg */
|
||||||
|
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||||
|
[SchemeSel] = { "#eeeeee", "#5294e2" },
|
||||||
|
[SchemeOut] = { "#000000", "#C000FF" },
|
||||||
|
};
|
||||||
|
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||||
|
static unsigned int lines = 10;
|
||||||
|
/* -h option; minimum height of a menu line */
|
||||||
|
static unsigned int lineheight = 0;
|
||||||
|
static unsigned int min_lineheight = 8;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Characters not considered part of a word while deleting words
|
||||||
|
* for example: " /?\"&[]"
|
||||||
|
*/
|
||||||
|
static const char worddelimiters[] = " ";
|
||||||
|
|
||||||
|
/* Size of the window border */
|
||||||
|
static const unsigned int border_width = 4;
|
||||||
BIN
dmenu-5.0/dmenu
BIN
dmenu-5.0/dmenu
Binary file not shown.
@@ -509,6 +509,119 @@ draw:
|
|||||||
drawmenu();
|
drawmenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
buttonpress(XEvent *e)
|
||||||
|
{
|
||||||
|
struct item *item;
|
||||||
|
XButtonPressedEvent *ev = &e->xbutton;
|
||||||
|
int x = 0, y = 0, h = bh, w;
|
||||||
|
|
||||||
|
if (ev->window != win)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* right-click: exit */
|
||||||
|
if (ev->button == Button3)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
if (prompt && *prompt)
|
||||||
|
x += promptw;
|
||||||
|
|
||||||
|
/* input field */
|
||||||
|
w = (lines > 0 || !matches) ? mw - x : inputw;
|
||||||
|
|
||||||
|
/* 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 <= x + w +
|
||||||
|
((!prev || !curr->left) ? TEXTW("<") : 0)) ||
|
||||||
|
(lines > 0 && ev->y >= y && ev->y <= y + h))) {
|
||||||
|
insert(NULL, -cursor);
|
||||||
|
drawmenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* middle-mouse click: paste selection */
|
||||||
|
if (ev->button == Button2) {
|
||||||
|
XConvertSelection(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 (ev->state & ~ControlMask)
|
||||||
|
return;
|
||||||
|
if (lines > 0) {
|
||||||
|
/* vertical list: (ctrl)left-click on item */
|
||||||
|
w = mw - x;
|
||||||
|
for (item = curr; item != next; item = item->right) {
|
||||||
|
y += h;
|
||||||
|
if (ev->y >= y && ev->y <= (y + h)) {
|
||||||
|
puts(item->text);
|
||||||
|
if (!(ev->state & ControlMask))
|
||||||
|
exit(0);
|
||||||
|
sel = item;
|
||||||
|
if (sel) {
|
||||||
|
sel->out = 1;
|
||||||
|
drawmenu();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (matches) {
|
||||||
|
/* left-click on left arrow */
|
||||||
|
x += inputw;
|
||||||
|
w = TEXTW("<");
|
||||||
|
if (prev && curr->left) {
|
||||||
|
if (ev->x >= x && ev->x <= x + w) {
|
||||||
|
sel = curr = prev;
|
||||||
|
calcoffsets();
|
||||||
|
drawmenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* horizontal list: (ctrl)left-click on item */
|
||||||
|
for (item = curr; item != next; item = item->right) {
|
||||||
|
x += w;
|
||||||
|
w = MIN(TEXTW(item->text), mw - x - TEXTW(">"));
|
||||||
|
if (ev->x >= x && ev->x <= x + w) {
|
||||||
|
puts(item->text);
|
||||||
|
if (!(ev->state & ControlMask))
|
||||||
|
exit(0);
|
||||||
|
sel = item;
|
||||||
|
if (sel) {
|
||||||
|
sel->out = 1;
|
||||||
|
drawmenu();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* left-click on right arrow */
|
||||||
|
w = TEXTW(">");
|
||||||
|
x = mw - w;
|
||||||
|
if (next && ev->x >= x && ev->x <= x + w) {
|
||||||
|
sel = curr = next;
|
||||||
|
calcoffsets();
|
||||||
|
drawmenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
paste(void)
|
paste(void)
|
||||||
{
|
{
|
||||||
@@ -570,6 +683,9 @@ run(void)
|
|||||||
break;
|
break;
|
||||||
cleanup();
|
cleanup();
|
||||||
exit(1);
|
exit(1);
|
||||||
|
case ButtonPress:
|
||||||
|
buttonpress(&ev);
|
||||||
|
break;
|
||||||
case Expose:
|
case Expose:
|
||||||
if (ev.xexpose.count == 0)
|
if (ev.xexpose.count == 0)
|
||||||
drw_map(drw, win, 0, 0, mw, mh);
|
drw_map(drw, win, 0, 0, mw, mh);
|
||||||
@@ -669,6 +785,7 @@ setup(void)
|
|||||||
swa.override_redirect = True;
|
swa.override_redirect = True;
|
||||||
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
||||||
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
|
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
|
||||||
|
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask | ButtonPressMask;
|
||||||
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, border_width,
|
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, border_width,
|
||||||
CopyFromParent, CopyFromParent, CopyFromParent,
|
CopyFromParent, CopyFromParent, CopyFromParent,
|
||||||
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
|
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
|
||||||
|
|||||||
@@ -89,6 +89,15 @@ calcoffsets(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
max_textw(void)
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
for (struct item *item = items; item && item->text; item++)
|
||||||
|
len = MAX(TEXTW(item->text), len);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cleanup(void)
|
cleanup(void)
|
||||||
{
|
{
|
||||||
@@ -612,6 +621,7 @@ setup(void)
|
|||||||
bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */
|
bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */
|
||||||
lines = MAX(lines, 0);
|
lines = MAX(lines, 0);
|
||||||
mh = (lines + 1) * bh;
|
mh = (lines + 1) * bh;
|
||||||
|
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
i = 0;
|
i = 0;
|
||||||
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
|
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
|
||||||
@@ -638,9 +648,9 @@ setup(void)
|
|||||||
if (INTERSECT(x, y, 1, 1, info[i]))
|
if (INTERSECT(x, y, 1, 1, info[i]))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
x = info[i].x_org;
|
mw = MIN(MAX(max_textw() + promptw, 300), info[i].width);
|
||||||
y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
|
x = info[i].x_org + ((info[i].width - mw) / 2);
|
||||||
mw = info[i].width;
|
y = info[i].y_org + ((info[i].height - mh) / 2);
|
||||||
XFree(info);
|
XFree(info);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
@@ -648,11 +658,10 @@ setup(void)
|
|||||||
if (!XGetWindowAttributes(dpy, parentwin, &wa))
|
if (!XGetWindowAttributes(dpy, parentwin, &wa))
|
||||||
die("could not get embedding window attributes: 0x%lx",
|
die("could not get embedding window attributes: 0x%lx",
|
||||||
parentwin);
|
parentwin);
|
||||||
x = 0;
|
mw = MIN(MAX(max_textw() + promptw, 300), wa.width);
|
||||||
y = topbar ? 0 : wa.height - mh;
|
x = (wa.width - mw) / 2;
|
||||||
mw = wa.width;
|
y = (wa.height - mh) / 2;
|
||||||
}
|
}
|
||||||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
|
||||||
inputw = MIN(inputw, mw/3);
|
inputw = MIN(inputw, mw/3);
|
||||||
match();
|
match();
|
||||||
|
|
||||||
|
|||||||
12
dmenu-5.0/dmenu.c.rej
Normal file
12
dmenu-5.0/dmenu.c.rej
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
--- dmenu.c
|
||||||
|
+++ dmenu.c
|
||||||
|
@@ -774,7 +890,8 @@ setup(void)
|
||||||
|
/* create menu window */
|
||||||
|
swa.override_redirect = True;
|
||||||
|
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
||||||
|
- swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
|
||||||
|
+ swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask |
|
||||||
|
+ ButtonPressMask;
|
||||||
|
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
|
||||||
|
CopyFromParent, CopyFromParent, CopyFromParent,
|
||||||
|
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
|
||||||
Binary file not shown.
Reference in New Issue
Block a user