summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-07 18:46:22 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-16 15:16:15 (GMT)
commitf3ce85b9effbb16d8cd08f5dc60c09c986c4607a (patch)
treeac4fc3efbb5ad872612b4dac7dae6d00364903a6
parent97011cc4382d4b27fc1f740efe6d5c702ce1cb64 (diff)
Improve filter updating
This should update filters less often, and also hopefully fix the issue where underlined links get stuck while scrolling. The idea is to not to do it on all mouse updates, only when needed on mouse updates, and also not display the filters if they are out of date. The only thing that should happen on screen changes now is setting the _filterUpdateRequired variable to true, which leads to the filters not being displayed until re-processed, which happens the next time the mouse moves, unless I fucked something up. REVIEW: 128393
-rw-r--r--src/SessionController.cpp41
-rw-r--r--src/SessionController.h7
-rw-r--r--src/TerminalDisplay.cpp20
-rw-r--r--src/TerminalDisplay.h1
4 files changed, 26 insertions, 43 deletions
diff --git a/src/SessionController.cpp b/src/SessionController.cpp
index 037a6d0..cacb51b 100644
--- a/src/SessionController.cpp
+++ b/src/SessionController.cpp
@@ -98,14 +98,11 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
, _copyToGroup(0)
, _profileList(0)
, _previousState(-1)
- , _viewUrlFilter(0)
- , _fileFilter(0)
, _searchFilter(0)
, _copyInputToAllTabsAction(0)
, _findAction(0)
, _findNextAction(0)
, _findPreviousAction(0)
- , _filterUpdateRequired(false)
, _searchStartLine(0)
, _prevSearchResultLine(0)
, _searchBar(0)
@@ -143,6 +140,12 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
view->installEventFilter(this);
view->setSessionController(this);
+ // install filter on the view to highlight URLs
+ _view->filterChain()->addFilter(new UrlFilter);
+
+ // install filter on the view to highlight Files
+ _view->filterChain()->addFilter(new FileFilter(_session));
+
// listen for session resize requests
connect(_session.data(), &Konsole::Session::resizeRequest, this, &Konsole::SessionController::sessionResizeRequest);
@@ -243,13 +246,6 @@ void SessionController::interactionHandler()
_interactionTimer->start();
}
-void SessionController::requireFilterUpdate()
-{
- // this method is called every time the screen window's output changes, so do not
- // do anything expensive here.
-
- _filterUpdateRequired = true;
-}
void SessionController::snapshot()
{
Q_ASSERT(_session != 0);
@@ -475,31 +471,6 @@ bool SessionController::eventFilter(QObject* watched , QEvent* event)
copyInputToAllTabs();
}
}
- // when a mouse move is received, create the filters and listen for output changes if
- // it has not already been created. If it already exists, then update only if the output
- // has changed since the last update ( _filterUpdateRequired == true )
- //
- // also check that no mouse buttons are pressed since the URL filter only applies when
- // the mouse is hovering over the view
- if (event->type() == QEvent::MouseMove &&
- (!_viewUrlFilter || !_fileFilter || _filterUpdateRequired) &&
- ((QMouseEvent*)event)->buttons() == Qt::NoButton) {
- if (_view->screenWindow() && !_viewUrlFilter && !_fileFilter) {
- connect(_view->screenWindow(), &Konsole::ScreenWindow::scrolled, this, &Konsole::SessionController::requireFilterUpdate);
- connect(_view->screenWindow(), &Konsole::ScreenWindow::outputChanged, this, &Konsole::SessionController::requireFilterUpdate);
-
- // install filter on the view to highlight URLs
- _viewUrlFilter = new UrlFilter();
- _view->filterChain()->addFilter(_viewUrlFilter);
-
- // install filter on the view to highlight Files
- _fileFilter = new FileFilter(_session);
- _view->filterChain()->addFilter(_fileFilter);
- }
-
- _view->processFilters();
- _filterUpdateRequired = false;
- }
}
return false;
diff --git a/src/SessionController.h b/src/SessionController.h
index b7b1c5c..3ac06f5 100644
--- a/src/SessionController.h
+++ b/src/SessionController.h
@@ -60,8 +60,6 @@ class ScreenWindow;
class TerminalDisplay;
class IncrementalSearchBar;
class ProfileList;
-class UrlFilter;
-class FileFilter;
class RegExpFilter;
class EditProfileDialog;
@@ -272,7 +270,6 @@ private slots:
// to take a snapshot of the state of the
// foreground process in the terminal
- void requireFilterUpdate();
void highlightMatches(bool highlight);
void scrollBackOptionsChanged(int mode , int lines);
void sessionResizeRequest(const QSize& size);
@@ -319,8 +316,6 @@ private:
QString _sessionIconName;
int _previousState;
- UrlFilter* _viewUrlFilter;
- FileFilter* _fileFilter;
RegExpFilter* _searchFilter;
QAction* _copyInputToAllTabsAction;
@@ -331,8 +326,6 @@ private:
QTimer* _interactionTimer;
- bool _filterUpdateRequired;
-
int _searchStartLine;
int _prevSearchResultLine;
QPointer<IncrementalSearchBar> _searchBar;
diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp
index d3d4f33..3c2bf25 100644
--- a/src/TerminalDisplay.cpp
+++ b/src/TerminalDisplay.cpp
@@ -117,6 +117,12 @@ void TerminalDisplay::setScreenWindow(ScreenWindow* window)
connect(_screenWindow.data() , &Konsole::ScreenWindow::outputChanged , this , &Konsole::TerminalDisplay::updateLineProperties);
connect(_screenWindow.data() , &Konsole::ScreenWindow::outputChanged , this , &Konsole::TerminalDisplay::updateImage);
connect(_screenWindow.data() , &Konsole::ScreenWindow::currentResultLineChanged , this , &Konsole::TerminalDisplay::updateImage);
+ connect(_screenWindow.data(), &Konsole::ScreenWindow::outputChanged, [this]() {
+ _filterUpdateRequired = true;
+ });
+ connect(_screenWindow.data(), &Konsole::ScreenWindow::scrolled, [this]() {
+ _filterUpdateRequired = true;
+ });
_screenWindow->setWindowLines(_lines);
}
}
@@ -366,6 +372,7 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _lineSpacing(0)
, _blendColor(qRgba(0, 0, 0, 0xff))
, _filterChain(new TerminalImageFilterChain())
+ , _filterUpdateRequired(true)
, _cursorShape(Enum::BlockCursor)
, _antialiasText(true)
, _printerFriendly(false)
@@ -1050,8 +1057,13 @@ QRegion TerminalDisplay::hotSpotRegion() const
void TerminalDisplay::processFilters()
{
- if (!_screenWindow)
+ if (!_screenWindow) {
+ return;
+ }
+
+ if (!_filterUpdateRequired) {
return;
+ }
QRegion preUpdateHotSpots = hotSpotRegion();
@@ -1069,6 +1081,7 @@ void TerminalDisplay::processFilters()
QRegion postUpdateHotSpots = hotSpotRegion();
update(preUpdateHotSpots | postUpdateHotSpots);
+ _filterUpdateRequired = false;
}
void TerminalDisplay::updateImage()
@@ -1324,6 +1337,10 @@ FilterChain* TerminalDisplay::filterChain() const
void TerminalDisplay::paintFilters(QPainter& painter)
{
+ if (_filterUpdateRequired) {
+ return;
+ }
+
// get color of character under mouse and use it to draw
// lines for filters
QPoint cursorPos = mapFromGlobal(QCursor::pos());
@@ -2053,6 +2070,7 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
int charColumn = 0;
getCharacterPosition(ev->pos(), charLine, charColumn);
+ processFilters();
// handle filters
// change link hot-spot appearance on mouse-over
Filter::HotSpot* spot = _filterChain->hotSpotAt(charLine, charColumn);
diff --git a/src/TerminalDisplay.h b/src/TerminalDisplay.h
index cfb74ed..7f09a52 100644
--- a/src/TerminalDisplay.h
+++ b/src/TerminalDisplay.h
@@ -905,6 +905,7 @@ private:
// search highlight
TerminalImageFilterChain* _filterChain;
QRegion _mouseOverHotspotArea;
+ bool _filterUpdateRequired;
Enum::CursorShapeEnum _cursorShape;