wayland/output: return all bound wl_output instances in outputResourceFrom (#13315)

ref https://github.com/hyprwm/Hyprland/discussions/13301
This commit is contained in:
Vaxry 2026-02-20 22:31:59 +00:00 committed by GitHub
parent 8b17a7404b
commit d91952c555
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 46 additions and 24 deletions

View file

@ -27,8 +27,11 @@ CExtWorkspaceGroupResource::CExtWorkspaceGroupResource(WP<CExtWorkspaceManagerRe
const auto& output = PROTO::outputs.at(m_monitor->m_name); const auto& output = PROTO::outputs.at(m_monitor->m_name);
if (auto resource = output->outputResourceFrom(m_resource->client())) if (auto resources = output->outputResourcesFrom(m_resource->client()); !resources.empty()) {
m_resource->sendOutputEnter(resource->getResource()->resource()); for (const auto& r : resources) {
m_resource->sendOutputEnter(r->getResource()->resource());
}
}
m_listeners.outputBound = output->m_events.outputBound.listen([this](const SP<CWLOutputResource>& output) { m_listeners.outputBound = output->m_events.outputBound.listen([this](const SP<CWLOutputResource>& output) {
if (output->client() == m_resource->client()) if (output->client() == m_resource->client())

View file

@ -154,17 +154,23 @@ void CForeignToplevelHandleWlr::sendMonitor(PHLMONITOR pMonitor) {
const auto CLIENT = m_resource->client(); const auto CLIENT = m_resource->client();
if (const auto PLASTMONITOR = g_pCompositor->getMonitorFromID(m_lastMonitorID); PLASTMONITOR && PROTO::outputs.contains(PLASTMONITOR->m_name)) { if (const auto PLASTMONITOR = g_pCompositor->getMonitorFromID(m_lastMonitorID); PLASTMONITOR && PROTO::outputs.contains(PLASTMONITOR->m_name)) {
const auto OLDRESOURCE = PROTO::outputs.at(PLASTMONITOR->m_name)->outputResourceFrom(CLIENT); const auto OLDRESOURCES = PROTO::outputs.at(PLASTMONITOR->m_name)->outputResourcesFrom(CLIENT);
if LIKELY (OLDRESOURCE) if LIKELY (!OLDRESOURCES.empty()) {
m_resource->sendOutputLeave(OLDRESOURCE->getResource()->resource()); for (const auto& r : OLDRESOURCES) {
m_resource->sendOutputLeave(r->getResource()->resource());
}
}
} }
if (PROTO::outputs.contains(pMonitor->m_name)) { if (PROTO::outputs.contains(pMonitor->m_name)) {
const auto NEWRESOURCE = PROTO::outputs.at(pMonitor->m_name)->outputResourceFrom(CLIENT); const auto NEWRESOURCES = PROTO::outputs.at(pMonitor->m_name)->outputResourcesFrom(CLIENT);
if LIKELY (NEWRESOURCE) if LIKELY (!NEWRESOURCES.empty()) {
m_resource->sendOutputEnter(NEWRESOURCE->getResource()->resource()); for (const auto& r : NEWRESOURCES) {
m_resource->sendOutputEnter(r->getResource()->resource());
}
}
} }
m_lastMonitorID = pMonitor->m_id; m_lastMonitorID = pMonitor->m_id;

View file

@ -44,8 +44,11 @@ void CPresentationFeedback::sendQueued(WP<CQueuedPresentationData> data, const t
auto client = m_resource->client(); auto client = m_resource->client();
if LIKELY (PROTO::outputs.contains(data->m_monitor->m_name) && data->m_wasPresented) { if LIKELY (PROTO::outputs.contains(data->m_monitor->m_name) && data->m_wasPresented) {
if LIKELY (auto outputResource = PROTO::outputs.at(data->m_monitor->m_name)->outputResourceFrom(client); outputResource) if LIKELY (auto outputResources = PROTO::outputs.at(data->m_monitor->m_name)->outputResourcesFrom(client); !outputResources.empty()) {
m_resource->sendSyncOutput(outputResource->getResource()->resource()); for (const auto& r : outputResources) {
m_resource->sendSyncOutput(r->getResource()->resource());
}
}
} }
if (data->m_wasPresented) { if (data->m_wasPresented) {

View file

@ -286,16 +286,20 @@ void CWLSurfaceResource::enter(PHLMONITOR monitor) {
return; return;
} }
auto output = PROTO::outputs.at(monitor->m_name)->outputResourceFrom(m_client); auto outputs = PROTO::outputs.at(monitor->m_name)->outputResourcesFrom(m_client);
if UNLIKELY (!output || !output->getResource() || !output->getResource()->resource()) { if UNLIKELY (outputs.empty() || std::ranges::all_of(outputs, [](const auto& o) { return !o->getResource() || !o->getResource()->resource(); })) {
LOGM(Log::ERR, "Cannot enter surface {:x} to {}, client hasn't bound the output", (uintptr_t)this, monitor->m_name); LOGM(Log::ERR, "Cannot enter surface {:x} to {}, client hasn't bound the output", (uintptr_t)this, monitor->m_name);
return; return;
} }
m_enteredOutputs.emplace_back(monitor); m_enteredOutputs.emplace_back(monitor);
m_resource->sendEnter(output->getResource().get()); for (const auto& o : outputs) {
if (!o->getResource() || !o->getResource()->resource())
continue;
m_resource->sendEnter(o->getResource().get());
}
m_events.enter.emit(monitor); m_events.enter.emit(monitor);
} }
@ -303,16 +307,20 @@ void CWLSurfaceResource::leave(PHLMONITOR monitor) {
if UNLIKELY (std::ranges::find(m_enteredOutputs, monitor) == m_enteredOutputs.end()) if UNLIKELY (std::ranges::find(m_enteredOutputs, monitor) == m_enteredOutputs.end())
return; return;
auto output = PROTO::outputs.at(monitor->m_name)->outputResourceFrom(m_client); auto outputs = PROTO::outputs.at(monitor->m_name)->outputResourcesFrom(m_client);
if UNLIKELY (!output) { if UNLIKELY (outputs.empty() || std::ranges::all_of(outputs, [](const auto& o) { return !o->getResource() || !o->getResource()->resource(); })) {
LOGM(Log::ERR, "Cannot leave surface {:x} from {}, client hasn't bound the output", (uintptr_t)this, monitor->m_name); LOGM(Log::ERR, "Cannot leave surface {:x} from {}, client hasn't bound the output", (uintptr_t)this, monitor->m_name);
return; return;
} }
std::erase(m_enteredOutputs, monitor); std::erase(m_enteredOutputs, monitor);
m_resource->sendLeave(output->getResource().get()); for (const auto& o : outputs) {
if (!o->getResource() || !o->getResource()->resource())
continue;
m_resource->sendLeave(o->getResource().get());
}
m_events.leave.emit(monitor); m_events.leave.emit(monitor);
} }

View file

@ -117,15 +117,17 @@ void CWLOutputProtocol::destroyResource(CWLOutputResource* resource) {
PROTO::outputs.erase(m_name); PROTO::outputs.erase(m_name);
} }
SP<CWLOutputResource> CWLOutputProtocol::outputResourceFrom(wl_client* client) { std::vector<SP<CWLOutputResource>> CWLOutputProtocol::outputResourcesFrom(wl_client* client) {
std::vector<SP<CWLOutputResource>> ret;
for (auto const& r : m_outputs) { for (auto const& r : m_outputs) {
if (r->client() != client) if (r->client() != client)
continue; continue;
return r; ret.emplace_back(r);
} }
return nullptr; return ret;
} }
void CWLOutputProtocol::remove() { void CWLOutputProtocol::remove() {

View file

@ -34,13 +34,13 @@ class CWLOutputProtocol : public IWaylandProtocol {
public: public:
CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, PHLMONITOR pMonitor); CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, PHLMONITOR pMonitor);
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
SP<CWLOutputResource> outputResourceFrom(wl_client* client); std::vector<SP<CWLOutputResource>> outputResourcesFrom(wl_client* client);
void sendDone(); void sendDone();
PHLMONITORREF m_monitor; PHLMONITORREF m_monitor;
WP<CWLOutputProtocol> m_self; WP<CWLOutputProtocol> m_self;
// will mark the protocol for removal, will be removed when no. of bound outputs is 0 (or when overwritten by a new global) // will mark the protocol for removal, will be removed when no. of bound outputs is 0 (or when overwritten by a new global)
void remove(); void remove();