aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVaxry <[email protected]>2024-03-28 02:04:30 +0000
committerVaxry <[email protected]>2024-03-28 02:07:06 +0000
commit0869f65b0b7e13b0d7f522decfc21244beb21c3a (patch)
tree0b482b2f4c0c5dfee4d9a076706e8330087be282
parent132ab8d035f2eb0ec75661526c6f342c5ec52159 (diff)
downloadHyprland-0869f65b0b7e13b0d7f522decfc21244beb21c3a.tar.gz
Hyprland-0869f65b0b7e13b0d7f522decfc21244beb21c3a.zip
input: add misc:hide_cursor_on_key_press
fixes #3045
-rw-r--r--src/config/ConfigManager.cpp1
-rw-r--r--src/render/Renderer.cpp77
-rw-r--r--src/render/Renderer.hpp9
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 <xf86drm.h>
}
-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<Hyprlang::INT>("general:cursor_inactive_timeout");
static auto PHIDEONTOUCH = CConfigValue<Hyprlang::INT>("misc:hide_cursor_on_touch");
+ static auto PHIDEONKEY = CConfigValue<Hyprlang::INT>("misc:hide_cursor_on_key_press");
- const auto PASSEDCURSORSECONDS = g_pInputManager->m_tmrLastCursorMovement.getSeconds();
-
- if (*PCURSORTIMEOUT > 0 || *PHIDEONTOUCH) {
- const bool HIDE = (*PCURSORTIMEOUT > 0 && *PCURSORTIMEOUT < PASSEDCURSORSECONDS) || (g_pInputManager->m_bLastInputTouch && *PHIDEONTOUCH);
+ if (*PCURSORTIMEOUT <= 0)
+ m_sCursorHiddenConditions.hiddenOnTimeout = false;
+ if (*PHIDEONTOUCH == 0)
+ m_sCursorHiddenConditions.hiddenOnTouch = false;
+ if (*PHIDEONKEY == 0)
+ m_sCursorHiddenConditions.hiddenOnKeyboard = false;
- if (HIDE && !m_bCursorHidden) {
- Debug::log(LOG, "Hiding the cursor (timeout)");
+ if (*PCURSORTIMEOUT > 0)
+ m_sCursorHiddenConditions.hiddenOnTimeout = *PCURSORTIMEOUT < g_pInputManager->m_tmrLastCursorMovement.getSeconds();
- for (auto& m : g_pCompositor->m_vMonitors)
- g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area?
+ const bool HIDE = m_sCursorHiddenConditions.hiddenOnTimeout || m_sCursorHiddenConditions.hiddenOnTouch || m_sCursorHiddenConditions.hiddenOnKeyboard;
- setCursorHidden(true);
+ if (HIDE == m_bCursorHidden)
+ return;
- } else if (!HIDE && m_bCursorHidden) {
- Debug::log(LOG, "Showing the cursor (timeout)");
+ if (HIDE) {
+ Debug::log(LOG, "Hiding the cursor (hl-mandated)");
- for (auto& m : g_pCompositor->m_vMonitors)
- g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area?
+ for (auto& m : g_pCompositor->m_vMonitors) {
+ if (m->output->software_cursor_locks == 0)
+ continue;
- 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<std::unique_ptr<STearingController>> 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<std::unique_ptr<CRenderbuffer>> m_vRenderbuffers;
friend class CHyprOpenGLImpl;