Просмотр исходного кода

chore: use proper defines for wayland buttons and improve click handling code

Almamu 1 год назад
Родитель
Сommit
7a4324b2ff

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

@@ -4,9 +4,8 @@
 
 namespace WallpaperEngine::Input {
 enum MouseClickStatus : int {
-    Waiting = 0,
-    Released = 1,
-    Clicked = 2
+    Released = 0,
+    Clicked = 1
 };
 
 /**

+ 2 - 23
src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp

@@ -19,29 +19,8 @@ void CGLFWMouseInput::update () {
     int leftClickState = glfwGetMouseButton (this->m_driver->getWindow (), GLFW_MOUSE_BUTTON_LEFT);
     int rightClickState = glfwGetMouseButton (this->m_driver->getWindow (), GLFW_MOUSE_BUTTON_RIGHT);
 
-    if (leftClickState == GLFW_RELEASE) {
-        if (this->m_leftClick == MouseClickStatus::Released) {
-            this->m_leftClick = MouseClickStatus::Waiting;
-        }
-
-        if (this->m_leftClick == MouseClickStatus::Clicked) {
-            this->m_leftClick = MouseClickStatus::Released;
-        }
-    } else {
-        this->m_leftClick = MouseClickStatus::Clicked;
-    }
-
-    if (rightClickState == GLFW_RELEASE) {
-        if (this->m_rightClick == MouseClickStatus::Released) {
-            this->m_rightClick = MouseClickStatus::Waiting;
-        }
-
-        if (this->m_rightClick == MouseClickStatus::Clicked) {
-            this->m_rightClick = MouseClickStatus::Released;
-        }
-    } else {
-        this->m_rightClick = MouseClickStatus::Clicked;
-    }
+    this->m_leftClick = leftClickState == GLFW_RELEASE ? MouseClickStatus::Released : MouseClickStatus::Clicked;
+    this->m_rightClick = rightClickState == GLFW_RELEASE ? MouseClickStatus::Released : MouseClickStatus::Clicked;
 
     // update current mouse position
     glfwGetCursorPos (this->m_driver->getWindow (), &this->m_mousePosition.x, &this->m_mousePosition.y);

+ 3 - 20
src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.cpp

@@ -7,24 +7,7 @@ CWaylandMouseInput::CWaylandMouseInput (WallpaperEngine::Render::Drivers::CWayla
     waylandDriver (driver),
     m_pos () {}
 
-void CWaylandMouseInput::update () {
-    if (!this->waylandDriver->getApp ().getContext ().settings.mouse.enabled) {
-        return;
-    }
-
-    if (!waylandDriver->viewportInFocus || !waylandDriver->viewportInFocus->rendering) {
-        return;
-    }
-
-    // TODO: IS CLEARING STATE HERE A GOOD SOLUTION? OR SHOULD BE HANDLED SOMEWHERE ELSE?
-    if (waylandDriver->viewportInFocus->leftClick == MouseClickStatus::Released) {
-        waylandDriver->viewportInFocus->leftClick = MouseClickStatus::Waiting;
-    }
-
-    if (waylandDriver->viewportInFocus->rightClick == MouseClickStatus::Released) {
-        waylandDriver->viewportInFocus->rightClick = MouseClickStatus::Waiting;
-    }
-}
+void CWaylandMouseInput::update () {}
 
 glm::dvec2 CWaylandMouseInput::position () const {
     if (!this->waylandDriver->getApp ().getContext ().settings.mouse.enabled) {
@@ -41,12 +24,12 @@ WallpaperEngine::Input::MouseClickStatus CWaylandMouseInput::leftClick () const
     if (waylandDriver->viewportInFocus && waylandDriver->viewportInFocus->rendering)
         return waylandDriver->viewportInFocus->leftClick;
 
-    return MouseClickStatus::Waiting;
+    return MouseClickStatus::Released;
 }
 
 WallpaperEngine::Input::MouseClickStatus CWaylandMouseInput::rightClick () const {
     if (waylandDriver->viewportInFocus && waylandDriver->viewportInFocus->rendering)
         return waylandDriver->viewportInFocus->rightClick;
 
-    return MouseClickStatus::Waiting;
+    return MouseClickStatus::Released;
 }

+ 3 - 4
src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.cpp

@@ -9,6 +9,7 @@
 extern "C" {
 #include "wlr-layer-shell-unstable-v1-protocol.h"
 #include "xdg-shell-protocol.h"
+#include <linux/input-event-codes.h>
 }
 #undef class
 #undef namespace
@@ -56,15 +57,13 @@ static void handlePointerButton (void* data, struct wl_pointer* wl_pointer, uint
     if (!driver->viewportInFocus)
         return;
 
-    sLog.debug("Button", button, " state ", button_state);
-
-    if (button == 272) {
+    if (button == BTN_LEFT) {
         if (button_state == WL_POINTER_BUTTON_STATE_PRESSED) {
             driver->viewportInFocus->leftClick = WallpaperEngine::Input::MouseClickStatus::Clicked;
         } else if (button_state == WL_POINTER_BUTTON_STATE_RELEASED) {
             driver->viewportInFocus->leftClick = WallpaperEngine::Input::MouseClickStatus::Released;
         }
-    } else if (button == 273) {
+    } else if (button == BTN_RIGHT) {
         if (button_state == WL_POINTER_BUTTON_STATE_PRESSED) {
             driver->viewportInFocus->rightClick = WallpaperEngine::Input::MouseClickStatus::Clicked;
         } else if (button_state == WL_POINTER_BUTTON_STATE_RELEASED) {

+ 2 - 2
src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.h

@@ -45,8 +45,8 @@ class CWaylandOutputViewport final : public COutputViewport {
     zwlr_layer_surface_v1* layerSurface = nullptr;
     wl_callback* frameCallback = nullptr;
     glm::dvec2 mousePos = {0, 0};
-    WallpaperEngine::Input::MouseClickStatus leftClick = WallpaperEngine::Input::MouseClickStatus::Waiting;
-    WallpaperEngine::Input::MouseClickStatus rightClick = WallpaperEngine::Input::MouseClickStatus::Waiting;
+    WallpaperEngine::Input::MouseClickStatus leftClick = WallpaperEngine::Input::MouseClickStatus::Released;
+    WallpaperEngine::Input::MouseClickStatus rightClick = WallpaperEngine::Input::MouseClickStatus::Released;
     wl_cursor* pointer = nullptr;
     wl_surface* cursorSurface = nullptr;
     bool callbackInitialized = false;

+ 5 - 2
src/WallpaperEngine/Render/Wallpapers/CWeb.cpp

@@ -93,13 +93,16 @@ void CWeb::updateMouse (glm::ivec4 viewport) {
     m_browser->GetHost ()->SendMouseMoveEvent (evt, false);
 
     // TODO: ANY OTHER MOUSE EVENTS TO SEND?
-    if (leftClick != WallpaperEngine::Input::MouseClickStatus::Waiting) {
+    if (leftClick != this->m_leftClick) {
         m_browser->GetHost ()->SendMouseClickEvent (evt, CefBrowserHost::MouseButtonType::MBT_LEFT, leftClick == WallpaperEngine::Input::MouseClickStatus::Released, 1);
     }
 
-    if (rightClick != WallpaperEngine::Input::MouseClickStatus::Waiting) {
+    if (rightClick != this->m_rightClick) {
         m_browser->GetHost ()->SendMouseClickEvent (evt, CefBrowserHost::MouseButtonType::MBT_RIGHT, rightClick == WallpaperEngine::Input::MouseClickStatus::Released, 1);
     }
+
+    this->m_leftClick = leftClick;
+    this->m_rightClick = rightClick;
 }
 
 CWeb::~CWeb () {

+ 3 - 0
src/WallpaperEngine/Render/Wallpapers/CWeb.h

@@ -109,6 +109,9 @@ namespace WallpaperEngine::Render
             int m_width;
             int m_height;
 
+            WallpaperEngine::Input::MouseClickStatus m_leftClick;
+            WallpaperEngine::Input::MouseClickStatus m_rightClick;
+
             glm::vec2 m_mousePosition;
             glm::vec2 m_mousePositionLast;
     };