Skip to content

Instantly share code, notes, and snippets.

@saitoha
Created July 28, 2012 14:03
Show Gist options
  • Select an option

  • Save saitoha/3193529 to your computer and use it in GitHub Desktop.

Select an option

Save saitoha/3193529 to your computer and use it in GitHub Desktop.
SGR 1006 mouse tracking for Konsole (master:KONSOLE_VERSION=2.9.999)
diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp
index 82458aa..0ee4c62 100644
--- a/src/TerminalDisplay.cpp
+++ b/src/TerminalDisplay.cpp
@@ -2165,20 +2165,26 @@ void TerminalDisplay::mouseReleaseEvent(QMouseEvent* ev)
// applies here, too.
if (!_mouseMarks && !(ev->modifiers() & Qt::ShiftModifier))
- emit mouseSignal(3, // release
+ emit mouseSignal(0, // left button
charColumn + 1,
- charLine + 1 + _scrollBar->value() - _scrollBar->maximum() , 0);
+ charLine + 1 + _scrollBar->value() - _scrollBar->maximum() ,
+ 3); // release
}
_dragInfo.state = diNone;
- }
+ } else {
- if (!_mouseMarks &&
- (ev->button() == Qt::RightButton || ev->button() == Qt::MidButton) &&
- !(ev->modifiers() & Qt::ShiftModifier)) {
- emit mouseSignal(3,
- charColumn + 1,
- charLine + 1 + _scrollBar->value() - _scrollBar->maximum() ,
- 0);
+ int button = 0;
+ if (ev->buttons() == Qt::MidButton)
+ button = 1;
+ if (ev->buttons() == Qt::RightButton)
+ button = 2;
+
+ if (!_mouseMarks && button != 0 && !(ev->modifiers() & Qt::ShiftModifier)) {
+ emit mouseSignal(button,
+ charColumn + 1,
+ charLine + 1 + _scrollBar->value() - _scrollBar->maximum() ,
+ 3); // release
+ }
}
}
diff --git a/src/Vt102Emulation.cpp b/src/Vt102Emulation.cpp
index 9bbb1bf..476383a 100644
--- a/src/Vt102Emulation.cpp
+++ b/src/Vt102Emulation.cpp
@@ -759,6 +759,11 @@ void Vt102Emulation::processToken(int token, int p, int q)
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', 1006) : setMode (MODE_Mouse1006); break; //XTERM
+ case TY_CSI_PR('l', 1006) : resetMode (MODE_Mouse1006); break; //XTERM
+ case TY_CSI_PR('s', 1006) : saveMode (MODE_Mouse1006); break; //XTERM
+ case TY_CSI_PR('r', 1006) : restoreMode (MODE_Mouse1006); 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
@@ -916,10 +921,19 @@ 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
+ if (!getMode(MODE_Mouse1006) && eventType == 3)
+ cb |= 0x03; //release
+
char command[32];
command[0] = '\0';
if (getMode(MODE_Mouse1015)) {
snprintf(command, sizeof(command), "\033[%d;%d;%dM", cb + 0x20, cx, cy);
+ } else if (getMode(MODE_Mouse1006)) {
+ if (eventType == 3) {
+ snprintf(command, sizeof(command), "\033[<%d;%d;%dm", cb, cx, cy);
+ } else {
+ snprintf(command, sizeof(command), "\033[<%d;%d;%dM", cb, cx, cy);
+ }
} else if (getMode(MODE_Mouse1005)) {
if (cx <= 2015 && cy <= 2015) {
// The xterm extension uses UTF-8 (up to 2 bytes) to encode
@@ -1179,6 +1193,7 @@ void Vt102Emulation::resetModes()
resetMode(MODE_Mouse1002); saveMode(MODE_Mouse1002);
resetMode(MODE_Mouse1003); saveMode(MODE_Mouse1003);
resetMode(MODE_Mouse1005); saveMode(MODE_Mouse1005);
+ resetMode(MODE_Mouse1006); saveMode(MODE_Mouse1006);
resetMode(MODE_Mouse1015); saveMode(MODE_Mouse1015);
resetMode(MODE_AppScreen); saveMode(MODE_AppScreen);
diff --git a/src/Vt102Emulation.h b/src/Vt102Emulation.h
index 4b0002b..bf05d70 100644
--- a/src/Vt102Emulation.h
+++ b/src/Vt102Emulation.h
@@ -41,11 +41,12 @@ class QKeyEvent;
#define MODE_Mouse1002 (MODES_SCREEN+5) // Use cell motion mouse tracking
#define MODE_Mouse1003 (MODES_SCREEN+6) // Use all motion mouse tracking
#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)
+#define MODE_Mouse1006 (MODES_SCREEN+8) // Xterm-style new extended coordinates
+#define MODE_Mouse1015 (MODES_SCREEN+9) // Urxvt-style extended coordinates
+#define MODE_Ansi (MODES_SCREEN+10) // Use US Ascii for character sets G0-G3 (DECANM)
+#define MODE_132Columns (MODES_SCREEN+11) // 80 <-> 132 column mode switch (DECCOLM)
+#define MODE_Allow132Columns (MODES_SCREEN+12) // Allow DECCOLM mode
+#define MODE_total (MODES_SCREEN+13)
namespace Konsole
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment