2023-07-18 15:30:28 +02:00
|
|
|
#include "XDGOutput.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
2024-03-03 19:39:20 +01:00
|
|
|
#include "../config/ConfigValue.hpp"
|
2024-05-25 22:43:51 +02:00
|
|
|
#include "../xwayland/XWayland.hpp"
|
2024-06-08 10:07:59 +02:00
|
|
|
#include "core/Output.hpp"
|
2023-07-18 15:30:28 +02:00
|
|
|
|
|
|
|
#define OUTPUT_MANAGER_VERSION 3
|
|
|
|
#define OUTPUT_DONE_DEPRECATED_SINCE_VERSION 3
|
|
|
|
#define OUTPUT_DESCRIPTION_MUTABLE_SINCE_VERSION 3
|
2024-04-20 20:34:18 +02:00
|
|
|
#define OUTPUT_NAME_SINCE_VERSION 2
|
|
|
|
#define OUTPUT_DESCRIPTION_SINCE_VERSION 2
|
2023-07-18 15:30:28 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
void CXDGOutputProtocol::onManagerResourceDestroy(wl_resource* res) {
|
|
|
|
std::erase_if(m_vManagerResources, [&](const auto& other) { return other->resource() == res; });
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXDGOutputProtocol::onOutputResourceDestroy(wl_resource* res) {
|
2024-04-20 20:34:18 +02:00
|
|
|
std::erase_if(m_vXDGOutputs, [&](const auto& other) { 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) {
|
2024-04-20 20:34:18 +02:00
|
|
|
const auto RESOURCE = m_vManagerResources.emplace_back(std::make_unique<CZxdgOutputManagerV1>(client, ver, id)).get();
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2024-04-20 20:34:18 +02:00
|
|
|
if (!RESOURCE->resource()) {
|
2024-04-22 19:44:25 +02:00
|
|
|
LOGM(LOG, "Couldn't bind XDGOutputMgr");
|
2024-04-20 20:34:18 +02:00
|
|
|
wl_client_post_no_memory(client);
|
2023-07-18 15:30:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-20 20:34:18 +02:00
|
|
|
RESOURCE->setDestroy([this](CZxdgOutputManagerV1* res) { this->onManagerResourceDestroy(res->resource()); });
|
|
|
|
RESOURCE->setOnDestroy([this](CZxdgOutputManagerV1* res) { this->onManagerResourceDestroy(res->resource()); });
|
|
|
|
RESOURCE->setGetXdgOutput([this](CZxdgOutputManagerV1* mgr, uint32_t id, wl_resource* output) { this->onManagerGetXDGOutput(mgr, id, output); });
|
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) {
|
2024-04-20 21:16:42 +02:00
|
|
|
static auto P = g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); });
|
|
|
|
static auto P2 = g_pHookSystem->hookDynamic("configReloaded", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); });
|
|
|
|
static auto P3 = 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);
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& o : m_vXDGOutputs) {
|
2024-04-20 20:34:18 +02:00
|
|
|
if (o->monitor == PMONITOR)
|
|
|
|
o->monitor = nullptr;
|
|
|
|
}
|
2023-07-18 15:30:28 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-20 20:34:18 +02:00
|
|
|
void CXDGOutputProtocol::onManagerGetXDGOutput(CZxdgOutputManagerV1* mgr, uint32_t id, wl_resource* outputResource) {
|
2024-06-08 10:07:59 +02:00
|
|
|
const auto OUTPUT = CWLOutputResource::fromResource(outputResource);
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
const auto PMONITOR = OUTPUT->monitor.get();
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2024-05-01 20:40:35 +02:00
|
|
|
const auto CLIENT = mgr->client();
|
2024-04-20 20:34:18 +02:00
|
|
|
|
2024-05-05 18:16:00 +02:00
|
|
|
CXDGOutput* pXDGOutput = m_vXDGOutputs.emplace_back(std::make_unique<CXDGOutput>(makeShared<CZxdgOutputV1>(CLIENT, mgr->version(), id), PMONITOR)).get();
|
2023-07-18 15:30:28 +02:00
|
|
|
#ifndef NO_XWAYLAND
|
2024-05-25 22:43:51 +02:00
|
|
|
if (g_pXWayland && g_pXWayland->pServer && g_pXWayland->pServer->xwaylandClient == CLIENT)
|
2023-07-18 15:30:28 +02:00
|
|
|
pXDGOutput->isXWayland = true;
|
|
|
|
#endif
|
2024-04-20 20:34:18 +02:00
|
|
|
pXDGOutput->client = CLIENT;
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2024-04-20 20:34:18 +02:00
|
|
|
if (!pXDGOutput->resource->resource()) {
|
2023-08-21 19:36:09 +02:00
|
|
|
m_vXDGOutputs.pop_back();
|
2024-05-01 20:40:35 +02:00
|
|
|
mgr->noMemory();
|
2023-07-18 15:30:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-01 19:53:36 +01:00
|
|
|
if (!PMONITOR)
|
|
|
|
return;
|
|
|
|
|
2024-05-01 20:40:35 +02:00
|
|
|
const auto XDGVER = pXDGOutput->resource->version();
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2024-04-20 20:34:18 +02:00
|
|
|
if (XDGVER >= OUTPUT_NAME_SINCE_VERSION)
|
|
|
|
pXDGOutput->resource->sendName(PMONITOR->szName.c_str());
|
2024-07-21 13:09:54 +02:00
|
|
|
if (XDGVER >= OUTPUT_DESCRIPTION_SINCE_VERSION && !PMONITOR->output->description.empty())
|
|
|
|
pXDGOutput->resource->sendDescription(PMONITOR->output->description.c_str());
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2024-04-20 20:34:18 +02:00
|
|
|
pXDGOutput->sendDetails();
|
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::updateAllOutputs() {
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& o : m_vXDGOutputs) {
|
2023-11-01 19:53:36 +01:00
|
|
|
|
|
|
|
if (!o->monitor)
|
|
|
|
continue;
|
|
|
|
|
2024-04-20 20:34:18 +02:00
|
|
|
o->sendDetails();
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
o->monitor->scheduleDone();
|
2023-07-18 15:30:28 +02:00
|
|
|
}
|
2023-07-28 17:12:24 +02:00
|
|
|
}
|
2024-04-20 20:34:18 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
CXDGOutput::CXDGOutput(SP<CZxdgOutputV1> resource_, CMonitor* monitor_) : monitor(monitor_), resource(resource_) {
|
|
|
|
if (!resource->resource())
|
|
|
|
return;
|
|
|
|
|
|
|
|
resource->setDestroy([](CZxdgOutputV1* pMgr) { PROTO::xdgOutput->onOutputResourceDestroy(pMgr->resource()); });
|
|
|
|
resource->setOnDestroy([](CZxdgOutputV1* pMgr) { PROTO::xdgOutput->onOutputResourceDestroy(pMgr->resource()); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXDGOutput::sendDetails() {
|
|
|
|
static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling");
|
|
|
|
|
|
|
|
if (!monitor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto POS = isXWayland ? monitor->vecXWaylandPosition : monitor->vecPosition;
|
|
|
|
resource->sendLogicalPosition(POS.x, POS.y);
|
|
|
|
|
|
|
|
if (*PXWLFORCESCALEZERO && isXWayland)
|
|
|
|
resource->sendLogicalSize(monitor->vecTransformedSize.x, monitor->vecTransformedSize.y);
|
|
|
|
else
|
|
|
|
resource->sendLogicalSize(monitor->vecSize.x, monitor->vecSize.y);
|
|
|
|
|
2024-05-01 20:40:35 +02:00
|
|
|
if (resource->version() < OUTPUT_DONE_DEPRECATED_SINCE_VERSION)
|
2024-04-20 20:34:18 +02:00
|
|
|
resource->sendDone();
|
|
|
|
}
|