Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#17 support mouse scrolling without hijacking the mouse

open
nobody
None
2015-01-12
2012-05-16
Andrew Pimlott
No

The mode-mouse option allows scrolling with the mouse. However, for any setting other than "off", it also causes tmux to hijack the mouse. That is, clicking and dragging does not select text (unless I also hold down shift). This is a big disadvantage for me.

I would like a mode in which the mouse behaves as close as possible to how it behaves without tmux, including some form of scrollback. I don't even care whether it's really scrolling back though tmux's buffer, or my terminal's. I just want to scroll to see my recent output in the common case. It's ok if there are some limitations. (I have been assuming all along that the program running under tmux is not mouse-aware. I don't care about mouse-aware programs.)

There is a hack for GNU screen: http://liquidat.wordpress.com/2008/10/17/short-tip-gnu-screen-with-proper-scroll-session-management-support/. I have no idea how it works, but it seems to do what I want.

I found a similar hack for tmux: http://superuser.com/a/300716/134608. But it doesn't seem to work (maybe it was only for older tmux?). At least, I see no effect. So I am posting this as a feature request.

I have tested the current tmux subversion, as well as tmux 1.6. My terminal is xterm. I am running Debian unstable.

Discussion

  • Both these links are about alternate screen which has nothing to do with the mouse. If alternate screen is on, it disables the terminal scrollback entirely for full screen applications (like tmux).

    It is impossible for tmux to handle any mouse input without taking over the mouse entirely. If you want it to only take the mouse in copy-mode set mouse-mode to "copy-mode". Otherwise it's all or nothing.

    To disable alternate screen, the command in the second link is the right one for tmux:

    set -g terminal-overrides 'xterm*:smcup@:rmcup@'

    If this didn't work, either your TERM outside tmux doesn't match xterm* or you did it wrong. Did you set it then detach all clients?

    Note you can do it entirely with an xterm resource (titeInhibit).

     
  • Andrew Pimlott
    Andrew Pimlott
    2012-05-16

    Thank you for this very informative reply! You're right, I was doing it wrong: When copying the command to my .tmux.conf, somehow I left out the "-g". When I put that back in, it seems to act just like I want. Perhaps it should be better documented.

    Regarding copy-mode, I find that when it is set, tmux still hijacks the mouse when I am not in copy-mode. It doesn't actually scroll until I go into copy-mode, but clicks aren't handled normally. Tested on current svn.

     
  • If you think the documentation could be better, feel free to suggest specific changes to the man page. Or write a tmux FAQ entry. Note that the alternate screen is a terminal feature so it's documented in xterm(1).

    It looks like we do capture the mouse when copy-mode is set - I'll have to look at why, that's probably a bug.

     
  • Andrew Pimlott
    Andrew Pimlott
    2012-05-16

    Ok, a FAQ entry is below. I was pleasantly surprised how well tmux plays with the scrollback buffer, even with multiple panes.

    * How can I make tmux use my terminal's scrollback buffer?

    Normally, tmux (like most full-screen applications) runs in your terminal's
    "alternate screen". Most terminals (such as xterm) do not save scrollback
    for the alternate screen. You might prefer tmux to use the normal screen,
    so it uses your terminal's scrollback buffer. This way, you can access the
    scrollback buffer as usual, for example using the mouse wheel.

    You can trick tmux into using the normal screen by telling it that your
    terminal does not have an alternate screen. Put the following in
    ~/.tmux.conf:

    set -g terminal-overrides 'xterm*:smcup@:rmcup@'

    Adjust if your $TERM does not start with xterm.

    This works especially well if you don't use the multi-pane features of tmux.
    But even as long as you have a single top pane, that pane will use the
    terminal's scrollback buffer. If you split your top pane horizontally,
    however, you defeat terminal scrollback.

    tmux will still emulate the alternate screen for applications run under
    tmux, so you don't really lose anything with this setting. The only
    disadvantage is that when you exit tmux, it will not restore whatever was
    there before you started.

    In the FAQ submitter's opinion, this setting should be the default.

     
  • Thanks. I'll look over this and add it. It isn't sensible to make this the default though, it is completely dependent on your terminal when and how it works.

     
  • Andrew Pimlott
    Andrew Pimlott
    2012-05-17

    Fair enough. You can leave off my editorializing. :-) And please make any corrections or qualifications to make it more accurate. Obviously, I have only tested with xterm and don't plan to test other terminals. I will let you know if I discover any unexpected effects with further use.

     
  • Andrew Pimlott
    Andrew Pimlott
    2012-05-18

    Here is another revision:

    * How can I make tmux use my terminal's scrollback buffer?

    Normally, tmux (like most full-screen applications) runs in your
    terminal's "alternate screen" if it has one. Most graphical terminals,
    such as xterm, support an alternate screen. But usually they don't save
    scrollback for the alternate screen. So you don't get scrollback in
    tmux.

    You might prefer tmux to use the normal screen, so it uses your
    terminal's scrollback buffer. This way, you can access the scrollback
    buffer as usual, for example using the scollbar and mouse wheel. You
    can trick tmux into using the normal screen by telling it that your
    terminal does not have an alternate screen. Put the following in
    ~/.tmux.conf:

    set-option -g terminal-overrides '\*:smcup@:rmcup@'
    

    (If you would rather disable the alternate screen altogether, see
    http://www.shallowsky.com/linux/noaltscreen.html.\)

    This works especially well if you don't use the multi-pane features of
    tmux. But even as long as you have a single top pane, that pane will
    use the terminal's scrollback buffer. If you split your top pane
    horizontally, however, you defeat terminal scrollback entirely.

    tmux will still emulate the alternate screen for applications run under
    tmux, so you don't really lose anything with this setting. The only
    disadvantage is that when you exit tmux, it will not restore whatever
    was there before you started.

    If your goal is to use the mouse wheel to scroll back, you get a similar
    effect with:

    set-window-option -g mode-mouse copy-mode
    

    The difference is, this uses tmux's scrollback buffer, not your
    terminal's. In most ways this is better: It works for all panes, and
    it works when you attach a new terminal. (You can also enable other
    mouse features to manipulate panes.) The trade-off is that tmux
    "captures" the mouse, so clicking doesn't select text as usual. In most
    terminals, you can get a normal click by holding down Shift. Still, if
    you don't like tmux capturing the mouse, the solution above still lets
    you scroll using the mouse wheel.

     
  • Ticket moved from /p/tmux/feature-requests/88/