From c708aff22c5d9e6ca9fd815eb8c7e340141590f2 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Tue, 18 Dec 2007 04:32:05 +0000 Subject: [PATCH] Fix the long standing limitation where multiple views on the same terminal session had to be the same size - the size of the smallest view. This means that it is now possible, for example, to have a large view on a session for browsing and examining output and a smaller view on the same session for input. The underlying terminal does not support the concept of multiple windows, so the size reported to terminal applications is still that of the smallest view. Full-screen applications such as vim and emacs will therefore be the size of the smallest view on all views. * Add a method in ScreenWindow to set the size of the window (in lines, the number of columns is still ifxed). * Call this method in TerminalDisplay to set the window size when the widget is resized or when the screen window of a display is initially set. * Fix ScreenWindow::getImage() and ScreenWindow::getLineProperties() so that they do not attempt to retrieve information about lines beyond the end of the screen. * Fix ScreenWindow::getLineProperties() to always return result vector of size windowColumns(), though the number of elements copied from the screen may be less. svn path=/trunk/KDE/kdebase/apps/konsole/; revision=749874 --- src/ScreenWindow.cpp | 23 ++++++++++++++++++++--- src/ScreenWindow.h | 5 +++++ src/TerminalDisplay.cpp | 4 ++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/ScreenWindow.cpp b/src/ScreenWindow.cpp index 8b3320940..df55098fa 100644 --- a/src/ScreenWindow.cpp +++ b/src/ScreenWindow.cpp @@ -33,6 +33,7 @@ ScreenWindow::ScreenWindow(QObject* parent) , _windowBuffer(0) , _windowBufferSize(0) , _bufferNeedsUpdate(true) + , _windowLines(1) , _currentLine(0) , _trackOutput(true) , _scrollCount(0) @@ -70,15 +71,26 @@ Character* ScreenWindow::getImage() return _windowBuffer; _screen->getImage(_windowBuffer,size, - _currentLine,_currentLine + windowLines() - 1); + _currentLine,endWindowLine()); _bufferNeedsUpdate = false; return _windowBuffer; } +int ScreenWindow::endWindowLine() const +{ + return qMin(_currentLine + windowLines() - 1, + _screen->getHistLines() + _screen->getLines() - 1); +} + QVector ScreenWindow::getLineProperties() { - return _screen->getLineProperties(_currentLine,_currentLine+windowLines()-1); + QVector result = _screen->getLineProperties(_currentLine,endWindowLine()); + + if (result.count() != windowLines()) + result.resize(windowLines()); + + return result; } QString ScreenWindow::selectedText( bool preserveLineBreaks ) const @@ -126,9 +138,14 @@ void ScreenWindow::clearSelection() emit selectionChanged(); } +void ScreenWindow::setWindowLines(int lines) +{ + Q_ASSERT(lines > 0); + _windowLines = lines; +} int ScreenWindow::windowLines() const { - return _screen->getLines(); + return _windowLines; } int ScreenWindow::windowColumns() const diff --git a/src/ScreenWindow.h b/src/ScreenWindow.h index 24d4b1a08..ebb86cc73 100644 --- a/src/ScreenWindow.h +++ b/src/ScreenWindow.h @@ -140,6 +140,8 @@ public: */ void clearSelection(); + /** Sets the number of lines in the window */ + void setWindowLines(int lines); /** Returns the number of lines in the window */ int windowLines() const; /** Returns the number of columns in the window */ @@ -233,11 +235,14 @@ signals: void selectionChanged(); private: + int endWindowLine() const; + Screen* _screen; // see setScreen() , screen() Character* _windowBuffer; int _windowBufferSize; bool _bufferNeedsUpdate; + int _windowLines; int _currentLine; // see scrollTo() , currentLine() bool _trackOutput; // see setTrackOutput() , trackOutput() int _scrollCount; // count of lines which the window has been scrolled by since diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp index a6f1b0e9e..75b3bc13c 100644 --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -111,6 +111,7 @@ void TerminalDisplay::setScreenWindow(ScreenWindow* window) #warning "The order here is not specified - does it matter whether updateImage or updateLineProperties comes first?" connect( _screenWindow , SIGNAL(outputChanged()) , this , SLOT(updateLineProperties()) ); connect( _screenWindow , SIGNAL(outputChanged()) , this , SLOT(updateImage()) ); + window->setWindowLines(_lines); } } @@ -1380,6 +1381,9 @@ void TerminalDisplay::updateImageSize() delete[] oldimg; } + if (_screenWindow) + _screenWindow->setWindowLines(_lines); + _resizing = (oldlin!=_lines) || (oldcol!=_columns); if ( _resizing )