renderer: cursor hiding logic improvements (#4184)

Co-authored-by: Dusan Popovic <dpx@binaryapparatus.com>
This commit is contained in:
dusanx 2023-12-18 16:06:06 +00:00 committed by GitHub
parent 460a326c90
commit 0c74df4f9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 31 deletions

View file

@ -324,13 +324,11 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
unsetCursorImage(); unsetCursorImage();
} }
if (g_pHyprRenderer->m_bHasARenderedCursor) {
// TODO: maybe wrap? // TODO: maybe wrap?
if (m_ecbClickBehavior == CLICKMODE_KILL) if (m_ecbClickBehavior == CLICKMODE_KILL)
setCursorImageOverride("crosshair"); setCursorImageOverride("crosshair");
else else
setCursorImageOverride("left_ptr"); setCursorImageOverride("left_ptr");
}
m_bEmptyFocusCursorSet = true; m_bEmptyFocusCursorSet = true;
} }
@ -490,7 +488,7 @@ void CInputManager::processMouseRequest(wlr_seat_pointer_request_set_cursor_even
else else
g_pHyprRenderer->m_bWindowRequestedCursorHide = false; g_pHyprRenderer->m_bWindowRequestedCursorHide = false;
if (!cursorImageUnlocked() || !g_pHyprRenderer->m_bHasARenderedCursor) if (!cursorImageUnlocked())
return; return;
if (e->seat_client == g_pCompositor->m_sSeat.seat->pointer_state.focused_client) { if (e->seat_client == g_pCompositor->m_sSeat.seat->pointer_state.focused_client) {
@ -513,7 +511,7 @@ void CInputManager::processMouseRequest(wlr_seat_pointer_request_set_cursor_even
} }
void CInputManager::processMouseRequest(wlr_cursor_shape_manager_v1_request_set_shape_event* e) { void CInputManager::processMouseRequest(wlr_cursor_shape_manager_v1_request_set_shape_event* e) {
if (!g_pHyprRenderer->m_bHasARenderedCursor || !cursorImageUnlocked()) if (!cursorImageUnlocked())
return; return;
if (e->seat_client == g_pCompositor->m_sSeat.seat->pointer_state.focused_client) { if (e->seat_client == g_pCompositor->m_sSeat.seat->pointer_state.focused_client) {
@ -555,9 +553,6 @@ void CInputManager::setCursorImageOverride(const std::string& name) {
} }
bool CInputManager::cursorImageUnlocked() { bool CInputManager::cursorImageUnlocked() {
if (!g_pHyprRenderer->m_bHasARenderedCursor)
return false;
if (m_ecbClickBehavior == CLICKMODE_KILL) if (m_ecbClickBehavior == CLICKMODE_KILL)
return false; return false;

View file

@ -2028,7 +2028,10 @@ void CHyprRenderer::setCursorSurface(wlr_surface* surf, int hotspotX, int hotspo
m_sLastCursorData.name = ""; m_sLastCursorData.name = "";
m_sLastCursorData.surf = surf; m_sLastCursorData.surf = surf;
m_sLastCursorData.hotspotX = hotspotX;
m_sLastCursorData.hotspotY = hotspotY;
if (shouldRenderCursor())
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) {
@ -2040,6 +2043,7 @@ void CHyprRenderer::setCursorFromName(const std::string& name) {
m_sLastCursorData.name = name; m_sLastCursorData.name = name;
m_sLastCursorData.surf.reset(); m_sLastCursorData.surf.reset();
if (shouldRenderCursor())
wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, name.c_str()); wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, name.c_str());
} }
@ -2052,20 +2056,27 @@ 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_bHasARenderedCursor) { if (HIDE && !m_bTimeoutRequestedCursorHide) {
m_bHasARenderedCursor = false; m_bTimeoutRequestedCursorHide = true;
setCursorSurface(nullptr, 0, 0); // hide wlr_cursor_set_surface(g_pCompositor->m_sWLRCursor, nullptr, 0, 0); // hide without saving surface
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_bHasARenderedCursor) { } else if (!HIDE && m_bTimeoutRequestedCursorHide) {
m_bHasARenderedCursor = true; m_bTimeoutRequestedCursorHide = false;
if (!m_bWindowRequestedCursorHide) if (m_bCursorHasSurface) { // restore last used name or surface, fallback to left_ptr if we don't have one
if (m_sLastCursorData.name == "") {
wlr_cursor_set_surface(g_pCompositor->m_sWLRCursor, m_sLastCursorData.surf.value_or(nullptr), m_sLastCursorData.hotspotX, m_sLastCursorData.hotspotY);
} else {
wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, m_sLastCursorData.name.c_str());
}
} else {
setCursorFromName("left_ptr"); setCursorFromName("left_ptr");
}
Debug::log(LOG, "Showing the cursor (timeout)"); Debug::log(LOG, "Showing the cursor (timeout)");
@ -2073,12 +2084,12 @@ void CHyprRenderer::ensureCursorRenderingMode() {
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 { } else {
m_bHasARenderedCursor = true; m_bTimeoutRequestedCursorHide = false;
} }
} }
bool CHyprRenderer::shouldRenderCursor() { bool CHyprRenderer::shouldRenderCursor() {
return m_bHasARenderedCursor && m_bCursorHasSurface; return !m_bTimeoutRequestedCursorHide && !m_bWindowRequestedCursorHide && m_bCursorHasSurface;
} }
std::tuple<float, float, float> CHyprRenderer::getRenderTimes(CMonitor* pMonitor) { std::tuple<float, float, float> CHyprRenderer::getRenderTimes(CMonitor* pMonitor) {

View file

@ -99,6 +99,8 @@ class CHyprRenderer {
CTimer m_tRenderTimer; CTimer m_tRenderTimer;
struct { struct {
int hotspotX;
int hotspotY;
std::optional<wlr_surface*> surf = nullptr; std::optional<wlr_surface*> surf = nullptr;
std::string name; std::string name;
} m_sLastCursorData; } m_sLastCursorData;
@ -115,7 +117,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_bHasARenderedCursor = true; bool m_bTimeoutRequestedCursorHide = 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;