Merge remote-tracking branch 'upstream/master' into unstable
This commit is contained in:
+55
-31
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2007-2008 Robert Knight <robertknight@gmail.com>
|
||||
Copyright 2007-2008 Robert Knight <robertknight@gmail.com>
|
||||
Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
|
||||
Copyright 1996 by Matthias Ettrich <ettrich@kde.org>
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
#include "Emulation.h"
|
||||
|
||||
// System
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
|
||||
// Qt
|
||||
#include <QApplication>
|
||||
@@ -55,7 +55,8 @@ Emulation::Emulation() :
|
||||
_codec(0),
|
||||
_decoder(0),
|
||||
_keyTranslator(0),
|
||||
_usesMouse(false)
|
||||
_usesMouse(false),
|
||||
_bracketedPasteMode(false)
|
||||
{
|
||||
// create screens with a default size
|
||||
_screen[0] = new Screen(40,80);
|
||||
@@ -64,10 +65,17 @@ Emulation::Emulation() :
|
||||
|
||||
QObject::connect(&_bulkTimer1, SIGNAL(timeout()), this, SLOT(showBulk()) );
|
||||
QObject::connect(&_bulkTimer2, SIGNAL(timeout()), this, SLOT(showBulk()) );
|
||||
|
||||
|
||||
// listen for mouse status changes
|
||||
connect( this , SIGNAL(programUsesMouseChanged(bool)) ,
|
||||
SLOT(usesMouseChanged(bool)) );
|
||||
connect(this , SIGNAL(programUsesMouseChanged(bool)) ,
|
||||
SLOT(usesMouseChanged(bool)));
|
||||
connect(this , SIGNAL(programBracketedPasteModeChanged(bool)) ,
|
||||
SLOT(bracketedPasteModeChanged(bool)));
|
||||
|
||||
connect(this, &Emulation::cursorChanged, [this] (KeyboardCursorShape cursorShape, bool blinkingCursorEnabled) {
|
||||
emit titleChanged( 50, QString(QLatin1String("CursorShape=%1;BlinkingCursorEnabled=%2"))
|
||||
.arg(static_cast<int>(cursorShape)).arg(blinkingCursorEnabled) );
|
||||
});
|
||||
}
|
||||
|
||||
bool Emulation::programUsesMouse() const
|
||||
@@ -80,6 +88,16 @@ void Emulation::usesMouseChanged(bool usesMouse)
|
||||
_usesMouse = usesMouse;
|
||||
}
|
||||
|
||||
bool Emulation::programBracketedPasteMode() const
|
||||
{
|
||||
return _bracketedPasteMode;
|
||||
}
|
||||
|
||||
void Emulation::bracketedPasteModeChanged(bool bracketedPasteMode)
|
||||
{
|
||||
_bracketedPasteMode = bracketedPasteMode;
|
||||
}
|
||||
|
||||
ScreenWindow* Emulation::createWindow()
|
||||
{
|
||||
ScreenWindow* window = new ScreenWindow();
|
||||
@@ -112,10 +130,10 @@ void Emulation::setScreen(int n)
|
||||
{
|
||||
Screen *old = _currentScreen;
|
||||
_currentScreen = _screen[n & 1];
|
||||
if (_currentScreen != old)
|
||||
if (_currentScreen != old)
|
||||
{
|
||||
// tell all windows onto this emulation to switch to the newly active screen
|
||||
foreach(ScreenWindow* window,_windows)
|
||||
for(ScreenWindow* window : const_cast<const QList<ScreenWindow*>&>(_windows))
|
||||
window->setScreen(_currentScreen);
|
||||
}
|
||||
}
|
||||
@@ -171,7 +189,7 @@ QString Emulation::keyBindings() const
|
||||
return _keyTranslator->name();
|
||||
}
|
||||
|
||||
void Emulation::receiveChar(int c)
|
||||
void Emulation::receiveChar(wchar_t c)
|
||||
// process application unicode input to terminal
|
||||
// this is a trivial scanner
|
||||
{
|
||||
@@ -191,12 +209,12 @@ void Emulation::receiveChar(int c)
|
||||
void Emulation::sendKeyEvent( QKeyEvent* ev )
|
||||
{
|
||||
emit stateSet(NOTIFYNORMAL);
|
||||
|
||||
|
||||
if (!ev->text().isEmpty())
|
||||
{ // A block of text
|
||||
// Note that the text is proper unicode.
|
||||
// We should do a conversion here
|
||||
emit sendData(ev->text().toUtf8(),ev->text().length());
|
||||
emit sendData(ev->text().toUtf8().constData(),ev->text().length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,12 +238,18 @@ void Emulation::receiveData(const char* text, int length)
|
||||
emit stateSet(NOTIFYACTIVITY);
|
||||
|
||||
bufferedUpdate();
|
||||
|
||||
QString unicodeText = _decoder->toUnicode(text,length);
|
||||
|
||||
/* XXX: the following code involves encoding & decoding of "UTF-16
|
||||
* surrogate pairs", which does not work with characters higher than
|
||||
* U+10FFFF
|
||||
* https://unicodebook.readthedocs.io/unicode_encodings.html#surrogates
|
||||
*/
|
||||
QString utf16Text = _decoder->toUnicode(text,length);
|
||||
std::wstring unicodeText = utf16Text.toStdWString();
|
||||
|
||||
//send characters to terminal emulator
|
||||
for (int i=0;i<unicodeText.length();i++)
|
||||
receiveChar(unicodeText[i].unicode());
|
||||
for (size_t i=0;i<unicodeText.length();i++)
|
||||
receiveChar(unicodeText[i]);
|
||||
|
||||
//look for z-modem indicator
|
||||
//-- someone who understands more about z-modems that I do may be able to move
|
||||
@@ -248,13 +272,13 @@ void Emulation::receiveData(const char* text, int length)
|
||||
//
|
||||
//There is something about stopping the _decoder if "we get a control code halfway a multi-byte sequence" (see below)
|
||||
//which hasn't been ported into the newer function (above). Hopefully someone who understands this better
|
||||
//can find an alternative way of handling the check.
|
||||
//can find an alternative way of handling the check.
|
||||
|
||||
|
||||
/*void Emulation::onRcvBlock(const char *s, int len)
|
||||
{
|
||||
emit notifySessionState(NOTIFYACTIVITY);
|
||||
|
||||
|
||||
bufferedUpdate();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
@@ -289,9 +313,9 @@ void Emulation::receiveData(const char* text, int length)
|
||||
}
|
||||
}*/
|
||||
|
||||
void Emulation::writeToStream( TerminalCharacterDecoder* _decoder ,
|
||||
void Emulation::writeToStream( TerminalCharacterDecoder* _decoder ,
|
||||
int startLine ,
|
||||
int endLine)
|
||||
int endLine)
|
||||
{
|
||||
_currentScreen->writeLinesToStream(_decoder,startLine,endLine);
|
||||
}
|
||||
@@ -339,7 +363,7 @@ char Emulation::eraseChar() const
|
||||
|
||||
void Emulation::setImageSize(int lines, int columns)
|
||||
{
|
||||
if ((lines < 1) || (columns < 1))
|
||||
if ((lines < 1) || (columns < 1))
|
||||
return;
|
||||
|
||||
QSize screenSize[2] = { QSize(_screen[0]->getColumns(),
|
||||
@@ -349,7 +373,7 @@ void Emulation::setImageSize(int lines, int columns)
|
||||
QSize newSize(columns,lines);
|
||||
|
||||
if (newSize == screenSize[0] && newSize == screenSize[1])
|
||||
return;
|
||||
return;
|
||||
|
||||
_screen[0]->resizeImage(lines,columns);
|
||||
_screen[1]->resizeImage(lines,columns);
|
||||
@@ -377,17 +401,17 @@ bool ExtendedCharTable::extendedCharMatch(ushort hash , ushort* unicodePoints ,
|
||||
{
|
||||
ushort* entry = extendedCharTable[hash];
|
||||
|
||||
// compare given length with stored sequence length ( given as the first ushort in the
|
||||
// stored buffer )
|
||||
if ( entry == 0 || entry[0] != length )
|
||||
// compare given length with stored sequence length ( given as the first ushort in the
|
||||
// stored buffer )
|
||||
if ( entry == 0 || entry[0] != length )
|
||||
return false;
|
||||
// if the lengths match, each character must be checked. the stored buffer starts at
|
||||
// entry[1]
|
||||
for ( int i = 0 ; i < length ; i++ )
|
||||
{
|
||||
if ( entry[i+1] != unicodePoints[i] )
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
ushort ExtendedCharTable::createExtendedChar(ushort* unicodePoints , ushort length)
|
||||
@@ -400,7 +424,7 @@ ushort ExtendedCharTable::createExtendedChar(ushort* unicodePoints , ushort leng
|
||||
{
|
||||
if ( extendedCharMatch(hash,unicodePoints,length) )
|
||||
{
|
||||
// this sequence already has an entry in the table,
|
||||
// this sequence already has an entry in the table,
|
||||
// return its hash
|
||||
return hash;
|
||||
}
|
||||
@@ -410,16 +434,16 @@ ushort ExtendedCharTable::createExtendedChar(ushort* unicodePoints , ushort leng
|
||||
// points then try next hash
|
||||
hash++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// add the new sequence to the table and
|
||||
// return that index
|
||||
ushort* buffer = new ushort[length+1];
|
||||
buffer[0] = length;
|
||||
for ( int i = 0 ; i < length ; i++ )
|
||||
buffer[i+1] = unicodePoints[i];
|
||||
|
||||
buffer[i+1] = unicodePoints[i];
|
||||
|
||||
extendedCharTable.insert(hash,buffer);
|
||||
|
||||
return hash;
|
||||
|
||||
Reference in New Issue
Block a user