Loading ...
Sorry, an error occurred while loading the content.

better xterm mouse support

Expand Messages
  • Joe Allen
    I ve submitted a patch for xterm to xterm s maintainer Thomas Dickey. This patch improves mouse support for console applications. I wrote this patch for my
    Message 1 of 4 , May 6, 2005
    • 0 Attachment
      I've submitted a patch for xterm to xterm's maintainer Thomas Dickey.
      This patch improves mouse support for
      console applications. I wrote this patch for my text editor JOE, but it
      is generally applicable, so I'm posting here.
      Perhaps somebody wants to modify VIM to take advantage of this.

      You can get the patch from the current CVS of JOE:
      http://sourceforge.net/projects/joe-editor/ in the
      file "xterm-patch", or wait for the next version of xterm (hopefully
      xterm-202).

      I will try to modify other open source terminal emulators (konsole and
      gnome-terminal especially) if I get any
      support for this. A further goal is to modify all terminal emulators to
      use xterm's sequences as the defacto
      standard for modified keys (like Ctrl-left arrow).

      When xterm mouse mode is enabled (ESC [ 1002 h): mouse button events are
      sent to the application.
      Mouse motion events are sent to the application if a mouse button is
      held down.

      This mode has some problems:

      Select & paste do not work very well. A program will allow you to
      select with left-click, but the selection does not become
      the X selection, so you can't paste it into other applications.
      Alternatively, shift-left-click selects the same way as when mouse
      mode is off, but then the application does not know about it.

      When the mouse is dragged past the edge of the window frame, xterm stops
      sending mouse coordinates. This prevents the
      application from implementing "auto-scroll", where the window scrolls at
      a rate dependent on the distance between the mouse
      cursor and the window frame.

      When mouse mode is off, "normal" select & paste has its own problems:

      Can only select one screen of text.

      Application may be in the wrong mode to accept paste text (auto-indent
      enabled, not in insert mode, etc.).


      This patch addresses all of these problems:

      With this patch, the following escape sequences become available:

      ESC [ ? P Send current X-selection to the program. The data
      is formatted
      as follows: ESC [ 200 ~ <base64-encoded data> ESC

      The base64 encoding is to eliminate the
      obvious security hole (cat
      a malicious file, and arbitrary text could be
      sent to the shell). The leading
      ESC [ 200 ~ should make it very easy for any
      application to use this patch:
      it allows the application's base-64 paste
      function to be bound to what looks like
      a key sequence.


      ESC [ ? 2 P Accept base64 encoded paste data until ESC.
      This data becomes the X "selected text" which
      can then be pasted by other applications.

      Thus select & paste are fully controllable by the application. In
      particular, left-click
      and middle-click can be made to work as they should, even when mouse
      mode is enabled.

      ESC [ ? 2 0 0 7 h Enable outside of frame mouse coordinates.

      ESC [ ? 2 0 0 7 l Disable outside of frame mouse coordinates.

      When outside of frame mouse coordinates are enabled, and
      xterm mouse support is enabled (ESC [ ? 1 0 0 2 h), mouse
      coordinates are sent even if they are outside of xterm's
      window frame.

      The coordinate code bytes should be interpreted like this
      (we need negative coordinates in case mouse is above or to
      left of window):

      Code Coordinate
      ---- ----------
      33 - 240 1 - 208 (normal)
      32 0 (left/top of frame)
      241 - 255 -15 - -1 (left/top of frame)

      (When this mode is off, codes 33 - 255 correspond to
      coordinates 1 - 223).

      Finally, this patch makes XTerm store UTF-8 data in the server's cut buffer,
      instead of latin1.
    • Bram Moolenaar
      ... I don t see something in here that I need for Vim. ... Vim uses Visual mode for its own selection. The user has the option to make this the X selection
      Message 2 of 4 , May 17, 2005
      • 0 Attachment
        Joe Allen wrote:

        > I've submitted a patch for xterm to xterm's maintainer Thomas Dickey.
        > This patch improves mouse support for console applications. I wrote
        > this patch for my text editor JOE, but it is generally applicable, so
        > I'm posting here. Perhaps somebody wants to modify VIM to take
        > advantage of this.

        I don't see something in here that I need for Vim.

        > You can get the patch from the current CVS of JOE:
        > http://sourceforge.net/projects/joe-editor/ in the
        > file "xterm-patch", or wait for the next version of xterm (hopefully
        > xterm-202).
        >
        > I will try to modify other open source terminal emulators (konsole and
        > gnome-terminal especially) if I get any support for this. A further
        > goal is to modify all terminal emulators to use xterm's sequences as
        > the defacto standard for modified keys (like Ctrl-left arrow).
        >
        > When xterm mouse mode is enabled (ESC [ 1002 h): mouse button events are
        > sent to the application. Mouse motion events are sent to the
        > application if a mouse button is held down.
        >
        > This mode has some problems:
        >
        > Select & paste do not work very well. A program will allow you to
        > select with left-click, but the selection does not become
        > the X selection, so you can't paste it into other applications.
        > Alternatively, shift-left-click selects the same way as when mouse
        > mode is off, but then the application does not know about it.

        Vim uses Visual mode for its own selection. The user has the option to
        make this the X selection too. Obviously this requires Vim to connect
        to the X server. That has already been implemented and is needed for
        other reasons as well (e.g., to obtain the window title, so that it can
        be restored, and to get and set the cut buffer contents).

        > When the mouse is dragged past the edge of the window frame, xterm stops
        > sending mouse coordinates. This prevents the application from
        > implementing "auto-scroll", where the window scrolls at a rate
        > dependent on the distance between the mouse cursor and the window
        > frame.

        That's interesting. Vim has the 'scrolloff' option so that the text can
        scroll while the mouse pointer is still inside the frame. Your
        implementation takes some of the available columns, that's a problem for
        some people (even 220 columns is not enough for some). Perhaps this can
        be done for rows and columns separately?

        > Application may be in the wrong mode to accept paste text (auto-indent
        > enabled, not in insert mode, etc.).

        Vim has the 'paste' option for this.

        It looks like your changes are only optional. I do hope that the modes
        are restored when an application exits, otherwise Vim might get into
        problems when it's started while the xterm doesn't work as expected.

        --
        TALL KNIGHT: We are now no longer the Knights Who Say Ni!
        ONE KNIGHT: Ni!
        OTHERS: Sh!
        ONE KNIGHT: (whispers) Sorry.
        "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
        \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
      • Andrew Pimlott
        [Replying to old mail.] ... While you re at it... :-) I don t enable the mouse in vim, because regular cut-n-paste functionality is much more valuable to me
        Message 3 of 4 , Jun 30, 2005
        • 0 Attachment
          [Replying to old mail.]

          On Fri, May 06, 2005 at 06:48:10PM -0400, Joe Allen wrote:
          > I've submitted a patch for xterm to xterm's maintainer Thomas Dickey.

          While you're at it... :-) I don't enable the mouse in vim, because
          regular cut-n-paste functionality is much more valuable to me than using
          it to control the cursor (and holding down shift is too much for my poor
          brain to remembe). But on the other hand, using the scroll wheel to
          scroll in vim would be much more valuable to me than scrolling through
          the xterm buffer.

          I would absolutely love it if I could have the best of both: button 1-3
          and motion events handled by xterm, but wheel (button 4-) events passed
          to vim. As I understand it, it is not possible to ask xterm for only
          some of the buttons. But if someone hacked this in, and hacked vim to
          support it, he would have my gratitude.

          Andrew
        • GI
          ... I think (but I could be mistaken) mrxvt has this feature. I know it has a feature to bind keys in the main screen only (so the bindings will not work when
          Message 4 of 4 , Jul 1, 2005
          • 0 Attachment
            On Thu, Jun 30, 2005 at 03:28:32PM -0700, Andrew Pimlott wrote:

            > [Replying to old mail.]
            >
            > On Fri, May 06, 2005 at 06:48:10PM -0400, Joe Allen wrote:
            > > I've submitted a patch for xterm to xterm's maintainer Thomas Dickey.
            >
            > While you're at it... :-) I don't enable the mouse in vim, because
            > regular cut-n-paste functionality is much more valuable to me than using
            > it to control the cursor (and holding down shift is too much for my poor
            > brain to remembe). But on the other hand, using the scroll wheel to
            > scroll in vim would be much more valuable to me than scrolling through
            > the xterm buffer.
            >
            > I would absolutely love it if I could have the best of both: button 1-3
            > and motion events handled by xterm, but wheel (button 4-) events passed
            > to vim. As I understand it, it is not possible to ask xterm for only
            > some of the buttons. But if someone hacked this in, and hacked vim to
            > support it, he would have my gratitude.

            I think (but I could be mistaken) mrxvt has this feature. I know it has
            a feature to bind keys in the main screen only (so the bindings will not
            work when running vim / less / mutt / etc). I'm not sure if that extends
            to mouse buttons.

            GI

            --
            'eieio' -- A gross misspelling of the word 'farm'.
          Your message has been successfully submitted and would be delivered to recipients shortly.