diff options
author | vaxerski <[email protected]> | 2022-06-24 23:27:02 +0200 |
---|---|---|
committer | vaxerski <[email protected]> | 2022-06-24 23:27:02 +0200 |
commit | 72c86b99eb87b23c11fdc795ec6f3668f283b95c (patch) | |
tree | 2d612e505a465b29f2d95a500d77a2f91485ea50 | |
parent | eb13be1240dfe83b42e26621069aeb09ecf39b66 (diff) | |
download | Hyprland-72c86b99eb87b23c11fdc795ec6f3668f283b95c.tar.gz Hyprland-72c86b99eb87b23c11fdc795ec6f3668f283b95c.zip |
added general:cursor_inactive_timeout
-rw-r--r-- | src/config/ConfigManager.cpp | 1 | ||||
-rw-r--r-- | src/events/Monitors.cpp | 2 | ||||
-rw-r--r-- | src/helpers/Timer.cpp | 17 | ||||
-rw-r--r-- | src/helpers/Timer.hpp | 15 | ||||
-rw-r--r-- | src/managers/input/InputManager.cpp | 8 | ||||
-rw-r--r-- | src/managers/input/InputManager.hpp | 3 | ||||
-rw-r--r-- | src/render/Renderer.cpp | 30 | ||||
-rw-r--r-- | src/render/Renderer.hpp | 3 |
8 files changed, 79 insertions, 0 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 711ce04c..966ef29d 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -33,6 +33,7 @@ void CConfigManager::setDefaultVars() { configValues["general:gaps_out"].intValue = 20; configValues["general:col.active_border"].intValue = 0xffffffff; configValues["general:col.inactive_border"].intValue = 0xff444444; + configValues["general:cursor_inactive_timeout"].intValue = 0; configValues["debug:int"].intValue = 0; configValues["debug:log_damage"].intValue = 0; diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index afbc0745..9da5f779 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -193,6 +193,8 @@ void Events::listener_monitorFrame(void* owner, void* data) { if (g_pConfigManager->m_bWantsMonitorReload) g_pConfigManager->performMonitorReload(); + + g_pHyprRenderer->ensureCursorRenderingMode(); // so that the cursor gets hidden/shown if the user requested timeouts } if (PMONITOR->framesToSkip > 0) { diff --git a/src/helpers/Timer.cpp b/src/helpers/Timer.cpp new file mode 100644 index 00000000..33162d30 --- /dev/null +++ b/src/helpers/Timer.cpp @@ -0,0 +1,17 @@ +#include "Timer.hpp" + +void CTimer::reset() { + m_tpLastReset = std::chrono::system_clock::now(); +} + +std::chrono::system_clock::duration CTimer::getDuration() { + return std::chrono::system_clock::now() - m_tpLastReset; +} + +int CTimer::getMillis() { + return std::chrono::duration_cast<std::chrono::milliseconds>(getDuration()).count(); +} + +float CTimer::getSeconds() { + return std::chrono::duration_cast<std::chrono::milliseconds>(getDuration()).count() / 1000.f; +}
\ No newline at end of file diff --git a/src/helpers/Timer.hpp b/src/helpers/Timer.hpp new file mode 100644 index 00000000..2e8d6adc --- /dev/null +++ b/src/helpers/Timer.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "../defines.hpp" + +class CTimer { +public: + void reset(); + float getSeconds(); + int getMillis(); + +private: + std::chrono::system_clock::time_point m_tpLastReset; + + std::chrono::system_clock::duration getDuration(); +};
\ No newline at end of file diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 46d6338e..d58a9986 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -14,12 +14,16 @@ void CInputManager::onMouseMoved(wlr_pointer_motion_event* e) { wlr_cursor_move(g_pCompositor->m_sWLRCursor, &e->pointer->base, DELTA.x * sensitivity, DELTA.y * sensitivity); mouseMoveUnified(e->time_msec); + + m_tmrLastCursorMovement.reset(); } void CInputManager::onMouseWarp(wlr_pointer_motion_absolute_event* e) { wlr_cursor_warp_absolute(g_pCompositor->m_sWLRCursor, &e->pointer->base, e->x, e->y); mouseMoveUnified(e->time_msec); + + m_tmrLastCursorMovement.reset(); } void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { @@ -205,6 +209,8 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { void CInputManager::onMouseButton(wlr_pointer_button_event* e) { wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sSeat.seat); + m_tmrLastCursorMovement.reset(); + const auto PKEYBOARD = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat); if (!PKEYBOARD) { // ??? @@ -383,6 +389,8 @@ void CInputManager::newMouse(wlr_input_device* mouse) { g_pCompositor->m_sSeat.mouse = PMOUSE; + m_tmrLastCursorMovement.reset(); + Debug::log(LOG, "New mouse created, pointer WLR: %x", mouse); } diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index ef962bdd..73c59b8f 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -4,6 +4,7 @@ #include <list> #include "../../helpers/WLClasses.hpp" #include "../../Window.hpp" +#include "../../helpers/Timer.hpp" class CInputManager { public: @@ -52,6 +53,8 @@ public: SKeyboard* m_pActiveKeyboard = nullptr; + CTimer m_tmrLastCursorMovement; + private: uint32_t m_uiCapabilities = 0; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 4525dde8..a917a1cc 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -754,3 +754,33 @@ void CHyprRenderer::applyMonitorRule(SMonitor* pMonitor, SMonitorRule* pMonitorR // frame skip pMonitor->framesToSkip = 1; } + +void CHyprRenderer::ensureCursorRenderingMode() { + static auto *const PCURSORTIMEOUT = &g_pConfigManager->getConfigValuePtr("general:cursor_inactive_timeout")->intValue; + + const auto PASSEDCURSORSECONDS = g_pInputManager->m_tmrLastCursorMovement.getSeconds(); + + if (*PCURSORTIMEOUT > 0) { + if (*PCURSORTIMEOUT < PASSEDCURSORSECONDS && m_bHasARenderedCursor) { + m_bHasARenderedCursor = false; + + wlr_cursor_set_surface(g_pCompositor->m_sWLRCursor, nullptr, 0, 0); // hide + + Debug::log(LOG, "Hiding the cursor (timeout)"); + + for (auto& m : g_pCompositor->m_lMonitors) + g_pHyprRenderer->damageMonitor(&m); // TODO: maybe just damage the cursor area? + } else if (*PCURSORTIMEOUT > PASSEDCURSORSECONDS && !m_bHasARenderedCursor) { + m_bHasARenderedCursor = true; + + wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", g_pCompositor->m_sWLRCursor); + + Debug::log(LOG, "Showing the cursor (timeout)"); + + for (auto& m : g_pCompositor->m_lMonitors) + g_pHyprRenderer->damageMonitor(&m); // TODO: maybe just damage the cursor area? + } + } else { + m_bHasARenderedCursor = true; + } +}
\ No newline at end of file diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 24caa09d..73508623 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -31,6 +31,7 @@ public: void applyMonitorRule(SMonitor*, SMonitorRule*, bool force = false); bool shouldRenderWindow(CWindow*, SMonitor*); bool shouldRenderWindow(CWindow*); + void ensureCursorRenderingMode(); DAMAGETRACKINGMODES damageTrackingModeFromStr(const std::string&); @@ -41,6 +42,8 @@ private: void renderLayer(SLayerSurface*, SMonitor*, timespec*); void renderDragIcon(SMonitor*, timespec*); + bool m_bHasARenderedCursor = true; + friend class CHyprOpenGLImpl; }; |