@@ -11,7 +11,7 @@ scroll_speed_num_lines_per_scroll_option="@scroll-speed-num-lines-per-scroll"
1111deprecated_prevent_scroll_for_fullscreen_alternate_buffer_option=" @prevent-scroll-for-fullscreen-alternate-buffer"
1212emulate_scroll_for_no_mouse_alternate_buffer_option=" @emulate-scroll-for-no-mouse-alternate-buffer"
1313
14- send_keys_to_tmux_cmd () {
14+ get_repeated_scroll_cmd () {
1515 local scroll_speed_num_lines_per_scroll=$( get_tmux_option " $scroll_speed_num_lines_per_scroll_option " " 3" )
1616 local cmd=" "
1717 if echo - | awk " { if ($scroll_speed_num_lines_per_scroll >= 1) { exit 0 } else { exit 1 } }" ; then # Positive whole number speed (round down).
@@ -27,7 +27,7 @@ send_keys_to_tmux_cmd() {
2727 echo " $cmd "
2828}
2929
30- bind_wheel_up_to_enter_copy_mode () {
30+ better_mouse_mode_main () {
3131 local scroll_down_to_exit=$( get_tmux_option " $scroll_down_exit_copy_mode_option " " on" )
3232 local scroll_in_moused_over_pane=$( get_tmux_option " $scroll_in_moused_over_pane_option " " on" )
3333 local scroll_without_changing_pane=$( get_tmux_option " $scroll_without_changing_pane_option " " off" )
@@ -58,33 +58,43 @@ bind_wheel_up_to_enter_copy_mode() {
5858 # here. Tmux uses quoting to denote levels of the if-blocks below. The
5959 # pattern used here for consistency is " \" ' \\\" \\\" ' \" " -- that is,
6060 # " for top-level quotes, \" for the next level in, ' for the third level,
61- # and \\\" for the fourth (note that the fourth comes from inside send_keys_to_tmux_cmd ).
61+ # and \\\" for the fourth (note that the fourth comes from inside get_repeated_scroll_cmd ).
6262 tmux bind-key -n WheelUpPane \
6363 if -Ft= " #{mouse_any_flag}" \
6464 " send-keys -M" \
6565 " \
6666 if -Ft= '$check_for_fullscreen_alternate_buffer ' \
67- \" $( send_keys_to_tmux_cmd up) \" \
67+ \" $( get_repeated_scroll_cmd up) \" \
6868 \" \
6969 $select_moused_over_pane_cmd \
7070 if -Ft= '#{pane_in_mode}' \
71- '$( send_keys_to_tmux_cmd -M) ' \
72- '$enter_copy_mode_cmd ; $( send_keys_to_tmux_cmd -M) ' \
71+ '$( get_repeated_scroll_cmd -M) ' \
72+ '$enter_copy_mode_cmd ; $( get_repeated_scroll_cmd -M) ' \
7373 \" \
7474 "
7575 # Enable sending scroll-downs to the moused-over-pane.
7676 # NOTE: the quoting pattern used here and in the above command for
7777 # consistency is " \" ' \\\" \\\" ' \" " -- that is, " for top-level quotes,
7878 # \" for the next level in, ' for the third level, and \\\" for the fourth
79- # (note that the fourth comes from inside send_keys_to_tmux_cmd ).
79+ # (note that the fourth comes from inside get_repeated_scroll_cmd ).
8080 tmux bind-key -n WheelDownPane \
8181 if -Ft= " #{mouse_any_flag}" \
8282 " send-keys -M" \
8383 " \
8484 if -Ft= \" $check_for_fullscreen_alternate_buffer \" \
85- \" $( send_keys_to_tmux_cmd down) \" \
86- \" $select_moused_over_pane_cmd $( send_keys_to_tmux_cmd -M) \" \
85+ \" $( get_repeated_scroll_cmd down) \" \
86+ \" $select_moused_over_pane_cmd $( get_repeated_scroll_cmd -M) \" \
8787 "
88+
89+ # For tmux 2.4+ you have to set the mouse wheel options seperately for copy-mode than from root.
90+ local tmux_version=$( get_tmux_version)
91+ if echo - | awk " { if ($tmux_version >= 2.4) { exit 0 } else { exit 1 } }" ; then # Use copy-mode tables to set scroll speed.
92+ local scroll_speed_num_lines_per_scroll=$( get_tmux_option " $scroll_speed_num_lines_per_scroll_option " " 3" )
93+ tmux bind-key -Tcopy-mode WheelUpPane send -N" $scroll_speed_num_lines_per_scroll " -X scroll-up
94+ tmux bind-key -Tcopy-mode WheelDownPane send -N" $scroll_speed_num_lines_per_scroll " -X scroll-down
95+ tmux bind-key -Tcopy-mode-vi WheelUpPane send -N" $scroll_speed_num_lines_per_scroll " -X scroll-up
96+ tmux bind-key -Tcopy-mode-vi WheelDownPane send -N" $scroll_speed_num_lines_per_scroll " -X scroll-down
97+ fi
8898}
8999
90- bind_wheel_up_to_enter_copy_mode
100+ better_mouse_mode_main
0 commit comments