split mouse input by backend

This commit is contained in:
vaxerski 2023-04-21 00:17:55 +01:00
parent bab0e7b65f
commit c5b27cd3dc
10 changed files with 139 additions and 60 deletions

View File

@ -75,7 +75,7 @@ if (ENABLE_WAYLAND)
add_compile_definitions(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" 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" "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() else()
set(WAYLAND_SOURCES "") set(WAYLAND_SOURCES "")
endif() endif()
@ -142,6 +142,8 @@ add_executable(
src/WallpaperEngine/Input/CInputContext.h src/WallpaperEngine/Input/CInputContext.h
src/WallpaperEngine/Input/CMouseInput.cpp src/WallpaperEngine/Input/CMouseInput.cpp
src/WallpaperEngine/Input/CMouseInput.h 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.h
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp

View File

@ -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;
}

View File

@ -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;
};
}

View File

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

View File

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

View File

@ -2,28 +2,3 @@
#include "CMouseInput.h" #include "CMouseInput.h"
using namespace WallpaperEngine::Input; 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);
}

View File

@ -16,38 +16,15 @@ namespace WallpaperEngine::Input
class CMouseInput class CMouseInput
{ {
public: public:
explicit CMouseInput(GLFWwindow* window);
#ifdef ENABLE_WAYLAND
explicit CMouseInput(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver* driver);
#endif
/** /**
* Takes current mouse position and updates it * Takes current mouse position and updates it
*/ */
void update (); virtual void update () = 0;
/** /**
* The virtual pointer's position * The virtual pointer's position
*/ */
glm::dvec2 position; virtual glm::dvec2 position () const = 0;
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
}; };
} }

View File

@ -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;
}

View File

@ -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;
};
}

View File

@ -248,7 +248,7 @@ void CScene::renderFrame (glm::ivec4 viewport)
void CScene::updateMouse (glm::ivec4 viewport) void CScene::updateMouse (glm::ivec4 viewport)
{ {
// update virtual mouse position first // 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) // 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 // rollover the position to the last