Git commit 6635190c1295743e6db3c796892c9fc90fb1f791 by Kurt Hindenburg, on = behalf of Mariusz Glebocki. Committed on 25/03/2018 at 13:45. Pushed by hindenburg into branch 'master'. Allow view-controlling keys in read-only mode Summary: Allow to use scrolling (Shift+Up/Down/PgUp/PgDown/Home/End) and a key for showing URL hints when the view is in read-only mode. Test Plan: * Prepare * Turn on scrollback * Set at least one modifier key for "Show URL hints" (edit profile =E2=86= =92 advanced) * Generate a few screens of text in Konsole * Display some URL (e.g. `echo 'www.kde.org'`) * Display current time every second: `while sleep 1; do printf '\r%s' "$(= date)"; done` * Turn on read-only mode * Patch tests * Scroll the view with Shift+Up/Down/PgUp/PgDown/Home/End - the view shou= ld scroll * Hold down URL hint key - the URL should be underlined with square and a= digit on the left * Press +1 - the URL should open in a web browser * Regressions tests * Press different keys (including Ctrl+C, Ctrl+Z, etc; skip those mapped = to Konsole actions) - nothing in terminal should happen * Press Ctrl+S - the time should not stop updating Reviewers: #konsole, hindenburg Reviewed By: #konsole, hindenburg Subscribers: hindenburg, #konsole Tags: #konsole Differential Revision: https://phabricator.kde.org/D11668 M +5 -1 src/SessionController.cpp M +15 -17 src/TerminalDisplay.cpp M +20 -14 src/Vt102Emulation.cpp https://commits.kde.org/konsole/6635190c1295743e6db3c796892c9fc90fb1f791 diff --git a/src/SessionController.cpp b/src/SessionController.cpp index d1a747ba..dfb6a587 100644 --- a/src/SessionController.cpp +++ b/src/SessionController.cpp @@ -1578,7 +1578,11 @@ void SessionController::updateReadOnlyActionStates() = bool SessionController::isReadOnly() const { - return _session->isReadOnly(); + if (!_session.isNull()) { + return _session->isReadOnly(); + } else { + return false; + } } = void SessionController::sessionTitleChanged() diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp index ca02dd55..2f2af66b 100644 --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -3421,12 +3421,6 @@ void TerminalDisplay::scrollScreenWindow(enum Screen= Window::RelativeScrollMode m = void TerminalDisplay::keyPressEvent(QKeyEvent* event) { - - if (_readOnly) { - event->accept(); - return; - } - if ((_urlHintsModifiers !=3D 0u) && event->modifiers() =3D=3D _urlHint= sModifiers) { int hintSelected =3D event->key() - 0x31; if (hintSelected >=3D 0 && hintSelected < 10 && hintSelected < _fi= lterChain->hotSpots().count()) { @@ -3443,25 +3437,29 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* even= t) } } = - _screenWindow->screen()->setCurrentTerminalDisplay(this); + if (!_readOnly) { + _screenWindow->screen()->setCurrentTerminalDisplay(this); = - _actSel =3D 0; // Key stroke implies a screen update, so TerminalDispl= ay won't - // know where the current selection is. + _actSel =3D 0; // Key stroke implies a screen update, so TerminalD= isplay won't + // know where the current selection is. = - if (_allowBlinkingCursor) { - _blinkCursorTimer->start(); - if (_cursorBlinking) { - // if cursor is blinking(hidden), blink it again to show it - blinkCursorEvent(); + if (_allowBlinkingCursor) { + _blinkCursorTimer->start(); + if (_cursorBlinking) { + // if cursor is blinking(hidden), blink it again to show it + blinkCursorEvent(); + } + Q_ASSERT(!_cursorBlinking); } - Q_ASSERT(!_cursorBlinking); } = emit keyPressedSignal(event); = #ifndef QT_NO_ACCESSIBILITY - QAccessibleTextCursorEvent textCursorEvent(this, _usedColumns * screen= Window()->screen()->getCursorY() + screenWindow()->screen()->getCursorX()); - QAccessible::updateAccessibility(&textCursorEvent); + if (!_readOnly) { + QAccessibleTextCursorEvent textCursorEvent(this, _usedColumns * sc= reenWindow()->screen()->getCursorY() + screenWindow()->screen()->getCursorX= ()); + QAccessible::updateAccessibility(&textCursorEvent); + } #endif = event->accept(); diff --git a/src/Vt102Emulation.cpp b/src/Vt102Emulation.cpp index 79369088..efaaf1df 100644 --- a/src/Vt102Emulation.cpp +++ b/src/Vt102Emulation.cpp @@ -37,6 +37,7 @@ = // Konsole #include "KeyboardTranslator.h" +#include "SessionController.h" #include "TerminalDisplay.h" = using Konsole::Vt102Emulation; @@ -1042,6 +1043,9 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event) const Qt::KeyboardModifiers modifiers =3D event->modifiers(); KeyboardTranslator::States states =3D KeyboardTranslator::NoState; = + TerminalDisplay * currentView =3D _currentScreen->currentTerminalDispl= ay(); + const bool isReadOnly =3D currentView->sessionController()->isReadOnly= (); + // get current states if (getMode(MODE_NewLine)) { states |=3D KeyboardTranslator::NewLineState; @@ -1059,16 +1063,18 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event) states |=3D KeyboardTranslator::ApplicationKeypadState; } = - // check flow control state - if ((modifiers &Qt::ControlModifier) !=3D 0u) { - switch (event->key()) { - case Qt::Key_S: - emit flowControlKeyPressed(true); - break; - case Qt::Key_Q: - case Qt::Key_C: // cancel flow control - emit flowControlKeyPressed(false); - break; + if (!isReadOnly) { + // check flow control state + if ((modifiers &Qt::ControlModifier) !=3D 0u) { + switch (event->key()) { + case Qt::Key_S: + emit flowControlKeyPressed(true); + break; + case Qt::Key_Q: + case Qt::Key_C: // cancel flow control + emit flowControlKeyPressed(false); + break; + } } } = @@ -1104,8 +1110,6 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event) = if ( entry.command() !=3D KeyboardTranslator::NoCommand ) { - TerminalDisplay * currentView =3D _currentScreen->currentTermi= nalDisplay(); - if ((entry.command() & KeyboardTranslator::EraseCommand) !=3D = 0) { textToSend +=3D eraseChar(); } else if ((entry.command() & KeyboardTranslator::ScrollPageUp= Command) !=3D 0) { @@ -1128,8 +1132,10 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event) textToSend +=3D _codec->fromUnicode(event->text()); } = - emit sendData(textToSend); - } else { + if (!isReadOnly) { + emit sendData(textToSend); + } + } else if (!isReadOnly) { // print an error message to the terminal if no key translator has= been // set QString translatorError =3D i18n("No keyboard translator availabl= e. "