renderer: improve cursor hiding infra

ref #4197
This commit is contained in:
Vaxry 2023-12-20 21:40:44 +01:00
parent a197fe3c11
commit 48ecb13b14
2 changed files with 41 additions and 19 deletions

View file

@ -2020,10 +2020,10 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR
return true; return true;
} }
void CHyprRenderer::setCursorSurface(wlr_surface* surf, int hotspotX, int hotspotY) { void CHyprRenderer::setCursorSurface(wlr_surface* surf, int hotspotX, int hotspotY, bool force) {
m_bCursorHasSurface = surf; m_bCursorHasSurface = surf;
if (surf == m_sLastCursorData.surf) if ((surf == m_sLastCursorData.surf || m_bCursorHidden) && !force)
return; return;
m_sLastCursorData.name = ""; m_sLastCursorData.name = "";
@ -2034,10 +2034,10 @@ void CHyprRenderer::setCursorSurface(wlr_surface* surf, int hotspotX, int hotspo
wlr_cursor_set_surface(g_pCompositor->m_sWLRCursor, surf, hotspotX, hotspotY); wlr_cursor_set_surface(g_pCompositor->m_sWLRCursor, surf, hotspotX, hotspotY);
} }
void CHyprRenderer::setCursorFromName(const std::string& name) { void CHyprRenderer::setCursorFromName(const std::string& name, bool force) {
m_bCursorHasSurface = true; m_bCursorHasSurface = true;
if (name == m_sLastCursorData.name) if ((name == m_sLastCursorData.name || m_bCursorHidden) && !force)
return; return;
m_sLastCursorData.name = name; m_sLastCursorData.name = name;
@ -2055,28 +2055,49 @@ void CHyprRenderer::ensureCursorRenderingMode() {
if (*PCURSORTIMEOUT > 0 || *PHIDEONTOUCH) { if (*PCURSORTIMEOUT > 0 || *PHIDEONTOUCH) {
const bool HIDE = (*PCURSORTIMEOUT > 0 && *PCURSORTIMEOUT < PASSEDCURSORSECONDS) || (g_pInputManager->m_bLastInputTouch && *PHIDEONTOUCH); const bool HIDE = (*PCURSORTIMEOUT > 0 && *PCURSORTIMEOUT < PASSEDCURSORSECONDS) || (g_pInputManager->m_bLastInputTouch && *PHIDEONTOUCH);
if (HIDE && !m_bTimeoutRequestedCursorHide) { if (HIDE && !m_bCursorHidden) {
m_bTimeoutRequestedCursorHide = true;
Debug::log(LOG, "Hiding the cursor (timeout)"); Debug::log(LOG, "Hiding the cursor (timeout)");
for (auto& m : g_pCompositor->m_vMonitors) for (auto& m : g_pCompositor->m_vMonitors)
g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area?
} else if (!HIDE && m_bTimeoutRequestedCursorHide) {
m_bTimeoutRequestedCursorHide = false;
setCursorHidden(true);
} else if (!HIDE && m_bCursorHidden) {
Debug::log(LOG, "Showing the cursor (timeout)"); Debug::log(LOG, "Showing the cursor (timeout)");
for (auto& m : g_pCompositor->m_vMonitors) for (auto& m : g_pCompositor->m_vMonitors)
g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area?
setCursorHidden(false);
} }
} else { } else {
m_bTimeoutRequestedCursorHide = false; setCursorHidden(false);
} }
} }
void CHyprRenderer::setCursorHidden(bool hide) {
if (hide == m_bCursorHidden)
return;
m_bCursorHidden = hide;
if (hide) {
wlr_cursor_unset_image(g_pCompositor->m_sWLRCursor);
return;
}
if (m_sLastCursorData.surf.has_value())
setCursorSurface(m_sLastCursorData.surf.value(), m_sLastCursorData.hotspotX, m_sLastCursorData.hotspotY, true);
else if (!m_sLastCursorData.name.empty())
setCursorFromName(m_sLastCursorData.name, true);
else
setCursorFromName("left_ptr", true);
}
bool CHyprRenderer::shouldRenderCursor() { bool CHyprRenderer::shouldRenderCursor() {
return !m_bTimeoutRequestedCursorHide && !m_bWindowRequestedCursorHide && m_bCursorHasSurface; return !m_bCursorHidden && !m_bWindowRequestedCursorHide && m_bCursorHasSurface;
} }
std::tuple<float, float, float> CHyprRenderer::getRenderTimes(CMonitor* pMonitor) { std::tuple<float, float, float> CHyprRenderer::getRenderTimes(CMonitor* pMonitor) {

View file

@ -56,14 +56,15 @@ class CHyprRenderer {
bool shouldRenderWindow(CWindow*); bool shouldRenderWindow(CWindow*);
void ensureCursorRenderingMode(); void ensureCursorRenderingMode();
bool shouldRenderCursor(); bool shouldRenderCursor();
void setCursorHidden(bool hide);
void calculateUVForSurface(CWindow*, wlr_surface*, bool main = false); void calculateUVForSurface(CWindow*, wlr_surface*, bool main = false);
std::tuple<float, float, float> getRenderTimes(CMonitor* pMonitor); // avg max min std::tuple<float, float, float> getRenderTimes(CMonitor* pMonitor); // avg max min
void renderLockscreen(CMonitor* pMonitor, timespec* now); void renderLockscreen(CMonitor* pMonitor, timespec* now);
void setOccludedForBackLayers(CRegion& region, CWorkspace* pWorkspace); void setOccludedForBackLayers(CRegion& region, CWorkspace* pWorkspace);
bool canSkipBackBufferClear(CMonitor* pMonitor); bool canSkipBackBufferClear(CMonitor* pMonitor);
void recheckSolitaryForMonitor(CMonitor* pMonitor); void recheckSolitaryForMonitor(CMonitor* pMonitor);
void setCursorSurface(wlr_surface* surf, int hotspotX, int hotspotY); void setCursorSurface(wlr_surface* surf, int hotspotX, int hotspotY, bool force = false);
void setCursorFromName(const std::string& name); void setCursorFromName(const std::string& name, bool force = false);
void renderSoftwareCursors(CMonitor* pMonitor, const CRegion& damage, std::optional<Vector2D> overridePos = {}); void renderSoftwareCursors(CMonitor* pMonitor, const CRegion& damage, std::optional<Vector2D> overridePos = {});
void onRenderbufferDestroy(CRenderbuffer* rb); void onRenderbufferDestroy(CRenderbuffer* rb);
CRenderbuffer* getCurrentRBO(); CRenderbuffer* getCurrentRBO();
@ -117,7 +118,7 @@ class CHyprRenderer {
void renderWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const CBox& geometry); void renderWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const CBox& geometry);
void renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f); void renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f);
bool m_bTimeoutRequestedCursorHide = false; bool m_bCursorHidden = false;
bool m_bCursorHasSurface = false; bool m_bCursorHasSurface = false;
CRenderbuffer* m_pCurrentRenderbuffer = nullptr; CRenderbuffer* m_pCurrentRenderbuffer = nullptr;
wlr_buffer* m_pCurrentWlrBuffer = nullptr; wlr_buffer* m_pCurrentWlrBuffer = nullptr;