From 21c38d9fd1d3d89376c870cec5c5e5dc7086bc3c Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Sat, 23 Sep 2023 18:20:35 +0200 Subject: [PATCH] Add support for disabling mouse interactions with the background (#176) Signed-off-by: Alexis Maiquez --- .../Application/CApplicationContext.cpp | 10 ++++++++++ src/WallpaperEngine/Application/CApplicationContext.h | 9 +++++++++ src/WallpaperEngine/Application/CApplicationState.h | 5 +++++ src/WallpaperEngine/Input/CMouseInput.h | 2 +- src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp | 6 ++++++ src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.h | 2 +- .../Input/Drivers/CWaylandMouseInput.cpp | 5 +++++ src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.h | 2 +- .../Render/Drivers/CWaylandOpenGLDriver.h | 1 + 9 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/WallpaperEngine/Application/CApplicationContext.cpp b/src/WallpaperEngine/Application/CApplicationContext.cpp index 857a995d..a4665c06 100644 --- a/src/WallpaperEngine/Application/CApplicationContext.cpp +++ b/src/WallpaperEngine/Application/CApplicationContext.cpp @@ -27,6 +27,7 @@ struct option long_options[] = { { "set-property", required_argument, nullptr, 'o' }, { "noautomute", no_argument, nullptr, 'm' }, { "no-fullscreen-pause", no_argument, nullptr, 'n' }, + { "disable-mouse", no_argument, nullptr, 'e' }, { nullptr, 0, nullptr, 0 } }; @@ -72,6 +73,10 @@ CApplicationContext::CApplicationContext (int argc, char* argv[]) .volume = 15, .automute = true }, + .mouse = + { + .enabled = true, + }, .screenshot = { .take = false, @@ -185,6 +190,10 @@ CApplicationContext::CApplicationContext (int argc, char* argv[]) this->settings.audio.automute = false; break; + case 'e': + this->settings.mouse.enabled = false; + break; + default: sLog.out ("Default on path parsing: ", optarg); break; @@ -280,4 +289,5 @@ void CApplicationContext::printHelp (const char* route) sLog.out ("\t--list-properties\t\t\tList all the available properties and their possible values"); sLog.out ("\t--set-property \tOverrides the default value of the given property"); sLog.out ("\t--no-fullscreen-pause\tPrevents the background pausing when an app is fullscreen"); + sLog.out ("\t--disable-mouse\tDisables mouse interactions"); } \ No newline at end of file diff --git a/src/WallpaperEngine/Application/CApplicationContext.h b/src/WallpaperEngine/Application/CApplicationContext.h index 5d37fbf4..92d77507 100644 --- a/src/WallpaperEngine/Application/CApplicationContext.h +++ b/src/WallpaperEngine/Application/CApplicationContext.h @@ -84,6 +84,15 @@ namespace WallpaperEngine::Application bool automute; } audio; + /** + * Mouse input settings + */ + struct + { + /** If the mouse movement is enabled */ + bool enabled; + } mouse; + /** * Screenshot settings */ diff --git a/src/WallpaperEngine/Application/CApplicationState.h b/src/WallpaperEngine/Application/CApplicationState.h index 173ea529..014e9c93 100644 --- a/src/WallpaperEngine/Application/CApplicationState.h +++ b/src/WallpaperEngine/Application/CApplicationState.h @@ -20,5 +20,10 @@ namespace WallpaperEngine::Application bool enabled; int volume; } audio{}; + + struct + { + bool enabled; + } mouse{}; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Input/CMouseInput.h b/src/WallpaperEngine/Input/CMouseInput.h index 06021f6d..2624b93f 100644 --- a/src/WallpaperEngine/Input/CMouseInput.h +++ b/src/WallpaperEngine/Input/CMouseInput.h @@ -18,7 +18,7 @@ namespace WallpaperEngine::Input /** * The virtual pointer's position */ - virtual glm::dvec2 position () const = 0; + [[nodiscard]] virtual glm::dvec2 position () const = 0; }; } diff --git a/src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp b/src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp index ffc88360..1a0f06ee 100644 --- a/src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp +++ b/src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp @@ -12,6 +12,12 @@ CGLFWMouseInput::CGLFWMouseInput (Render::Drivers::CX11OpenGLDriver* driver) : void CGLFWMouseInput::update () { + if (!this->m_driver->getApp ().getContext ().settings.mouse.enabled) + { + this->m_reportedPosition = {0, 0}; + return; + } + // update current mouse position glfwGetCursorPos (this->m_driver->getWindow (), &this->m_mousePosition.x, &this->m_mousePosition.y); // interpolate to the new position diff --git a/src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.h b/src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.h index 73bf9d13..874917a5 100644 --- a/src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.h +++ b/src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.h @@ -27,7 +27,7 @@ namespace WallpaperEngine::Input::Drivers /** * The virtual pointer's position */ - glm::dvec2 position () const override; + [[nodiscard]] glm::dvec2 position () const override; private: Render::Drivers::CX11OpenGLDriver* m_driver; diff --git a/src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.cpp b/src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.cpp index 2261996e..296a10fa 100644 --- a/src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.cpp +++ b/src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.cpp @@ -14,6 +14,11 @@ void CWaylandMouseInput::update () glm::dvec2 CWaylandMouseInput::position() const { + if (!this->waylandDriver->getApp().getContext ().settings.mouse.enabled) + { + return {0, 0}; + } + if (waylandDriver->viewportInFocus && waylandDriver->viewportInFocus->rendering) return waylandDriver->viewportInFocus->mousePos; diff --git a/src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.h b/src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.h index dd83a617..d6d91098 100644 --- a/src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.h +++ b/src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.h @@ -26,7 +26,7 @@ namespace WallpaperEngine::Input::Drivers /** * The virtual pointer's position */ - glm::dvec2 position () const override; + [[nodiscard]] glm::dvec2 position () const override; private: /** diff --git a/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h b/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h index 4c7e3d0f..f6c71b04 100644 --- a/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h +++ b/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h @@ -10,6 +10,7 @@ #include "WallpaperEngine/Render/Drivers/CVideoDriver.h" #include "WallpaperEngine/Application/CApplicationContext.h" +#include "WallpaperEngine/Application/CWallpaperApplication.h" #include "WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.h" #include "WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.h" #include "WallpaperEngine/Render/Drivers/Output/CWaylandOutput.h"