summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Glebocki <[email protected]>2018-03-25 09:10:33 -0400
committerKurt Hindenburg <[email protected]>2018-03-25 09:59:40 -0400
commitb94162c11b3e4859b8464852fe53d818af25576c (patch)
treec2dbab4941c765b2c43725275779762e612ee192
parentfefd2e56c0875ece23e90de4b77d8e09c3c5577d (diff)
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 → 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 should scroll * Hold down URL hint key - the URL should be underlined with square and a digit on the left * Press <URL-hint-key>+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 (cherry picked from commit 6635190c1295743e6db3c796892c9fc90fb1f791)
-rw-r--r--src/SessionController.cpp6
-rw-r--r--src/TerminalDisplay.cpp32
-rw-r--r--src/Vt102Emulation.cpp34
3 files changed, 40 insertions, 32 deletions
diff --git a/src/SessionController.cpp b/src/SessionController.cpp
index d1a747b..dfb6a58 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 ca02dd5..2f2af66 100644
--- a/src/TerminalDisplay.cpp
+++ b/src/TerminalDisplay.cpp
@@ -3421,12 +3421,6 @@ void TerminalDisplay::scrollScreenWindow(enum ScreenWindow::RelativeScrollMode m
void TerminalDisplay::keyPressEvent(QKeyEvent* event)
{
-
- if (_readOnly) {
- event->accept();
- return;
- }
-
if ((_urlHintsModifiers != 0u) && event->modifiers() == _urlHintsModifiers) {
int hintSelected = event->key() - 0x31;
if (hintSelected >= 0 && hintSelected < 10 && hintSelected < _filterChain->hotSpots().count()) {
@@ -3443,25 +3437,29 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event)
}
}
- _screenWindow->screen()->setCurrentTerminalDisplay(this);
+ if (!_readOnly) {
+ _screenWindow->screen()->setCurrentTerminalDisplay(this);
- _actSel = 0; // Key stroke implies a screen update, so TerminalDisplay won't
- // know where the current selection is.
+ _actSel = 0; // Key stroke implies a screen update, so TerminalDisplay 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 * screenWindow()->screen()->getCursorY() + screenWindow()->screen()->getCursorX());
- QAccessible::updateAccessibility(&textCursorEvent);
+ if (!_readOnly) {
+ QAccessibleTextCursorEvent textCursorEvent(this, _usedColumns * screenWindow()->screen()->getCursorY() + screenWindow()->screen()->getCursorX());
+ QAccessible::updateAccessibility(&textCursorEvent);
+ }
#endif
event->accept();
diff --git a/src/Vt102Emulation.cpp b/src/Vt102Emulation.cpp
index 7936908..efaaf1d 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 = event->modifiers();
KeyboardTranslator::States states = KeyboardTranslator::NoState;
+ TerminalDisplay * currentView = _currentScreen->currentTerminalDisplay();
+ const bool isReadOnly = currentView->sessionController()->isReadOnly();
+
// get current states
if (getMode(MODE_NewLine)) {
states |= KeyboardTranslator::NewLineState;
@@ -1059,16 +1063,18 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
states |= KeyboardTranslator::ApplicationKeypadState;
}
- // check flow control state
- if ((modifiers &Qt::ControlModifier) != 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) != 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() != KeyboardTranslator::NoCommand )
{
- TerminalDisplay * currentView = _currentScreen->currentTerminalDisplay();
-
if ((entry.command() & KeyboardTranslator::EraseCommand) != 0) {
textToSend += eraseChar();
} else if ((entry.command() & KeyboardTranslator::ScrollPageUpCommand) != 0) {
@@ -1128,8 +1132,10 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
textToSend += _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 = i18n("No keyboard translator available. "