2024-04-19 23:16:35 +02:00
|
|
|
#include "TearingControl.hpp"
|
|
|
|
#include "../managers/ProtocolManager.hpp"
|
|
|
|
#include "../desktop/Window.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
2024-06-08 10:07:59 +02:00
|
|
|
#include "core/Compositor.hpp"
|
2024-04-19 23:16:35 +02:00
|
|
|
|
|
|
|
CTearingControlProtocol::CTearingControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
|
2024-04-27 13:43:12 +02:00
|
|
|
static auto P =
|
|
|
|
g_pHookSystem->hookDynamic("destroyWindow", [this](void* self, SCallbackInfo& info, std::any param) { this->onWindowDestroy(std::any_cast<PHLWINDOW>(param)); });
|
2024-04-19 23:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTearingControlProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
2024-04-20 14:25:29 +02:00
|
|
|
const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CWpTearingControlManagerV1>(client, ver, id)).get();
|
|
|
|
RESOURCE->setOnDestroy([this](CWpTearingControlManagerV1* p) { this->onManagerResourceDestroy(p->resource()); });
|
2024-04-19 23:16:35 +02:00
|
|
|
|
2024-04-20 14:25:29 +02:00
|
|
|
RESOURCE->setDestroy([this](CWpTearingControlManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
|
2024-06-08 10:07:59 +02:00
|
|
|
RESOURCE->setGetTearingControl([this](CWpTearingControlManagerV1* pMgr, uint32_t id, wl_resource* surface) {
|
|
|
|
this->onGetController(pMgr->client(), pMgr, id, CWLSurfaceResource::fromResource(surface));
|
|
|
|
});
|
2024-04-19 23:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTearingControlProtocol::onManagerResourceDestroy(wl_resource* res) {
|
|
|
|
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
|
|
|
|
}
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CTearingControlProtocol::onGetController(wl_client* client, CWpTearingControlManagerV1* pMgr, uint32_t id, SP<CWLSurfaceResource> surf) {
|
2024-05-05 18:16:00 +02:00
|
|
|
const auto CONTROLLER = m_vTearingControllers.emplace_back(std::make_unique<CTearingControl>(makeShared<CWpTearingControlV1>(client, pMgr->version(), id), surf)).get();
|
2024-04-19 23:16:35 +02:00
|
|
|
|
|
|
|
if (!CONTROLLER->good()) {
|
2024-05-01 20:40:35 +02:00
|
|
|
pMgr->noMemory();
|
2024-04-19 23:16:35 +02:00
|
|
|
m_vTearingControllers.pop_back();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTearingControlProtocol::onControllerDestroy(CTearingControl* control) {
|
|
|
|
std::erase_if(m_vTearingControllers, [control](const auto& other) { return other.get() == control; });
|
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
void CTearingControlProtocol::onWindowDestroy(PHLWINDOW pWindow) {
|
2024-04-19 23:16:35 +02:00
|
|
|
for (auto& c : m_vTearingControllers) {
|
2024-04-27 13:43:12 +02:00
|
|
|
if (c->pWindow.lock() == pWindow)
|
|
|
|
c->pWindow.reset();
|
2024-04-19 23:16:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
CTearingControl::CTearingControl(SP<CWpTearingControlV1> resource_, SP<CWLSurfaceResource> surf_) : resource(resource_) {
|
2024-04-19 23:16:35 +02:00
|
|
|
resource->setData(this);
|
2024-04-20 14:25:29 +02:00
|
|
|
resource->setOnDestroy([this](CWpTearingControlV1* res) { PROTO::tearing->onControllerDestroy(this); });
|
|
|
|
resource->setDestroy([this](CWpTearingControlV1* res) { PROTO::tearing->onControllerDestroy(this); });
|
|
|
|
resource->setSetPresentationHint([this](CWpTearingControlV1* res, wpTearingControlV1PresentationHint hint) { this->onHint(hint); });
|
2024-04-19 23:16:35 +02:00
|
|
|
|
2024-04-20 01:08:49 +02:00
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
2024-06-08 10:07:59 +02:00
|
|
|
if (w->m_pWLSurface->resource() == surf_) {
|
2024-04-27 13:43:12 +02:00
|
|
|
pWindow = w;
|
2024-04-20 01:08:49 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-04-19 23:16:35 +02:00
|
|
|
}
|
|
|
|
|
2024-04-20 14:25:29 +02:00
|
|
|
void CTearingControl::onHint(wpTearingControlV1PresentationHint hint_) {
|
|
|
|
hint = hint_;
|
2024-04-19 23:16:35 +02:00
|
|
|
updateWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTearingControl::updateWindow() {
|
2024-04-27 13:43:12 +02:00
|
|
|
if (pWindow.expired())
|
2024-04-19 23:16:35 +02:00
|
|
|
return;
|
|
|
|
|
2024-05-05 18:16:00 +02:00
|
|
|
pWindow->m_bTearingHint = hint == WP_TEARING_CONTROL_V1_PRESENTATION_HINT_ASYNC;
|
2024-04-19 23:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CTearingControl::good() {
|
2024-04-20 14:25:29 +02:00
|
|
|
return resource->resource();
|
2024-04-19 23:16:35 +02:00
|
|
|
}
|