mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-07 21:05:58 +01:00
renderer: cursor hiding logic improvements (#4184)
Co-authored-by: Dusan Popovic <dpx@binaryapparatus.com>
This commit is contained in:
parent
460a326c90
commit
0c74df4f9e
3 changed files with 39 additions and 31 deletions
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -2026,10 +2026,13 @@ void CHyprRenderer::setCursorSurface(wlr_surface* surf, int hotspotX, int hotspo
|
||||||
if (surf == m_sLastCursorData.surf)
|
if (surf == m_sLastCursorData.surf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_sLastCursorData.name = "";
|
m_sLastCursorData.name = "";
|
||||||
m_sLastCursorData.surf = surf;
|
m_sLastCursorData.surf = surf;
|
||||||
|
m_sLastCursorData.hotspotX = hotspotX;
|
||||||
|
m_sLastCursorData.hotspotY = hotspotY;
|
||||||
|
|
||||||
wlr_cursor_set_surface(g_pCompositor->m_sWLRCursor, surf, hotspotX, hotspotY);
|
if (shouldRenderCursor())
|
||||||
|
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) {
|
||||||
m_bCursorHasSurface = true;
|
m_bCursorHasSurface = true;
|
||||||
|
@ -2040,7 +2043,8 @@ void CHyprRenderer::setCursorFromName(const std::string& name) {
|
||||||
m_sLastCursorData.name = name;
|
m_sLastCursorData.name = name;
|
||||||
m_sLastCursorData.surf.reset();
|
m_sLastCursorData.surf.reset();
|
||||||
|
|
||||||
wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, name.c_str());
|
if (shouldRenderCursor())
|
||||||
|
wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprRenderer::ensureCursorRenderingMode() {
|
void CHyprRenderer::ensureCursorRenderingMode() {
|
||||||
|
@ -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) {
|
||||||
|
@ -2353,4 +2364,4 @@ CRenderbuffer* CHyprRenderer::getCurrentRBO() {
|
||||||
|
|
||||||
bool CHyprRenderer::isNvidia() {
|
bool CHyprRenderer::isNvidia() {
|
||||||
return m_bNvidia;
|
return m_bNvidia;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,12 +117,12 @@ 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;
|
||||||
eRenderMode m_eRenderMode = RENDER_MODE_NORMAL;
|
eRenderMode m_eRenderMode = RENDER_MODE_NORMAL;
|
||||||
int m_iLastBufferAge = 0;
|
int m_iLastBufferAge = 0;
|
||||||
|
|
||||||
bool m_bNvidia = false;
|
bool m_bNvidia = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue