mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Support Wayland display reconnection
This commit is contained in:
parent
58451aed91
commit
ce8e42bcc2
3 changed files with 22 additions and 24 deletions
|
@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/linux/linux_wayland_integration.h"
|
#include "platform/linux/linux_wayland_integration.h"
|
||||||
|
|
||||||
#include "base/platform/linux/base_linux_wayland_utilities.h"
|
#include "base/platform/linux/base_linux_wayland_utilities.h"
|
||||||
#include "base/platform/base_platform_info.h"
|
|
||||||
#include "base/qt_signal_producer.h"
|
#include "base/qt_signal_producer.h"
|
||||||
#include "base/flat_map.h"
|
#include "base/flat_map.h"
|
||||||
|
|
||||||
|
@ -20,7 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <qwayland-wayland.h>
|
#include <qwayland-wayland.h>
|
||||||
#include <qwayland-plasma-shell.h>
|
#include <qwayland-plasma-shell.h>
|
||||||
|
|
||||||
using namespace QNativeInterface;
|
using QWlApp = QNativeInterface::QWaylandApplication;
|
||||||
using namespace QNativeInterface::Private;
|
using namespace QNativeInterface::Private;
|
||||||
using namespace base::Platform::Wayland;
|
using namespace base::Platform::Wayland;
|
||||||
|
|
||||||
|
@ -38,9 +37,17 @@ public:
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
struct WaylandIntegration::Private : public AutoDestroyer<QtWayland::wl_registry> {
|
struct WaylandIntegration::Private
|
||||||
|
: public AutoDestroyer<QtWayland::wl_registry> {
|
||||||
|
Private(not_null<QWlApp*> native)
|
||||||
|
: AutoDestroyer(wl_display_get_registry(native->display()))
|
||||||
|
, display(native->display()) {
|
||||||
|
wl_display_roundtrip(display);
|
||||||
|
}
|
||||||
|
|
||||||
QtWayland::org_kde_plasma_surface plasmaSurface(QWindow *window);
|
QtWayland::org_kde_plasma_surface plasmaSurface(QWindow *window);
|
||||||
|
|
||||||
|
const not_null<wl_display*> display;
|
||||||
std::optional<PlasmaShell> plasmaShell;
|
std::optional<PlasmaShell> plasmaShell;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -102,36 +109,27 @@ QtWayland::org_kde_plasma_surface WaylandIntegration::Private::plasmaSurface(
|
||||||
}
|
}
|
||||||
|
|
||||||
WaylandIntegration::WaylandIntegration()
|
WaylandIntegration::WaylandIntegration()
|
||||||
: _private(std::make_unique<Private>()) {
|
: _private(std::make_unique<Private>(qApp->nativeInterface<QWlApp>())) {
|
||||||
const auto native = qApp->nativeInterface<QWaylandApplication>();
|
|
||||||
if (!native) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto display = native->display();
|
|
||||||
if (!display) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_private->init(wl_display_get_registry(display));
|
|
||||||
wl_display_roundtrip(display);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WaylandIntegration::~WaylandIntegration() = default;
|
WaylandIntegration::~WaylandIntegration() = default;
|
||||||
|
|
||||||
WaylandIntegration *WaylandIntegration::Instance() {
|
WaylandIntegration *WaylandIntegration::Instance() {
|
||||||
if (!IsWayland()) return nullptr;
|
const auto native = qApp->nativeInterface<QWlApp>();
|
||||||
static std::optional<WaylandIntegration> instance(std::in_place);
|
if (!native) return nullptr;
|
||||||
[[maybe_unused]] static const auto Inited = [] {
|
static std::optional<WaylandIntegration> instance;
|
||||||
|
if (instance && native->display() != instance->_private->display) {
|
||||||
|
instance.reset();
|
||||||
|
}
|
||||||
|
if (!instance) {
|
||||||
|
instance.emplace();
|
||||||
base::qt_signal_producer(
|
base::qt_signal_producer(
|
||||||
QGuiApplication::platformNativeInterface(),
|
QGuiApplication::platformNativeInterface(),
|
||||||
&QObject::destroyed
|
&QObject::destroyed
|
||||||
) | rpl::start_with_next([] {
|
) | rpl::start_with_next([] {
|
||||||
instance = std::nullopt;
|
instance = std::nullopt;
|
||||||
}, instance->_private->lifetime());
|
}, instance->_private->lifetime());
|
||||||
return true;
|
}
|
||||||
}();
|
|
||||||
if (!instance) return nullptr;
|
|
||||||
return &*instance;
|
return &*instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6de11e6ab705f27158f338e3e17c8b0767750721
|
Subproject commit 5916b1db7ccae3ba0fafa8309d50c2c09a19604b
|
2
cmake
2
cmake
|
@ -1 +1 @@
|
||||||
Subproject commit 0ae4e78a12d7fdea687ca52647465b9cf9ef95ee
|
Subproject commit 0bacdcaaa4ac11348cc5562e94eac1e5bdb58789
|
Loading…
Add table
Reference in a new issue