Use new base_linux_wayland_utilities
This commit is contained in:
parent
fc66a0eea8
commit
54841de991
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#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"
|
||||
|
@ -20,62 +21,27 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
using namespace QNativeInterface;
|
||||
using namespace QNativeInterface::Private;
|
||||
using namespace base::Platform::Wayland;
|
||||
|
||||
namespace Platform {
|
||||
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 {
|
||||
org_kde_plasma_surface *plasmaSurface(QWindow *window);
|
||||
std::unique_ptr<wl_registry, WlRegistryDeleter> registry;
|
||||
QtWaylandAutoDestroyer<QtWayland::org_kde_plasma_shell> plasmaShell;
|
||||
QtWayland::org_kde_plasma_surface plasmaSurface(QWindow *window);
|
||||
|
||||
std::unique_ptr<wl_registry, RegistryDeleter> registry;
|
||||
AutoDestroyer<QtWayland::org_kde_plasma_shell> plasmaShell;
|
||||
uint32_t plasmaShellName = 0;
|
||||
base::flat_map<wl_surface*, std::unique_ptr<
|
||||
org_kde_plasma_surface,
|
||||
PlasmaSurfaceDeleter>> plasmaSurfaces;
|
||||
base::flat_map<
|
||||
wl_surface*,
|
||||
AutoDestroyer<QtWayland::org_kde_plasma_surface>
|
||||
> plasmaSurfaces;
|
||||
rpl::lifetime lifetime;
|
||||
|
||||
static const struct wl_registry_listener RegistryListener;
|
||||
static const wl_registry_listener RegistryListener;
|
||||
};
|
||||
|
||||
const struct wl_registry_listener WaylandIntegration::Private::RegistryListener = {
|
||||
const wl_registry_listener WaylandIntegration::Private::RegistryListener = {
|
||||
decltype(wl_registry_listener::global)(+[](
|
||||
Private *data,
|
||||
wl_registry *registry,
|
||||
|
@ -92,40 +58,39 @@ const struct wl_registry_listener WaylandIntegration::Private::RegistryListener
|
|||
wl_registry *registry,
|
||||
uint32_t name) {
|
||||
if (name == data->plasmaShellName) {
|
||||
free(data->plasmaShell.object());
|
||||
data->plasmaShell.init(nullptr);
|
||||
data->plasmaShell = {};
|
||||
data->plasmaShellName = 0;
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
org_kde_plasma_surface *WaylandIntegration::Private::plasmaSurface(
|
||||
QtWayland::org_kde_plasma_surface WaylandIntegration::Private::plasmaSurface(
|
||||
QWindow *window) {
|
||||
if (!plasmaShell.isInitialized()) {
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto native = window->nativeInterface<QWaylandWindow>();
|
||||
if (!native) {
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto surface = native->surface();
|
||||
if (!surface) {
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto it = plasmaSurfaces.find(surface);
|
||||
if (it != plasmaSurfaces.cend()) {
|
||||
return it->second.get();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
const auto result = plasmaShell.get_surface(surface);
|
||||
if (!result) {
|
||||
return nullptr;
|
||||
const auto plasmaSurface = plasmaShell.get_surface(surface);
|
||||
if (!plasmaSurface) {
|
||||
return {};
|
||||
}
|
||||
|
||||
plasmaSurfaces.emplace(surface, result);
|
||||
const auto result = plasmaSurfaces.emplace(surface, plasmaSurface);
|
||||
|
||||
base::qt_signal_producer(
|
||||
native,
|
||||
|
@ -137,7 +102,7 @@ org_kde_plasma_surface *WaylandIntegration::Private::plasmaSurface(
|
|||
}
|
||||
}, lifetime);
|
||||
|
||||
return result;
|
||||
return result.first->second;
|
||||
}
|
||||
|
||||
WaylandIntegration::WaylandIntegration()
|
||||
|
@ -182,11 +147,11 @@ bool WaylandIntegration::skipTaskbarSupported() {
|
|||
|
||||
void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) {
|
||||
auto plasmaSurface = _private->plasmaSurface(window);
|
||||
if (!plasmaSurface) {
|
||||
if (!plasmaSurface.isInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
org_kde_plasma_surface_set_skip_taskbar(plasmaSurface, skip);
|
||||
plasmaSurface.set_skip_taskbar(skip);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8402502615af3d58da6785f00681fc5fb43b907f
|
||||
Subproject commit 26894d78fa7b49fd218e54d1f118842a3ab4288b
|
|
@ -1 +1 @@
|
|||
Subproject commit a7d503188918904d12a069bca7d3f6c92b9fb553
|
||||
Subproject commit bf4cb33faba84b855eff583bb1b20004434b5424
|
Loading…
Reference in New Issue