summaryrefslogtreecommitdiff
path: root/src/events/Devices.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-04-17 21:40:04 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-04-17 21:40:04 +0200
commit7b1eaca84014d88a420bcbd3f97467f74e82ab33 (patch)
treee5147e4b6eeed31a9e1827e582e79852ed74e5f9 /src/events/Devices.cpp
parentb0f5e4ab5656fb3b72efa7ce646d4b47ae82b814 (diff)
Implemented mouse constraints
has some todos but mostly works
Diffstat (limited to 'src/events/Devices.cpp')
-rw-r--r--src/events/Devices.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp
index 57fb221f..ade94b5d 100644
--- a/src/events/Devices.cpp
+++ b/src/events/Devices.cpp
@@ -80,4 +80,40 @@ void Events::listener_newInput(wl_listener* listener, void* data) {
uint32_t capabilities = WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD;
wlr_seat_set_capabilities(g_pCompositor->m_sSeat.seat, capabilities);
+}
+
+void Events::listener_newConstraint(wl_listener* listener, void* data) {
+ const auto PCONSTRAINT = (wlr_pointer_constraint_v1*)data;
+
+ Debug::log(LOG, "New mouse constraint at %x", PCONSTRAINT);
+
+ g_pInputManager->m_lConstraints.emplace_back();
+ const auto CONSTRAINT = &g_pInputManager->m_lConstraints.back();
+
+ CONSTRAINT->pMouse = g_pCompositor->m_sSeat.mouse;
+ CONSTRAINT->constraint = PCONSTRAINT;
+
+ CONSTRAINT->hyprListener_destroyConstraint.initCallback(&PCONSTRAINT->events.destroy, &Events::listener_destroyConstraint, CONSTRAINT, "Constraint");
+ CONSTRAINT->hyprListener_setConstraintRegion.initCallback(&PCONSTRAINT->events.set_region, &Events::listener_setConstraintRegion, CONSTRAINT, "Constraint");
+
+ if (g_pCompositor->m_pLastFocus == PCONSTRAINT->surface) {
+ g_pInputManager->constrainMouse(CONSTRAINT->pMouse, PCONSTRAINT);
+ }
+}
+
+void Events::listener_destroyConstraint(void* owner, void* data) {
+ const auto PCONSTRAINT = (SConstraint*)owner;
+
+ if (PCONSTRAINT->pMouse->currentConstraint == PCONSTRAINT->constraint) {
+ PCONSTRAINT->pMouse->hyprListener_commitConstraint.removeCallback();
+ PCONSTRAINT->pMouse->currentConstraint = nullptr;
+ }
+
+ Debug::log(LOG, "Unconstrained mouse from %x", PCONSTRAINT->constraint);
+
+ g_pInputManager->m_lConstraints.remove(*PCONSTRAINT);
+}
+
+void Events::listener_setConstraintRegion(void* owner, void* data) {
+ // no
} \ No newline at end of file