summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Hindenburg <kurt.hindenburg@gmail.com>2012-01-21 18:21:36 (GMT)
committerKurt Hindenburg <kurt.hindenburg@gmail.com>2012-01-21 18:21:36 (GMT)
commitb876f2a3edcb63f29588fdde6b20dc6c9d13bc24 (patch)
treeb7e0f58cec978c42c2e6b36728448e4a3c049930
parent5bbeaae8d6cabb400a1a362c3010537e52e22c75 (diff)
Support extended mouse coordinates.
Using the legacy method, mouse coordinates can be reported only up to 223. If you have a wider terminal, you cannot use the mouse in the rightmost columns. There exist two extensions to overcome this problem, a broken one invented by xterm (the "DEC 1005" mode) which is supported by xterm, urxvt and iterm2; and a good one invented by urxvt (the "DEC 1015" mode), supported by urxvt and iterm2. Many thanks to Egmont Koblinger egmont@gmail.com for report and patch. BUG: 285984 FIXED-IN: 4.9
-rw-r--r--src/Vt102Emulation.cpp34
-rw-r--r--src/Vt102Emulation.h10
2 files changed, 38 insertions, 6 deletions
diff --git a/src/Vt102Emulation.cpp b/src/Vt102Emulation.cpp
index 197f59b..afbddd6 100644
--- a/src/Vt102Emulation.cpp
+++ b/src/Vt102Emulation.cpp
@@ -767,6 +767,16 @@ void Vt102Emulation::processToken(int token, int p, int q)
case TY_CSI_PR('s', 1003) : saveMode (MODE_Mouse1003); break; //XTERM
case TY_CSI_PR('r', 1003) : restoreMode (MODE_Mouse1003); break; //XTERM
+ case TY_CSI_PR('h', 1005) : setMode (MODE_Mouse1005); break; //XTERM
+ case TY_CSI_PR('l', 1005) : resetMode (MODE_Mouse1005); break; //XTERM
+ case TY_CSI_PR('s', 1005) : saveMode (MODE_Mouse1005); break; //XTERM
+ case TY_CSI_PR('r', 1005) : restoreMode (MODE_Mouse1005); break; //XTERM
+
+ case TY_CSI_PR('h', 1015) : setMode (MODE_Mouse1015); break; //URXVT
+ case TY_CSI_PR('l', 1015) : resetMode (MODE_Mouse1015); break; //URXVT
+ case TY_CSI_PR('s', 1015) : saveMode (MODE_Mouse1015); break; //URXVT
+ case TY_CSI_PR('r', 1015) : restoreMode (MODE_Mouse1015); break; //URXVT
+
case TY_CSI_PR('h', 1034) : /* IGNORED: 8bitinput activation */ break; //XTERM
case TY_CSI_PR('h', 1047) : setMode (MODE_AppScreen); break; //XTERM
@@ -919,8 +929,26 @@ void Vt102Emulation::sendMouseEvent(int cb, int cx, int cy , int eventType)
if ((getMode(MODE_Mouse1002) || getMode(MODE_Mouse1003)) && eventType == 1)
cb += 0x20; //add 32 to signify motion event
- char command[20];
- sprintf(command, "\033[M%c%c%c", cb + 0x20, cx + 0x20, cy + 0x20);
+ char command[32];
+ command[0] = '\0';
+ if (getMode(MODE_Mouse1015)) {
+ sprintf(command, "\033[%d;%d;%dM", cb + 0x20, cx, cy);
+ } else if (getMode(MODE_Mouse1005)) {
+ if (cx <= 2015 && cy <= 2015) {
+ // The xterm extension uses UTF-8 (up to 2 bytes) to encode
+ // coordinate+32, no matter what the locale is. We could easily
+ // convert manually, but QString can also do it for us.
+ QChar coords[2];
+ coords[0] = cx + 0x20;
+ coords[1] = cy + 0x20;
+ QString coordsStr = QString(coords, 2);
+ QByteArray utf8 = coordsStr.toUtf8();
+ sprintf(command, "\033[M%c%s", cb + 0x20, (const char *)utf8);
+ }
+ } else if (cx <= 223 && cy <= 223) {
+ sprintf(command, "\033[M%c%c%c", cb + 0x20, cx + 0x20, cy + 0x20);
+ }
+
sendString(command);
}
@@ -1152,6 +1180,8 @@ void Vt102Emulation::resetModes()
resetMode(MODE_Mouse1001); saveMode(MODE_Mouse1001);
resetMode(MODE_Mouse1002); saveMode(MODE_Mouse1002);
resetMode(MODE_Mouse1003); saveMode(MODE_Mouse1003);
+ resetMode(MODE_Mouse1005); saveMode(MODE_Mouse1005);
+ resetMode(MODE_Mouse1015); saveMode(MODE_Mouse1015);
resetMode(MODE_AppScreen); saveMode(MODE_AppScreen);
resetMode(MODE_AppCuKeys); saveMode(MODE_AppCuKeys);
diff --git a/src/Vt102Emulation.h b/src/Vt102Emulation.h
index b676070..c7b7877 100644
--- a/src/Vt102Emulation.h
+++ b/src/Vt102Emulation.h
@@ -39,10 +39,12 @@
#define MODE_Mouse1001 (MODES_SCREEN+4) // Use Hilight mouse tracking
#define MODE_Mouse1002 (MODES_SCREEN+5) // Use cell motion mouse tracking
#define MODE_Mouse1003 (MODES_SCREEN+6) // Use all motion mouse tracking
-#define MODE_Ansi (MODES_SCREEN+7) // Use US Ascii for character sets G0-G3 (DECANM)
-#define MODE_132Columns (MODES_SCREEN+8) // 80 <-> 132 column mode switch (DECCOLM)
-#define MODE_Allow132Columns (MODES_SCREEN+9) // Allow DECCOLM mode
-#define MODE_total (MODES_SCREEN+10)
+#define MODE_Mouse1005 (MODES_SCREEN+7) // Xterm-style extended coordinates
+#define MODE_Mouse1015 (MODES_SCREEN+8) // Urxvt-style extended coordinates
+#define MODE_Ansi (MODES_SCREEN+9) // Use US Ascii for character sets G0-G3 (DECANM)
+#define MODE_132Columns (MODES_SCREEN+10) // 80 <-> 132 column mode switch (DECCOLM)
+#define MODE_Allow132Columns (MODES_SCREEN+11) // Allow DECCOLM mode
+#define MODE_total (MODES_SCREEN+12)
namespace Konsole
{