Migrate from kwayland to QtWaylandScanner
This commit is contained in:
parent
0a876226fe
commit
6ee08faa24
|
@ -85,15 +85,9 @@
|
||||||
[submodule "Telegram/ThirdParty/jemalloc"]
|
[submodule "Telegram/ThirdParty/jemalloc"]
|
||||||
path = Telegram/ThirdParty/jemalloc
|
path = Telegram/ThirdParty/jemalloc
|
||||||
url = https://github.com/jemalloc/jemalloc
|
url = https://github.com/jemalloc/jemalloc
|
||||||
[submodule "Telegram/ThirdParty/kwayland"]
|
|
||||||
path = Telegram/ThirdParty/kwayland
|
|
||||||
url = https://github.com/KDE/kwayland.git
|
|
||||||
[submodule "Telegram/ThirdParty/dispatch"]
|
[submodule "Telegram/ThirdParty/dispatch"]
|
||||||
path = Telegram/ThirdParty/dispatch
|
path = Telegram/ThirdParty/dispatch
|
||||||
url = https://github.com/apple/swift-corelibs-libdispatch
|
url = https://github.com/apple/swift-corelibs-libdispatch
|
||||||
[submodule "Telegram/ThirdParty/extra-cmake-modules"]
|
|
||||||
path = Telegram/ThirdParty/extra-cmake-modules
|
|
||||||
url = https://github.com/KDE/extra-cmake-modules.git
|
|
||||||
[submodule "Telegram/ThirdParty/plasma-wayland-protocols"]
|
[submodule "Telegram/ThirdParty/plasma-wayland-protocols"]
|
||||||
path = Telegram/ThirdParty/plasma-wayland-protocols
|
path = Telegram/ThirdParty/plasma-wayland-protocols
|
||||||
url = https://github.com/KDE/plasma-wayland-protocols.git
|
url = https://github.com/KDE/plasma-wayland-protocols.git
|
||||||
|
|
|
@ -95,7 +95,7 @@ PRIVATE
|
||||||
desktop-app::external_xxhash
|
desktop-app::external_xxhash
|
||||||
)
|
)
|
||||||
|
|
||||||
target_precompile_headers(Telegram PRIVATE ${src_loc}/stdafx.h)
|
target_precompile_headers(Telegram PRIVATE $<$<COMPILE_LANGUAGE:CXX,OBJCXX>:${src_loc}/stdafx.h>)
|
||||||
nice_target_sources(Telegram ${src_loc}
|
nice_target_sources(Telegram ${src_loc}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${style_files}
|
${style_files}
|
||||||
|
@ -1436,10 +1436,19 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION)
|
if (NOT DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION)
|
||||||
|
if (DESKTOP_APP_QT6)
|
||||||
|
qt6_generate_wayland_protocol_client_sources(Telegram
|
||||||
|
FILES
|
||||||
|
${third_party_loc}/plasma-wayland-protocols/src/protocols/plasma-shell.xml
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "This piece of cmake code is not ported to Qt 5")
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(Telegram
|
target_link_libraries(Telegram
|
||||||
PRIVATE
|
PRIVATE
|
||||||
desktop-app::lib_waylandshells
|
desktop-app::lib_waylandshells
|
||||||
desktop-app::external_kwayland
|
desktop-app::external_wayland_client
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -8,52 +8,171 @@ 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/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
|
#include "base/qt_signal_producer.h"
|
||||||
|
#include "base/flat_map.h"
|
||||||
|
#include "qwayland-plasma-shell.h"
|
||||||
|
|
||||||
#include <connection_thread.h>
|
#include <QtGui/QGuiApplication>
|
||||||
#include <registry.h>
|
#include <QtGui/QWindow>
|
||||||
#include <surface.h>
|
#include <qpa/qplatformnativeinterface.h>
|
||||||
#include <plasmashell.h>
|
#include <wayland-client.h>
|
||||||
|
|
||||||
using namespace KWayland::Client;
|
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct WlRegistryDeleter {
|
||||||
|
void operator()(wl_registry *value) {
|
||||||
|
wl_registry_destroy(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PlasmaSurfaceDeleter {
|
||||||
|
void operator()(org_kde_plasma_surface *value) {
|
||||||
|
org_kde_plasma_surface_destroy(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class QtWaylandAutoDestroyer : public T {
|
||||||
|
public:
|
||||||
|
QtWaylandAutoDestroyer() = default;
|
||||||
|
|
||||||
|
~QtWaylandAutoDestroyer() {
|
||||||
|
if (!this->isInitialized()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr auto HasDestroy = requires(const T &t) {
|
||||||
|
t.destroy();
|
||||||
|
};
|
||||||
|
|
||||||
|
if constexpr (HasDestroy) {
|
||||||
|
this->destroy();
|
||||||
|
} else {
|
||||||
|
free(this->object());
|
||||||
|
this->init(nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
struct WaylandIntegration::Private {
|
struct WaylandIntegration::Private {
|
||||||
std::unique_ptr<ConnectionThread> connection;
|
org_kde_plasma_surface *plasmaSurface(QWindow *window);
|
||||||
Registry registry;
|
std::unique_ptr<wl_registry, WlRegistryDeleter> registry;
|
||||||
std::unique_ptr<PlasmaShell> plasmaShell;
|
QtWaylandAutoDestroyer<QtWayland::org_kde_plasma_shell> plasmaShell;
|
||||||
|
uint32_t plasmaShellName = 0;
|
||||||
|
base::flat_map<wl_surface*, std::unique_ptr<
|
||||||
|
org_kde_plasma_surface,
|
||||||
|
PlasmaSurfaceDeleter>> plasmaSurfaces;
|
||||||
|
rpl::lifetime lifetime;
|
||||||
|
|
||||||
|
static const struct wl_registry_listener RegistryListener;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const struct wl_registry_listener WaylandIntegration::Private::RegistryListener = {
|
||||||
|
decltype(wl_registry_listener::global)(+[](
|
||||||
|
Private *data,
|
||||||
|
wl_registry *registry,
|
||||||
|
uint32_t name,
|
||||||
|
const char *interface,
|
||||||
|
uint32_t version) {
|
||||||
|
if (interface == qstr("org_kde_plasma_shell")) {
|
||||||
|
data->plasmaShell.init(registry, name, version);
|
||||||
|
data->plasmaShellName = name;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
decltype(wl_registry_listener::global_remove)(+[](
|
||||||
|
Private *data,
|
||||||
|
wl_registry *registry,
|
||||||
|
uint32_t name) {
|
||||||
|
if (name == data->plasmaShellName) {
|
||||||
|
free(data->plasmaShell.object());
|
||||||
|
data->plasmaShell.init(nullptr);
|
||||||
|
data->plasmaShellName = 0;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
org_kde_plasma_surface *WaylandIntegration::Private::plasmaSurface(
|
||||||
|
QWindow *window) {
|
||||||
|
if (!plasmaShell.isInitialized()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto native = QGuiApplication::platformNativeInterface();
|
||||||
|
if (!native) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto surface = reinterpret_cast<wl_surface*>(
|
||||||
|
native->nativeResourceForWindow(QByteArray("surface"), window));
|
||||||
|
|
||||||
|
if (!surface) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto it = plasmaSurfaces.find(surface);
|
||||||
|
if (it != plasmaSurfaces.cend()) {
|
||||||
|
return it->second.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto result = plasmaShell.get_surface(surface);
|
||||||
|
if (!result) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
plasmaSurfaces.emplace(surface, result);
|
||||||
|
|
||||||
|
base::qt_signal_producer(
|
||||||
|
window,
|
||||||
|
&QObject::destroyed
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
auto it = plasmaSurfaces.find(surface);
|
||||||
|
if (it != plasmaSurfaces.cend()) {
|
||||||
|
plasmaSurfaces.erase(it);
|
||||||
|
}
|
||||||
|
}, lifetime);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
WaylandIntegration::WaylandIntegration()
|
WaylandIntegration::WaylandIntegration()
|
||||||
: _private(std::make_unique<Private>()) {
|
: _private(std::make_unique<Private>()) {
|
||||||
_private->connection = std::unique_ptr<ConnectionThread>{
|
const auto native = QGuiApplication::platformNativeInterface();
|
||||||
ConnectionThread::fromApplication(),
|
if (!native) {
|
||||||
};
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_private->registry.create(_private->connection.get());
|
const auto display = reinterpret_cast<wl_display*>(
|
||||||
_private->registry.setup();
|
native->nativeResourceForIntegration(QByteArray("wl_display")));
|
||||||
|
|
||||||
QObject::connect(
|
if (!display) {
|
||||||
_private->connection.get(),
|
return;
|
||||||
&ConnectionThread::connectionDied,
|
}
|
||||||
&_private->registry,
|
|
||||||
&Registry::destroy);
|
|
||||||
|
|
||||||
QObject::connect(
|
_private->registry.reset(wl_display_get_registry(display));
|
||||||
&_private->registry,
|
wl_registry_add_listener(
|
||||||
&Registry::plasmaShellAnnounced,
|
_private->registry.get(),
|
||||||
[=](uint name, uint version) {
|
&Private::RegistryListener,
|
||||||
_private->plasmaShell = std::unique_ptr<PlasmaShell>{
|
_private.get());
|
||||||
_private->registry.createPlasmaShell(name, version),
|
|
||||||
};
|
|
||||||
|
|
||||||
QObject::connect(
|
base::qt_signal_producer(
|
||||||
_private->connection.get(),
|
native,
|
||||||
&ConnectionThread::connectionDied,
|
&QObject::destroyed
|
||||||
_private->plasmaShell.get(),
|
) | rpl::start_with_next([=] {
|
||||||
&PlasmaShell::destroy);
|
// too late for standard destructors, just free
|
||||||
});
|
for (auto it = _private->plasmaSurfaces.begin()
|
||||||
|
; it != _private->plasmaSurfaces.cend()
|
||||||
|
; ++it) {
|
||||||
|
free(it->second.release());
|
||||||
|
_private->plasmaSurfaces.erase(it);
|
||||||
|
}
|
||||||
|
free(_private->plasmaShell.object());
|
||||||
|
_private->plasmaShell.init(nullptr);
|
||||||
|
free(_private->registry.release());
|
||||||
|
}, _private->lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
WaylandIntegration::~WaylandIntegration() = default;
|
WaylandIntegration::~WaylandIntegration() = default;
|
||||||
|
@ -65,26 +184,16 @@ WaylandIntegration *WaylandIntegration::Instance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaylandIntegration::skipTaskbarSupported() {
|
bool WaylandIntegration::skipTaskbarSupported() {
|
||||||
return _private->plasmaShell != nullptr;
|
return _private->plasmaShell.isInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) {
|
void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) {
|
||||||
const auto shell = _private->plasmaShell.get();
|
auto plasmaSurface = _private->plasmaSurface(window);
|
||||||
if (!shell) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto surface = Surface::fromWindow(window);
|
|
||||||
if (!surface) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto plasmaSurface = shell->createSurface(surface, surface);
|
|
||||||
if (!plasmaSurface) {
|
if (!plasmaSurface) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plasmaSurface->setSkipTaskbar(skip);
|
org_kde_plasma_surface_set_skip_taskbar(plasmaSurface, skip);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit eccf695824fa931bca471bad3f1aa3a1f244fdd6
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 15af039af2044c7a2d7cfea0d2c1a99bf6c151ac
|
|
Loading…
Reference in New Issue