Commit 967c42a1 authored by Christian Muehlhaeuser's avatar Christian Muehlhaeuser Committed by Kurt Hindenburg
Browse files

Support status report requests for text-colors

Summary:
Konsole already responds to background color status report
requests, but ignores requests for the foreground color.
This adds the support and makes Konsole behave like other xterm /
VTE-based terminals.

Test Plan:
Run 'printf "\033]10;?\a"' in a bash shell and Konsole should
respond with the current foreground color setting on stdout.
parent 06fe343e
......@@ -678,6 +678,10 @@ bool Session::isPrimaryScreen()
void Session::sessionAttributeRequest(int id)
{
switch (id) {
case TextColor:
// Get 'TerminalDisplay' (_view) foreground color
emit getForegroundColor();
break;
case BackgroundColor:
// Get 'TerminalDisplay' (_view) background color
emit getBackgroundColor();
......@@ -801,10 +805,10 @@ void Session::sendSignal(int signal)
}
}
void Session::reportBackgroundColor(const QColor& c)
void Session::reportColor(SessionAttributes r, const QColor& c)
{
#define to65k(a) (QStringLiteral("%1").arg(int(((a)*0xFFFF)), 4, 16, QLatin1Char('0')))
QString msg = QStringLiteral("\033]11;rgb:")
QString msg = QStringLiteral("\033]%1;rgb:").arg(r)
+ to65k(c.redF()) + QLatin1Char('/')
+ to65k(c.greenF()) + QLatin1Char('/')
+ to65k(c.blueF()) + QLatin1Char('\a');
......@@ -812,6 +816,16 @@ void Session::reportBackgroundColor(const QColor& c)
#undef to65k
}
void Session::reportForegroundColor(const QColor& c)
{
reportColor(SessionAttributes::TextColor, c);
}
void Session::reportBackgroundColor(const QColor& c)
{
reportColor(SessionAttributes::BackgroundColor, c);
}
bool Session::kill(int signal)
{
if (_shellProcess->pid() <= 0) {
......
......@@ -372,6 +372,8 @@ public:
void sendSignal(int signal);
void reportColor(SessionAttributes r, const QColor &c);
void reportForegroundColor(const QColor &c);
void reportBackgroundColor(const QColor &c);
bool isReadOnly() const;
......@@ -697,6 +699,12 @@ Q_SIGNALS:
*/
void selectionChanged(const QString &text);
/**
* Emitted when foreground request ("\033]10;?\a") terminal code received.
* Terminal is expected send "\033]10;rgb:RRRR/GGGG/BBBB\a" response.
*/
void getForegroundColor();
/**
* Emitted when background request ("\033]11;?\a") terminal code received.
* Terminal is expected send "\033]11;rgb:RRRR/GGGG/BBBB\a" response.
......
......@@ -213,6 +213,9 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
connect(backgroundTimer, &QTimer::timeout, this, &Konsole::SessionController::snapshot);
backgroundTimer->start();
// xterm '10;?' request
connect(_session.data(), &Konsole::Session::getForegroundColor,
this, &Konsole::SessionController::sendForegroundColor);
// xterm '11;?' request
connect(_session.data(), &Konsole::Session::getBackgroundColor,
this, &Konsole::SessionController::sendBackgroundColor);
......@@ -479,6 +482,12 @@ void SessionController::sendSignal(QAction* action)
_session->sendSignal(signal);
}
void SessionController::sendForegroundColor()
{
const QColor c = _view->getForegroundColor();
_session->reportForegroundColor(c);
}
void SessionController::sendBackgroundColor()
{
const QColor c = _view->getBackgroundColor();
......
......@@ -248,6 +248,7 @@ private Q_SLOTS:
void handleWebShortcutAction();
void configureWebShortcuts();
void sendSignal(QAction *action);
void sendForegroundColor();
void sendBackgroundColor();
void toggleReadOnly();
......
......@@ -189,6 +189,11 @@ void TerminalDisplay::setForegroundColor(const QColor& color)
onColorsChanged();
}
QColor TerminalDisplay::getForegroundColor() const
{
return _colorTable[DEFAULT_FORE_COLOR];
}
void TerminalDisplay::setColorTable(const ColorEntry table[])
{
for (int i = 0; i < TABLE_COLORS; i++) {
......
......@@ -326,6 +326,12 @@ public:
void printContent(QPainter &painter, bool friendly);
/**
* Gets the foreground of the display
* @see setForegroundColor(), setColorTable(), setBackgroundColor()
*/
QColor getForegroundColor() const;
/**
* Gets the background of the display
* @see setBackgroundColor(), setColorTable(), setForegroundColor()
......
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