internal: listen to output.damage events

This commit is contained in:
vaxerski 2023-04-07 16:31:51 +01:00
parent a35ea4d242
commit cd1b982b2a
4 changed files with 18 additions and 4 deletions

View file

@ -98,6 +98,7 @@ namespace Events {
DYNLISTENFUNC(monitorFrame);
DYNLISTENFUNC(monitorDestroy);
DYNLISTENFUNC(monitorStateRequest);
DYNLISTENFUNC(monitorDamage);
// XWayland
LISTENER(readyXWayland);

View file

@ -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);
}

View file

@ -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<CMonitor>& 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() {

View file

@ -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();