1

From the Xterm Control Sequences doc:

Normal tracking mode sends an escape sequence on both button press and release.  Modifier key (shift, ctrl, meta) information is also sent.  It is enabled by specifying parameter 1000 to DECSET.  On button press or release, xterm sends CSI M CbCxCy.

  • The low two bits of Cb encode button information: 0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release.

  • The next three bits encode the modifiers which were down when the button was pressed and are added together:  4=Shift, 8=Meta, 16=Control.  Note however that the shift and control bits are normally unavailable because xterm uses the control modifier with mouse for popup menus, and the shift modifier is used in the default translations for button events.  The Meta modifier recognized by xterm is the mod1 mask, and is not necessarily the "Meta" key (see xmodmap(1)).

  • Cx and Cy are the x and y coordinates of the mouse event, encoded as in X10 mode.

What happens when for example, left click is pressed with Shift at (1, 1), right click is pressed with Control at (2, 2), left click is released at (3, 3), and right click is released at (4, 4)?

Wouldn't you get

ESC [ M 0000100 ! !
ESC [ M 0010001 " "
ESC [ M 0000011 # #
ESC [ M 0000011 $ $

in your stdin? How should this be handled on the client program? How could it?

The control sequences documentation is incredibly hard to read which makes this unnecessarily difficult.

2
  • You are asking about "Press Shift, Press Left Mouse, Release Shift, Press Ctrl, Press Right Mouse, Release Ctrl, Release Left Mouse, Release Right Mouse" and you are complaining that the button release events are ambiguous, in that they could occur in either order?
    – icarus
    Commented May 12, 2019 at 3:45
  • Yes, there is no way to distinguish releasing mouse button N from mouse button M. Also, this format completely disregards mice with more buttons.
    – Aly
    Commented May 12, 2019 at 4:00

2 Answers 2

3

The documentation answers the question here:

The low two bits of Cb encode button information: 0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release.

That is, you cannot distinguish different button-releases using the Normal tracking mode protocol. It is ambiguous.

The issue about ambiguous button-release is addressed in Extended Coordinates by the SGR (1006) code:

  • A different final character is used for button release to resolve the X10 ambiguity regarding which button was released.

For best readability, a PDF works (plain text is dead last).

However, the question asks about a case which is seldom used, because a Shift modifier normally is used to "always" select/paste, while a Control modifier normally is used to activate menus. Those features are optional (see the manual page description of omitTranslation as well as allowMouseOps). If you're not actually asking about xterm, of course, there is no way to guess what the terminal might do, since none of the xterm-alikes document any of this.

5
  • 1
    well, I don't think that some example of how to use those will hurt anybody.
    – user313992
    Commented May 12, 2019 at 14:06
  • How would my original case look in terms of bytes/characters sent to the program? And how can my program tell the terminal I want to take advantage of 1006?
    – Aly
    Commented May 12, 2019 at 16:15
  • See Mouse tracking, to enable: printf '\033[?1006h' Commented May 12, 2019 at 17:11
  • @ThomasDickey How come when I cat and type ESC [ ? 1 0 0 6 h RET, I see nothing going into or coming out of cat when I click in the terminal? Also, let's say I got rid of the Shift/Control stuff, what would my inputs look like to the program then?
    – Aly
    Commented May 13, 2019 at 2:33
  • "For best readability, a PDF works (plain text is dead last)." --- No, my first choice is plain text, then HTML and at last PDF. Because you can open a plain text on any editor and do a search on it. Commented Aug 25, 2022 at 17:23
1

Also, this format completely disregards mice with more buttons.

Well, the very next paragraph after the one you quoted says:

Wheel mice may return buttons 4 and 5.  Those buttons are represented by the same event codes as buttons 1 and 2 respectively, except that 64 is added to the event code.  Release events for the wheel buttons are not reported

2
  • Is it because 4 and 5 are only reported as presses? (Due to being wheel actions)
    – Aly
    Commented May 12, 2019 at 16:13
  • So then what do $C_x$ and $C_y$ mean for wheel mice? Commented Jul 31, 2023 at 19:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .