From 12255411f27e2c937334b1d84671ae46d5ef3c0c Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 28 May 2019 09:50:54 +0000 Subject: [PATCH 1/3] Allow menu items to be disabled by putting a - at the start of their name, rather than just including #[dim] which still allowed them to be chosen. --- key-bindings.c | 4 ++-- menu.c | 22 ++++++++++++++++------ screen-write.c | 15 +++++++++++---- tmux.1 | 2 ++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/key-bindings.c b/key-bindings.c index d20eca4b..3f74cb37 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -299,7 +299,7 @@ key_bindings_init(void) "bind -n MouseDown3Status display-menu -t= -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\"" " 'Swap Left' 'l' {swap-window -t:-1}" " 'Swap Right' 'r' {swap-window -t:+1}" - " '#{?pane_marked_set,,#[dim]}Swap Marked' 's' {swap-window}" + " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-window}" " ''" " 'Kill' 'X' {kill-window}" " 'Respawn' 'R' {respawn-window -k}" @@ -319,7 +319,7 @@ key_bindings_init(void) " ''" " 'Swap Up' 'u' {swap-pane -U}" " 'Swap Down' 'd' {swap-pane -D}" - " '#{?pane_marked_set,,#[dim]}Swap Marked' 's' {swap-pane}" + " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane}" " ''" " 'Kill' 'X' {kill-pane}" " 'Respawn' 'R' {respawn-pane -k}" diff --git a/menu.c b/menu.c index 9aedf6d9..fd35399b 100644 --- a/menu.c +++ b/menu.c @@ -80,7 +80,7 @@ menu_add_item(struct menu *menu, const struct menu_item *item, menu->count--; return; } - if (item->key != KEYC_UNKNOWN && item->key != KEYC_NONE) { + if (*s != '-' && item->key != KEYC_UNKNOWN && item->key != KEYC_NONE) { key = key_string_lookup_key(item->key); xasprintf(&name, "%s#[default] #[align=right](%s)", s, key); } else @@ -182,6 +182,7 @@ menu_key_cb(struct client *c, struct key_event *event) const struct menu_item *item; struct cmdq_item *new_item; struct cmd_parse_result *pr; + const char *name; if (KEYC_IS_MOUSE(event->key)) { if (md->flags & MENU_NOMOUSE) @@ -207,21 +208,27 @@ menu_key_cb(struct client *c, struct key_event *event) } switch (event->key) { case KEYC_UP: + if (old == -1) + old = 0; do { if (md->choice == -1 || md->choice == 0) md->choice = count - 1; else md->choice--; - } while (menu->items[md->choice].name == NULL); + name = menu->items[md->choice].name; + } while ((name == NULL || *name == '-') && md->choice != old); c->flags |= CLIENT_REDRAWOVERLAY; return (0); case KEYC_DOWN: + if (old == -1) + old = 0; do { if (md->choice == -1 || md->choice == count - 1) md->choice = 0; - else - md->choice++; - } while (menu->items[md->choice].name == NULL); + else + md->choice++; + name = menu->items[md->choice].name; + } while ((name == NULL || *name == '-') && md->choice != old); c->flags |= CLIENT_REDRAWOVERLAY; return (0); case '\r': @@ -233,6 +240,9 @@ menu_key_cb(struct client *c, struct key_event *event) return (1); } for (i = 0; i < (u_int)count; i++) { + name = menu->items[i].name; + if (name == NULL || *name == '-') + continue; if (event->key == menu->items[i].key) { md->choice = i; goto chosen; @@ -244,7 +254,7 @@ chosen: if (md->choice == -1) return (1); item = &menu->items[md->choice]; - if (item->name == NULL) + if (item->name == NULL || *item->name == '-') return (1); if (md->cb != NULL) { md->cb(md->menu, md->choice, item->key, md->data); diff --git a/screen-write.c b/screen-write.c index ad3808ae..174c7a82 100644 --- a/screen-write.c +++ b/screen-write.c @@ -410,6 +410,7 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice) struct screen *s = ctx->s; struct grid_cell gc; u_int cx, cy, i, j; + const char *name; cx = s->cx; cy = s->cy; @@ -421,18 +422,24 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice) format_draw(ctx, &gc, menu->width, menu->title, NULL); for (i = 0; i < menu->count; i++) { - if (menu->items[i].name == NULL) { + name = menu->items[i].name; + if (name == NULL) { screen_write_cursormove(ctx, cx, cy + 1 + i, 0); screen_write_hline(ctx, menu->width + 4, 1, 1); } else { - if (choice >= 0 && i == (u_int)choice) + if (choice >= 0 && i == (u_int)choice && *name != '-') gc.attr |= GRID_ATTR_REVERSE; screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0); for (j = 0; j < menu->width; j++) screen_write_putc(ctx, &gc, ' '); screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0); - format_draw(ctx, &gc, menu->width, menu->items[i].name, - NULL); + if (*name == '-') { + name++; + gc.attr |= GRID_ATTR_DIM; + format_draw(ctx, &gc, menu->width, name, NULL); + gc.attr &= ~GRID_ATTR_DIM; + } else + format_draw(ctx, &gc, menu->width, name, NULL); if (choice >= 0 && i == (u_int)choice) gc.attr &= ~GRID_ATTR_REVERSE; } diff --git a/tmux.1 b/tmux.1 index 735e932d..fc51ec30 100644 --- a/tmux.1 +++ b/tmux.1 @@ -4674,6 +4674,8 @@ The name and command are formats, see the and .Sx STYLES sections. +If the name begins with a hyphen (-), then the item is disabled (shown dim) and +may not be chosen. The name may be empty for a separator line, in which case both the key and command should be omitted. .Pp From 99a8469ee4924be2b02aafc86f930426f15a3d55 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 28 May 2019 10:05:24 +0000 Subject: [PATCH 2/3] Add key bindings to open the window and pane menus (C-m and M-m for now). --- key-bindings.c | 96 +++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/key-bindings.c b/key-bindings.c index 3f74cb37..51b043a9 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -24,6 +24,52 @@ #include "tmux.h" +#define DEFAULT_CLIENT_MENU \ + " 'Detach' 'd' {detach-client}" \ + " 'Detach & Kill' 'X' {detach-client -P}" \ + " 'Detach Others' 'o' {detach-client -a}" \ + " ''" \ + " 'Lock' 'l' {lock-client}" +#define DEFAULT_SESSION_MENU \ + " 'Next' 'n' {switch-client -n}" \ + " 'Previous' 'p' {switch-client -p}" \ + " ''" \ + " 'Renumber' 'N' {move-window -r}" \ + " 'Rename' 'n' {command-prompt -I \"#S\" \"rename-session -- '%%'\"}" \ + " ''" \ + " 'New Session' 's' {new-session}" \ + " 'New Window' 'w' {new-window}" +#define DEFAULT_WINDOW_MENU \ + " 'Swap Left' 'l' {swap-window -t:-1}" \ + " 'Swap Right' 'r' {swap-window -t:+1}" \ + " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-window}" \ + " ''" \ + " 'Kill' 'X' {kill-window}" \ + " 'Respawn' 'R' {respawn-window -k}" \ + " '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" \ + " 'Rename' 'n' {command-prompt -I \"#W\" \"rename-window -- '%%'\"}" \ + " ''" \ + " 'New After' 'w' {new-window -a}" \ + " 'New At End' 'W' {new-window}" +#define DEFAULT_PANE_MENU \ + " '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {copy-mode -t=; send -Xt= search-backward \"#{q:mouse_word}\"}" \ + " '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {send-keys -l -- \"#{q:mouse_word}\"}" \ + " '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {set-buffer -- \"#{q:mouse_word}\"}" \ + " '#{?mouse_line,Copy Line,}' 'l' {set-buffer -- \"#{q:mouse_line}\"}" \ + " ''" \ + " 'Horizontal Split' 'h' {split-window -h}" \ + " 'Vertical Split' 'v' {split-window -v}" \ + " ''" \ + " 'Swap Up' 'u' {swap-pane -U}" \ + " 'Swap Down' 'd' {swap-pane -D}" \ + " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane}" \ + " ''" \ + " 'Kill' 'X' {kill-pane}" \ + " 'Respawn' 'R' {respawn-pane -k}" \ + " '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" \ + " '#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z}" + + static int key_bindings_cmp(struct key_binding *, struct key_binding *); RB_GENERATE_STATIC(key_bindings, key_binding, entry, key_bindings_cmp); static int key_table_cmp(struct key_table *, struct key_table *); @@ -281,50 +327,12 @@ key_bindings_init(void) "bind -n MouseDown3Pane if -Ft= '#{||:mouse_any_flag,pane_in_mode}' 'select-pane -t=; send-keys -M' 'select-pane -mt='", "bind -n WheelUpPane if -Ft= '#{mouse_any_flag}' 'send-keys -M' 'if -Ft= \"#{pane_in_mode}\" \"send-keys -M\" \"copy-mode -et=\"'", - "bind -n MouseDown3StatusRight display-menu -t= -xM -yS -T \"#[align=centre]#{client_name}\"" - " 'Detach' 'd' {detach-client}" - " 'Detach & Kill' 'X' {detach-client -P}" - " 'Detach Others' 'o' {detach-client -a}" - " ''" - " 'Lock' 'l' {lock-client}", - "bind -n MouseDown3StatusLeft display-menu -t= -xM -yS -T \"#[align=centre]#{session_name}\"" - " 'Next' 'n' {switch-client -n}" - " 'Previous' 'p' {switch-client -p}" - " ''" - " 'Renumber' 'N' {move-window -r}" - " 'Rename' 'n' {command-prompt -I \"#S\" \"rename-session -- '%%'\"}" - " ''" - " 'New Session' 's' {new-session}" - " 'New Window' 'w' {new-window}", - "bind -n MouseDown3Status display-menu -t= -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\"" - " 'Swap Left' 'l' {swap-window -t:-1}" - " 'Swap Right' 'r' {swap-window -t:+1}" - " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-window}" - " ''" - " 'Kill' 'X' {kill-window}" - " 'Respawn' 'R' {respawn-window -k}" - " '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" - " 'Rename' 'n' {command-prompt -I \"#W\" \"rename-window -- '%%'\"}" - " ''" - " 'New After' 'w' {new-window -a}" - " 'New At End' 'W' {new-window}", - "bind -n M-MouseDown3Pane display-menu -t= -xM -yM -T \"#[align=centre]#{pane_index} (#{pane_id})\"" - " '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {copy-mode -t=; send -Xt= search-backward \"#{q:mouse_word}\"}" - " '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {send-keys -l -- \"#{q:mouse_word}\"}" - " '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {set-buffer -- \"#{q:mouse_word}\"}" - " '#{?mouse_line,Copy Line,}' 'l' {set-buffer -- \"#{q:mouse_line}\"}" - " ''" - " 'Horizontal Split' 'h' {split-window -h}" - " 'Vertical Split' 'v' {split-window -v}" - " ''" - " 'Swap Up' 'u' {swap-pane -U}" - " 'Swap Down' 'd' {swap-pane -D}" - " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane}" - " ''" - " 'Kill' 'X' {kill-pane}" - " 'Respawn' 'R' {respawn-pane -k}" - " '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" - " '#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z}", + "bind -n MouseDown3StatusRight display-menu -t= -xM -yS -T \"#[align=centre]#{client_name}\" " DEFAULT_CLIENT_MENU, + "bind -n MouseDown3StatusLeft display-menu -t= -xM -yS -T \"#[align=centre]#{session_name}\" " DEFAULT_SESSION_MENU, + "bind -n MouseDown3Status display-menu -t= -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\" " DEFAULT_WINDOW_MENU, + "bind C-m display-menu -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\" " DEFAULT_WINDOW_MENU, + "bind -n M-MouseDown3Pane display-menu -t= -xM -yM -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU, + "bind M-m display-menu -xP -yP -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU, "bind -Tcopy-mode C-Space send -X begin-selection", "bind -Tcopy-mode C-a send -X start-of-line", From e0fd2950548def0124733b43fb347e82878f47b3 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 28 May 2019 10:27:11 +0000 Subject: [PATCH 3/3] Change the default right click pane to open the menu if not in a mode and no application mouse. --- key-bindings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/key-bindings.c b/key-bindings.c index 51b043a9..0c9ba67b 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -324,13 +324,13 @@ key_bindings_init(void) "bind -n WheelDownStatus next-window", "bind -n WheelUpStatus previous-window", "bind -n MouseDrag1Pane if -Ft= '#{mouse_any_flag}' 'if -Ft= \"#{pane_in_mode}\" \"copy-mode -M\" \"send-keys -M\"' 'copy-mode -M'", - "bind -n MouseDown3Pane if -Ft= '#{||:mouse_any_flag,pane_in_mode}' 'select-pane -t=; send-keys -M' 'select-pane -mt='", "bind -n WheelUpPane if -Ft= '#{mouse_any_flag}' 'send-keys -M' 'if -Ft= \"#{pane_in_mode}\" \"send-keys -M\" \"copy-mode -et=\"'", "bind -n MouseDown3StatusRight display-menu -t= -xM -yS -T \"#[align=centre]#{client_name}\" " DEFAULT_CLIENT_MENU, "bind -n MouseDown3StatusLeft display-menu -t= -xM -yS -T \"#[align=centre]#{session_name}\" " DEFAULT_SESSION_MENU, "bind -n MouseDown3Status display-menu -t= -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\" " DEFAULT_WINDOW_MENU, "bind C-m display-menu -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\" " DEFAULT_WINDOW_MENU, + "bind -n MouseDown3Pane if -Ft= '#{||:#{mouse_any_flag},#{pane_in_mode}}' 'select-pane -t=; send-keys -M' {display-menu -t= -xM -yM -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU "}", "bind -n M-MouseDown3Pane display-menu -t= -xM -yM -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU, "bind M-m display-menu -xP -yP -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU,