From 0869f65b0b7e13b0d7f522decfc21244beb21c3a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 28 Mar 2024 02:04:30 +0000 Subject: [PATCH] input: add misc:hide_cursor_on_key_press fixes #3045 --- src/config/ConfigManager.cpp | 1 + src/render/Renderer.cpp | 77 ++++++++++++++++++++++++++++-------- src/render/Renderer.hpp | 9 ++++- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index d13b871d..17dea1a7 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -349,6 +349,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("misc:background_color", Hyprlang::INT{0xff111111}); m_pConfig->addConfigValue("misc:new_window_takes_over_fullscreen", Hyprlang::INT{0}); m_pConfig->addConfigValue("misc:enable_hyprcursor", Hyprlang::INT{1}); + m_pConfig->addConfigValue("misc:hide_cursor_on_key_press", Hyprlang::INT{0}); m_pConfig->addConfigValue("group:insert_after_current", Hyprlang::INT{1}); m_pConfig->addConfigValue("group:focus_removed_window", Hyprlang::INT{1}); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index c48bbdd4..960add70 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -11,8 +11,13 @@ extern "C" { #include } -CHyprRenderer::CHyprRenderer() { +static int cursorTicker(void* data) { + g_pHyprRenderer->ensureCursorRenderingMode(); + wl_event_source_timer_update(g_pHyprRenderer->m_pCursorTicker, 500); + return 0; +} +CHyprRenderer::CHyprRenderer() { if (g_pCompositor->m_sWLRSession) { wlr_device* dev; wl_list_for_each(dev, &g_pCompositor->m_sWLRSession->devices, link) { @@ -52,6 +57,30 @@ CHyprRenderer::CHyprRenderer() { if (m_bNvidia) Debug::log(WARN, "NVIDIA detected, please remember to follow nvidia instructions on the wiki"); + + // cursor hiding stuff + + g_pHookSystem->hookDynamic("keyPress", [&](void* self, SCallbackInfo& info, std::any param) { + if (m_sCursorHiddenConditions.hiddenOnKeyboard) + return; + + m_sCursorHiddenConditions.hiddenOnKeyboard = true; + ensureCursorRenderingMode(); + }); + + g_pHookSystem->hookDynamic("mouseMove", [&](void* self, SCallbackInfo& info, std::any param) { + if (!m_sCursorHiddenConditions.hiddenOnKeyboard && m_sCursorHiddenConditions.hiddenOnTouch == g_pInputManager->m_bLastInputTouch && + !m_sCursorHiddenConditions.hiddenOnTimeout) + return; + + m_sCursorHiddenConditions.hiddenOnKeyboard = false; + m_sCursorHiddenConditions.hiddenOnTimeout = false; + m_sCursorHiddenConditions.hiddenOnTouch = g_pInputManager->m_bLastInputTouch; + ensureCursorRenderingMode(); + }); + + m_pCursorTicker = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, cursorTicker, nullptr); + wl_event_source_timer_update(m_pCursorTicker, 500); } static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { @@ -1090,8 +1119,6 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { if (g_pConfigManager->m_bWantsMonitorReload) g_pConfigManager->performMonitorReload(); - - ensureCursorRenderingMode(); // so that the cursor gets hidden/shown if the user requested timeouts } // // @@ -2269,29 +2296,45 @@ void CHyprRenderer::setCursorFromName(const std::string& name, bool force) { void CHyprRenderer::ensureCursorRenderingMode() { static auto PCURSORTIMEOUT = CConfigValue("general:cursor_inactive_timeout"); static auto PHIDEONTOUCH = CConfigValue("misc:hide_cursor_on_touch"); + static auto PHIDEONKEY = CConfigValue("misc:hide_cursor_on_key_press"); - const auto PASSEDCURSORSECONDS = g_pInputManager->m_tmrLastCursorMovement.getSeconds(); + if (*PCURSORTIMEOUT <= 0) + m_sCursorHiddenConditions.hiddenOnTimeout = false; + if (*PHIDEONTOUCH == 0) + m_sCursorHiddenConditions.hiddenOnTouch = false; + if (*PHIDEONKEY == 0) + m_sCursorHiddenConditions.hiddenOnKeyboard = false; - if (*PCURSORTIMEOUT > 0 || *PHIDEONTOUCH) { - const bool HIDE = (*PCURSORTIMEOUT > 0 && *PCURSORTIMEOUT < PASSEDCURSORSECONDS) || (g_pInputManager->m_bLastInputTouch && *PHIDEONTOUCH); + if (*PCURSORTIMEOUT > 0) + m_sCursorHiddenConditions.hiddenOnTimeout = *PCURSORTIMEOUT < g_pInputManager->m_tmrLastCursorMovement.getSeconds(); - if (HIDE && !m_bCursorHidden) { - Debug::log(LOG, "Hiding the cursor (timeout)"); + const bool HIDE = m_sCursorHiddenConditions.hiddenOnTimeout || m_sCursorHiddenConditions.hiddenOnTouch || m_sCursorHiddenConditions.hiddenOnKeyboard; - for (auto& m : g_pCompositor->m_vMonitors) - g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? + if (HIDE == m_bCursorHidden) + return; - setCursorHidden(true); + if (HIDE) { + Debug::log(LOG, "Hiding the cursor (hl-mandated)"); - } else if (!HIDE && m_bCursorHidden) { - Debug::log(LOG, "Showing the cursor (timeout)"); + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->output->software_cursor_locks == 0) + continue; - for (auto& m : g_pCompositor->m_vMonitors) - g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? - - setCursorHidden(false); + g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? } + + setCursorHidden(true); + } else { + Debug::log(LOG, "Showing the cursor (hl-mandated)"); + + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->output->software_cursor_locks == 0) + continue; + + g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? + } + setCursorHidden(false); } } diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index d73b4c5f..0a684af3 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -96,6 +96,7 @@ class CHyprRenderer { bool m_bCrashingInProgress = false; float m_fCrashingDistort = 0.5f; wl_event_source* m_pCrashingLoop = nullptr; + wl_event_source* m_pCursorTicker = nullptr; std::vector> m_vTearingControllers; @@ -128,7 +129,13 @@ class CHyprRenderer { bool m_bNvidia = false; - CRenderbuffer* getOrCreateRenderbuffer(wlr_buffer* buffer, uint32_t fmt); + struct { + bool hiddenOnTouch = false; + bool hiddenOnTimeout = false; + bool hiddenOnKeyboard = false; + } m_sCursorHiddenConditions; + + CRenderbuffer* getOrCreateRenderbuffer(wlr_buffer* buffer, uint32_t fmt); std::vector> m_vRenderbuffers; friend class CHyprOpenGLImpl;