Skip to content

Commit

Permalink
protocols: implement hyprland-ctm-control v2
Browse files Browse the repository at this point in the history
  • Loading branch information
outfoxxed committed Feb 1, 2025
1 parent ddf180f commit 064edeb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/managers/ProtocolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ CProtocolManager::CProtocolManager() {
PROTO::xdgDialog = makeUnique<CXDGDialogProtocol>(&xdg_dialog_v1_interface, 1, "XDGDialog");
PROTO::singlePixel = makeUnique<CSinglePixelProtocol>(&wp_single_pixel_buffer_manager_v1_interface, 1, "SinglePixel");
PROTO::securityContext = makeUnique<CSecurityContextProtocol>(&wp_security_context_manager_v1_interface, 1, "SecurityContext");
PROTO::ctm = makeUnique<CHyprlandCTMControlProtocol>(&hyprland_ctm_control_manager_v1_interface, 1, "CTMControl");
PROTO::ctm = makeUnique<CHyprlandCTMControlProtocol>(&hyprland_ctm_control_manager_v1_interface, 2, "CTMControl");
PROTO::hyprlandSurface = makeUnique<CHyprlandSurfaceProtocol>(&hyprland_surface_manager_v1_interface, 2, "HyprlandSurface");

if (*PENABLEXXCM) {
Expand Down
22 changes: 21 additions & 1 deletion src/protocols/CTMControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP<CHyprlandCtmControlM

resource->setSetCtmForOutput([this](CHyprlandCtmControlManagerV1* r, wl_resource* output, wl_fixed_t mat0, wl_fixed_t mat1, wl_fixed_t mat2, wl_fixed_t mat3, wl_fixed_t mat4,
wl_fixed_t mat5, wl_fixed_t mat6, wl_fixed_t mat7, wl_fixed_t mat8) {
if (blocked)
return;

const auto OUTPUTRESOURCE = CWLOutputResource::fromResource(output);

if UNLIKELY (!OUTPUTRESOURCE)
Expand All @@ -41,6 +44,9 @@ CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP<CHyprlandCtmControlM
});

resource->setCommit([this](CHyprlandCtmControlManagerV1* r) {
if (blocked)
return;

LOGM(LOG, "Committing ctms to outputs");

for (auto& m : g_pCompositor->m_vMonitors) {
Expand All @@ -54,7 +60,17 @@ CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP<CHyprlandCtmControlM
});
}

void CHyprlandCTMControlResource::block() {
blocked = true;

if (resource->version() >= 2)
resource->sendBlocked();
}

CHyprlandCTMControlResource::~CHyprlandCTMControlResource() {
if (blocked)
return;

for (auto& m : g_pCompositor->m_vMonitors) {
PROTO::ctm->setCTM(m, Mat3x3::identity());
}
Expand All @@ -69,7 +85,6 @@ CHyprlandCTMControlProtocol::CHyprlandCTMControlProtocol(const wl_interface* ifa
}

void CHyprlandCTMControlProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {

const auto RESOURCE = m_vManagers.emplace_back(makeShared<CHyprlandCTMControlResource>(makeShared<CHyprlandCtmControlManagerV1>(client, ver, id)));

if UNLIKELY (!RESOURCE->good()) {
Expand All @@ -78,6 +93,11 @@ void CHyprlandCTMControlProtocol::bindManager(wl_client* client, void* data, uin
return;
}

if (m_pManager)
RESOURCE->block();
else
m_pManager = RESOURCE;

LOGM(LOG, "New CTM Manager at 0x{:x}", (uintptr_t)RESOURCE.get());
}

Expand Down
5 changes: 4 additions & 1 deletion src/protocols/CTMControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class CHyprlandCTMControlResource {
~CHyprlandCTMControlResource();

bool good();
void block();

private:
SP<CHyprlandCtmControlManagerV1> resource;

std::unordered_map<std::string, Mat3x3> ctms;
bool blocked = false;
};

class CHyprlandCTMControlProtocol : public IWaylandProtocol {
Expand All @@ -37,6 +39,7 @@ class CHyprlandCTMControlProtocol : public IWaylandProtocol {

//
std::vector<SP<CHyprlandCTMControlResource>> m_vManagers;
WP<CHyprlandCTMControlResource> m_pManager;

//
struct SCTMData {
Expand All @@ -51,4 +54,4 @@ class CHyprlandCTMControlProtocol : public IWaylandProtocol {

namespace PROTO {
inline UP<CHyprlandCTMControlProtocol> ctm;
};
};

0 comments on commit 064edeb

Please sign in to comment.