Quellcode durchsuchen

split mouse input by backend

vaxerski vor 3 Jahren
Ursprung
Commit
c5b27cd3dc

+ 3 - 1
CMakeLists.txt

@@ -75,7 +75,7 @@ if (ENABLE_WAYLAND)
     add_compile_definitions(ENABLE_WAYLAND)
     set(WAYLAND_SOURCES "src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h" "src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.cpp" "src/WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.cpp"
     "src/WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.h" "src/WallpaperEngine/Render/Drivers/Output/CWaylandOutput.cpp" "src/WallpaperEngine/Render/Drivers/Output/CWaylandOutput.h"
-    "xdg-shell-protocol.c" "wlr-layer-shell-unstable-v1-protocol.c")
+    "src/WallpaperEngine/Input/CWaylandMouseInput.cpp" "src/WallpaperEngine/Input/CWaylandMouseInput.h" "xdg-shell-protocol.c" "wlr-layer-shell-unstable-v1-protocol.c")
 else()
     set(WAYLAND_SOURCES "")
 endif()
@@ -142,6 +142,8 @@ add_executable(
     src/WallpaperEngine/Input/CInputContext.h
     src/WallpaperEngine/Input/CMouseInput.cpp
     src/WallpaperEngine/Input/CMouseInput.h
+    src/WallpaperEngine/Input/CGLFWMouseInput.cpp
+    src/WallpaperEngine/Input/CGLFWMouseInput.h
 
     src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h
     src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp

+ 21 - 0
src/WallpaperEngine/Input/CGLFWMouseInput.cpp

@@ -0,0 +1,21 @@
+#include <glm/common.hpp>
+#include "CGLFWMouseInput.h"
+
+using namespace WallpaperEngine::Input;
+
+CGLFWMouseInput::CGLFWMouseInput (GLFWwindow* window) : m_reportedPosition (), m_mousePosition (), m_window (window) {}
+
+void CGLFWMouseInput::update ()
+{
+    if (!m_window)
+        return;
+
+    // update current mouse position
+    glfwGetCursorPos (this->m_window, &this->m_mousePosition.x, &this->m_mousePosition.y);
+    // interpolate to the new position
+    this->m_reportedPosition = glm::mix (this->m_reportedPosition, this->m_mousePosition, 1.0);
+}
+
+glm::dvec2 CGLFWMouseInput::position() const {
+    return this->m_reportedPosition;
+}

+ 41 - 0
src/WallpaperEngine/Input/CGLFWMouseInput.h

@@ -0,0 +1,41 @@
+#pragma once
+
+#include "CMouseInput.h"
+
+#include <glm/vec2.hpp>
+#include "GLFW/glfw3.h"
+
+namespace WallpaperEngine::Input
+{
+    /**
+     * Handles mouse input for the background
+     */
+    class CGLFWMouseInput : public CMouseInput
+    {
+    public:
+        explicit CGLFWMouseInput(GLFWwindow* window);
+
+        /**
+         * Takes current mouse position and updates it
+         */
+        void update () override;
+
+        /**
+         * The virtual pointer's position
+         */
+        glm::dvec2 position () const override;
+
+    private:
+        /**
+         * The GLFW window to get mouse position from
+         */
+        GLFWwindow* m_window = nullptr;
+
+        /**
+         * The current mouse position
+         */
+        glm::dvec2 m_mousePosition;
+        glm::dvec2 m_reportedPosition;
+    };
+}
+

+ 10 - 6
src/WallpaperEngine/Input/CInputContext.cpp

@@ -1,28 +1,32 @@
 #include "CInputContext.h"
 #include "WallpaperEngine/Render/Drivers/CX11OpenGLDriver.h"
+#include "WallpaperEngine/Input/CGLFWMouseInput.h"
+#ifdef ENABLE_WAYLAND
 #include "WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h"
+#include "WallpaperEngine/Input/CWaylandMouseInput.h"
+#endif
 
 using namespace WallpaperEngine::Input;
 using namespace WallpaperEngine::Render::Drivers;
 
-CInputContext::CInputContext (CX11OpenGLDriver& videoDriver) :
-    m_mouse (videoDriver.getWindow ())
+CInputContext::CInputContext (CX11OpenGLDriver& videoDriver)
 {
+    m_mouse = std::make_unique<CGLFWMouseInput>(videoDriver.getWindow());
 }
 
 #ifdef ENABLE_WAYLAND
-CInputContext::CInputContext (CWaylandOpenGLDriver& videoDriver) :
-    m_mouse (&videoDriver)
+CInputContext::CInputContext (CWaylandOpenGLDriver& videoDriver)
 {
+    m_mouse = std::make_unique<CWaylandMouseInput>(&videoDriver);
 }
 #endif
 
 void CInputContext::update ()
 {
-    this->m_mouse.update ();
+    this->m_mouse->update ();
 }
 
 const CMouseInput& CInputContext::getMouseInput () const
 {
-    return this->m_mouse;
+    return *this->m_mouse.get();
 }

+ 1 - 1
src/WallpaperEngine/Input/CInputContext.h

@@ -25,6 +25,6 @@ namespace WallpaperEngine::Input
         [[nodiscard]] const CMouseInput& getMouseInput () const;
 
     private:
-        CMouseInput m_mouse;
+        std::unique_ptr<CMouseInput> m_mouse;
     };
 }

+ 1 - 26
src/WallpaperEngine/Input/CMouseInput.cpp

@@ -1,29 +1,4 @@
 #include <glm/common.hpp>
 #include "CMouseInput.h"
 
-using namespace WallpaperEngine::Input;
-
-CMouseInput::CMouseInput (GLFWwindow* window) : position (), m_mousePosition (), m_window (window) {}
-#ifdef ENABLE_WAYLAND
-CMouseInput::CMouseInput(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver* driver) {
-    waylandDriver = driver;
-}
-#endif
-
-void CMouseInput::update ()
-{
-    if (!m_window) {
-#ifdef ENABLE_WAYLAND
-        if (!waylandDriver || !waylandDriver->lastLSInFocus)
-            return;
-
-        this->position = waylandDriver->lastLSInFocus->mousePos;
-#endif
-        return;
-    }
-
-    // update current mouse position
-    glfwGetCursorPos (this->m_window, &this->m_mousePosition.x, &this->m_mousePosition.y);
-    // interpolate to the new position
-    this->position = glm::mix (this->position, this->m_mousePosition, 1.0);
-}
+using namespace WallpaperEngine::Input;

+ 2 - 25
src/WallpaperEngine/Input/CMouseInput.h

@@ -16,38 +16,15 @@ namespace WallpaperEngine::Input
     class CMouseInput
     {
     public:
-        explicit CMouseInput(GLFWwindow* window);
-#ifdef ENABLE_WAYLAND
-        explicit CMouseInput(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver* driver);
-#endif
-
         /**
          * Takes current mouse position and updates it
          */
-        void update ();
+        virtual void update () = 0;
 
         /**
          * The virtual pointer's position
          */
-        glm::dvec2 position;
-
-    private:
-        /**
-         * The GLFW window to get mouse position from
-         */
-        GLFWwindow* m_window = nullptr;
-
-        /**
-         * The current mouse position
-         */
-        glm::dvec2 m_mousePosition;
-
-#ifdef ENABLE_WAYLAND
-        /**
-         * Wayland: Driver
-        */
-        WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver* waylandDriver = nullptr;
-#endif
+        virtual glm::dvec2 position () const = 0;
     };
 }
 

+ 20 - 0
src/WallpaperEngine/Input/CWaylandMouseInput.cpp

@@ -0,0 +1,20 @@
+#include <glm/common.hpp>
+#include "CWaylandMouseInput.h"
+
+using namespace WallpaperEngine::Input;
+
+CWaylandMouseInput::CWaylandMouseInput(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver* driver) {
+    waylandDriver = driver;
+}
+
+void CWaylandMouseInput::update ()
+{
+    ;
+}
+
+glm::dvec2 CWaylandMouseInput::position() const {
+    if (!waylandDriver || !waylandDriver->lastLSInFocus)
+        return {0, 0};
+
+    return waylandDriver->lastLSInFocus->mousePos;
+}

+ 39 - 0
src/WallpaperEngine/Input/CWaylandMouseInput.h

@@ -0,0 +1,39 @@
+#pragma once
+
+#include "CMouseInput.h"
+#include "../Render/Drivers/CWaylandOpenGLDriver.h"
+
+#include <glm/vec2.hpp>
+#include "GLFW/glfw3.h"
+
+
+namespace WallpaperEngine::Input
+{
+    /**
+     * Handles mouse input for the background
+     */
+    class CWaylandMouseInput : public CMouseInput
+    {
+    public:
+        explicit CWaylandMouseInput(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver* driver);
+
+        /**
+         * Takes current mouse position and updates it
+         */
+        void update () override;
+
+        /**
+         * The virtual pointer's position
+         */
+        glm::dvec2 position () const override;
+
+    private:
+        /**
+         * Wayland: Driver
+        */
+        WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver* waylandDriver = nullptr;
+
+        glm::dvec2 pos;
+    };
+}
+

+ 1 - 1
src/WallpaperEngine/Render/CScene.cpp

@@ -248,7 +248,7 @@ void CScene::renderFrame (glm::ivec4 viewport)
 void CScene::updateMouse (glm::ivec4 viewport)
 {
     // update virtual mouse position first
-    glm::dvec2 position = this->getContext ().getInputContext ().getMouseInput ().position;
+    glm::dvec2 position = this->getContext ().getInputContext ().getMouseInput ().position();
     // TODO: PROPERLY TRANSLATE THESE TO WHAT'S VISIBLE ON SCREEN (FOR BACKGROUNDS THAT DO NOT EXACTLY FIT ON SCREEN)
 
     // rollover the position to the last