Skip to content

Commit

Permalink
chore: use proper defines for wayland buttons and improve click handl…
Browse files Browse the repository at this point in the history
…ing code
  • Loading branch information
Almamu committed Nov 8, 2024
1 parent ea9ca54 commit 7a4324b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 54 deletions.
5 changes: 2 additions & 3 deletions src/WallpaperEngine/Input/CMouseInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace WallpaperEngine::Input {
enum MouseClickStatus : int {
Waiting = 0,
Released = 1,
Clicked = 2
Released = 0,
Clicked = 1
};

/**
Expand Down
25 changes: 2 additions & 23 deletions src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 3 additions & 20 deletions src/WallpaperEngine/Input/Drivers/CWaylandMouseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
7 changes: 3 additions & 4 deletions src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/WallpaperEngine/Render/Wallpapers/CWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
3 changes: 3 additions & 0 deletions src/WallpaperEngine/Render/Wallpapers/CWeb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 7a4324b

Please sign in to comment.