From c059c8c5d0a03c4177a140497434523984906870 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 23 Nov 2010 17:49:40 +0000 Subject: [PATCH] MessageReceived(): Override B_MOUSE_WHEEL_CHANGED when in alternative screen mode and send the key/page up/down escape sequences instead of trying to scroll. Makes mouse wheel scrolling in less, nano,... working. Closes #6460. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39589 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TermView.cpp | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index 1e4b6b8e81..beab93fa7d 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -1937,6 +1937,54 @@ TermView::MessageReceived(BMessage *msg) break; } + case B_MOUSE_WHEEL_CHANGED: + { + // overridden to allow scrolling emulation in alternative screen + // mode + BAutolock locker(fTextBuffer); + float deltaY = 0; + if (fTextBuffer->IsAlternateScreenActive() + && msg->FindFloat("be:wheel_delta_y", &deltaY) == B_OK + && deltaY != 0) { + // We are in alternative screen mode and have a vertical delta + // we can work with -- emulate scrolling via terminal escape + // sequences. + locker.Unlock(); + + // scroll pagewise, if one of Option, Command, or Control is + // pressed + int32 steps; + const char* stepString; + if ((modifiers() + & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) + != 0) { + // pagewise + stepString = deltaY > 0 + ? PAGE_DOWN_KEY_CODE : PAGE_UP_KEY_CODE; + steps = abs((int)deltaY); + } else { + // three lines per step + stepString = deltaY > 0 + ? DOWN_ARROW_KEY_CODE : UP_ARROW_KEY_CODE; + steps = 3 * abs((int)deltaY); + } + + // We want to do only a single write(), so compose a string + // repeating the sequence as often as required by the delta. + BString toWrite; + for (int32 i = 0; i Write(ctrl_l, 1);