* Applied slightly changed patch by Olivier that adds basic xterm style mouse
support, thanks! * This probably closes bug #2854, confirmation pending. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30268 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -91,6 +91,7 @@ const uint32 MSG_REMOVE_RESIZE_VIEW_IF_NEEDED = 'rmrv';
|
||||
const uint32 MSG_TERMINAL_BUFFER_CHANGED = 'bufc';
|
||||
const uint32 MSG_SET_TERMNAL_TITLE = 'sett';
|
||||
const uint32 MSG_QUIT_TERMNAL = 'qutt';
|
||||
const uint32 MSG_REPORT_ANY_MOUSE_EVENT = 'mous';
|
||||
|
||||
// Preference Read/Write Keys
|
||||
const char* const PREF_HALF_FONT_FAMILY = "Half Font Family";
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
/*
|
||||
* Copyright 2001-2007, Haiku, Inc.
|
||||
* Copyright 2001-2009, Haiku, Inc.
|
||||
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
//! Escape sequence parse and character encoding.
|
||||
|
||||
#include "TermParse.h"
|
||||
|
||||
#include <ctype.h>
|
||||
@@ -23,25 +26,19 @@
|
||||
#include "VTparse.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// EscParse ... Escape sequence parse and character encoding.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
extern int gUTF8GroundTable[]; /* UTF8 Ground table */
|
||||
extern int gCS96GroundTable[]; /* CS96 Ground table */
|
||||
extern int gISO8859GroundTable[]; /* ISO8859 & EUC Ground table */
|
||||
extern int gSJISGroundTable[]; /* Shift-JIS Ground table */
|
||||
|
||||
extern int gEscTable[]; /* ESC */
|
||||
extern int gCsiTable[]; /* ESC [ */
|
||||
extern int gDecTable[]; /* ESC [ ? */
|
||||
extern int gScrTable[]; /* ESC # */
|
||||
extern int gIgnoreTable[]; /* ignore table */
|
||||
extern int gIesTable[]; /* ignore ESC table */
|
||||
extern int gEscTable[]; /* ESC */
|
||||
extern int gCsiTable[]; /* ESC [ */
|
||||
extern int gDecTable[]; /* ESC [ ? */
|
||||
extern int gScrTable[]; /* ESC # */
|
||||
extern int gIgnoreTable[]; /* ignore table */
|
||||
extern int gIesTable[]; /* ignore ESC table */
|
||||
extern int gEscIgnoreTable[]; /* ESC ignore table */
|
||||
extern int gMbcsTable[]; /* ESC $ */
|
||||
extern int gMbcsTable[]; /* ESC $ */
|
||||
|
||||
|
||||
|
||||
@@ -1109,8 +1106,23 @@ TermParse::_DecPrivateModeSet(int value)
|
||||
// Use Alternate Screen Buffer.
|
||||
fBuffer->UseAlternateScreenBuffer(false);
|
||||
break;
|
||||
case 1000:
|
||||
// TODO: Send Mouse X & Y on button press and release.
|
||||
break;
|
||||
case 1003:
|
||||
// Use All Motion Mouse Tracking
|
||||
fBuffer->ReportAnyMouseEvent(true);
|
||||
break;
|
||||
case 1034:
|
||||
// Interpret "meta" key, sets eighth bit.
|
||||
// TODO: Interprete "meta" key, sets eighth bit.
|
||||
// Not supported yet.
|
||||
break;
|
||||
case 1036:
|
||||
// TODO: Send ESC when Meta modifies a key
|
||||
// Not supported yet.
|
||||
break;
|
||||
case 1039:
|
||||
// TODO: Send ESC when Alt modifies a key
|
||||
// Not supported yet.
|
||||
break;
|
||||
case 1049:
|
||||
@@ -1155,8 +1167,23 @@ TermParse::_DecPrivateModeReset(int value)
|
||||
// Use Normal Screen Buffer.
|
||||
fBuffer->UseNormalScreenBuffer();
|
||||
break;
|
||||
case 1000:
|
||||
// TODO: Don't send Mouse X & Y on button press and release.
|
||||
break;
|
||||
case 1003:
|
||||
// Disable All Motion Mouse Tracking.
|
||||
fBuffer->ReportAnyMouseEvent(false);
|
||||
break;
|
||||
case 1034:
|
||||
// Don’t interpret "meta" key.
|
||||
// Don't interprete "meta" key.
|
||||
// Not supported yet.
|
||||
break;
|
||||
case 1036:
|
||||
// TODO: Don't send ESC when Meta modifies a key
|
||||
// Not supported yet.
|
||||
break;
|
||||
case 1039:
|
||||
// TODO: Don't send ESC when Alt modifies a key
|
||||
// Not supported yet.
|
||||
break;
|
||||
case 1049:
|
||||
|
||||
@@ -170,7 +170,8 @@ TermView::TermView(BRect frame, int32 argc, const char** argv, int32 historySize
|
||||
fColumns(COLUMNS_DEFAULT),
|
||||
fRows(ROWS_DEFAULT),
|
||||
fEncoding(M_UTF8),
|
||||
fScrBufSize(historySize)
|
||||
fScrBufSize(historySize),
|
||||
fReportAnyMouseEvent(false)
|
||||
{
|
||||
_InitObject(argc, argv);
|
||||
}
|
||||
@@ -183,7 +184,8 @@ TermView::TermView(int rows, int columns, int32 argc, const char** argv,
|
||||
fColumns(columns),
|
||||
fRows(rows),
|
||||
fEncoding(M_UTF8),
|
||||
fScrBufSize(historySize)
|
||||
fScrBufSize(historySize),
|
||||
fReportAnyMouseEvent(false)
|
||||
{
|
||||
_InitObject(argc, argv);
|
||||
SetTermSize(fRows, fColumns, true);
|
||||
@@ -207,7 +209,8 @@ TermView::TermView(BMessage* archive)
|
||||
fColumns(COLUMNS_DEFAULT),
|
||||
fRows(ROWS_DEFAULT),
|
||||
fEncoding(M_UTF8),
|
||||
fScrBufSize(1000)
|
||||
fScrBufSize(1000),
|
||||
fReportAnyMouseEvent(false)
|
||||
{
|
||||
// We need this
|
||||
SetFlags(Flags() | B_WILL_DRAW | B_PULSE_NEEDED);
|
||||
@@ -277,6 +280,7 @@ TermView::_InitObject(int32 argc, const char** argv)
|
||||
fMouseTracking = false;
|
||||
fIMflag = false;
|
||||
fCheckMouseTracking = false;
|
||||
fReportAnyMouseEvent = false;
|
||||
|
||||
fTextBuffer = new(std::nothrow) TerminalBuffer;
|
||||
if (fTextBuffer == NULL)
|
||||
@@ -1517,7 +1521,13 @@ TermView::MessageReceived(BMessage *msg)
|
||||
SetTitle(title);
|
||||
break;
|
||||
}
|
||||
|
||||
case MSG_REPORT_ANY_MOUSE_EVENT:
|
||||
{
|
||||
bool reportAnyMouseEvent;
|
||||
if (msg->FindBool("reportAnyMouseEvent", &reportAnyMouseEvent) == B_OK)
|
||||
fReportAnyMouseEvent = reportAnyMouseEvent;
|
||||
break;
|
||||
}
|
||||
case MSG_REMOVE_RESIZE_VIEW_IF_NEEDED:
|
||||
{
|
||||
BPoint point;
|
||||
@@ -2023,6 +2033,37 @@ TermView::_MouseDistanceSinceLastClick(BPoint where)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TermView::_SendMouseEvent(int32 buttons, int32 mode, int32 x, int32 y,
|
||||
bool motion)
|
||||
{
|
||||
char xtermButtons;
|
||||
if (buttons == B_PRIMARY_MOUSE_BUTTON)
|
||||
xtermButtons = 32 + 0;
|
||||
else if (buttons == B_SECONDARY_MOUSE_BUTTON)
|
||||
xtermButtons = 32 + 1;
|
||||
else if (buttons == B_TERTIARY_MOUSE_BUTTON)
|
||||
xtermButtons = 32 + 2;
|
||||
else
|
||||
xtermButtons = 32 + 3;
|
||||
|
||||
if (motion)
|
||||
xtermButtons += 32;
|
||||
|
||||
char xtermX = x + 1 + 32;
|
||||
char xtermY = y + 1 + 32;
|
||||
|
||||
char destBuffer[6];
|
||||
destBuffer[0] = '\033';
|
||||
destBuffer[1] = '[';
|
||||
destBuffer[2] = 'M';
|
||||
destBuffer[3] = xtermButtons;
|
||||
destBuffer[4] = xtermX;
|
||||
destBuffer[5] = xtermY;
|
||||
fShell->Write(destBuffer, 6);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TermView::MouseDown(BPoint where)
|
||||
{
|
||||
@@ -2030,10 +2071,19 @@ TermView::MouseDown(BPoint where)
|
||||
MakeFocus();
|
||||
|
||||
int32 buttons;
|
||||
int32 modifier;
|
||||
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
|
||||
Window()->CurrentMessage()->FindInt32("modifiers", &modifier);
|
||||
|
||||
fMouseButtons = buttons;
|
||||
|
||||
if (fReportAnyMouseEvent) {
|
||||
|
||||
TermPos clickPos = _ConvertToTerminal(where);
|
||||
_SendMouseEvent(buttons, modifier, clickPos.x, clickPos.y, false);
|
||||
return;
|
||||
}
|
||||
|
||||
// paste button
|
||||
if ((buttons & (B_SECONDARY_MOUSE_BUTTON | B_TERTIARY_MOUSE_BUTTON)) != 0) {
|
||||
Paste(gMouseClipboard);
|
||||
@@ -2043,14 +2093,13 @@ TermView::MouseDown(BPoint where)
|
||||
|
||||
// Select Region
|
||||
if (buttons == B_PRIMARY_MOUSE_BUTTON) {
|
||||
int32 mod, clicks;
|
||||
Window()->CurrentMessage()->FindInt32("modifiers", &mod);
|
||||
int32 clicks;
|
||||
Window()->CurrentMessage()->FindInt32("clicks", &clicks);
|
||||
|
||||
if (_HasSelection()) {
|
||||
TermPos inPos = _ConvertToTerminal(where);
|
||||
if (_CheckSelectedRegion(inPos)) {
|
||||
if (mod & B_CONTROL_KEY) {
|
||||
if (modifier & B_CONTROL_KEY) {
|
||||
BPoint p;
|
||||
uint32 bt;
|
||||
do {
|
||||
@@ -2081,7 +2130,7 @@ TermView::MouseDown(BPoint where)
|
||||
|
||||
TermPos clickPos = _ConvertToTerminal(where);
|
||||
|
||||
if (mod & B_SHIFT_KEY) {
|
||||
if (modifier & B_SHIFT_KEY) {
|
||||
fInitialSelectionStart = clickPos;
|
||||
fInitialSelectionEnd = clickPos;
|
||||
_ExtendSelection(fInitialSelectionStart, true, false);
|
||||
@@ -2098,22 +2147,21 @@ TermView::MouseDown(BPoint where)
|
||||
case 1:
|
||||
fCheckMouseTracking = true;
|
||||
fSelectGranularity = SELECT_CHARS;
|
||||
break;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
_SelectWord(where, (mod & B_SHIFT_KEY) != 0, false);
|
||||
_SelectWord(where, (modifier & B_SHIFT_KEY) != 0, false);
|
||||
fMouseTracking = true;
|
||||
fSelectGranularity = SELECT_WORDS;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
_SelectLine(where, (mod & B_SHIFT_KEY) != 0, false);
|
||||
_SelectLine(where, (modifier & B_SHIFT_KEY) != 0, false);
|
||||
fMouseTracking = true;
|
||||
fSelectGranularity = SELECT_LINES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
fLastClickPoint = where;
|
||||
}
|
||||
|
||||
@@ -2121,6 +2169,15 @@ TermView::MouseDown(BPoint where)
|
||||
void
|
||||
TermView::MouseMoved(BPoint where, uint32 transit, const BMessage *message)
|
||||
{
|
||||
if (fReportAnyMouseEvent) {
|
||||
int32 modifier;
|
||||
Window()->CurrentMessage()->FindInt32("modifiers", &modifier);
|
||||
|
||||
TermPos clickPos = _ConvertToTerminal(where);
|
||||
_SendMouseEvent(fMouseButtons, modifier, clickPos.x, clickPos.y, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fCheckMouseTracking) {
|
||||
if (_MouseDistanceSinceLastClick(where) > 9)
|
||||
fMouseTracking = true;
|
||||
@@ -2169,15 +2226,15 @@ TermView::MouseMoved(BPoint where, uint32 transit, const BMessage *message)
|
||||
}
|
||||
|
||||
_ExtendSelection(_ConvertToTerminal(where), true, true);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
case SELECT_WORDS:
|
||||
_SelectWord(where, true, true);
|
||||
break;
|
||||
break;
|
||||
case SELECT_LINES:
|
||||
_SelectLine(where, true, true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2196,16 +2253,22 @@ TermView::MouseUp(BPoint where)
|
||||
// clipboard.
|
||||
int32 buttons;
|
||||
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
|
||||
if ((buttons & B_PRIMARY_MOUSE_BUTTON) == 0
|
||||
&& (fMouseButtons & B_PRIMARY_MOUSE_BUTTON) != 0) {
|
||||
Copy(gMouseClipboard);
|
||||
}
|
||||
|
||||
if (fReportAnyMouseEvent) {
|
||||
TermPos clickPos = _ConvertToTerminal(where);
|
||||
_SendMouseEvent(0, 0, clickPos.x, clickPos.y, false);
|
||||
} else {
|
||||
if ((buttons & B_PRIMARY_MOUSE_BUTTON) == 0
|
||||
&& (fMouseButtons & B_PRIMARY_MOUSE_BUTTON) != 0) {
|
||||
Copy(gMouseClipboard);
|
||||
}
|
||||
|
||||
}
|
||||
fMouseButtons = buttons;
|
||||
}
|
||||
|
||||
|
||||
// Select a range of text
|
||||
//! Select a range of text.
|
||||
void
|
||||
TermView::_Select(TermPos start, TermPos end, bool inclusive,
|
||||
bool setInitialSelection)
|
||||
@@ -2267,7 +2330,7 @@ TermView::_Select(TermPos start, TermPos end, bool inclusive,
|
||||
}
|
||||
|
||||
|
||||
// extend selection (shift + mouse click)
|
||||
//! Extend selection (shift + mouse click).
|
||||
void
|
||||
TermView::_ExtendSelection(TermPos pos, bool inclusive,
|
||||
bool useInitialSelection)
|
||||
|
||||
@@ -177,6 +177,8 @@ private:
|
||||
void _ScrollTo(float y, bool scrollGfx);
|
||||
void _ScrollToRange(TermPos start, TermPos end);
|
||||
|
||||
void _SendMouseEvent(int32 button, int32 mode, int32 x,
|
||||
int32 y, bool motion);
|
||||
private:
|
||||
class CharClassifier;
|
||||
|
||||
@@ -252,6 +254,8 @@ private:
|
||||
int fSelectGranularity;
|
||||
BPoint fLastClickPoint;
|
||||
|
||||
bool fReportAnyMouseEvent;
|
||||
|
||||
// Input Method parameter.
|
||||
int fIMViewPtr;
|
||||
TermPos fIMStartPos;
|
||||
|
||||
@@ -74,6 +74,17 @@ TerminalBuffer::Encoding() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TerminalBuffer::ReportAnyMouseEvent(bool reportAnyMouseEvent)
|
||||
{
|
||||
if (fListenerValid) {
|
||||
BMessage message(MSG_REPORT_ANY_MOUSE_EVENT);
|
||||
message.AddBool("reportAnyMouseEvent", reportAnyMouseEvent);
|
||||
fListener.SendMessage(&message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TerminalBuffer::SetEncoding(int encoding)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,8 @@ public:
|
||||
void UseAlternateScreenBuffer(bool clear);
|
||||
void UseNormalScreenBuffer();
|
||||
|
||||
void ReportAnyMouseEvent(bool reportAnyMouseEvent);
|
||||
|
||||
protected:
|
||||
virtual void NotifyListener();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user