aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicm <nicm>2020-10-30 08:55:56 +0000
committernicm <nicm>2020-10-30 08:55:56 +0000
commit649e5970e98b0073763f42a25dcab02aadea688f (patch)
tree9918f6fc4c7830ff919f9f2fbabdfc38bb16e76c
parenta868bacb46e3c900530bed47a1c6f85b0fbe701c (diff)
downloadrtmux-649e5970e98b0073763f42a25dcab02aadea688f.tar.gz
rtmux-649e5970e98b0073763f42a25dcab02aadea688f.tar.bz2
rtmux-649e5970e98b0073763f42a25dcab02aadea688f.zip
Add a -O flag to display-menu to change the mouse behaviour and not
close the menu when the mouse is released, from teo_paul1 at yahoo dot com.
-rw-r--r--cmd-display-menu.c6
-rw-r--r--menu.c22
-rw-r--r--server-client.c2
-rw-r--r--tmux.111
-rw-r--r--tmux.h1
5 files changed, 33 insertions, 9 deletions
diff --git a/cmd-display-menu.c b/cmd-display-menu.c
index ae322444..205d1243 100644
--- a/cmd-display-menu.c
+++ b/cmd-display-menu.c
@@ -36,8 +36,8 @@ const struct cmd_entry cmd_display_menu_entry = {
.name = "display-menu",
.alias = "menu",
- .args = { "c:t:T:x:y:", 1, -1 },
- .usage = "[-c target-client] " CMD_TARGET_PANE_USAGE " [-T title] "
+ .args = { "c:t:OT:x:y:", 1, -1 },
+ .usage = "[-O] [-c target-client] " CMD_TARGET_PANE_USAGE " [-T title] "
"[-x position] [-y position] name key command ...",
.target = { 't', CMD_FIND_PANE, 0 },
@@ -229,6 +229,8 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
cmd_display_menu_get_position(tc, item, args, &px, &py, menu->width + 4,
menu->count + 2);
+ if (args_has(args, 'O'))
+ flags |= MENU_STAYOPEN;
if (!event->m.valid)
flags |= MENU_NOMOUSE;
if (menu_display(menu, flags, item, px, py, tc, target, NULL,
diff --git a/menu.c b/menu.c
index 4fcf660a..3bd56ab1 100644
--- a/menu.c
+++ b/menu.c
@@ -203,16 +203,28 @@ menu_key_cb(struct client *c, struct key_event *event)
m->x > md->px + 4 + menu->width ||
m->y < md->py + 1 ||
m->y > md->py + 1 + count - 1) {
- if (MOUSE_RELEASE(m->b))
- return (1);
+ if (~md->flags & MENU_STAYOPEN) {
+ if (MOUSE_RELEASE(m->b))
+ return (1);
+ } else {
+ if (!MOUSE_RELEASE(m->b) &&
+ MOUSE_WHEEL(m->b) == 0 &&
+ !MOUSE_DRAG(m->b))
+ return (1);
+ }
if (md->choice != -1) {
md->choice = -1;
c->flags |= CLIENT_REDRAWOVERLAY;
}
return (0);
}
- if (MOUSE_RELEASE(m->b))
- goto chosen;
+ if (~md->flags & MENU_STAYOPEN) {
+ if (MOUSE_RELEASE(m->b))
+ goto chosen;
+ } else {
+ if (MOUSE_WHEEL(m->b) == 0 && !MOUSE_DRAG(m->b))
+ goto chosen;
+ }
md->choice = m->y - (md->py + 1);
if (md->choice != old)
c->flags |= CLIENT_REDRAWOVERLAY;
@@ -303,6 +315,8 @@ chosen:
if (md->choice == -1)
return (1);
item = &menu->items[md->choice];
+ if ((md->flags & MENU_STAYOPEN) && item->name == NULL)
+ return (0);
if (item->name == NULL || *item->name == '-')
return (1);
if (md->cb != NULL) {
diff --git a/server-client.c b/server-client.c
index 4c9706f7..3c2b54d5 100644
--- a/server-client.c
+++ b/server-client.c
@@ -1693,8 +1693,8 @@ server_client_reset_state(struct client *c)
* mode.
*/
if (options_get_number(oo, "mouse")) {
- mode &= ~ALL_MOUSE_MODES;
if (c->overlay_draw == NULL) {
+ mode &= ~ALL_MOUSE_MODES;
TAILQ_FOREACH(loop, &w->panes, entry) {
if (loop->screen->mode & MODE_MOUSE_ALL)
mode |= MODE_MOUSE_ALL;
diff --git a/tmux.1 b/tmux.1
index 7900ecce..955ce16e 100644
--- a/tmux.1
+++ b/tmux.1
@@ -5331,6 +5331,7 @@ option.
This command works only from inside
.Nm .
.It Xo Ic display-menu
+.Op Fl O
.Op Fl c Ar target-client
.Op Fl t Ar target-pane
.Op Fl T Ar title
@@ -5382,8 +5383,14 @@ Both may be a row or column number, or one of the following special values:
Each menu consists of items followed by a key shortcut shown in brackets.
If the menu is too large to fit on the terminal, it is not displayed.
Pressing the key shortcut chooses the corresponding item.
-If the mouse is enabled and the menu is opened from a mouse key binding, releasing
-the mouse button with an item selected will choose that item.
+If the mouse is enabled and the menu is opened from a mouse key binding,
+releasing the mouse button with an item selected chooses that item and
+releasing the mouse button without an item selected closes the menu.
+.Fl O
+changes this behaviour so that the menu does not close when the mouse button is
+released without an item selected the menu is not closed and a mouse button
+must be clicked to choose an item.
+.Pp
The following keys are also available:
.Bl -column "Key" "Function" -offset indent
.It Sy "Key" Ta Sy "Function"
diff --git a/tmux.h b/tmux.h
index 4ba2c13b..1845775d 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2978,6 +2978,7 @@ __dead void printflike(1, 2) fatalx(const char *, ...);
/* menu.c */
#define MENU_NOMOUSE 0x1
#define MENU_TAB 0x2
+#define MENU_STAYOPEN 0x4
struct menu *menu_create(const char *);
void menu_add_items(struct menu *, const struct menu_item *,
struct cmdq_item *, struct client *,