From 20d8541cf7e637e51ec5512083487296f51f8174 Mon Sep 17 00:00:00 2001 From: Nuno Sa Date: Tue, 16 Apr 2024 10:22:34 +0200 Subject: [PATCH] tmux: tmux.conf: support mouse in wayland This adds the same behavior for the mouse bindings as when X is used. It relies on an out of tree change on the tmux-yank plugin. Signed-off-by: Nuno Sa --- tmux/tmux.conf | 69 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/tmux/tmux.conf b/tmux/tmux.conf index 0d2987f..2607c13 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -27,27 +27,56 @@ set-option -g prefix C-x bind-key C-x send-prefix setw -g word-separators ' ,;()' -# This allows for middle mouse paste (from other apps) without having to press shift. -bind -n MouseDown2Pane run "tmux set-buffer -b primary_selection -- \"$(xsel -o)\"; \ - tmux paste-buffer -b primary_selection; tmux delete-buffer -b primary_selection" - -# With the above binding, the default double and triple click actions do not work as the middle -# button paste now looks for the system clipboard to paste from. As such we need the next bindings -# to fix that. The double click bindings will select the whole text until the next separator (as -# specified in word-separators) is found. Hence, we can double click anywhere in some word to select -# the full word. -bind -T copy-mode-vi DoubleClick1Pane select-pane \; send -X previous-word \; send -X select-word \; \ - send -X copy-pipe-no-clear "xsel -i" -bind -n DoubleClick1Pane select-pane \; copy-mode \; send -X previous-word \; send -X select-word \; \ - send -X copy-pipe-no-clear "xsel -i" -bind -T copy-mode-vi TripleClick1Pane select-pane \; send -X select-line \; send -X copy-pipe-no-clear "xsel -i" -bind -n TripleClick1Pane select-pane \; copy-mode \; send -X select-line \; run-shell -d 0.3 \; send -X copy-pipe-no-clear "xsel -i" -bind -n MouseDrag1Pane copy-mode -M +if-shell '[[ $(env | grep XDG_SESSION_TYPE | cut -d"=" -f2) = wayland ]]' { + set -g @yank_wayland_mouse 'true' + # This allows for middle mouse paste (from other apps) without having to press shift. + bind -n MouseDown2Pane run "tmux set-buffer -b primary_selection -- \"$(wl-paste --primary)\"; \ + tmux paste-buffer -b primary_selection; tmux delete-buffer -b primary_selection" + + # With the above binding, the default double and triple click actions do not work as the middle + # button paste now looks for the system clipboard to paste from. As such we need the next bindings + # to fix that. The double click bindings will select the whole text until the next separator (as + # specified in word-separators) is found. Hence, we can double click anywhere in some word to select + # the full word. + bind -T copy-mode-vi DoubleClick1Pane select-pane \; send -X previous-word \; send -X select-word \; \ + send -X copy-pipe-no-clear "wl-copy --primary" + bind -n DoubleClick1Pane select-pane \; copy-mode \; send -X previous-word \; send -X select-word \; \ + send -X copy-pipe-no-clear "wl-copy --primary" + bind -T copy-mode-vi TripleClick1Pane select-pane \; send -X select-line \; \ + send -X copy-pipe-no-clear "wl-copy --primary" + bind -n TripleClick1Pane select-pane \; copy-mode \; send -X select-line \; run-shell -d 0.3 \; \ + send -X copy-pipe-no-clear "wl-copy --primary" + + # As @yank_action is not set to automatically exit copy-mode, use mouse righ-click to easily exit + # copy-mode when the mouse is being used. This works for me, as I don't really find the context menu + # useful. Might revisit this binding in the future though. + bind -T copy-mode-vi MouseDown3Pane select-pane\; copy-mode -H \; send -X copy-pipe-and-cancel "wl-copy" +} { + # This allows for middle mouse paste (from other apps) without having to press shift. + bind -n MouseDown2Pane run "tmux set-buffer -b primary_selection -- \"$(xsel -o)\"; \ + tmux paste-buffer -b primary_selection; tmux delete-buffer -b primary_selection" + + # With the above binding, the default double and triple click actions do not work as the middle + # button paste now looks for the system clipboard to paste from. As such we need the next bindings + # to fix that. The double click bindings will select the whole text until the next separator (as + # specified in word-separators) is found. Hence, we can double click anywhere in some word to select + # the full word. + bind -T copy-mode-vi DoubleClick1Pane select-pane \; send -X previous-word \; send -X select-word \; \ + send -X copy-pipe-no-clear "xsel -i" + bind -n DoubleClick1Pane select-pane \; copy-mode \; send -X previous-word \; send -X select-word \; \ + send -X copy-pipe-no-clear "xsel -i" + bind -T copy-mode-vi TripleClick1Pane select-pane \; send -X select-line \; send -X copy-pipe-no-clear "xsel -i" + bind -n TripleClick1Pane select-pane \; copy-mode \; send -X select-line \; run-shell -d 0.3 \; \ + send -X copy-pipe-no-clear "xsel -i" + + # As @yank_action is not set to automatically exit copy-mode, use mouse righ-click to easily exit + # copy-mode when the mouse is being used. This works for me, as I don't really find the context menu + # useful. Might revisit this binding in the future though. + bind -T copy-mode-vi MouseDown3Pane select-pane\; copy-mode -H \; \ + send -X copy-pipe-and-cancel "xsel -i --clipboard" +} -# As @yank_action is not set to automatically exit copy-mode, use mouse righ-click to easily exit -# copy-mode when the mouse is being used. This works for me, as I don't really find the context menu -# useful. Might revisit this binding in the future though. -bind -T copy-mode-vi MouseDown3Pane select-pane\; copy-mode -H \; send -X copy-pipe-and-cancel "xsel -i --clipboard" +bind -n MouseDrag1Pane copy-mode -M # use left mouse key to clear a selection bind -T copy-mode-vi MouseDown1Pane select-pane\; send -X clear-selection