From cd1b982b2a53a526eb3b4e3c53787038e18f993d Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:31:51 +0100 Subject: [PATCH] internal: listen to output.damage events --- src/events/Events.hpp | 1 + src/events/Monitors.cpp | 7 +++++++ src/helpers/Monitor.cpp | 9 +++++++-- src/helpers/Monitor.hpp | 5 +++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/events/Events.hpp b/src/events/Events.hpp index ae441fbb..26db2b22 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -98,6 +98,7 @@ namespace Events { DYNLISTENFUNC(monitorFrame); DYNLISTENFUNC(monitorDestroy); DYNLISTENFUNC(monitorStateRequest); + DYNLISTENFUNC(monitorDamage); // XWayland LISTENER(readyXWayland); diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index ccdb3ef0..4749ff22 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -196,3 +196,10 @@ void Events::listener_monitorStateRequest(void* owner, void* data) { wlr_output_commit_state(PMONITOR->output, E->state); } + +void Events::listener_monitorDamage(void* owner, void* data) { + const auto PMONITOR = (CMonitor*)owner; + const auto E = (wlr_output_event_damage*)data; + + PMONITOR->addDamage(E->damage); +} diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 573518ab..e12598eb 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -20,9 +20,11 @@ void CMonitor::onConnect(bool noRule) { hyprListener_monitorDestroy.removeCallback(); hyprListener_monitorFrame.removeCallback(); hyprListener_monitorStateRequest.removeCallback(); + hyprListener_monitorDamage.removeCallback(); hyprListener_monitorFrame.initCallback(&output->events.frame, &Events::listener_monitorFrame, this); hyprListener_monitorDestroy.initCallback(&output->events.destroy, &Events::listener_monitorDestroy, this); hyprListener_monitorStateRequest.initCallback(&output->events.request_state, &Events::listener_monitorStateRequest, this); + hyprListener_monitorDamage.initCallback(&output->events.damage, &Events::listener_monitorDamage, this); if (m_bEnabled) { wlr_output_enable(output, 1); @@ -215,6 +217,7 @@ void CMonitor::onDisconnect() { m_bRenderingInitPassed = false; hyprListener_monitorFrame.removeCallback(); + hyprListener_monitorDamage.removeCallback(); for (size_t i = 0; i < 4; ++i) { for (auto& ls : m_aLayerSurfaceLayers[i]) { @@ -289,12 +292,14 @@ void CMonitor::onDisconnect() { std::erase_if(g_pCompositor->m_vMonitors, [&](std::shared_ptr& el) { return el.get() == this; }); } -void CMonitor::addDamage(pixman_region32_t* rg) { +void CMonitor::addDamage(const pixman_region32_t* rg) { wlr_damage_ring_add(&damage, rg); + g_pCompositor->scheduleFrameForMonitor(this); } -void CMonitor::addDamage(wlr_box* box) { +void CMonitor::addDamage(const wlr_box* box) { wlr_damage_ring_add_box(&damage, box); + g_pCompositor->scheduleFrameForMonitor(this); } bool CMonitor::isMirror() { diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index ca4b146c..3414f698 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -65,6 +65,7 @@ class CMonitor { DYNLISTENER(monitorFrame); DYNLISTENER(monitorDestroy); DYNLISTENER(monitorStateRequest); + DYNLISTENER(monitorDamage); // hack: a group = workspaces on a monitor. // I don't really care lol :P @@ -73,8 +74,8 @@ class CMonitor { // methods void onConnect(bool noRule); void onDisconnect(); - void addDamage(pixman_region32_t* rg); - void addDamage(wlr_box* box); + void addDamage(const pixman_region32_t* rg); + void addDamage(const wlr_box* box); void setMirror(const std::string&); bool isMirror(); float getDefaultScale();