diff --git a/tray/CMakeLists.txt b/tray/CMakeLists.txt index a25f84b..49a4de3 100644 --- a/tray/CMakeLists.txt +++ b/tray/CMakeLists.txt @@ -132,6 +132,18 @@ endif () # apply basic configuration include(BasicConfig) +# configure support for layer-shell protocol +if (LINUX) + option(LAYER_SHELL_PROTOCOL_SUPPORT "whether to compile with support for the layer-shell protocol" OFF) + if (LAYER_SHELL_PROTOCOL_SUPPORT) + use_package(TARGET_NAME LayerShellQt::Interface PACKAGE_NAME LayerShellQt PACKAGE_ARGS "REQUIRED") + set_property( + SOURCE application/main.cpp + APPEND + PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_LAYER_SHELL_PROTOCOL_SUPPORT) + endif () +endif () + # add an option to unify left- and right-click context menus useful on Mac OS if (APPLE) set(UNIFY_TRAY_MENUS_BY_DEFAULT ON) diff --git a/tray/application/main.cpp b/tray/application/main.cpp index a921ce7..dc0cb0e 100644 --- a/tray/application/main.cpp +++ b/tray/application/main.cpp @@ -30,6 +30,10 @@ #include #include +#ifdef SYNCTHINGTRAY_LAYER_SHELL_PROTOCOL_SUPPORT +#include +#endif + #include #include #include @@ -106,6 +110,14 @@ int initSyncthingTray(bool windowed, bool waitForTray, const Argument &connectio auto *const trayIcon = new TrayIcon(QString::fromLocal8Bit(connectionConfig), QApplication::instance()); trayIcon->show(); widget = &trayIcon->trayMenu().widget(); +#ifdef SYNCTHINGTRAY_LAYER_SHELL_PROTOCOL_SUPPORT + if (auto *const qtWindow = trayIcon->trayMenu().windowHandle()) { + if (auto *const layerShellWindow = LayerShellQt::Window::get(qtWindow)) { + layerShellWindow->setAnchors( + static_cast(LayerShellQt::Window::AnchorTop | LayerShellQt::Window::AnchorRight)); + } + } +#endif } // show wizard on first launch @@ -211,6 +223,9 @@ int runApplication(int argc, const char *const *argv) // do first-time initializations SET_QT_APPLICATION_INFO; +#ifdef SYNCTHINGTRAY_LAYER_SHELL_PROTOCOL_SUPPORT + LayerShellQt::Shell::useLayerShell(); +#endif QApplication application(argc, const_cast(argv)); QGuiApplication::setQuitOnLastWindowClosed(false); SingleInstance singleInstance(argc, argv, newInstanceArg.isPresent());