* 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_TERMINAL_BUFFER_CHANGED = 'bufc';
|
||||||
const uint32 MSG_SET_TERMNAL_TITLE = 'sett';
|
const uint32 MSG_SET_TERMNAL_TITLE = 'sett';
|
||||||
const uint32 MSG_QUIT_TERMNAL = 'qutt';
|
const uint32 MSG_QUIT_TERMNAL = 'qutt';
|
||||||
|
const uint32 MSG_REPORT_ANY_MOUSE_EVENT = 'mous';
|
||||||
|
|
||||||
// Preference Read/Write Keys
|
// Preference Read/Write Keys
|
||||||
const char* const PREF_HALF_FONT_FAMILY = "Half Font Family";
|
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]>
|
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
||||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//! Escape sequence parse and character encoding.
|
||||||
|
|
||||||
#include "TermParse.h"
|
#include "TermParse.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -23,12 +26,6 @@
|
|||||||
#include "VTparse.h"
|
#include "VTparse.h"
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
// EscParse ... Escape sequence parse and character encoding.
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
extern int gUTF8GroundTable[]; /* UTF8 Ground table */
|
extern int gUTF8GroundTable[]; /* UTF8 Ground table */
|
||||||
extern int gCS96GroundTable[]; /* CS96 Ground table */
|
extern int gCS96GroundTable[]; /* CS96 Ground table */
|
||||||
extern int gISO8859GroundTable[]; /* ISO8859 & EUC Ground table */
|
extern int gISO8859GroundTable[]; /* ISO8859 & EUC Ground table */
|
||||||
@@ -1109,8 +1106,23 @@ TermParse::_DecPrivateModeSet(int value)
|
|||||||
// Use Alternate Screen Buffer.
|
// Use Alternate Screen Buffer.
|
||||||
fBuffer->UseAlternateScreenBuffer(false);
|
fBuffer->UseAlternateScreenBuffer(false);
|
||||||
break;
|
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:
|
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.
|
// Not supported yet.
|
||||||
break;
|
break;
|
||||||
case 1049:
|
case 1049:
|
||||||
@@ -1155,8 +1167,23 @@ TermParse::_DecPrivateModeReset(int value)
|
|||||||
// Use Normal Screen Buffer.
|
// Use Normal Screen Buffer.
|
||||||
fBuffer->UseNormalScreenBuffer();
|
fBuffer->UseNormalScreenBuffer();
|
||||||
break;
|
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:
|
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.
|
// Not supported yet.
|
||||||
break;
|
break;
|
||||||
case 1049:
|
case 1049:
|
||||||
|
|||||||
@@ -170,7 +170,8 @@ TermView::TermView(BRect frame, int32 argc, const char** argv, int32 historySize
|
|||||||
fColumns(COLUMNS_DEFAULT),
|
fColumns(COLUMNS_DEFAULT),
|
||||||
fRows(ROWS_DEFAULT),
|
fRows(ROWS_DEFAULT),
|
||||||
fEncoding(M_UTF8),
|
fEncoding(M_UTF8),
|
||||||
fScrBufSize(historySize)
|
fScrBufSize(historySize),
|
||||||
|
fReportAnyMouseEvent(false)
|
||||||
{
|
{
|
||||||
_InitObject(argc, argv);
|
_InitObject(argc, argv);
|
||||||
}
|
}
|
||||||
@@ -183,7 +184,8 @@ TermView::TermView(int rows, int columns, int32 argc, const char** argv,
|
|||||||
fColumns(columns),
|
fColumns(columns),
|
||||||
fRows(rows),
|
fRows(rows),
|
||||||
fEncoding(M_UTF8),
|
fEncoding(M_UTF8),
|
||||||
fScrBufSize(historySize)
|
fScrBufSize(historySize),
|
||||||
|
fReportAnyMouseEvent(false)
|
||||||
{
|
{
|
||||||
_InitObject(argc, argv);
|
_InitObject(argc, argv);
|
||||||
SetTermSize(fRows, fColumns, true);
|
SetTermSize(fRows, fColumns, true);
|
||||||
@@ -207,7 +209,8 @@ TermView::TermView(BMessage* archive)
|
|||||||
fColumns(COLUMNS_DEFAULT),
|
fColumns(COLUMNS_DEFAULT),
|
||||||
fRows(ROWS_DEFAULT),
|
fRows(ROWS_DEFAULT),
|
||||||
fEncoding(M_UTF8),
|
fEncoding(M_UTF8),
|
||||||
fScrBufSize(1000)
|
fScrBufSize(1000),
|
||||||
|
fReportAnyMouseEvent(false)
|
||||||
{
|
{
|
||||||
// We need this
|
// We need this
|
||||||
SetFlags(Flags() | B_WILL_DRAW | B_PULSE_NEEDED);
|
SetFlags(Flags() | B_WILL_DRAW | B_PULSE_NEEDED);
|
||||||
@@ -277,6 +280,7 @@ TermView::_InitObject(int32 argc, const char** argv)
|
|||||||
fMouseTracking = false;
|
fMouseTracking = false;
|
||||||
fIMflag = false;
|
fIMflag = false;
|
||||||
fCheckMouseTracking = false;
|
fCheckMouseTracking = false;
|
||||||
|
fReportAnyMouseEvent = false;
|
||||||
|
|
||||||
fTextBuffer = new(std::nothrow) TerminalBuffer;
|
fTextBuffer = new(std::nothrow) TerminalBuffer;
|
||||||
if (fTextBuffer == NULL)
|
if (fTextBuffer == NULL)
|
||||||
@@ -1517,7 +1521,13 @@ TermView::MessageReceived(BMessage *msg)
|
|||||||
SetTitle(title);
|
SetTitle(title);
|
||||||
break;
|
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:
|
case MSG_REMOVE_RESIZE_VIEW_IF_NEEDED:
|
||||||
{
|
{
|
||||||
BPoint point;
|
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
|
void
|
||||||
TermView::MouseDown(BPoint where)
|
TermView::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
@@ -2030,10 +2071,19 @@ TermView::MouseDown(BPoint where)
|
|||||||
MakeFocus();
|
MakeFocus();
|
||||||
|
|
||||||
int32 buttons;
|
int32 buttons;
|
||||||
|
int32 modifier;
|
||||||
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
|
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
|
||||||
|
Window()->CurrentMessage()->FindInt32("modifiers", &modifier);
|
||||||
|
|
||||||
fMouseButtons = buttons;
|
fMouseButtons = buttons;
|
||||||
|
|
||||||
|
if (fReportAnyMouseEvent) {
|
||||||
|
|
||||||
|
TermPos clickPos = _ConvertToTerminal(where);
|
||||||
|
_SendMouseEvent(buttons, modifier, clickPos.x, clickPos.y, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// paste button
|
// paste button
|
||||||
if ((buttons & (B_SECONDARY_MOUSE_BUTTON | B_TERTIARY_MOUSE_BUTTON)) != 0) {
|
if ((buttons & (B_SECONDARY_MOUSE_BUTTON | B_TERTIARY_MOUSE_BUTTON)) != 0) {
|
||||||
Paste(gMouseClipboard);
|
Paste(gMouseClipboard);
|
||||||
@@ -2043,14 +2093,13 @@ TermView::MouseDown(BPoint where)
|
|||||||
|
|
||||||
// Select Region
|
// Select Region
|
||||||
if (buttons == B_PRIMARY_MOUSE_BUTTON) {
|
if (buttons == B_PRIMARY_MOUSE_BUTTON) {
|
||||||
int32 mod, clicks;
|
int32 clicks;
|
||||||
Window()->CurrentMessage()->FindInt32("modifiers", &mod);
|
|
||||||
Window()->CurrentMessage()->FindInt32("clicks", &clicks);
|
Window()->CurrentMessage()->FindInt32("clicks", &clicks);
|
||||||
|
|
||||||
if (_HasSelection()) {
|
if (_HasSelection()) {
|
||||||
TermPos inPos = _ConvertToTerminal(where);
|
TermPos inPos = _ConvertToTerminal(where);
|
||||||
if (_CheckSelectedRegion(inPos)) {
|
if (_CheckSelectedRegion(inPos)) {
|
||||||
if (mod & B_CONTROL_KEY) {
|
if (modifier & B_CONTROL_KEY) {
|
||||||
BPoint p;
|
BPoint p;
|
||||||
uint32 bt;
|
uint32 bt;
|
||||||
do {
|
do {
|
||||||
@@ -2081,7 +2130,7 @@ TermView::MouseDown(BPoint where)
|
|||||||
|
|
||||||
TermPos clickPos = _ConvertToTerminal(where);
|
TermPos clickPos = _ConvertToTerminal(where);
|
||||||
|
|
||||||
if (mod & B_SHIFT_KEY) {
|
if (modifier & B_SHIFT_KEY) {
|
||||||
fInitialSelectionStart = clickPos;
|
fInitialSelectionStart = clickPos;
|
||||||
fInitialSelectionEnd = clickPos;
|
fInitialSelectionEnd = clickPos;
|
||||||
_ExtendSelection(fInitialSelectionStart, true, false);
|
_ExtendSelection(fInitialSelectionStart, true, false);
|
||||||
@@ -2101,19 +2150,18 @@ TermView::MouseDown(BPoint where)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
_SelectWord(where, (mod & B_SHIFT_KEY) != 0, false);
|
_SelectWord(where, (modifier & B_SHIFT_KEY) != 0, false);
|
||||||
fMouseTracking = true;
|
fMouseTracking = true;
|
||||||
fSelectGranularity = SELECT_WORDS;
|
fSelectGranularity = SELECT_WORDS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
_SelectLine(where, (mod & B_SHIFT_KEY) != 0, false);
|
_SelectLine(where, (modifier & B_SHIFT_KEY) != 0, false);
|
||||||
fMouseTracking = true;
|
fMouseTracking = true;
|
||||||
fSelectGranularity = SELECT_LINES;
|
fSelectGranularity = SELECT_LINES;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fLastClickPoint = where;
|
fLastClickPoint = where;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2121,6 +2169,15 @@ TermView::MouseDown(BPoint where)
|
|||||||
void
|
void
|
||||||
TermView::MouseMoved(BPoint where, uint32 transit, const BMessage *message)
|
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 (fCheckMouseTracking) {
|
||||||
if (_MouseDistanceSinceLastClick(where) > 9)
|
if (_MouseDistanceSinceLastClick(where) > 9)
|
||||||
fMouseTracking = true;
|
fMouseTracking = true;
|
||||||
@@ -2196,16 +2253,22 @@ TermView::MouseUp(BPoint where)
|
|||||||
// clipboard.
|
// clipboard.
|
||||||
int32 buttons;
|
int32 buttons;
|
||||||
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
|
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
|
||||||
|
|
||||||
|
if (fReportAnyMouseEvent) {
|
||||||
|
TermPos clickPos = _ConvertToTerminal(where);
|
||||||
|
_SendMouseEvent(0, 0, clickPos.x, clickPos.y, false);
|
||||||
|
} else {
|
||||||
if ((buttons & B_PRIMARY_MOUSE_BUTTON) == 0
|
if ((buttons & B_PRIMARY_MOUSE_BUTTON) == 0
|
||||||
&& (fMouseButtons & B_PRIMARY_MOUSE_BUTTON) != 0) {
|
&& (fMouseButtons & B_PRIMARY_MOUSE_BUTTON) != 0) {
|
||||||
Copy(gMouseClipboard);
|
Copy(gMouseClipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
fMouseButtons = buttons;
|
fMouseButtons = buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Select a range of text
|
//! Select a range of text.
|
||||||
void
|
void
|
||||||
TermView::_Select(TermPos start, TermPos end, bool inclusive,
|
TermView::_Select(TermPos start, TermPos end, bool inclusive,
|
||||||
bool setInitialSelection)
|
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
|
void
|
||||||
TermView::_ExtendSelection(TermPos pos, bool inclusive,
|
TermView::_ExtendSelection(TermPos pos, bool inclusive,
|
||||||
bool useInitialSelection)
|
bool useInitialSelection)
|
||||||
|
|||||||
@@ -177,6 +177,8 @@ private:
|
|||||||
void _ScrollTo(float y, bool scrollGfx);
|
void _ScrollTo(float y, bool scrollGfx);
|
||||||
void _ScrollToRange(TermPos start, TermPos end);
|
void _ScrollToRange(TermPos start, TermPos end);
|
||||||
|
|
||||||
|
void _SendMouseEvent(int32 button, int32 mode, int32 x,
|
||||||
|
int32 y, bool motion);
|
||||||
private:
|
private:
|
||||||
class CharClassifier;
|
class CharClassifier;
|
||||||
|
|
||||||
@@ -252,6 +254,8 @@ private:
|
|||||||
int fSelectGranularity;
|
int fSelectGranularity;
|
||||||
BPoint fLastClickPoint;
|
BPoint fLastClickPoint;
|
||||||
|
|
||||||
|
bool fReportAnyMouseEvent;
|
||||||
|
|
||||||
// Input Method parameter.
|
// Input Method parameter.
|
||||||
int fIMViewPtr;
|
int fIMViewPtr;
|
||||||
TermPos fIMStartPos;
|
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
|
void
|
||||||
TerminalBuffer::SetEncoding(int encoding)
|
TerminalBuffer::SetEncoding(int encoding)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public:
|
|||||||
void UseAlternateScreenBuffer(bool clear);
|
void UseAlternateScreenBuffer(bool clear);
|
||||||
void UseNormalScreenBuffer();
|
void UseNormalScreenBuffer();
|
||||||
|
|
||||||
|
void ReportAnyMouseEvent(bool reportAnyMouseEvent);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void NotifyListener();
|
virtual void NotifyListener();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user