summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-05-12 12:13:02 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-05-12 12:13:02 +0200
commitd438bd970a621db7e158936459922f8165ccee78 (patch)
tree258047d4b46a2bfac53e637d25453533c0ab4ec4 /src
parentac7903f5217baa1a784341390c2848edbca33ccf (diff)
Added virtual pointer protocol
Diffstat (limited to 'src')
-rw-r--r--src/Compositor.cpp3
-rw-r--r--src/Compositor.hpp1
-rw-r--r--src/events/Devices.cpp14
-rw-r--r--src/events/Events.hpp4
-rw-r--r--src/helpers/WLClasses.hpp1
-rw-r--r--src/includes.hpp1
-rw-r--r--src/managers/InputManager.cpp31
7 files changed, 46 insertions, 9 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index df6257dd..ee1a0a1c 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -100,6 +100,8 @@ CCompositor::CCompositor() {
m_sWLRRelPointerMgr = wlr_relative_pointer_manager_v1_create(m_sWLDisplay);
m_sWLRVKeyboardMgr = wlr_virtual_keyboard_manager_v1_create(m_sWLDisplay);
+
+ m_sWLRVirtPtrMgr = wlr_virtual_pointer_manager_v1_create(m_sWLDisplay);
}
CCompositor::~CCompositor() {
@@ -132,6 +134,7 @@ void CCompositor::initAllSignals() {
addWLSignal(&m_sWLRInhibitMgr->events.deactivate, &Events::listen_InhibitDeactivate, m_sWLRInhibitMgr, "InhibitMgr");
addWLSignal(&m_sWLRPointerConstraints->events.new_constraint, &Events::listen_newConstraint, m_sWLRPointerConstraints, "PointerConstraints");
addWLSignal(&m_sWLRXDGDecoMgr->events.new_toplevel_decoration, &Events::listen_NewXDGDeco, m_sWLRXDGDecoMgr, "XDGDecoMgr");
+ addWLSignal(&m_sWLRVirtPtrMgr->events.new_virtual_pointer, &Events::listen_newVirtPtr, m_sWLRVirtPtrMgr, "VirtPtrMgr");
signal(SIGINT, handleCritSignal);
signal(SIGTERM, handleCritSignal);
diff --git a/src/Compositor.hpp b/src/Compositor.hpp
index 99ef411f..4256dead 100644
--- a/src/Compositor.hpp
+++ b/src/Compositor.hpp
@@ -55,6 +55,7 @@ public:
wlr_relative_pointer_manager_v1* m_sWLRRelPointerMgr;
wlr_server_decoration_manager* m_sWLRServerDecoMgr;
wlr_xdg_decoration_manager_v1* m_sWLRXDGDecoMgr;
+ wlr_virtual_pointer_manager_v1* m_sWLRVirtPtrMgr;
// ------------------------------------------------- //
diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp
index ade94b5d..11c27418 100644
--- a/src/events/Devices.cpp
+++ b/src/events/Devices.cpp
@@ -116,4 +116,18 @@ void Events::listener_destroyConstraint(void* owner, void* data) {
void Events::listener_setConstraintRegion(void* owner, void* data) {
// no
+}
+
+void Events::listener_newVirtPtr(wl_listener* listener, void* data) {
+ const auto EV = (wlr_virtual_pointer_v1_new_pointer_event*)data;
+ const auto POINTER = EV->new_pointer;
+ const auto DEVICE = &POINTER->pointer.base;
+
+ g_pInputManager->newMouse(DEVICE);
+}
+
+void Events::listener_destroyMouse(void* owner, void* data) {
+ const auto PMOUSE = (SMouse*)owner;
+
+ g_pInputManager->destroyMouse(PMOUSE->mouse);
} \ No newline at end of file
diff --git a/src/events/Events.hpp b/src/events/Events.hpp
index 67c91839..3b5d29ab 100644
--- a/src/events/Events.hpp
+++ b/src/events/Events.hpp
@@ -62,6 +62,10 @@ namespace Events {
LISTENER(newInput);
+ // Virt Ptr
+ LISTENER(newVirtPtr);
+ DYNLISTENFUNC(destroyMouse);
+
DYNLISTENFUNC(keyboardKey);
DYNLISTENFUNC(keyboardMod);
DYNLISTENFUNC(keyboardDestroy);
diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp
index 95aea982..544498f5 100644
--- a/src/helpers/WLClasses.hpp
+++ b/src/helpers/WLClasses.hpp
@@ -71,6 +71,7 @@ struct SMouse {
pixman_region32_t confinedTo;
DYNLISTENER(commitConstraint);
+ DYNLISTENER(destroyMouse);
bool operator==(const SMouse& b) {
return mouse == b.mouse;
diff --git a/src/includes.hpp b/src/includes.hpp
index d0298c08..960acd2e 100644
--- a/src/includes.hpp
+++ b/src/includes.hpp
@@ -72,6 +72,7 @@ extern "C" {
#include <wlr/types/wlr_output_damage.h>
#include <wlr/types/wlr_input_inhibitor.h>
#include <wlr/types/wlr_keyboard_shortcuts_inhibit_v1.h>
+#include <wlr/types/wlr_virtual_pointer_v1.h>
#include <wlr/util/log.h>
#include <wlr/xwayland.h>
#include <wlr/util/region.h>
diff --git a/src/managers/InputManager.cpp b/src/managers/InputManager.cpp
index b3b6db37..0719f90e 100644
--- a/src/managers/InputManager.cpp
+++ b/src/managers/InputManager.cpp
@@ -26,6 +26,11 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
if (!g_pCompositor->m_bReadyToProcess)
return;
+ if (!g_pCompositor->m_sSeat.mouse) {
+ Debug::log(ERR, "BUG THIS: Mouse move on mouse nullptr!");
+ return;
+ }
+
// update stuff
updateDragIcon();
@@ -139,14 +144,18 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
if (g_pCompositor->m_sSeat.mouse->currentConstraint) {
const auto CONSTRAINTWINDOW = g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse);
- const auto CONSTRAINTPOS = CONSTRAINTWINDOW->m_bIsX11 ? Vector2D(CONSTRAINTWINDOW->m_uSurface.xwayland->x, CONSTRAINTWINDOW->m_uSurface.xwayland->y) : CONSTRAINTWINDOW->m_vRealPosition.vec();
- const auto CONSTRAINTSIZE = CONSTRAINTWINDOW->m_bIsX11 ? Vector2D(CONSTRAINTWINDOW->m_uSurface.xwayland->width, CONSTRAINTWINDOW->m_uSurface.xwayland->height) : CONSTRAINTWINDOW->m_vRealSize.vec();
-
- if (VECINRECT(mouseCoords, CONSTRAINTPOS.x, CONSTRAINTPOS.y, CONSTRAINTPOS.x + CONSTRAINTSIZE.x, CONSTRAINTPOS.y + CONSTRAINTSIZE.y)) {
- // todo: this is incorrect, but it will work in most cases for now
- // i made this cuz i wanna play minecraft lol
- Vector2D deltaToMiddle = CONSTRAINTPOS + CONSTRAINTSIZE / 2.f - mouseCoords;
- wlr_cursor_move(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, deltaToMiddle.x, deltaToMiddle.y);
+ if (!CONSTRAINTWINDOW) {
+ g_pCompositor->m_sSeat.mouse->currentConstraint = nullptr;
+ } else {
+ const auto CONSTRAINTPOS = CONSTRAINTWINDOW->m_bIsX11 ? Vector2D(CONSTRAINTWINDOW->m_uSurface.xwayland->x, CONSTRAINTWINDOW->m_uSurface.xwayland->y) : CONSTRAINTWINDOW->m_vRealPosition.vec();
+ const auto CONSTRAINTSIZE = CONSTRAINTWINDOW->m_bIsX11 ? Vector2D(CONSTRAINTWINDOW->m_uSurface.xwayland->width, CONSTRAINTWINDOW->m_uSurface.xwayland->height) : CONSTRAINTWINDOW->m_vRealSize.vec();
+
+ if (VECINRECT(mouseCoords, CONSTRAINTPOS.x, CONSTRAINTPOS.y, CONSTRAINTPOS.x + CONSTRAINTSIZE.x, CONSTRAINTPOS.y + CONSTRAINTSIZE.y)) {
+ // todo: this is incorrect, but it will work in most cases for now
+ // i made this cuz i wanna play minecraft lol
+ Vector2D deltaToMiddle = CONSTRAINTPOS + CONSTRAINTSIZE / 2.f - mouseCoords;
+ wlr_cursor_move(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, deltaToMiddle.x, deltaToMiddle.y);
+ }
}
}
}
@@ -283,6 +292,8 @@ void CInputManager::newMouse(wlr_input_device* mouse) {
}
}
+ PMOUSE->hyprListener_destroyMouse.initCallback(&mouse->events.destroy, &Events::listener_destroyMouse, PMOUSE, "Mouse");
+
wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, mouse);
g_pCompositor->m_sSeat.mouse = PMOUSE;
@@ -302,11 +313,13 @@ void CInputManager::destroyMouse(wlr_input_device* mouse) {
for (auto& m : m_lMice) {
if (m.mouse == mouse) {
m_lMice.remove(m);
- return;
+ break;
}
}
g_pCompositor->m_sSeat.mouse = m_lMice.size() > 0 ? &m_lMice.front() : nullptr;
+
+ g_pCompositor->m_sSeat.mouse->currentConstraint = nullptr;
}
void CInputManager::onKeyboardKey(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) {