Terminal: Add support for extended mouse coordinates

Fixes #11949

Change-Id: I779d1a9af2e3208ba3c055692de5e62b6a7b72fc
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1919
Reviewed-by: Stephan Aßmus <superstippi@gmx.de>
This commit is contained in:
Lukasz Towarek 2019-10-15 20:42:22 +00:00 committed by Stephan Aßmus
parent d8779e44ee
commit e3c74f400e
6 changed files with 98 additions and 35 deletions

View File

@ -177,9 +177,9 @@ enum {
#define TAB_WIDTH 8 #define TAB_WIDTH 8
#define MIN_COLS 10 #define MIN_COLS 10
#define MAX_COLS 256 #define MAX_COLS 999
#define MIN_ROWS 10 #define MIN_ROWS 10
#define MAX_ROWS 256 #define MAX_ROWS 999
// Insert mode flag // Insert mode flag
#define MODE_OVER 0 #define MODE_OVER 0

View File

@ -1395,6 +1395,10 @@ TermParse::_DecPrivateModeSet(int value)
// Use All Motion Mouse Tracking // Use All Motion Mouse Tracking
fBuffer->ReportAnyMouseEvent(true); fBuffer->ReportAnyMouseEvent(true);
break; break;
case 1006:
// Enable extended mouse coordinates with SGR scheme
fBuffer->EnableExtendedMouseCoordinates(true);
break;
case 1034: case 1034:
// Interpret "meta" key, sets eighth bit. // Interpret "meta" key, sets eighth bit.
fBuffer->EnableInterpretMetaKey(true); fBuffer->EnableInterpretMetaKey(true);
@ -1470,6 +1474,10 @@ TermParse::_DecPrivateModeReset(int value)
// Disable All Motion Mouse Tracking. // Disable All Motion Mouse Tracking.
fBuffer->ReportAnyMouseEvent(false); fBuffer->ReportAnyMouseEvent(false);
break; break;
case 1006:
// Disable extended mouse coordinates with SGR scheme
fBuffer->EnableExtendedMouseCoordinates(false);
break;
case 1034: case 1034:
// Don't interpret "meta" key. // Don't interpret "meta" key.
fBuffer->EnableInterpretMetaKey(false); fBuffer->EnableInterpretMetaKey(false);

View File

@ -174,7 +174,8 @@ TermView::TermView(BRect frame, const ShellParameters& shellParameters,
fReportX10MouseEvent(false), fReportX10MouseEvent(false),
fReportNormalMouseEvent(false), fReportNormalMouseEvent(false),
fReportButtonMouseEvent(false), fReportButtonMouseEvent(false),
fReportAnyMouseEvent(false) fReportAnyMouseEvent(false),
fEnableExtendedMouseCoordinates(false)
{ {
status_t status = _InitObject(shellParameters); status_t status = _InitObject(shellParameters);
if (status != B_OK) if (status != B_OK)
@ -197,7 +198,8 @@ TermView::TermView(int rows, int columns,
fReportX10MouseEvent(false), fReportX10MouseEvent(false),
fReportNormalMouseEvent(false), fReportNormalMouseEvent(false),
fReportButtonMouseEvent(false), fReportButtonMouseEvent(false),
fReportAnyMouseEvent(false) fReportAnyMouseEvent(false),
fEnableExtendedMouseCoordinates(false)
{ {
status_t status = _InitObject(shellParameters); status_t status = _InitObject(shellParameters);
if (status != B_OK) if (status != B_OK)
@ -230,7 +232,8 @@ TermView::TermView(BMessage* archive)
fReportX10MouseEvent(false), fReportX10MouseEvent(false),
fReportNormalMouseEvent(false), fReportNormalMouseEvent(false),
fReportButtonMouseEvent(false), fReportButtonMouseEvent(false),
fReportAnyMouseEvent(false) fReportAnyMouseEvent(false),
fEnableExtendedMouseCoordinates(false)
{ {
BRect frame = Bounds(); BRect frame = Bounds();
@ -317,6 +320,7 @@ TermView::_InitObject(const ShellParameters& shellParameters)
fReportNormalMouseEvent = false; fReportNormalMouseEvent = false;
fReportButtonMouseEvent = false; fReportButtonMouseEvent = false;
fReportAnyMouseEvent = false; fReportAnyMouseEvent = false;
fEnableExtendedMouseCoordinates = false;
fMouseClipboard = be_clipboard; fMouseClipboard = be_clipboard;
fDefaultState = new(std::nothrow) DefaultState(this); fDefaultState = new(std::nothrow) DefaultState(this);
fSelectState = new(std::nothrow) SelectState(this); fSelectState = new(std::nothrow) SelectState(this);
@ -1846,18 +1850,21 @@ TermView::MessageReceived(BMessage *msg)
} }
case MSG_REPORT_MOUSE_EVENT: case MSG_REPORT_MOUSE_EVENT:
{ {
bool report; bool value;
if (msg->FindBool("reportX10MouseEvent", &report) == B_OK) if (msg->FindBool("reportX10MouseEvent", &value) == B_OK)
fReportX10MouseEvent = report; fReportX10MouseEvent = value;
if (msg->FindBool("reportNormalMouseEvent", &report) == B_OK) if (msg->FindBool("reportNormalMouseEvent", &value) == B_OK)
fReportNormalMouseEvent = report; fReportNormalMouseEvent = value;
if (msg->FindBool("reportButtonMouseEvent", &report) == B_OK) if (msg->FindBool("reportButtonMouseEvent", &value) == B_OK)
fReportButtonMouseEvent = report; fReportButtonMouseEvent = value;
if (msg->FindBool("reportAnyMouseEvent", &report) == B_OK) if (msg->FindBool("reportAnyMouseEvent", &value) == B_OK)
fReportAnyMouseEvent = report; fReportAnyMouseEvent = value;
if (msg->FindBool("enableExtendedMouseCoordinates", &value) == B_OK)
fEnableExtendedMouseCoordinates = value;
break; break;
} }
case MSG_REMOVE_RESIZE_VIEW_IF_NEEDED: case MSG_REMOVE_RESIZE_VIEW_IF_NEEDED:
@ -2407,30 +2414,65 @@ void
TermView::_SendMouseEvent(int32 buttons, int32 mode, int32 x, int32 y, TermView::_SendMouseEvent(int32 buttons, int32 mode, int32 x, int32 y,
bool motion) bool motion)
{ {
char xtermButtons; if (!fEnableExtendedMouseCoordinates) {
if (buttons == B_PRIMARY_MOUSE_BUTTON) char xtermButtons;
xtermButtons = 32 + 0; if (buttons == B_PRIMARY_MOUSE_BUTTON)
else if (buttons == B_SECONDARY_MOUSE_BUTTON) xtermButtons = 32 + 0;
xtermButtons = 32 + 1; else if (buttons == B_SECONDARY_MOUSE_BUTTON)
else if (buttons == B_TERTIARY_MOUSE_BUTTON) xtermButtons = 32 + 1;
xtermButtons = 32 + 2; else if (buttons == B_TERTIARY_MOUSE_BUTTON)
else xtermButtons = 32 + 2;
xtermButtons = 32 + 3; else
xtermButtons = 32 + 3;
if (motion) if (motion)
xtermButtons += 32; xtermButtons += 32;
char xtermX = x + 1 + 32; char xtermX = x + 1 + 32;
char xtermY = y + 1 + 32; char xtermY = y + 1 + 32;
char destBuffer[6]; char destBuffer[6];
destBuffer[0] = '\033'; destBuffer[0] = '\033';
destBuffer[1] = '['; destBuffer[1] = '[';
destBuffer[2] = 'M'; destBuffer[2] = 'M';
destBuffer[3] = xtermButtons; destBuffer[3] = xtermButtons;
destBuffer[4] = xtermX; destBuffer[4] = xtermX;
destBuffer[5] = xtermY; destBuffer[5] = xtermY;
fShell->Write(destBuffer, 6); fShell->Write(destBuffer, 6);
} else {
char xtermButtons;
if (buttons == B_PRIMARY_MOUSE_BUTTON)
xtermButtons = 0;
else if (buttons == B_SECONDARY_MOUSE_BUTTON)
xtermButtons = 1;
else if (buttons == B_TERTIARY_MOUSE_BUTTON)
xtermButtons = 2;
else
xtermButtons = 3;
if (motion)
xtermButtons += 32;
int16 xtermX = x + 1;
int16 xtermY = y + 1;
char destBuffer[13];
destBuffer[0] = '\033';
destBuffer[1] = '[';
destBuffer[2] = '<';
destBuffer[3] = xtermButtons + '0';
destBuffer[4] = ';';
destBuffer[5] = xtermX / 100 % 10 + '0';
destBuffer[6] = xtermX / 10 % 10 + '0';
destBuffer[7] = xtermX % 10 + '0';
destBuffer[8] = ';';
destBuffer[9] = xtermY / 100 % 10 + '0';
destBuffer[10] = xtermY / 10 % 10 + '0';
destBuffer[11] = xtermY % 10 + '0';
// No support for button press/release
destBuffer[12] = 'M';
fShell->Write(destBuffer, 13);
}
} }

View File

@ -359,6 +359,7 @@ private:
bool fReportNormalMouseEvent; bool fReportNormalMouseEvent;
bool fReportButtonMouseEvent; bool fReportButtonMouseEvent;
bool fReportAnyMouseEvent; bool fReportAnyMouseEvent;
bool fEnableExtendedMouseCoordinates;
BClipboard* fMouseClipboard; BClipboard* fMouseClipboard;
// states // states

View File

@ -157,6 +157,17 @@ TerminalBuffer::ReportAnyMouseEvent(bool reportAnyMouseEvent)
} }
void
TerminalBuffer::EnableExtendedMouseCoordinates(bool enable)
{
if (fListenerValid) {
BMessage message(MSG_REPORT_MOUSE_EVENT);
message.AddBool("enableExtendedMouseCoordinates", enable);
fListener.SendMessage(&message);
}
}
void void
TerminalBuffer::SetEncoding(int encoding) TerminalBuffer::SetEncoding(int encoding)
{ {

View File

@ -60,6 +60,7 @@ public:
void ReportNormalMouseEvent(bool report); void ReportNormalMouseEvent(bool report);
void ReportButtonMouseEvent(bool report); void ReportButtonMouseEvent(bool report);
void ReportAnyMouseEvent(bool report); void ReportAnyMouseEvent(bool report);
void EnableExtendedMouseCoordinates(bool enable);
protected: protected:
virtual void NotifyListener(); virtual void NotifyListener();