2023-07-18 15:30:28 +02:00
|
|
|
#include "XDGOutput.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
|
|
|
|
|
|
|
#include "xdg-output-unstable-v1-protocol.h"
|
|
|
|
|
|
|
|
#define OUTPUT_MANAGER_VERSION 3
|
|
|
|
#define OUTPUT_DONE_DEPRECATED_SINCE_VERSION 3
|
|
|
|
#define OUTPUT_DESCRIPTION_MUTABLE_SINCE_VERSION 3
|
|
|
|
|
|
|
|
static void destroyManagerResource(wl_client* client, wl_resource* resource) {
|
2023-08-21 19:36:09 +02:00
|
|
|
RESOURCE_OR_BAIL(PRESOURCE);
|
|
|
|
reinterpret_cast<CXDGOutputProtocol*>(PRESOURCE->data())->onManagerResourceDestroy(resource);
|
2023-07-18 15:30:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void destroyOutputResource(wl_client* client, wl_resource* resource) {
|
2023-08-21 19:36:09 +02:00
|
|
|
RESOURCE_OR_BAIL(PRESOURCE);
|
|
|
|
reinterpret_cast<CXDGOutputProtocol*>(PRESOURCE->data())->onOutputResourceDestroy(resource);
|
2023-07-18 15:30:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void getXDGOutput(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* outputResource) {
|
2023-08-21 19:36:09 +02:00
|
|
|
RESOURCE_OR_BAIL(PRESOURCE);
|
|
|
|
reinterpret_cast<CXDGOutputProtocol*>(PRESOURCE->data())->onManagerGetXDGOutput(client, resource, id, outputResource);
|
2023-07-18 15:30:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
static const struct zxdg_output_manager_v1_interface MANAGER_IMPL = {
|
|
|
|
.destroy = destroyManagerResource,
|
|
|
|
.get_xdg_output = getXDGOutput,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct zxdg_output_v1_interface OUTPUT_IMPL = {
|
|
|
|
.destroy = destroyOutputResource,
|
|
|
|
};
|
|
|
|
|
|
|
|
void CXDGOutputProtocol::onManagerResourceDestroy(wl_resource* res) {
|
|
|
|
std::erase_if(m_vManagerResources, [&](const auto& other) { return other->resource() == res; });
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXDGOutputProtocol::onOutputResourceDestroy(wl_resource* res) {
|
2023-08-21 19:36:09 +02:00
|
|
|
std::erase_if(m_vXDGOutputs, [&](const auto& other) {
|
|
|
|
if (!other->resource)
|
|
|
|
return false; // ???
|
|
|
|
return other->resource->resource() == res;
|
|
|
|
});
|
2023-07-18 15:30:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CXDGOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
2023-08-21 19:36:09 +02:00
|
|
|
const auto RESOURCE = m_vManagerResources.emplace_back(std::make_unique<CWaylandResource>(client, &zxdg_output_manager_v1_interface, ver, id)).get();
|
2023-07-18 15:30:28 +02:00
|
|
|
|
|
|
|
if (!RESOURCE->good()) {
|
|
|
|
Debug::log(LOG, "Couldn't bind XDGOutputMgr");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-21 19:36:09 +02:00
|
|
|
RESOURCE->setImplementation(&MANAGER_IMPL, nullptr);
|
|
|
|
RESOURCE->setData(this);
|
2023-07-18 15:30:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CXDGOutputProtocol::CXDGOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
|
2023-10-21 15:52:43 +02:00
|
|
|
g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); });
|
|
|
|
g_pHookSystem->hookDynamic("configReloaded", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); });
|
|
|
|
g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
|
2023-07-18 15:30:28 +02:00
|
|
|
const auto PMONITOR = std::any_cast<CMonitor*>(param);
|
2023-09-05 13:33:04 +02:00
|
|
|
std::erase_if(m_vXDGOutputs, [&](const auto& other) {
|
|
|
|
const auto REMOVE = other->monitor == PMONITOR;
|
|
|
|
if (REMOVE)
|
|
|
|
other->resource->markDefunct(); // so that wl_resource_destroy is not sent
|
|
|
|
return REMOVE;
|
|
|
|
});
|
2023-07-18 15:30:28 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXDGOutputProtocol::onManagerGetXDGOutput(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* outputResource) {
|
2023-11-01 19:53:36 +01:00
|
|
|
const auto OUTPUT = wlr_output_from_resource(outputResource);
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2023-11-01 19:53:36 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromOutput(OUTPUT);
|
2023-07-18 15:30:28 +02:00
|
|
|
|
|
|
|
SXDGOutput* pXDGOutput = m_vXDGOutputs.emplace_back(std::make_unique<SXDGOutput>(PMONITOR)).get();
|
|
|
|
#ifndef NO_XWAYLAND
|
2023-07-28 17:12:24 +02:00
|
|
|
if (g_pXWaylandManager->m_sWLRXWayland && g_pXWaylandManager->m_sWLRXWayland->server && g_pXWaylandManager->m_sWLRXWayland->server->client == client)
|
2023-07-18 15:30:28 +02:00
|
|
|
pXDGOutput->isXWayland = true;
|
|
|
|
#endif
|
|
|
|
pXDGOutput->client = client;
|
|
|
|
|
|
|
|
pXDGOutput->resource = std::make_unique<CWaylandResource>(client, &zxdg_output_v1_interface, wl_resource_get_version(resource), id);
|
|
|
|
|
|
|
|
if (!pXDGOutput->resource->good()) {
|
|
|
|
pXDGOutput->resource.release();
|
2023-08-21 19:36:09 +02:00
|
|
|
m_vXDGOutputs.pop_back();
|
2023-07-18 15:30:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-21 19:36:09 +02:00
|
|
|
pXDGOutput->resource->setImplementation(&OUTPUT_IMPL, nullptr);
|
|
|
|
pXDGOutput->resource->setData(this);
|
2023-11-01 19:53:36 +01:00
|
|
|
|
|
|
|
if (!PMONITOR)
|
|
|
|
return;
|
|
|
|
|
2023-07-18 15:30:28 +02:00
|
|
|
const auto XDGVER = pXDGOutput->resource->version();
|
|
|
|
|
|
|
|
if (XDGVER >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION)
|
|
|
|
zxdg_output_v1_send_name(pXDGOutput->resource->resource(), PMONITOR->szName.c_str());
|
|
|
|
if (XDGVER >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION && PMONITOR->output->description)
|
|
|
|
zxdg_output_v1_send_description(pXDGOutput->resource->resource(), PMONITOR->output->description);
|
|
|
|
|
2023-08-19 21:14:12 +02:00
|
|
|
updateOutputDetails(pXDGOutput);
|
2023-07-18 15:30:28 +02:00
|
|
|
|
|
|
|
const auto OUTPUTVER = wl_resource_get_version(outputResource);
|
|
|
|
if (OUTPUTVER >= WL_OUTPUT_DONE_SINCE_VERSION && XDGVER >= OUTPUT_DONE_DEPRECATED_SINCE_VERSION)
|
|
|
|
wl_output_send_done(outputResource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXDGOutputProtocol::updateOutputDetails(SXDGOutput* pOutput) {
|
2024-02-18 16:00:34 +01:00
|
|
|
static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling");
|
2023-08-25 18:22:25 +02:00
|
|
|
|
2023-11-01 19:53:36 +01:00
|
|
|
if (!pOutput->resource->good() || !pOutput->monitor)
|
2023-08-21 19:36:09 +02:00
|
|
|
return;
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2023-08-25 18:22:25 +02:00
|
|
|
const auto POS = pOutput->isXWayland ? pOutput->monitor->vecXWaylandPosition : pOutput->monitor->vecPosition;
|
2023-08-15 17:55:29 +02:00
|
|
|
zxdg_output_v1_send_logical_position(pOutput->resource->resource(), POS.x, POS.y);
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2024-02-18 16:00:34 +01:00
|
|
|
if (**PXWLFORCESCALEZERO && pOutput->isXWayland)
|
2023-08-15 17:55:29 +02:00
|
|
|
zxdg_output_v1_send_logical_size(pOutput->resource->resource(), pOutput->monitor->vecTransformedSize.x, pOutput->monitor->vecTransformedSize.y);
|
2023-07-18 15:30:28 +02:00
|
|
|
else
|
|
|
|
zxdg_output_v1_send_logical_size(pOutput->resource->resource(), pOutput->monitor->vecSize.x, pOutput->monitor->vecSize.y);
|
|
|
|
|
|
|
|
if (wl_resource_get_version(pOutput->resource->resource()) < OUTPUT_DONE_DEPRECATED_SINCE_VERSION)
|
|
|
|
zxdg_output_v1_send_done(pOutput->resource->resource());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXDGOutputProtocol::updateAllOutputs() {
|
|
|
|
for (auto& o : m_vXDGOutputs) {
|
2023-11-01 19:53:36 +01:00
|
|
|
|
|
|
|
if (!o->monitor)
|
|
|
|
continue;
|
|
|
|
|
2023-07-18 15:30:28 +02:00
|
|
|
updateOutputDetails(o.get());
|
|
|
|
|
|
|
|
wlr_output_schedule_done(o->monitor->output);
|
|
|
|
}
|
2023-07-28 17:12:24 +02:00
|
|
|
}
|