WIP: Improve positioning of tray widget under Wayland

* Add support for the layer shell protocol
This commit is contained in:
Martchus 2022-11-26 17:24:42 +01:00
parent 71675c7b18
commit 864d2777b5
2 changed files with 27 additions and 0 deletions

View File

@ -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)

View File

@ -30,6 +30,10 @@
#include <qtutilities/resources/resources.h>
#include <qtutilities/settingsdialog/qtsettings.h>
#ifdef SYNCTHINGTRAY_LAYER_SHELL_PROTOCOL_SUPPORT
#include <LayerShellQt/Shell>
#endif
#include <QApplication>
#include <QMessageBox>
#include <QNetworkAccessManager>
@ -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::Anchors>(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<char **>(argv));
QGuiApplication::setQuitOnLastWindowClosed(false);
SingleInstance singleInstance(argc, argv, newInstanceArg.isPresent());