mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-13 21:02:34 +08:00
chore: use proper defines for wayland buttons and improve click handling code
This commit is contained in:
parent
ea9ca543f9
commit
7a4324b2ff
@ -4,9 +4,8 @@
|
|||||||
|
|
||||||
namespace WallpaperEngine::Input {
|
namespace WallpaperEngine::Input {
|
||||||
enum MouseClickStatus : int {
|
enum MouseClickStatus : int {
|
||||||
Waiting = 0,
|
Released = 0,
|
||||||
Released = 1,
|
Clicked = 1
|
||||||
Clicked = 2
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,29 +19,8 @@ void CGLFWMouseInput::update () {
|
|||||||
int leftClickState = glfwGetMouseButton (this->m_driver->getWindow (), GLFW_MOUSE_BUTTON_LEFT);
|
int leftClickState = glfwGetMouseButton (this->m_driver->getWindow (), GLFW_MOUSE_BUTTON_LEFT);
|
||||||
int rightClickState = glfwGetMouseButton (this->m_driver->getWindow (), GLFW_MOUSE_BUTTON_RIGHT);
|
int rightClickState = glfwGetMouseButton (this->m_driver->getWindow (), GLFW_MOUSE_BUTTON_RIGHT);
|
||||||
|
|
||||||
if (leftClickState == GLFW_RELEASE) {
|
this->m_leftClick = leftClickState == GLFW_RELEASE ? MouseClickStatus::Released : MouseClickStatus::Clicked;
|
||||||
if (this->m_leftClick == MouseClickStatus::Released) {
|
this->m_rightClick = rightClickState == GLFW_RELEASE ? MouseClickStatus::Released : MouseClickStatus::Clicked;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update current mouse position
|
// update current mouse position
|
||||||
glfwGetCursorPos (this->m_driver->getWindow (), &this->m_mousePosition.x, &this->m_mousePosition.y);
|
glfwGetCursorPos (this->m_driver->getWindow (), &this->m_mousePosition.x, &this->m_mousePosition.y);
|
||||||
|
@ -7,24 +7,7 @@ CWaylandMouseInput::CWaylandMouseInput (WallpaperEngine::Render::Drivers::CWayla
|
|||||||
waylandDriver (driver),
|
waylandDriver (driver),
|
||||||
m_pos () {}
|
m_pos () {}
|
||||||
|
|
||||||
void CWaylandMouseInput::update () {
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::dvec2 CWaylandMouseInput::position () const {
|
glm::dvec2 CWaylandMouseInput::position () const {
|
||||||
if (!this->waylandDriver->getApp ().getContext ().settings.mouse.enabled) {
|
if (!this->waylandDriver->getApp ().getContext ().settings.mouse.enabled) {
|
||||||
@ -41,12 +24,12 @@ WallpaperEngine::Input::MouseClickStatus CWaylandMouseInput::leftClick () const
|
|||||||
if (waylandDriver->viewportInFocus && waylandDriver->viewportInFocus->rendering)
|
if (waylandDriver->viewportInFocus && waylandDriver->viewportInFocus->rendering)
|
||||||
return waylandDriver->viewportInFocus->leftClick;
|
return waylandDriver->viewportInFocus->leftClick;
|
||||||
|
|
||||||
return MouseClickStatus::Waiting;
|
return MouseClickStatus::Released;
|
||||||
}
|
}
|
||||||
|
|
||||||
WallpaperEngine::Input::MouseClickStatus CWaylandMouseInput::rightClick () const {
|
WallpaperEngine::Input::MouseClickStatus CWaylandMouseInput::rightClick () const {
|
||||||
if (waylandDriver->viewportInFocus && waylandDriver->viewportInFocus->rendering)
|
if (waylandDriver->viewportInFocus && waylandDriver->viewportInFocus->rendering)
|
||||||
return waylandDriver->viewportInFocus->rightClick;
|
return waylandDriver->viewportInFocus->rightClick;
|
||||||
|
|
||||||
return MouseClickStatus::Waiting;
|
return MouseClickStatus::Released;
|
||||||
}
|
}
|
@ -9,6 +9,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
||||||
#include "xdg-shell-protocol.h"
|
#include "xdg-shell-protocol.h"
|
||||||
|
#include <linux/input-event-codes.h>
|
||||||
}
|
}
|
||||||
#undef class
|
#undef class
|
||||||
#undef namespace
|
#undef namespace
|
||||||
@ -56,15 +57,13 @@ static void handlePointerButton (void* data, struct wl_pointer* wl_pointer, uint
|
|||||||
if (!driver->viewportInFocus)
|
if (!driver->viewportInFocus)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sLog.debug("Button", button, " state ", button_state);
|
if (button == BTN_LEFT) {
|
||||||
|
|
||||||
if (button == 272) {
|
|
||||||
if (button_state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
if (button_state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||||
driver->viewportInFocus->leftClick = WallpaperEngine::Input::MouseClickStatus::Clicked;
|
driver->viewportInFocus->leftClick = WallpaperEngine::Input::MouseClickStatus::Clicked;
|
||||||
} else if (button_state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
} else if (button_state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
||||||
driver->viewportInFocus->leftClick = WallpaperEngine::Input::MouseClickStatus::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) {
|
if (button_state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||||
driver->viewportInFocus->rightClick = WallpaperEngine::Input::MouseClickStatus::Clicked;
|
driver->viewportInFocus->rightClick = WallpaperEngine::Input::MouseClickStatus::Clicked;
|
||||||
} else if (button_state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
} else if (button_state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
||||||
|
@ -45,8 +45,8 @@ class CWaylandOutputViewport final : public COutputViewport {
|
|||||||
zwlr_layer_surface_v1* layerSurface = nullptr;
|
zwlr_layer_surface_v1* layerSurface = nullptr;
|
||||||
wl_callback* frameCallback = nullptr;
|
wl_callback* frameCallback = nullptr;
|
||||||
glm::dvec2 mousePos = {0, 0};
|
glm::dvec2 mousePos = {0, 0};
|
||||||
WallpaperEngine::Input::MouseClickStatus leftClick = WallpaperEngine::Input::MouseClickStatus::Waiting;
|
WallpaperEngine::Input::MouseClickStatus leftClick = WallpaperEngine::Input::MouseClickStatus::Released;
|
||||||
WallpaperEngine::Input::MouseClickStatus rightClick = WallpaperEngine::Input::MouseClickStatus::Waiting;
|
WallpaperEngine::Input::MouseClickStatus rightClick = WallpaperEngine::Input::MouseClickStatus::Released;
|
||||||
wl_cursor* pointer = nullptr;
|
wl_cursor* pointer = nullptr;
|
||||||
wl_surface* cursorSurface = nullptr;
|
wl_surface* cursorSurface = nullptr;
|
||||||
bool callbackInitialized = false;
|
bool callbackInitialized = false;
|
||||||
|
@ -93,13 +93,16 @@ void CWeb::updateMouse (glm::ivec4 viewport) {
|
|||||||
m_browser->GetHost ()->SendMouseMoveEvent (evt, false);
|
m_browser->GetHost ()->SendMouseMoveEvent (evt, false);
|
||||||
|
|
||||||
// TODO: ANY OTHER MOUSE EVENTS TO SEND?
|
// 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);
|
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);
|
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 () {
|
CWeb::~CWeb () {
|
||||||
|
@ -109,6 +109,9 @@ namespace WallpaperEngine::Render
|
|||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
|
|
||||||
|
WallpaperEngine::Input::MouseClickStatus m_leftClick;
|
||||||
|
WallpaperEngine::Input::MouseClickStatus m_rightClick;
|
||||||
|
|
||||||
glm::vec2 m_mousePosition;
|
glm::vec2 m_mousePosition;
|
||||||
glm::vec2 m_mousePositionLast;
|
glm::vec2 m_mousePositionLast;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user