Commit dcb23b61 authored by Tomaz  Canabrava's avatar Tomaz Canabrava
Browse files

Revert "Remove RandomSeed on TerminalDisplay."

This reverts commit fa4bd94d.

Crashes PartTest
parent 93b63626
......@@ -656,7 +656,7 @@ TerminalDisplay *ViewManager::createView(Session *session)
// Use Qt::UniqueConnection to avoid duplicate connection
connect(session, &Konsole::Session::finished, this, &Konsole::ViewManager::sessionFinished,
Qt::UniqueConnection);
TerminalDisplay *display = createTerminalDisplay();
TerminalDisplay *display = createTerminalDisplay(session);
const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
applyProfileToView(display, profile);
......@@ -786,9 +786,10 @@ void ViewManager::viewDestroyed(QWidget *view)
// emit unplugController(_pluggedController);
}
TerminalDisplay *ViewManager::createTerminalDisplay()
TerminalDisplay *ViewManager::createTerminalDisplay(Session *session)
{
auto display = new TerminalDisplay(nullptr);
display->setRandomSeed(session->sessionId() | (qApp->applicationPid() << 10));
connect(display, &TerminalDisplay::requestToggleExpansion,
_viewContainer, &TabbedViewContainer::toggleMaximizeCurrentTerminal);
......
......@@ -403,7 +403,7 @@ private:
// creates a new terminal display
// the 'session' is used so that the terminal display's random seed
// can be set to something which depends uniquely on that session
TerminalDisplay *createTerminalDisplay();
TerminalDisplay *createTerminalDisplay(Session *session = nullptr);
// creates a new controller for a session/display pair which provides the menu
// actions associated with that view, and exposes basic information
......
......@@ -12,7 +12,6 @@
// Qt
#include <QPainter>
#include <QApplication>
// KDE
#include <KConfig>
......@@ -245,13 +244,13 @@ void ColorScheme::setColorTableEntry(int index, const ColorEntry &entry)
}
}
ColorEntry ColorScheme::colorEntry(int index, uint sessionId) const
ColorEntry ColorScheme::colorEntry(int index, uint randomSeed) const
{
Q_ASSERT(index >= 0 && index < TABLE_COLORS);
ColorEntry entry = colorTable()[index];
if (!_colorRandomization || sessionId == 0 || _randomTable == nullptr
if (!_colorRandomization || randomSeed == 0 || _randomTable == nullptr
|| _randomTable[index].isNull()) {
return entry;
}
......@@ -267,7 +266,7 @@ ColorEntry ColorScheme::colorEntry(int index, uint sessionId) const
// 32-bit Mersenne Twister
// Can't use default_random_engine, because in GCC this maps to
// minstd_rand0 which always gives us 0 on the first number.
std::mt19937 randomEngine(sessionId | qApp->applicationPid() << 10);
std::mt19937 randomEngine(randomSeed);
// Use hues located around base color's hue.
// H=0 [|= =] H=128 [ =|= ] H=360 [= =|]
......@@ -321,10 +320,10 @@ ColorEntry ColorScheme::colorEntry(int index, uint sessionId) const
return {qRound(red * 255), qRound(green * 255), qRound(blue * 255)};
}
void ColorScheme::getColorTable(ColorEntry *table, uint sessionId) const
void ColorScheme::getColorTable(ColorEntry *table, uint randomSeed) const
{
for (int i = 0; i < TABLE_COLORS; i++) {
table[i] = colorEntry(i, sessionId);
table[i] = colorEntry(i, randomSeed);
}
}
......
......@@ -65,15 +65,17 @@ public:
*
* @param table Array into which the color entries for this color scheme
* are copied.
* @param randomSeed Color schemes may allow certain colors in their
* palette to be randomized. The seed is used to pick the random color.
*/
void getColorTable(ColorEntry *table, uint sessionId = 0) const;
void getColorTable(ColorEntry *table, uint randomSeed = 0) const;
/**
* Retrieves a single color entry from the table.
*
* See getColorTable()
*/
ColorEntry colorEntry(int index, uint sessionId = 0) const;
ColorEntry colorEntry(int index, uint randomSeed = 0) const;
/**
* Convenience method. Returns the
......
......@@ -30,10 +30,10 @@ namespace Konsole
setColorTable(ColorScheme::defaultTable);
}
void TerminalColor::applyProfile(const Profile::Ptr &profile, ColorScheme const *colorScheme, uint sessionId)
void TerminalColor::applyProfile(const Profile::Ptr &profile, ColorScheme const *colorScheme, int randomSeed)
{
ColorEntry table[TABLE_COLORS];
colorScheme->getColorTable(table, sessionId);
colorScheme->getColorTable(table, randomSeed);
setColorTable(table);
setOpacity(colorScheme->opacity());
......
......@@ -30,7 +30,7 @@ namespace Konsole
public:
explicit TerminalColor(QWidget *parent);
void applyProfile(const Profile::Ptr &profile, ColorScheme const *colorScheme, uint sessionId);
void applyProfile(const Profile::Ptr &profile, ColorScheme const *colorScheme, int randomSeed);
QColor backgroundColor() const;
QColor foregroundColor() const;
......
......@@ -361,6 +361,7 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _image(nullptr)
, _imageSize(0)
, _lineProperties(QVector<LineProperty>())
, _randomSeed(0)
, _resizing(false)
, _showTerminalSizeHint(true)
, _bidiEnabled(false)
......@@ -620,6 +621,15 @@ void TerminalDisplay::scrollScreenWindow(enum ScreenWindow::RelativeScrollMode m
viewScrolledByUser();
}
void TerminalDisplay::setRandomSeed(uint randomSeed)
{
_randomSeed = randomSeed;
}
uint TerminalDisplay::randomSeed() const
{
return _randomSeed;
}
void TerminalDisplay::processFilters()
{
......@@ -2968,7 +2978,7 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
{
// load color scheme
_colorScheme = ViewManager::colorSchemeForProfile(profile);
_terminalColor->applyProfile(profile, _colorScheme, sessionController()->session()->sessionId());
_terminalColor->applyProfile(profile, _colorScheme, randomSeed());
setWallpaper(_colorScheme->wallpaper());
// load font
......
......@@ -72,6 +72,17 @@ public:
void applyProfile(const QExplicitlySharedDataPointer<Profile>& profile);
/**
* Sets the seed used to generate random colors for the display
* (in color schemes that support them).
*/
void setRandomSeed(uint randomSeed);
/**
* Returns the seed used to generate random colors for the display
* (in color schemes that support them).
*/
uint randomSeed() const;
/** Sets the opacity of the terminal display. */
void setOpacity(qreal opacity);
......@@ -690,6 +701,8 @@ private:
ColorEntry _colorTable[TABLE_COLORS];
uint _randomSeed;
bool _resizing;
bool _showTerminalSizeHint;
bool _bidiEnabled;
......
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