Skip to content

Commit

Permalink
Support Wayland display reconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin committed Sep 23, 2023
1 parent 58451ae commit 3e3ab16
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
42 changes: 20 additions & 22 deletions Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ For license and copyright information please follow this link:
#include "platform/linux/linux_wayland_integration.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/flat_map.h"

Expand All @@ -20,7 +19,7 @@ For license and copyright information please follow this link:
#include <qwayland-wayland.h>
#include <qwayland-plasma-shell.h>

using namespace QNativeInterface;
using QWlApp = QNativeInterface::QWaylandApplication;
using namespace QNativeInterface::Private;
using namespace base::Platform::Wayland;

Expand All @@ -38,9 +37,17 @@ class PlasmaShell : public Global<QtWayland::org_kde_plasma_shell> {

} // 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);

const not_null<wl_display*> display;
std::optional<PlasmaShell> plasmaShell;

protected:
Expand Down Expand Up @@ -102,36 +109,27 @@ QtWayland::org_kde_plasma_surface WaylandIntegration::Private::plasmaSurface(
}

WaylandIntegration::WaylandIntegration()
: _private(std::make_unique<Private>()) {
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);
: _private(std::make_unique<Private>(qApp->nativeInterface<QWlApp>())) {
}

WaylandIntegration::~WaylandIntegration() = default;

WaylandIntegration *WaylandIntegration::Instance() {
if (!IsWayland()) return nullptr;
static std::optional<WaylandIntegration> instance(std::in_place);
[[maybe_unused]] static const auto Inited = [] {
const auto native = qApp->nativeInterface<QWlApp>();
if (!native) return nullptr;
static std::optional<WaylandIntegration> instance;
if (instance && native->display() != instance->_private->display) {
instance.reset();
}
if (!instance) {
instance.emplace();
base::qt_signal_producer(
QGuiApplication::platformNativeInterface(),
&QObject::destroyed
) | rpl::start_with_next([] {
instance = std::nullopt;
}, instance->_private->lifetime());
return true;
}();
if (!instance) return nullptr;
}
return &*instance;
}

Expand Down
2 changes: 1 addition & 1 deletion Telegram/lib_base
2 changes: 1 addition & 1 deletion cmake

0 comments on commit 3e3ab16

Please sign in to comment.