fix: port Konsole to Redox Qt surface

This commit is contained in:
2026-05-07 09:11:47 +01:00
parent b54b2dbf76
commit 702cbfd429
19 changed files with 534 additions and 30 deletions
@@ -65,8 +65,6 @@ endif()
set(konsole_LIBS
KF6::XmlGui
Qt::Multimedia
Qt::PrintSupport
Qt::Xml
KF6::Notifications
KF6::WindowSystem
@@ -79,6 +77,14 @@ set(konsole_LIBS
KF6::NewStuffCore
)
if(TARGET Qt6::Multimedia)
list(APPEND konsole_LIBS Qt::Multimedia)
endif()
if(TARGET Qt6::PrintSupport)
list(APPEND konsole_LIBS Qt::PrintSupport)
endif()
if(NOT WIN32)
list(APPEND konsole_LIBS
KF6::Pty
@@ -234,13 +240,16 @@ set(konsoleprivate_SRCS ${windowadaptors_SRCS}
widgets/TerminalHeaderBar.cpp
widgets/ViewContainer.cpp
widgets/ViewSplitter.cpp
widgets/KonsolePrintManager.cpp
${dbus_xml_srcs}
../data/data.qrc
../desktop/konsole.qrc)
if(TARGET Qt6::PrintSupport)
list(APPEND konsoleprivate_SRCS widgets/KonsolePrintManager.cpp)
endif()
kconfig_add_kcfg_files(konsoleprivate_SRCS settings/KonsoleSettings.kcfgc)
### Konsole Application
@@ -408,4 +417,3 @@ if(COVERAGE_GENERATE_HTML)
COMMAND ${GENHTML} --ignore-errors source --demangle-cpp -o coverage coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
@@ -33,7 +33,8 @@ void EscapeSequenceUrlExtractor::appendUrlText_impl(uint c)
const int realCcolumn = _screen->getCursorY() + _screen->getHistLines();
_currentUrl.begin = Coordinate{realCcolumn, _screen->getCursorX() - 1};
}
_currentUrl.text += QString::fromUcs4(&c, 1);
const auto codepoint = static_cast<char32_t>(c);
_currentUrl.text += QString::fromUcs4(&codepoint, 1);
}
void EscapeSequenceUrlExtractor::setUrl(const QString &url)
@@ -370,7 +370,7 @@ void MainWindow::setupActions()
});
// Set up themes
auto *manager = new KColorSchemeManager(actionCollection());
auto *manager = KColorSchemeManager::instance();
manager->setAutosaveChanges(true);
KActionMenu *selectionMenu = KColorSchemeMenu::createMenu(manager, this);
auto winColorSchemeMenu = new QAction(this);
@@ -1272,6 +1272,7 @@ ProcessInfo *ProcessInfo::newInstance(int pid, int sessionPid)
#elif defined(Q_OS_OPENBSD)
info = new OpenBSDProcessInfo(pid);
#else
Q_UNUSED(sessionPid);
info = new NullProcessInfo(pid);
#endif
info->readProcessInfo(pid);
@@ -1838,16 +1838,17 @@ void Screen::setSelectionEnd(const int x, const int y, const bool trimTrailingWh
// Do not let this code go to a release.
if (_screenLines.size() < line) {
QFile konsoleInfo(QStringLiteral("~/konsole_info_crash_array_out_of_bounds.txt"));
konsoleInfo.open(QIODevice::WriteOnly);
QTextStream messages(&konsoleInfo);
if (konsoleInfo.open(QIODevice::WriteOnly)) {
QTextStream messages(&konsoleInfo);
messages << "_selBegin" << _selBegin << "\n";
messages << "endPos" << endPos << "\n";
messages << "_selBottomRight" << _selBottomRight << "\n";
messages << "bottomRow Calculation: (_selBottomRight / _columns) = " << _selBottomRight << "/" << _columns << "\n";
messages << "line Calculation: (bottomRow - _history->getLines()) = " << bottomRow << "-" << _history->getLines() << "\n";
messages << "_screenLines.count()" << _screenLines.size() << "\n";
messages << "line" << line << "\n";
messages << "_selBegin" << _selBegin << "\n";
messages << "endPos" << endPos << "\n";
messages << "_selBottomRight" << _selBottomRight << "\n";
messages << "bottomRow Calculation: (_selBottomRight / _columns) = " << _selBottomRight << "/" << _columns << "\n";
messages << "line Calculation: (bottomRow - _history->getLines()) = " << bottomRow << "-" << _history->getLines() << "\n";
messages << "_screenLines.count()" << _screenLines.size() << "\n";
messages << "line" << line << "\n";
}
}
// HACK: do not crash.
@@ -12,7 +12,9 @@
#include <cstdio>
// Qt
#if HAVE_QTMULTIMEDIA
#include <QAudioOutput>
#endif
#include <QBuffer>
#include <QEvent>
#include <QKeyEvent>
@@ -70,7 +72,9 @@ Vt102Emulation::Vt102Emulation()
, _pendingSessionAttributesUpdates(QHash<int, QString>())
, _sessionAttributesUpdateTimer(new QTimer(this))
, _reportFocusEvents(false)
#if HAVE_QTMULTIMEDIA
, player(nullptr)
#endif
{
_sessionAttributesUpdateTimer->setSingleShot(true);
QObject::connect(_sessionAttributesUpdateTimer, &QTimer::timeout, this, &Konsole::Vt102Emulation::updateSessionAttributes);
@@ -1295,6 +1299,7 @@ void Vt102Emulation::processSessionAttributeRequest(const int tokenSize, const u
}
}
if (inlineMedia) {
#if HAVE_QTMULTIMEDIA
if (player == nullptr) {
player = new QMediaPlayer(this);
player->setAudioOutput(new QAudioOutput(player));
@@ -1306,6 +1311,7 @@ void Vt102Emulation::processSessionAttributeRequest(const int tokenSize, const u
delete (QIODevice *)(player->sourceDevice());
player->setSourceDevice(buffer);
player->play();
#endif
return;
}
if (!inlineImage) {
@@ -1333,6 +1339,7 @@ void Vt102Emulation::processSessionAttributeRequest(const int tokenSize, const u
_sessionAttributesUpdateTimer->start(20);
}
#if HAVE_QTMULTIMEDIA
void Vt102Emulation::deletePlayer(QMediaPlayer::MediaStatus mediaStatus)
{
if (mediaStatus == QMediaPlayer::EndOfMedia || mediaStatus == QMediaPlayer::InvalidMedia) {
@@ -1342,6 +1349,7 @@ void Vt102Emulation::deletePlayer(QMediaPlayer::MediaStatus mediaStatus)
player = nullptr;
}
}
#endif
void Vt102Emulation::updateSessionAttributes()
{
@@ -9,9 +9,12 @@
#define VT102EMULATION_H
// Qt
#include "config-konsole.h"
#include <QHash>
#include <QMap>
#if HAVE_QTMULTIMEDIA
#include <QMediaPlayer>
#endif
#include <QPair>
#include <QVector>
#include <QList>
@@ -100,7 +103,9 @@ private Q_SLOTS:
// pair in _pendingSessionAttributesUpdates.
// Used to buffer multiple attribute updates in the current session
void updateSessionAttributes();
#if HAVE_QTMULTIMEDIA
void deletePlayer(QMediaPlayer::MediaStatus);
#endif
private:
unsigned int applyCharset(uint c);
@@ -315,7 +320,9 @@ private:
// For kitty graphics protocol - image cache
int getFreeGraphicsImageId();
#if HAVE_QTMULTIMEDIA
QMediaPlayer *player;
#endif
};
}
@@ -201,11 +201,11 @@ QImage ColorSchemeWallpaper::FlipImage(const QImage image, const ColorSchemeWall
{
switch (flipType) {
case Horizontal:
return image.mirrored(true, false);
return image.flipped(Qt::Horizontal);
case Vertical:
return image.mirrored(false, true);
return image.flipped(Qt::Vertical);
case Both:
return image.mirrored(true, true);
return image.flipped(Qt::Horizontal | Qt::Vertical);
default:
return image;
}
@@ -17,3 +17,7 @@
/* Defined if system has the malloc_trim function, which is a GNU extension */
#cmakedefine01 HAVE_MALLOC_TRIM
#cmakedefine01 HAVE_QTMULTIMEDIA
#cmakedefine01 HAVE_QTPRINTSUPPORT
@@ -93,7 +93,7 @@ QSharedPointer<HotSpot> FileFilter::newHotSpot(int startLine, int startColumn, i
// '.' and '..' could be valid hotspots, but '..................' most likely isn't
static const QRegularExpression allDotRe{QRegularExpression::anchoredPattern(QStringLiteral("\\.{3}"))};
if (allDotRe.match(filename).hasMatch()) {
if (allDotRe.matchView(filename).hasMatch()) {
return nullptr;
}
@@ -33,8 +33,9 @@ bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParen
void FilterModel::setInvertFilter(bool invert)
{
beginFilterChange();
m_invertFilter = invert;
invalidateFilter();
endFilterChange(QSortFilterProxyModel::Direction::Rows);
}
#include "moc_filtermodel.cpp"
@@ -314,7 +314,11 @@ void QuickCommandsWidget::runShellCheck()
}
QTemporaryFile file;
file.open();
if (!file.open()) {
ui->warning->setPlainText(file.errorString());
ui->tabWidget->setTabText(1, i18n("Warnings (*)"));
return;
}
QTextStream ts(&file);
ts << "#!/bin/bash\n";
@@ -31,8 +31,9 @@ bool SSHManagerFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &s
void SSHManagerFilterModel::setInvertFilter(bool invert)
{
beginFilterChange();
m_invertFilter = invert;
invalidateFilter();
endFilterChange(QSortFilterProxyModel::Direction::Rows);
}
#include "moc_sshmanagerfiltermodel.cpp"
@@ -8,6 +8,8 @@
// Own
#include "SessionController.h"
#include "config-konsole.h"
#include "profile/ProfileManager.h"
#include "terminalDisplay/TerminalColor.h"
#include "terminalDisplay/TerminalFonts.h"
@@ -145,7 +147,9 @@ SessionController::SessionController(Session *sessionParam, TerminalDisplay *vie
setupExtraActions();
}
#if HAVE_QTPRINTSUPPORT
connect(this, &SessionController::requestPrint, view(), &TerminalDisplay::printScreen);
#endif
actionCollection()->addAssociatedWidget(viewParam);
@@ -730,9 +734,11 @@ void SessionController::setupCommonActions()
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
#endif
#if HAVE_QTPRINTSUPPORT
action = KStandardAction::print(this, &SessionController::requestPrint, collection);
action->setText(i18n("&Print Screen..."));
collection->setDefaultShortcut(action, Konsole::ACCEL | Qt::Key_P);
#endif
action = collection->addAction(QStringLiteral("adjust-history"), this, &SessionController::showHistoryOptions);
action->setText(i18n("Adjust Scrollback..."));
@@ -55,7 +55,9 @@
#include "../characters/ExtendedCharTable.h"
#include "../characters/LineBlockCharacters.h"
#include "../decoders/PlainTextDecoder.h"
#if HAVE_QTPRINTSUPPORT
#include "../widgets/KonsolePrintManager.h"
#endif
#include "../widgets/TerminalDisplayAccessible.h"
#include "EscapeSequenceUrlExtractor.h"
#include "PrintOptions.h"
@@ -308,6 +310,7 @@ TerminalDisplay::TerminalDisplay(QWidget *parent)
_terminalPainter = new TerminalPainter(this);
#if HAVE_QTPRINTSUPPORT
auto ldrawBackground = [this](QPainter &painter, const QRect &rect, const QColor &backgroundColor, bool useOpacitySetting) {
_terminalPainter->drawBackground(painter, rect, backgroundColor, useOpacitySetting);
};
@@ -319,6 +322,7 @@ TerminalDisplay::TerminalDisplay(QWidget *parent)
};
_printManager.reset(new KonsolePrintManager(ldrawBackground, ldrawContents, lgetBackgroundColor));
#endif
ubidi = ubidi_open();
}
@@ -2305,7 +2309,7 @@ void TerminalDisplay::doPaste(QString text, bool appendReturn)
if (isUnsafe(c)) {
const QString sequence = charToSequence(c);
const QString description = characterDescriptions.value(c.unicode(), QString());
QString entry = QStringLiteral("U+%1").arg(c.unicode(), 4, 16, QLatin1Char('0'));
QString entry = QStringLiteral("U+%1").arg(static_cast<uint>(c.unicode()), 4, 16, QLatin1Char('0'));
if (!sequence.isEmpty()) {
entry += QStringLiteral("\t%1").arg(sequence);
}
@@ -3182,6 +3186,7 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
void TerminalDisplay::printScreen()
{
#if HAVE_QTPRINTSUPPORT
auto lprintContent = [this](QPainter &painter, bool friendly) {
QPoint columnLines(_usedLines, _usedColumns);
auto lfontget = [this]() {
@@ -3194,6 +3199,7 @@ void TerminalDisplay::printScreen()
_printManager->printContent(painter, friendly, columnLines, lfontget, lfontset);
};
_printManager->printRequest(lprintContent, this);
#endif
}
Character TerminalDisplay::getCursorCharacter(int column, int line)
@@ -8,6 +8,8 @@
#ifndef TERMINALDISPLAY_H
#define TERMINALDISPLAY_H
#include "config-konsole.h"
// Qt
#include <QColor>
#include <QPointer>
@@ -834,7 +836,9 @@ private:
TerminalColor *_terminalColor = nullptr;
std::unique_ptr<TerminalFont> _terminalFont;
#if HAVE_QTPRINTSUPPORT
std::unique_ptr<KonsolePrintManager> _printManager;
#endif
bool _semanticUpDown;
bool _semanticInputClick;