Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique app support #87

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kcm_fcitx5\")
add_definitions(-DFCITX_GETTEXT_DOMAIN=\"fcitx5-configtool\")
add_definitions(-DQT_NO_KEYWORDS)

set(CONFIG_QT_UNIQUE_APP_SUPPORT 0)
if (ENABLE_CONFIG_QT)
find_package(KF${QT_MAJOR_VERSION}ItemViews REQUIRED)
find_package(KF${QT_MAJOR_VERSION}DBusAddons 5.91)
find_package(KF${QT_MAJOR_VERSION}WindowSystem 5.91)

if (TARGET KF${QT_MAJOR_VERSION}::DBusAddons AND TARGET KF${QT_MAJOR_VERSION}::WindowSystem)
set(CONFIG_QT_UNIQUE_APP_SUPPORT 1)
endif()
endif()

if (ENABLE_KCM)
Expand Down
1 change: 1 addition & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#cmakedefine ISOCODES_ISO639_2_JSON "@ISOCODES_ISO639_2_JSON@"
#cmakedefine ISOCODES_ISO639_3_JSON "@ISOCODES_ISO639_3_JSON@"
#cmakedefine ISOCODES_ISO639_5_JSON "@ISOCODES_ISO639_5_JSON@"
#cmakedefine CONFIG_QT_UNIQUE_APP_SUPPORT

#define FCITX5_QT_GUI_WRAPPER "@FCITX5_QT_GUI_WRAPPER@"

Expand Down
10 changes: 9 additions & 1 deletion src/configtool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ set_target_properties(fcitx5-config-qt
AUTOUIC_OPTIONS "-tr=fcitx::tr2fcitx;--include=fcitxqti18nhelper.h")

target_link_libraries(fcitx5-config-qt
Qt${QT_MAJOR_VERSION}::Widgets configwidgetslib
Qt${QT_MAJOR_VERSION}::Widgets
configwidgetslib
)

if (CONFIG_QT_UNIQUE_APP_SUPPORT)
target_link_libraries(fcitx5-config-qt
KF${QT_MAJOR_VERSION}::DBusAddons
KF${QT_MAJOR_VERSION}::WindowSystem
)
endif()

install(TARGETS fcitx5-config-qt DESTINATION ${CMAKE_INSTALL_BINDIR})
fcitx5_translate_desktop_file(org.fcitx.fcitx5-config-qt.desktop.in
org.fcitx.fcitx5-config-qt.desktop PO_DIRECTORY ${PROJECT_SOURCE_DIR}/po/fcitx5-configtool)
Expand Down
34 changes: 34 additions & 0 deletions src/configtool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#include "config.h"
#include "mainwindow.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QSessionManager>

#ifdef CONFIG_QT_UNIQUE_APP_SUPPORT
#include <KDBusService>
#include <KWindowSystem>
#endif

int main(int argc, char *argv[]) {
QApplication app(argc, argv);
Expand All @@ -16,7 +23,34 @@ int main(int argc, char *argv[]) {
app.setOrganizationDomain("fcitx.org");
fcitx::registerFcitxQtDBusTypes();

QCommandLineParser parser;
parser.addVersionOption();
parser.addHelpOption();
parser.process(app);

auto disableSessionManagement = [](QSessionManager &sm) {
sm.setRestartHint(QSessionManager::RestartNever);
};
QObject::connect(&app, &QGuiApplication::commitDataRequest,
disableSessionManagement);
QObject::connect(&app, &QGuiApplication::saveStateRequest,
disableSessionManagement);

fcitx::kcm::MainWindow mainWindow;

#ifdef CONFIG_QT_UNIQUE_APP_SUPPORT
KDBusService dbusService(KDBusService::Unique);
QObject::connect(
&dbusService, &KDBusService::activateRequested, &mainWindow,
[&mainWindow](const QStringList & /*args*/,
const QString & /*workingDir*/) {
mainWindow.show();
KWindowSystem::updateStartupId(mainWindow.windowHandle());
mainWindow.raise();
KWindowSystem::activateWindow(mainWindow.windowHandle());
});
#endif

mainWindow.show();

return app.exec();
Expand Down
6 changes: 6 additions & 0 deletions src/migrator/app/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "config.h"
#include "mainwindow.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
#include <QPluginLoader>
#include <QSessionManager>
Expand All @@ -22,6 +23,11 @@ int main(int argc, char *argv[]) {
app.setOrganizationDomain("fcitx.org");
fcitx::registerFcitxQtDBusTypes();

QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
parser.process(app);

auto disableSessionManagement = [](QSessionManager &sm) {
sm.setRestartHint(QSessionManager::RestartNever);
};
Expand Down
10 changes: 10 additions & 0 deletions src/plasmathemegenerator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QDebug>
#include <QDir>
#include <QPainter>
#include <QSessionManager>
#include <QSocketNotifier>
#include <fcitx-config/iniparser.h>
#include <fcitx-config/rawconfig.h>
Expand Down Expand Up @@ -81,6 +82,7 @@ class WatcherApp : public QGuiApplication {
parser.setApplicationDescription(
i18n("Generate Fcitx 5 Classic UI Theme based on Plasma theme"));
parser.addHelpOption();
parser.addVersionOption();
parser.addOptions(
{{{"t", "theme"}, i18n("Plasma theme name <name> "), i18n("name")},
{{"o", "output"}, i18n("Output path <output> "), i18n("output")}});
Expand Down Expand Up @@ -151,6 +153,14 @@ class WatcherApp : public QGuiApplication {
}
});
}

auto disableSessionManagement = [](QSessionManager &sm) {
sm.setRestartHint(QSessionManager::RestartNever);
};
QObject::connect(this, &QGuiApplication::commitDataRequest,
disableSessionManagement);
QObject::connect(this, &QGuiApplication::saveStateRequest,
disableSessionManagement);
return true;
}

Expand Down
Loading