Commit 38208f94 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Add option to always invert text selection colours

The recent change of blending the background/foreground colours for text
selection doesn't work everywhere, users with vision impairment or
colour-blindness would probably find it hard to distinguish text selection
colours; and the current code can't possibly cover all variations of colour
schemes out there. The same goes with certain displays and viewing angles,
some display types are notoriously awful when viewed at an angle.

BUG: 435309
FIXED-IN: 21.08
parent 4ef7296b
......@@ -19,11 +19,13 @@
#include "terminalDisplay/TerminalDisplay.h"
#include "session/SessionController.h"
#include "session/Session.h"
#include "session/SessionManager.h"
#include "history/HistoryType.h"
#include "history/HistoryScrollNone.h"
#include "characters/ExtendedCharTable.h"
#include "profile/Profile.h"
#include "profile/ProfileManager.h"
#include "EscapeSequenceUrlExtractor.h"
using namespace Konsole;
......@@ -620,7 +622,7 @@ void Screen::copyFromHistory(Character* dest, int startLine, int count) const
if (_selBegin != -1) {
for (int column = 0; column < lastColumn; ++column) {
if (isSelected(column, line)) {
dest[destLineOffset + column].rendition |= RE_SELECTED;
setTextSelectionRendition(dest[destLineOffset + column]);
}
}
}
......@@ -644,14 +646,28 @@ void Screen::copyFromScreen(Character* dest , int startLine , int count) const
dest[destIndex] = _screenLines.at(srcIndex / _columns).value(srcIndex % _columns, Screen::DefaultChar);
// invert selected text
if (_selBegin != -1 && isSelected(column, line + _history->getLines()) && column < lastColumn) {
dest[destIndex].rendition |= RE_SELECTED;
setTextSelectionRendition(dest[destIndex]);
}
}
}
}
void Screen::setTextSelectionRendition(Character &ch) const
{
Q_ASSERT(_currentTerminalDisplay);
auto currentProfile = SessionManager::instance()->sessionProfile(_currentTerminalDisplay->session());
const bool isInvert = currentProfile ? currentProfile->property<bool>(Profile::InvertSelectionColors)
: false;
if (isInvert) {
reverseRendition(ch);
} else {
ch.rendition |= RE_BLEND_SELECTION_COLORS;
}
}
void Screen::getImage(Character* dest, int size, int startLine, int endLine) const
{
Q_ASSERT(startLine >= 0);
......
......@@ -658,6 +658,13 @@ private:
// starting from 'startLine', where 0 is the first line in the history
void copyFromHistory(Character *dest, int startLine, int count) const;
// Sets the text selection colors, either:
// - using reverseRendition(), which inverts the foreground/background
// colors OR
// - setting the RE_BLEND_SELECTION_COLORS RenditionFlag, which will
// blend the foreground/background colors
void setTextSelectionRendition(Character &ch) const;
// returns a buffer that can hold at most 'count' characters,
// where the number of reallocations and object reinitializations
// should be as minimal as possible
......
......@@ -38,7 +38,7 @@ const RenditionFlags RE_FAINT = (1 << 7);
const RenditionFlags RE_STRIKEOUT = (1 << 8);
const RenditionFlags RE_CONCEAL = (1 << 9);
const RenditionFlags RE_OVERLINE = (1 << 10);
const RenditionFlags RE_SELECTED = (1 << 11);
const RenditionFlags RE_BLEND_SELECTION_COLORS = (1 << 11);
/**
* A single character in the terminal which consists of a unicode character
......
......@@ -73,6 +73,7 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = {
, { TabColor, "TabColor", APPEARANCE_GROUP, QVariant::Color }
, { DimValue, "DimmValue", APPEARANCE_GROUP, QVariant::Int }
, { DimWhenInactive , "DimWhenInactive" , GENERAL_GROUP , QVariant::Bool }
, { InvertSelectionColors , "InvertSelectionColors" , GENERAL_GROUP , QVariant::Bool }
// Keyboard
, { KeyBindings , "KeyBindings" , KEYBOARD_GROUP , QVariant::String }
......@@ -169,6 +170,7 @@ void Profile::useFallback()
setProperty(ShowTerminalSizeHint, true);
setProperty(DimWhenInactive, false);
setProperty(DimValue, 128);
setProperty(InvertSelectionColors, false);
setProperty(StartInCurrentSessionDir, true);
setProperty(MenuIndex, QStringLiteral("0"));
setProperty(SilenceSeconds, 10);
......
......@@ -107,6 +107,10 @@ public:
/** (bool) If the background color should change to indicate if the window is active
*/
DimWhenInactive,
/**
* (bool) Whether to always invert the colors for text selection.
*/
InvertSelectionColors,
/** (QFont) The font to use in terminal displays using this profile. */
Font,
/** (QString) The name of the color scheme to use in terminal
......
......@@ -2801,7 +2801,7 @@ SessionController* TerminalDisplay::sessionController()
return _sessionController;
}
Session::Ptr TerminalDisplay::currentSession() const
Session::Ptr TerminalDisplay::session() const
{
return _sessionController->session();
}
......
......@@ -135,7 +135,7 @@ public:
void setSessionController(SessionController *controller);
SessionController *sessionController();
Session::Ptr currentSession() const;
Session::Ptr session() const;
/**
* Sets the shape of the keyboard cursor. This is the cursor drawn
......
......@@ -384,7 +384,7 @@ namespace Konsole
std::optional<QColor> calculateBackgroundColor(const Character* style, const QColor *colorTable)
{
auto c1 = style->backgroundColor.color(colorTable);
if (!(style->rendition & RE_SELECTED)) {
if (!(style->rendition & RE_BLEND_SELECTION_COLORS)) {
return c1;
}
......
......@@ -489,6 +489,13 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="invertSelectionColorsCheckbox">
<property name="text">
<string>Always invert the colors of selected text</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
......
......@@ -792,6 +792,11 @@ void EditProfileDialog::setupAppearancePage(const Profile::Ptr &profile)
connect(_appearanceUi->dimValue, &QSlider::valueChanged,
this, &Konsole::EditProfileDialog::setDimValue);
_appearanceUi->invertSelectionColorsCheckbox->setChecked(profile->property<bool>(Profile::InvertSelectionColors));
connect(_appearanceUi->invertSelectionColorsCheckbox, &QCheckBox::toggled, this, [this](bool checked) {
updateTempProfileProperty(Profile::InvertSelectionColors, checked);
});
_appearanceUi->displayVerticalLine->setChecked(profile->verticalLine());
connect(_appearanceUi->displayVerticalLine, &QCheckBox::toggled,
this, &EditProfileDialog::setVerticalLine);
......
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