tdesktop/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp

129 lines
3.0 KiB
C++
Raw Normal View History

2020-11-11 23:18:18 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "platform/linux/linux_wayland_integration.h"
#include "base/platform/base_platform_info.h"
#include <connection_thread.h>
#include <registry.h>
#include <surface.h>
#include <xdgforeign.h>
#include <plasmashell.h>
using namespace KWayland::Client;
2020-11-11 23:18:18 +00:00
namespace Platform {
namespace internal {
2021-07-25 21:30:56 +00:00
struct WaylandIntegration::Private {
std::unique_ptr<ConnectionThread> connection;
Registry registry;
std::unique_ptr<XdgExporter> xdgExporter;
std::unique_ptr<PlasmaShell> plasmaShell;
};
2021-07-25 21:30:56 +00:00
WaylandIntegration::WaylandIntegration()
: _private(std::make_unique<Private>()) {
_private->connection = std::unique_ptr<ConnectionThread>{
ConnectionThread::fromApplication(),
};
2021-07-25 21:30:56 +00:00
_private->registry.create(_private->connection.get());
_private->registry.setup();
2021-07-25 21:30:56 +00:00
QObject::connect(
_private->connection.get(),
&ConnectionThread::connectionDied,
2021-07-25 21:30:56 +00:00
&_private->registry,
&Registry::destroy);
2021-07-25 21:30:56 +00:00
QObject::connect(
&_private->registry,
&Registry::exporterUnstableV2Announced,
[=](uint name, uint version) {
2021-07-25 21:30:56 +00:00
_private->xdgExporter = std::unique_ptr<XdgExporter>{
_private->registry.createXdgExporter(name, version),
};
2021-07-25 21:30:56 +00:00
QObject::connect(
_private->connection.get(),
2021-05-13 04:39:16 +00:00
&ConnectionThread::connectionDied,
2021-07-25 21:30:56 +00:00
_private->xdgExporter.get(),
2021-05-13 04:39:16 +00:00
&XdgExporter::destroy);
});
2021-07-25 21:30:56 +00:00
QObject::connect(
&_private->registry,
&Registry::plasmaShellAnnounced,
[=](uint name, uint version) {
2021-07-25 21:30:56 +00:00
_private->plasmaShell = std::unique_ptr<PlasmaShell>{
_private->registry.createPlasmaShell(name, version),
};
2021-07-25 21:30:56 +00:00
QObject::connect(
_private->connection.get(),
&ConnectionThread::connectionDied,
2021-07-25 21:30:56 +00:00
_private->plasmaShell.get(),
&PlasmaShell::destroy);
});
}
WaylandIntegration::~WaylandIntegration() = default;
2020-11-11 23:18:18 +00:00
WaylandIntegration *WaylandIntegration::Instance() {
if (!IsWayland()) return nullptr;
2020-11-11 23:18:18 +00:00
static WaylandIntegration instance;
return &instance;
}
QString WaylandIntegration::nativeHandle(QWindow *window) {
2021-07-25 21:30:56 +00:00
if (const auto exporter = _private->xdgExporter.get()) {
if (const auto surface = Surface::fromWindow(window)) {
if (const auto exported = exporter->exportTopLevel(
surface,
2021-05-13 04:39:16 +00:00
surface)) {
QEventLoop loop;
QObject::connect(
exported,
&XdgExported::done,
&loop,
&QEventLoop::quit);
loop.exec();
return exported->handle();
}
}
}
return {};
}
bool WaylandIntegration::skipTaskbarSupported() {
2021-07-25 21:30:56 +00:00
return _private->plasmaShell != nullptr;
}
void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) {
2021-07-25 21:30:56 +00:00
const auto shell = _private->plasmaShell.get();
if (!shell) {
return;
}
const auto surface = Surface::fromWindow(window);
if (!surface) {
return;
}
const auto plasmaSurface = shell->createSurface(surface, surface);
if (!plasmaSurface) {
return;
}
plasmaSurface->setSkipTaskbar(skip);
}
2020-11-11 23:18:18 +00:00
} // namespace internal
} // namespace Platform