Skip to content

Commit 0570a6f

Browse files
committed
fix(ui): fix "Start minimized" setting
1 parent 6e7ef6c commit 0570a6f

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ add_executable(ktailctl property_list_model.hpp main.cpp
1414
string_filter.hpp string_filter.cpp
1515
tailscale/preferences/app_connector.hpp
1616
)
17-
target_link_libraries(ktailctl PRIVATE Qt6::Core Qt6::Quick Qt6::Widgets Qt6::Qml KF6::CoreAddons KF6::I18n KF6::DBusAddons KF6::GuiAddons KF6::IconThemes KF6::ConfigCore)
17+
target_link_libraries(ktailctl PRIVATE Qt6::Core Qt6::Quick Qt6::Widgets Qt6::Qml KF6::CoreAddons KF6::I18n KF6::DBusAddons KF6::GuiAddons KF6::IconThemes KF6::ConfigCore KF6::WindowSystem)
1818
ecm_add_qml_module(ktailctl URI org.fkoehler.KTailctl GENERATE_PLUGIN_SOURCE)
1919
ecm_target_qml_sources(ktailctl SOURCES ui/Main.qml)
2020
install(TARGETS ktailctl ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})

src/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <KLocalizedContext>
66
#include <KLocalizedString>
77
#include <KSharedConfig>
8+
#include <KWindowSystem>
89
#include <QApplication>
910
#include <QByteArray>
1011
#include <QCoreApplication>
@@ -108,6 +109,15 @@ auto main(int argc, char *argv[]) -> int
108109

109110
auto *window = dynamic_cast<QQuickWindow *>(engine->rootObjects().constFirst());
110111

112+
// honor the "Start minimized" setting on startup
113+
if (window != nullptr) {
114+
if (Config::startMinimized()) {
115+
window->hide();
116+
} else {
117+
window->show();
118+
}
119+
}
120+
111121
// clicking tray icon should toggle window
112122
auto *tray_icon = new TrayIcon(tailscale);
113123
tray_icon->setVisible(Config::enableTrayIcon());
@@ -135,6 +145,17 @@ auto main(int argc, char *argv[]) -> int
135145
});
136146
QObject::connect(tray_icon, &TrayIcon::quitRequested, &app, &QCoreApplication::quit, Qt::QueuedConnection);
137147

148+
// re-launching the unique instance should reveal and focus the window
149+
QObject::connect(&service, &KDBusService::activateRequested, window, [window](const QStringList &, const QString &) {
150+
if (window == nullptr) {
151+
return;
152+
}
153+
window->show();
154+
KWindowSystem::updateStartupId(window);
155+
window->raise();
156+
KWindowSystem::activateWindow(window);
157+
});
158+
138159
QObject::connect(&app, &QCoreApplication::aboutToQuit, &app, [&engine]() {
139160
engine.reset();
140161
});

0 commit comments

Comments
 (0)