Skip to content

Commit

Permalink
Mouse support on the scrollbars, from Michael Grant.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicm committed Nov 12, 2024
1 parent c26d71d commit 713caca
Show file tree
Hide file tree
Showing 7 changed files with 633 additions and 69 deletions.
11 changes: 8 additions & 3 deletions cmd-copy-mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const struct cmd_entry cmd_copy_mode_entry = {
.name = "copy-mode",
.alias = NULL,

.args = { "deHMs:t:uq", 0, 0, NULL },
.usage = "[-deHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
.args = { "deHMqSs:t:u", 0, 0, NULL },
.usage = "[-deHMqSu] [-s src-pane] " CMD_TARGET_PANE_USAGE,

.source = { 's', CMD_FIND_PANE, 0 },
.target = { 't', CMD_FIND_PANE, 0 },
Expand Down Expand Up @@ -92,7 +92,12 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'u'))
window_copy_pageup(wp, 0);
if (args_has(args, 'd'))
window_copy_pagedown(wp, 0, args_has(args, 'e'));
window_copy_pagedown(wp, 0, args_has(args, 'e'));
if (args_has(args, 'S')) {
window_copy_scroll(wp, c->tty.mouse_slider_mpos, event->m.y,
args_has(args, 'e'));
return (CMD_RETURN_NORMAL);
}

return (CMD_RETURN_NORMAL);
}
5 changes: 5 additions & 0 deletions key-bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ key_bindings_init(void)
"bind -n MouseDown3Pane { if -Ft= '#{||:#{mouse_any_flag},#{&&:#{pane_in_mode},#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}}}' { select-pane -t=; send -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 " }",

/* Mouse on scrollbar. */
"bind -n MouseDown1ScrollbarUp { copy-mode -u }",
"bind -n MouseDown1ScrollbarDown { copy-mode -d }",
"bind -n MouseDrag1ScrollbarSlider { copy-mode -S }",

/* Copy mode (emacs) keys. */
"bind -Tcopy-mode C-Space { send -X begin-selection }",
"bind -Tcopy-mode C-a { send -X start-of-line }",
Expand Down
4 changes: 4 additions & 0 deletions screen-redraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,10 @@ screen_redraw_draw_pane_scrollbar(struct screen_redraw_ctx *ctx,

screen_redraw_draw_scrollbar(ctx, wp, sb_pos, sb_x, sb_y, sb_h,
slider_h, slider_y);

/* Store current position and height of the slider */
wp->sb_slider_y = slider_y; /* top of slider y pos in scrollbar */
wp->sb_slider_h = slider_h; /* height of slider */
}

static void
Expand Down
Loading

0 comments on commit 713caca

Please sign in to comment.