From 8386ba27474976c1d6da55d2e7a628d277effc38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 6 Apr 2022 19:18:15 +0200 Subject: [PATCH] Terminal: fixes motion events * fReportButtonMouseEvent 1002 means only drag events are to be reported. * only one of the modes 1000/1002/1003 can be selected. * makes sure to report a button when dragging. * secondary and tertiary buttons were reversed. * extended buffer is now filled with snprintf. * fixes #17684 Change-Id: I59d80937ae193343dc1e7006c4371320fc2182d7 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5184 Tested-by: Commit checker robot Reviewed-by: waddlesplash --- src/apps/terminal/TermView.cpp | 57 +++++++++++++++------------- src/apps/terminal/TermViewStates.cpp | 2 +- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index 0de6514469..e6d377a01c 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -1903,14 +1903,22 @@ TermView::MessageReceived(BMessage *message) if (message->FindBool("reportX10MouseEvent", &value) == B_OK) fReportX10MouseEvent = value; - if (message->FindBool("reportNormalMouseEvent", &value) == B_OK) + // setting one of the three disables the other two + if (message->FindBool("reportNormalMouseEvent", &value) == B_OK) { fReportNormalMouseEvent = value; - - if (message->FindBool("reportButtonMouseEvent", &value) == B_OK) + fReportButtonMouseEvent = false; + fReportAnyMouseEvent = false; + } + if (message->FindBool("reportButtonMouseEvent", &value) == B_OK) { fReportButtonMouseEvent = value; - - if (message->FindBool("reportAnyMouseEvent", &value) == B_OK) + fReportNormalMouseEvent = false; + fReportAnyMouseEvent = false; + } + if (message->FindBool("reportAnyMouseEvent", &value) == B_OK) { fReportAnyMouseEvent = value; + fReportNormalMouseEvent = false; + fReportButtonMouseEvent = false; + } if (message->FindBool( "enableExtendedMouseCoordinates", &value) == B_OK) @@ -2475,7 +2483,8 @@ TermView::_SendMouseEvent(int32 buttons, int32 mode, int32 x, int32 y, else xtermButtons = 32 + 3; - if (motion) + // dragging motion + if (buttons != 0 && motion && fReportButtonMouseEvent) xtermButtons += 32; char xtermX = x + 1 + 32; @@ -2492,38 +2501,32 @@ TermView::_SendMouseEvent(int32 buttons, int32 mode, int32 x, int32 y, } else { char xtermButtons; if ((buttons & B_PRIMARY_MOUSE_BUTTON) - != (fMouseButtons & B_PRIMARY_MOUSE_BUTTON)) { + != (motion ? 0 : (fMouseButtons & B_PRIMARY_MOUSE_BUTTON))) { xtermButtons = 0; } else if ((buttons & B_SECONDARY_MOUSE_BUTTON) - != (fMouseButtons & B_SECONDARY_MOUSE_BUTTON)) { - xtermButtons = 1; - } else if ((buttons & B_TERTIARY_MOUSE_BUTTON) - != (fMouseButtons & B_TERTIARY_MOUSE_BUTTON)) { + != (motion ? 0 : (fMouseButtons & B_SECONDARY_MOUSE_BUTTON))) { xtermButtons = 2; + } else if ((buttons & B_TERTIARY_MOUSE_BUTTON) + != (motion ? 0 : (fMouseButtons & B_TERTIARY_MOUSE_BUTTON))) { + xtermButtons = 1; } else xtermButtons = 3; - if (motion) + // nur button events requested + if (buttons == 0 && motion && fReportButtonMouseEvent) + return; + + // dragging motion + if (buttons != 0 && motion && fReportButtonMouseEvent) 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'; - destBuffer[12] = upEvent ? 'm' : 'M'; - fShell->Write(destBuffer, 13); + char destBuffer[21]; + int size = snprintf(destBuffer, sizeof(destBuffer), "\033[<%u;%u;%u%c", + xtermButtons, xtermX, xtermY, upEvent ? 'm' : 'M'); + fShell->Write(destBuffer, size); } } diff --git a/src/apps/terminal/TermViewStates.cpp b/src/apps/terminal/TermViewStates.cpp index 5f1615b1f7..dc1fb1bb30 100644 --- a/src/apps/terminal/TermViewStates.cpp +++ b/src/apps/terminal/TermViewStates.cpp @@ -160,7 +160,7 @@ TermView::StandardBaseState::_StandardMouseMoved(BPoint where, int32 modifiers) TermPos clickPos = fView->_ConvertToTerminal(where); - if (fView->fReportButtonMouseEvent) { + if (fView->fReportButtonMouseEvent || fView->fEnableExtendedMouseCoordinates) { if (fView->fPrevPos.x != clickPos.x || fView->fPrevPos.y != clickPos.y) { fView->_SendMouseEvent(fView->fMouseButtons, modifiers,