Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

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
parent 97011cc4
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -905,6 +905,7 @@ private:
// search highlight
TerminalImageFilterChain* _filterChain;
QRegion _mouseOverHotspotArea;
bool _filterUpdateRequired;
Enum::CursorShapeEnum _cursorShape;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment