2024-06-08 10:07:59 +02:00
|
|
|
#include "Output.hpp"
|
2024-10-16 21:59:29 +01:00
|
|
|
#include "Compositor.hpp"
|
|
|
|
|
#include "../../Compositor.hpp"
|
2024-06-08 10:07:59 +02:00
|
|
|
#include "../../helpers/Monitor.hpp"
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
CWLOutputResource::CWLOutputResource(SP<CWlOutput> resource_, PHLMONITOR pMonitor) : m_monitor(pMonitor), m_resource(resource_) {
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!good())
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
m_resource->setData(this);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
m_client = m_resource->client();
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
if (!m_monitor)
|
2024-06-15 17:56:44 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
m_resource->setOnDestroy([this](CWlOutput* r) {
|
|
|
|
|
if (m_monitor && PROTO::outputs.contains(m_monitor->m_name))
|
|
|
|
|
PROTO::outputs.at(m_monitor->m_name)->destroyResource(this);
|
2024-06-08 10:07:59 +02:00
|
|
|
});
|
2025-05-03 16:02:49 +02:00
|
|
|
m_resource->setRelease([this](CWlOutput* r) {
|
|
|
|
|
if (m_monitor && PROTO::outputs.contains(m_monitor->m_name))
|
|
|
|
|
PROTO::outputs.at(m_monitor->m_name)->destroyResource(this);
|
2024-06-08 10:07:59 +02:00
|
|
|
});
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
if (m_resource->version() >= 4) {
|
|
|
|
|
m_resource->sendName(m_monitor->m_name.c_str());
|
|
|
|
|
m_resource->sendDescription(m_monitor->m_description.c_str());
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateState();
|
2024-10-16 21:59:29 +01:00
|
|
|
|
|
|
|
|
PROTO::compositor->forEachSurface([](SP<CWLSurfaceResource> surf) {
|
|
|
|
|
auto HLSurf = CWLSurface::fromResource(surf);
|
|
|
|
|
|
|
|
|
|
if (!HLSurf)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const auto GEOMETRY = HLSurf->getSurfaceBoxGlobal();
|
|
|
|
|
|
|
|
|
|
if (!GEOMETRY.has_value())
|
|
|
|
|
return;
|
|
|
|
|
|
2025-04-22 15:23:29 +02:00
|
|
|
for (auto& m : g_pCompositor->m_monitors) {
|
2024-12-10 01:40:31 +00:00
|
|
|
if (!m->logicalBox().expand(-4).overlaps(*GEOMETRY))
|
2024-10-16 21:59:29 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
surf->enter(m);
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SP<CWLOutputResource> CWLOutputResource::fromResource(wl_resource* res) {
|
2025-08-14 19:44:56 +05:00
|
|
|
auto data = sc<CWLOutputResource*>(sc<CWlOutput*>(wl_resource_get_user_data(res))->data());
|
2025-05-03 16:02:49 +02:00
|
|
|
return data ? data->m_self.lock() : nullptr;
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CWLOutputResource::good() {
|
2025-05-03 16:02:49 +02:00
|
|
|
return m_resource->resource();
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_client* CWLOutputResource::client() {
|
2025-05-03 16:02:49 +02:00
|
|
|
return m_client;
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SP<CWlOutput> CWLOutputResource::getResource() {
|
2025-05-03 16:02:49 +02:00
|
|
|
return m_resource;
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWLOutputResource::updateState() {
|
2025-05-03 16:02:49 +02:00
|
|
|
if (!m_monitor || (m_owner && m_owner->m_defunct))
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
if (m_resource->version() >= 2)
|
|
|
|
|
m_resource->sendScale(std::ceil(m_monitor->m_scale));
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-08-14 19:44:56 +05:00
|
|
|
m_resource->sendMode(WL_OUTPUT_MODE_CURRENT, m_monitor->m_pixelSize.x, m_monitor->m_pixelSize.y, m_monitor->m_refreshRate * 1000.0);
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-08-14 19:44:56 +05:00
|
|
|
m_resource->sendGeometry(0, 0, m_monitor->m_output->physicalSize.x, m_monitor->m_output->physicalSize.y, m_monitor->m_output->subpixel, m_monitor->m_output->make.c_str(),
|
|
|
|
|
m_monitor->m_output->model.c_str(), m_monitor->m_transform);
|
2024-09-30 17:42:36 +01:00
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
if (m_resource->version() >= 2)
|
|
|
|
|
m_resource->sendDone();
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-26 02:06:13 +01:00
|
|
|
CWLOutputProtocol::CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, PHLMONITOR pMonitor) :
|
2025-05-03 16:02:49 +02:00
|
|
|
IWaylandProtocol(iface, ver, name), m_monitor(pMonitor), m_name(pMonitor->m_name) {
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.modeChanged = m_monitor->m_events.modeChanged.listen([this] {
|
2025-05-03 16:02:49 +02:00
|
|
|
for (auto const& o : m_outputs) {
|
2024-06-08 10:07:59 +02:00
|
|
|
o->updateState();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWLOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
2025-05-03 16:02:49 +02:00
|
|
|
if UNLIKELY (m_defunct)
|
2024-06-15 17:56:44 +02:00
|
|
|
Debug::log(WARN, "[wl_output] Binding a wl_output that's inert?? Possible client bug.");
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
const auto RESOURCE = m_outputs.emplace_back(makeShared<CWLOutputResource>(makeShared<CWlOutput>(client, ver, id), m_monitor.lock()));
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-01-17 18:21:34 +01:00
|
|
|
if UNLIKELY (!RESOURCE->good()) {
|
2024-06-08 10:07:59 +02:00
|
|
|
wl_client_post_no_memory(client);
|
2025-05-03 16:02:49 +02:00
|
|
|
m_outputs.pop_back();
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
RESOURCE->m_self = RESOURCE;
|
|
|
|
|
RESOURCE->m_owner = m_self;
|
2025-06-26 09:32:44 -07:00
|
|
|
m_events.outputBound.emit(RESOURCE);
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWLOutputProtocol::destroyResource(CWLOutputResource* resource) {
|
2025-05-03 16:02:49 +02:00
|
|
|
std::erase_if(m_outputs, [&](const auto& other) { return other.get() == resource; });
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
if (m_outputs.empty() && m_defunct)
|
|
|
|
|
PROTO::outputs.erase(m_name);
|
2024-06-08 10:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SP<CWLOutputResource> CWLOutputProtocol::outputResourceFrom(wl_client* client) {
|
2025-05-03 16:02:49 +02:00
|
|
|
for (auto const& r : m_outputs) {
|
2024-06-08 10:07:59 +02:00
|
|
|
if (r->client() != client)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CWLOutputProtocol::remove() {
|
2025-05-03 16:02:49 +02:00
|
|
|
if UNLIKELY (m_defunct)
|
2024-06-08 10:07:59 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
m_defunct = true;
|
2024-06-08 10:07:59 +02:00
|
|
|
removeGlobal();
|
|
|
|
|
}
|
2024-06-09 22:28:51 +02:00
|
|
|
|
|
|
|
|
bool CWLOutputProtocol::isDefunct() {
|
2025-05-03 16:02:49 +02:00
|
|
|
return m_defunct;
|
2024-06-09 22:28:51 +02:00
|
|
|
}
|
2024-07-21 13:09:54 +02:00
|
|
|
|
|
|
|
|
void CWLOutputProtocol::sendDone() {
|
2025-05-03 16:02:49 +02:00
|
|
|
if UNLIKELY (m_defunct)
|
2024-10-09 00:26:40 +01:00
|
|
|
return;
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
for (auto const& r : m_outputs) {
|
|
|
|
|
r->m_resource->sendDone();
|
2024-07-21 13:09:54 +02:00
|
|
|
}
|
|
|
|
|
}
|