Disable DBus (and X11) on Windows/macOS/Android per default

Like Kate, one should not try to use DBus on platform that not
support it. At the moment we have hacks in the Craft blueprints
to avoid the worst, but not using it is much nicer.

If the user wants to compile it, we have a USE_DBUS CMake option.
This commit is contained in:
Christoph Cullmann
2024-06-05 13:42:44 +00:00
committed by Kurt Hindenburg
parent e756f94cbc
commit b94f2c5cde
8 changed files with 81 additions and 36 deletions

View File

@@ -9,7 +9,6 @@ Dependencies:
'frameworks/knotifications': '@latest-kf6'
'frameworks/ki18n': '@latest-kf6'
'frameworks/kcoreaddons': '@latest-kf6'
'frameworks/kdbusaddons': '@latest-kf6'
'frameworks/kbookmarks': '@latest-kf6'
'frameworks/kconfigwidgets': '@latest-kf6'
'frameworks/kcrash': '@latest-kf6'
@@ -28,6 +27,7 @@ Dependencies:
- 'on': ['Linux/Qt6', 'FreeBSD/Qt6']
'require':
'frameworks/kdbusaddons': '@latest-kf6'
'frameworks/kpty': '@latest-kf6'
'frameworks/kglobalaccel': '@latest-kf6'

View File

@@ -45,7 +45,6 @@ include(ECMEnableSanitizers)
find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED
Core
DBus
Multimedia
PrintSupport
Widgets
@@ -59,7 +58,6 @@ find_package(KF6 ${KF6_DEP_VERSION} REQUIRED
CoreAddons
Crash
GuiAddons
DBusAddons
I18n
IconThemes
KIO
@@ -80,10 +78,22 @@ if (NOT WIN32)
)
endif()
if (NOT WIN32 AND NOT APPLE)
# shall we use DBus?
# enabled per default on Linux & BSD systems
set(USE_DBUS_DEFAULT OFF)
if(UNIX AND NOT APPLE AND NOT ANDROID AND NOT HAIKU)
set(USE_DBUS_DEFAULT ON)
endif()
option(USE_DBUS "Build components using DBus" ${USE_DBUS_DEFAULT})
if(USE_DBUS)
find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED
DBus
)
find_package(KF6 ${KF6_DEP_VERSION} REQUIRED
DBusAddons
GlobalAccel
)
set(HAVE_DBUS 1)
endif()
find_package(KF6DocTools ${KF6_DEP_VERSION})
@@ -94,7 +104,7 @@ set_package_properties(KF6DocTools PROPERTIES DESCRIPTION
find_package(ICU 61.0 COMPONENTS uc i18n REQUIRED)
if(NOT APPLE)
if(UNIX AND NOT APPLE AND NOT ANDROID AND NOT HAIKU)
option(WITHOUT_X11 "Build without X11 integration (skips finding X11)" OFF)
if (NOT WITHOUT_X11)
find_package(X11)
@@ -130,7 +140,7 @@ add_subdirectory( src )
add_subdirectory( data )
add_subdirectory( desktop )
if (NOT WIN32 AND NOT APPLE)
if (HAVE_DBUS)
add_subdirectory( kconf_update )
endif()

View File

@@ -18,7 +18,7 @@
// KDE
#include <KActionCollection>
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
#if HAVE_DBUS
#include <KGlobalAccel>
#endif
#include <KLocalizedString>
@@ -509,7 +509,7 @@ void Application::startBackgroundMode(MainWindow *window)
return;
}
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
#if HAVE_DBUS
KActionCollection *collection = window->actionCollection();
QAction *action = collection->addAction(QStringLiteral("toggle-background-window"));
action->setObjectName(QStringLiteral("Konsole Background Mode"));

View File

@@ -32,28 +32,36 @@ option(ENABLE_DECRQCRA "Konsole: enable DEC request checksum rectangular area" O
### Development tools
option(KONSOLE_BUILD_UNI2CHARACTERWIDTH "Konsole: build uni2characterwidth executable" OFF)
### Konsole source files shared between embedded terminal and main application
# qdbuscpp2xml -m Session.h -o org.kde.konsole.Session.xml
# qdbuscpp2xml -M -s ViewManager.h -o org.kde.konsole.Konsole.xml
set(dbus_xml_srcs)
if (HAVE_DBUS)
### Konsole source files shared between embedded terminal and main application
# qdbuscpp2xml -m Session.h -o org.kde.konsole.Session.xml
# qdbuscpp2xml -M -s ViewManager.h -o org.kde.konsole.Konsole.xml
# Generate dbus .xml files; do not store .xml in source folder
qt_generate_dbus_interface(ViewManager.h org.kde.konsole.Window.xml OPTIONS -m)
# Generate dbus .xml files; do not store .xml in source folder
qt_generate_dbus_interface(ViewManager.h org.kde.konsole.Window.xml OPTIONS -m)
qt_add_dbus_adaptor(windowadaptors_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Window.xml
ViewManager.h
Konsole::ViewManager)
qt_add_dbus_adaptor(windowadaptors_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Window.xml
ViewManager.h
Konsole::ViewManager)
# qdbuscpp2xml -m Session.h -o org.kde.konsole.Session.xml
# Generate dbus .xml files; do not store .xml in source folder
qt_generate_dbus_interface(session/Session.h org.kde.konsole.Session.xml OPTIONS -m)
# qdbuscpp2xml -m Session.h -o org.kde.konsole.Session.xml
# Generate dbus .xml files; do not store .xml in source folder
qt_generate_dbus_interface(session/Session.h org.kde.konsole.Session.xml OPTIONS -m)
qt_add_dbus_adaptor(
sessionadaptors_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Session.xml
session/Session.h
Konsole::Session
)
qt_add_dbus_adaptor(
sessionadaptors_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Session.xml
session/Session.h
Konsole::Session
)
set(dbus_xml_srcs
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Session.xml
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Window.xml
)
endif()
set(konsole_LIBS
KF6::XmlGui
@@ -68,7 +76,6 @@ set(konsole_LIBS
KF6::Bookmarks
KF6::I18n
KF6::KIOWidgets
KF6::DBusAddons
KF6::NewStuffCore
)
@@ -78,8 +85,9 @@ if (NOT WIN32)
)
endif()
if (NOT WIN32 AND NOT APPLE)
if (HAVE_DBUS)
list(APPEND konsole_LIBS
KF6::DBusAddons
KF6::GlobalAccel
)
endif()
@@ -221,14 +229,13 @@ set(konsoleprivate_SRCS ${windowadaptors_SRCS}
session/SessionListModel.cpp
session/SessionManager.cpp
session/SessionTask.cpp
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Session.xml
widgets/TerminalDisplayAccessible.cpp
widgets/TerminalHeaderBar.cpp
widgets/ViewContainer.cpp
widgets/ViewSplitter.cpp
widgets/KonsolePrintManager.cpp
${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Window.xml)
${dbus_xml_srcs})
kconfig_add_kcfg_files(konsoleprivate_SRCS settings/KonsoleSettings.kcfgc)

View File

@@ -19,8 +19,10 @@
#include <QJsonArray>
#include <QJsonDocument>
#if HAVE_DBUS
#include <QDBusArgument>
#include <QDBusMetaType>
#endif
// KDE
#include <KActionCollection>
@@ -30,7 +32,9 @@
#include <KMessageBox>
// Konsole
#if HAVE_DBUS
#include <windowadaptor.h>
#endif
#include "colorscheme/ColorScheme.h"
#include "colorscheme/ColorSchemeManager.h"
@@ -62,7 +66,9 @@ ViewManager::ViewManager(QObject *parent, KActionCollection *collection)
, _managerId(0)
, _terminalDisplayHistoryIndex(-1)
{
#if HAVE_DBUS
qDBusRegisterMetaType<QList<double>>();
#endif
_viewContainer = createContainer();
// setup actions which are related to the views
@@ -77,11 +83,13 @@ ViewManager::ViewManager(QObject *parent, KActionCollection *collection)
connect(ProfileManager::instance(), &Konsole::ProfileManager::profileChanged, this, &Konsole::ViewManager::profileChanged);
connect(SessionManager::instance(), &Konsole::SessionManager::sessionUpdated, this, &Konsole::ViewManager::updateViewsForSession);
_managerId = ++lastManagerId;
#if HAVE_DBUS
// prepare DBus communication
new WindowAdaptor(this);
_managerId = ++lastManagerId;
QDBusConnection::sessionBus().registerObject(QLatin1String("/Windows/") + QString::number(_managerId), this);
#endif
}
ViewManager::~ViewManager() = default;

View File

@@ -5,6 +5,8 @@
#cmakedefine01 HAVE_X11
#cmakedefine01 HAVE_DBUS
/* If defined, remove public access to dbus sendInput/runCommand */
#cmakedefine01 REMOVE_SENDTEXT_RUNCOMMAND_DBUS_METHODS

View File

@@ -27,10 +27,13 @@
// KDE
#include <KAboutData>
#include <KCrash>
#include <KDBusService>
#include <KIconTheme>
#include <KLocalizedString>
#if HAVE_DBUS
#include <KDBusService>
#endif
#define HAVE_STYLE_MANAGER __has_include(<KStyleManager>)
#if HAVE_STYLE_MANAGER
#include <KStyleManager>
@@ -54,6 +57,7 @@ bool shouldUseNewProcess(int argc, char *argv[]);
// restore sessions saved by KDE.
void restoreSession(Application &app);
#if HAVE_DBUS
// Workaround for a bug in KDBusService: https://bugs.kde.org/show_bug.cgi?id=355545
// It calls exit(), but the program can't exit before the QApplication is deleted:
// https://bugreports.qt.io/browse/QTBUG-48709
@@ -64,6 +68,7 @@ void deleteQApplication()
delete qApp;
}
}
#endif
// This override resolves following problem: since some qt version if
// XDG_CURRENT_DESKTOP ≠ kde, then pressing and immediately releasing Alt
@@ -150,6 +155,7 @@ int main(int argc, char *argv[])
}
#endif
#if HAVE_DBUS
// Check if any of the arguments makes it impossible to re-use an existing process.
// We need to do this manually and before creating a QApplication, because
// QApplication takes/removes the Qt specific arguments that are incompatible.
@@ -157,6 +163,7 @@ int main(int argc, char *argv[])
if (!needNewProcess) { // We need to avoid crashing
needToDeleteQApplication = true;
}
#endif
auto app = new QApplication(argc, argv);
@@ -210,6 +217,7 @@ int main(int argc, char *argv[])
parser->process(args);
about.processCommandLine(parser.data());
#if HAVE_DBUS
/// ! DON'T TOUCH THIS ! ///
const KDBusService::StartupOption startupOption =
Konsole::KonsoleSettings::useSingleInstance() && !needNewProcess ? KDBusService::Unique : KDBusService::Multiple;
@@ -224,14 +232,17 @@ int main(int argc, char *argv[])
KDBusService dbusService(startupOption | KDBusService::NoExitOnFailure);
needToDeleteQApplication = false;
#endif
// If we reach this location, there was no existing copy of Konsole
// running, so create a new instance.
Application konsoleApp(parser, customCommand);
#if HAVE_DBUS
// The activateRequested() signal is emitted when a second instance
// of Konsole is started.
QObject::connect(&dbusService, &KDBusService::activateRequested, &konsoleApp, &Application::slotActivateRequested);
#endif
if (app->isSessionRestored()) {
restoreSession(konsoleApp);

View File

@@ -24,6 +24,7 @@
#include <QDir>
#include <QFile>
#include <QKeyEvent>
#include <QThread>
// KDE
#include <KActionCollection>
@@ -40,7 +41,9 @@
#include <KShell>
// Konsole
#if HAVE_DBUS
#include <sessionadaptor.h>
#endif
#include "Pty.h"
#include "SSHProcessInfo.h"
@@ -82,9 +85,6 @@ Session::Session(QObject *parent)
{
_uniqueIdentifier = QUuid::createUuid();
// prepare DBus communication
new SessionAdaptor(this);
int maxSessionId = 0;
auto allSessions = SessionManager::instance()->sessions();
for (const auto &session : allSessions) {
@@ -93,7 +93,12 @@ Session::Session(QObject *parent)
}
}
_sessionId = maxSessionId + 1;
#if HAVE_DBUS
// prepare DBus communication
new SessionAdaptor(this);
QDBusConnection::sessionBus().registerObject(QLatin1String("/Sessions/") + QString::number(_sessionId), this);
#endif
// create emulation backend
_emulation = new Vt102Emulation();
@@ -559,11 +564,13 @@ void Session::run()
addEnvironmentEntry(QStringLiteral("WINDOWID=%1").arg(QString::number(windowId())));
#if HAVE_DBUS
const QString dbusService = QDBusConnection::sessionBus().baseService();
addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_SERVICE=%1").arg(dbusService));
const QString dbusObject = QStringLiteral("/Sessions/%1").arg(QString::number(_sessionId));
addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_SESSION=%1").arg(dbusObject));
#endif
#ifndef Q_OS_WIN
const auto originalEnvironment = _shellProcess->environment();