2022-03-21 15:17:04 +01:00
|
|
|
#include "../Compositor.hpp"
|
|
|
|
#include "../helpers/WLClasses.hpp"
|
2022-06-09 12:46:55 +02:00
|
|
|
#include "../managers/input/InputManager.hpp"
|
2022-03-21 15:17:04 +01:00
|
|
|
#include "../render/Renderer.hpp"
|
|
|
|
#include "Events.hpp"
|
2022-04-21 22:00:03 +02:00
|
|
|
#include "../debug/HyprCtl.hpp"
|
2024-03-03 19:39:20 +01:00
|
|
|
#include "../config/ConfigValue.hpp"
|
2022-03-21 15:17:04 +01:00
|
|
|
|
|
|
|
// --------------------------------------------------------- //
|
|
|
|
// __ __ ____ _ _ _____ _______ ____ _____ _____ //
|
|
|
|
// | \/ |/ __ \| \ | |_ _|__ __/ __ \| __ \ / ____| //
|
|
|
|
// | \ / | | | | \| | | | | | | | | | |__) | (___ //
|
|
|
|
// | |\/| | | | | . ` | | | | | | | | | _ / \___ \ //
|
|
|
|
// | | | | |__| | |\ |_| |_ | | | |__| | | \ \ ____) | //
|
|
|
|
// |_| |_|\____/|_| \_|_____| |_| \____/|_| \_\_____/ //
|
|
|
|
// //
|
|
|
|
// --------------------------------------------------------- //
|
|
|
|
|
2022-06-17 20:31:15 +02:00
|
|
|
void Events::listener_monitorFrame(void* owner, void* data) {
|
2024-03-25 02:46:59 +01:00
|
|
|
if (g_pCompositor->m_bExitTriggered) {
|
|
|
|
// Only signal cleanup once
|
|
|
|
g_pCompositor->m_bExitTriggered = false;
|
|
|
|
g_pCompositor->cleanup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
CMonitor* const PMONITOR = (CMonitor*)owner;
|
2022-03-21 15:17:04 +01:00
|
|
|
|
2024-06-20 18:05:35 +02:00
|
|
|
// FIXME:
|
|
|
|
// if ((g_pCompositor->m_sWLRSession && !g_pCompositor->m_sWLRSession->active) || !g_pCompositor->m_bSessionActive || g_pCompositor->m_bUnsafeState) {
|
|
|
|
// Debug::log(WARN, "Attempted to render frame on inactive session!");
|
2023-03-15 16:11:41 +01:00
|
|
|
|
2024-06-20 18:05:35 +02:00
|
|
|
// if (g_pCompositor->m_bUnsafeState && std::ranges::any_of(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](auto& m) {
|
|
|
|
// return m->output != g_pCompositor->m_pUnsafeOutput->output;
|
|
|
|
// })) {
|
|
|
|
// // restore from unsafe state
|
|
|
|
// g_pCompositor->leaveUnsafeState();
|
|
|
|
// }
|
2023-03-15 16:11:41 +01:00
|
|
|
|
2024-06-20 18:05:35 +02:00
|
|
|
// return; // cannot draw on session inactive (different tty)
|
|
|
|
// }
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
if (!PMONITOR->m_bEnabled)
|
|
|
|
return;
|
2022-07-13 18:18:23 +02:00
|
|
|
|
2023-10-04 14:48:44 +02:00
|
|
|
g_pHyprRenderer->recheckSolitaryForMonitor(PMONITOR);
|
|
|
|
|
2023-09-30 18:07:50 +02:00
|
|
|
PMONITOR->tearingState.busy = false;
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
if (PMONITOR->tearingState.activelyTearing && PMONITOR->solitaryClient.lock() /* can be invalidated by a recheck */) {
|
2023-09-28 22:48:33 +02:00
|
|
|
|
2023-09-30 18:07:50 +02:00
|
|
|
if (!PMONITOR->tearingState.frameScheduledWhileBusy)
|
|
|
|
return; // we did not schedule a frame yet to be displayed, but we are tearing. Why render?
|
|
|
|
|
2023-10-04 14:39:40 +02:00
|
|
|
PMONITOR->tearingState.nextRenderTorn = true;
|
|
|
|
PMONITOR->tearingState.frameScheduledWhileBusy = false;
|
2023-09-30 18:07:50 +02:00
|
|
|
}
|
2023-09-28 22:48:33 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PENABLERAT = CConfigValue<Hyprlang::INT>("misc:render_ahead_of_time");
|
|
|
|
static auto PRATSAFE = CConfigValue<Hyprlang::INT>("misc:render_ahead_safezone");
|
2022-05-28 17:32:19 +02:00
|
|
|
|
2023-03-24 20:23:16 +01:00
|
|
|
PMONITOR->lastPresentationTimer.reset();
|
2022-06-29 11:44:00 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PENABLERAT && !PMONITOR->tearingState.nextRenderTorn) {
|
2023-03-24 20:23:16 +01:00
|
|
|
if (!PMONITOR->RATScheduled) {
|
|
|
|
// render
|
|
|
|
g_pHyprRenderer->renderMonitor(PMONITOR);
|
2022-07-13 18:18:23 +02:00
|
|
|
}
|
2022-07-31 16:54:36 +02:00
|
|
|
|
2023-03-24 20:23:16 +01:00
|
|
|
PMONITOR->RATScheduled = false;
|
2022-07-13 18:18:23 +02:00
|
|
|
|
2023-03-24 20:23:16 +01:00
|
|
|
const auto& [avg, max, min] = g_pHyprRenderer->getRenderTimes(PMONITOR);
|
2022-04-12 20:02:57 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (max + *PRATSAFE > 1000.0 / PMONITOR->refreshRate)
|
2022-11-05 13:50:47 +01:00
|
|
|
return;
|
2022-05-06 16:06:21 +02:00
|
|
|
|
2023-03-24 20:23:16 +01:00
|
|
|
const auto MSLEFT = 1000.0 / PMONITOR->refreshRate - PMONITOR->lastPresentationTimer.getMillis();
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2023-03-24 20:23:16 +01:00
|
|
|
PMONITOR->RATScheduled = true;
|
2022-04-14 16:43:29 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
const auto ESTRENDERTIME = std::ceil(avg + *PRATSAFE);
|
2023-03-24 20:23:16 +01:00
|
|
|
const auto TIMETOSLEEP = std::floor(MSLEFT - ESTRENDERTIME);
|
2022-03-21 15:17:04 +01:00
|
|
|
|
2023-03-24 23:24:12 +01:00
|
|
|
if (MSLEFT < 1 || MSLEFT < ESTRENDERTIME || TIMETOSLEEP < 1)
|
2023-03-24 20:23:16 +01:00
|
|
|
g_pHyprRenderer->renderMonitor(PMONITOR);
|
|
|
|
else
|
|
|
|
wl_event_source_timer_update(PMONITOR->renderTimer, TIMETOSLEEP);
|
2022-09-13 15:25:42 +02:00
|
|
|
} else {
|
2023-03-24 20:23:16 +01:00
|
|
|
g_pHyprRenderer->renderMonitor(PMONITOR);
|
2022-05-28 17:40:57 +02:00
|
|
|
}
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-06-17 20:31:15 +02:00
|
|
|
void Events::listener_monitorDestroy(void* owner, void* data) {
|
2024-06-20 18:05:35 +02:00
|
|
|
CMonitor* pMonitor = nullptr;
|
2022-03-21 15:17:04 +01:00
|
|
|
|
2022-11-19 14:14:55 +01:00
|
|
|
for (auto& m : g_pCompositor->m_vRealMonitors) {
|
2024-06-20 18:05:35 +02:00
|
|
|
if (m->output == pMonitor->output) {
|
2022-06-30 15:44:26 +02:00
|
|
|
pMonitor = m.get();
|
2022-03-21 15:17:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pMonitor)
|
|
|
|
return;
|
|
|
|
|
2023-09-06 12:51:36 +02:00
|
|
|
Debug::log(LOG, "Destroy called for monitor {}", pMonitor->output->name);
|
2022-11-19 14:01:32 +01:00
|
|
|
|
2023-11-12 14:14:05 +01:00
|
|
|
pMonitor->onDisconnect(true);
|
2022-05-31 17:17:44 +02:00
|
|
|
|
2023-03-15 16:11:41 +01:00
|
|
|
pMonitor->output = nullptr;
|
|
|
|
pMonitor->m_bRenderingInitPassed = false;
|
|
|
|
|
2023-09-06 21:45:37 +02:00
|
|
|
Debug::log(LOG, "Removing monitor {} from realMonitors", pMonitor->szName);
|
2022-11-19 14:01:32 +01:00
|
|
|
|
2024-05-05 18:16:00 +02:00
|
|
|
std::erase_if(g_pCompositor->m_vRealMonitors, [&](SP<CMonitor>& el) { return el.get() == pMonitor; });
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
2022-11-19 17:28:04 +01:00
|
|
|
|
|
|
|
void Events::listener_monitorStateRequest(void* owner, void* data) {
|
2024-06-20 18:05:35 +02:00
|
|
|
// const auto PMONITOR = (CMonitor*)owner;
|
|
|
|
// const auto E = (wlr_output_event_request_state*)data;
|
2024-02-14 23:05:36 +01:00
|
|
|
|
2024-06-20 18:05:35 +02:00
|
|
|
// if (!PMONITOR->createdByUser)
|
|
|
|
// return;
|
2024-02-14 23:05:36 +01:00
|
|
|
|
2024-06-20 18:05:35 +02:00
|
|
|
// const auto SIZE = E->state->mode ? Vector2D{E->state->mode->width, E->state->mode->height} : Vector2D{E->state->custom_mode.width, E->state->custom_mode.height};
|
2024-02-14 23:05:36 +01:00
|
|
|
|
2024-06-20 18:05:35 +02:00
|
|
|
// PMONITOR->forceSize = SIZE;
|
2024-02-14 23:05:36 +01:00
|
|
|
|
2024-06-20 18:05:35 +02:00
|
|
|
// SMonitorRule rule = PMONITOR->activeMonitorRule;
|
|
|
|
// rule.resolution = SIZE;
|
2022-11-19 17:28:04 +01:00
|
|
|
|
2024-06-20 18:05:35 +02:00
|
|
|
// g_pHyprRenderer->applyMonitorRule(PMONITOR, &rule);
|
2022-11-19 17:28:04 +01:00
|
|
|
}
|
2023-04-07 17:31:51 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2023-04-07 18:25:56 +02:00
|
|
|
|
|
|
|
void Events::listener_monitorNeedsFrame(void* owner, void* data) {
|
|
|
|
const auto PMONITOR = (CMonitor*)owner;
|
|
|
|
|
|
|
|
g_pCompositor->scheduleFrameForMonitor(PMONITOR);
|
|
|
|
}
|
2023-04-12 22:40:51 +02:00
|
|
|
|
|
|
|
void Events::listener_monitorCommit(void* owner, void* data) {
|
|
|
|
const auto PMONITOR = (CMonitor*)owner;
|
|
|
|
|
2024-06-20 18:05:35 +02:00
|
|
|
if (true) { // FIXME: E->state->committed & WLR_OUTPUT_STATE_BUFFER
|
|
|
|
g_pProtocolManager->m_pScreencopyProtocolManager->onOutputCommit(PMONITOR);
|
|
|
|
g_pProtocolManager->m_pToplevelExportProtocolManager->onOutputCommit(PMONITOR);
|
2023-07-20 12:42:25 +02:00
|
|
|
}
|
2023-06-23 21:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_monitorBind(void* owner, void* data) {
|
2023-07-18 15:30:28 +02:00
|
|
|
;
|
2023-04-12 22:40:51 +02:00
|
|
|
}
|