summaryrefslogtreecommitdiff
path: root/src/events
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2024-03-02 21:04:55 +0000
committerGitHub <noreply@github.com>2024-03-02 21:04:55 +0000
commitd72ea5f2a7fdb0d0a7bf914412327195b05199b0 (patch)
tree0ebc3bb4c8320e88cfa9010d314122c9533dcc0e /src/events
parent328ab431655f207a5ee59737291f8e8d85fab992 (diff)
input: Rewritten pointer constraints (#4889)
* rewritten constraints * send pointer enter on activate if not pointer focus * minor cleanup * simulate movement on commit * don't ignore oneshot prop * various fixes * dont send motion on confined * update pos hint on region change
Diffstat (limited to 'src/events')
-rw-r--r--src/events/Devices.cpp40
-rw-r--r--src/events/Events.hpp3
-rw-r--r--src/events/Layers.cpp7
-rw-r--r--src/events/Windows.cpp7
4 files changed, 12 insertions, 45 deletions
diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp
index 1ba6cad4..64050320 100644
--- a/src/events/Devices.cpp
+++ b/src/events/Devices.cpp
@@ -97,44 +97,14 @@ void Events::listener_newConstraint(wl_listener* listener, void* data) {
Debug::log(LOG, "New mouse constraint at {:x}", (uintptr_t)PCONSTRAINT);
- g_pInputManager->m_lConstraints.emplace_back();
- const auto CONSTRAINT = &g_pInputManager->m_lConstraints.back();
+ const auto SURFACE = CWLSurface::surfaceFromWlr(PCONSTRAINT->surface);
- 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);
-
- if (!CONSTRAINT->hintSet)
- CONSTRAINT->positionHint = Vector2D{-1, -1};
+ if (!SURFACE) {
+ Debug::log(ERR, "Refusing a constraint from an unassigned wl_surface {:x}", (uintptr_t)PCONSTRAINT->surface);
+ return;
}
-}
-
-void Events::listener_destroyConstraint(void* owner, void* data) {
- const auto PCONSTRAINT = (SConstraint*)owner;
-
- if (PCONSTRAINT->pMouse->currentConstraint == PCONSTRAINT->constraint) {
- PCONSTRAINT->pMouse->hyprListener_commitConstraint.removeCallback();
-
- const auto PWINDOW = g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse);
-
- if (PWINDOW && PCONSTRAINT->active && PCONSTRAINT->constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED)
- g_pInputManager->warpMouseToConstraintMiddle(PCONSTRAINT);
-
- PCONSTRAINT->pMouse->currentConstraint = nullptr;
- }
-
- Debug::log(LOG, "Unconstrained mouse from {:x}", (uintptr_t)PCONSTRAINT->constraint);
-
- g_pInputManager->m_lConstraints.remove(*PCONSTRAINT);
-}
-void Events::listener_setConstraintRegion(void* owner, void* data) {
- // no
+ SURFACE->appendConstraint(PCONSTRAINT);
}
void Events::listener_newVirtPtr(wl_listener* listener, void* data) {
diff --git a/src/events/Events.hpp b/src/events/Events.hpp
index 69faf6c1..a105846e 100644
--- a/src/events/Events.hpp
+++ b/src/events/Events.hpp
@@ -65,10 +65,7 @@ namespace Events {
DYNLISTENFUNC(keyboardMod);
DYNLISTENFUNC(keyboardDestroy);
- DYNLISTENFUNC(commitConstraint);
LISTENER(newConstraint);
- DYNLISTENFUNC(setConstraintRegion);
- DYNLISTENFUNC(destroyConstraint);
// Various
LISTENER(requestMouse);
diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp
index 2d94f1ed..ad65f8fb 100644
--- a/src/events/Layers.cpp
+++ b/src/events/Layers.cpp
@@ -144,7 +144,7 @@ void Events::listener_mapLayerSurface(void* owner, void* data) {
const bool GRABSFOCUS = layersurface->layerSurface->current.keyboard_interactive != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE &&
// don't focus if constrained
- (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint);
+ (!g_pCompositor->m_sSeat.mouse || !g_pInputManager->isConstrained());
if (GRABSFOCUS) {
g_pCompositor->focusSurface(layersurface->layerSurface->surface);
@@ -340,8 +340,7 @@ void Events::listener_commitLayerSurface(void* owner, void* data) {
layersurface->realSize.setValueAndWarp(layersurface->geometry.size());
}
- if (layersurface->layerSurface->current.keyboard_interactive &&
- (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint) // don't focus if constrained
+ if (layersurface->layerSurface->current.keyboard_interactive && (!g_pCompositor->m_sSeat.mouse || !g_pInputManager->isConstrained()) // don't focus if constrained
&& !layersurface->keyboardExclusive && layersurface->mapped) {
g_pCompositor->focusSurface(layersurface->layerSurface->surface);
@@ -349,7 +348,7 @@ void Events::listener_commitLayerSurface(void* owner, void* data) {
g_pInputManager->getMouseCoordsInternal() - Vector2D(layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y);
wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, layersurface->layerSurface->surface, LOCAL.x, LOCAL.y);
wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, 0, LOCAL.x, LOCAL.y);
- } else if (!layersurface->layerSurface->current.keyboard_interactive && (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint) &&
+ } else if (!layersurface->layerSurface->current.keyboard_interactive && (!g_pCompositor->m_sSeat.mouse || !g_pInputManager->isConstrained()) &&
layersurface->keyboardExclusive) {
g_pInputManager->refocus();
}
diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp
index 83a37ec3..778b857e 100644
--- a/src/events/Windows.cpp
+++ b/src/events/Windows.cpp
@@ -476,8 +476,9 @@ void Events::listener_mapWindow(void* owner, void* data) {
}
if (!PWINDOW->m_sAdditionalConfigData.noFocus && !PWINDOW->m_bNoInitialFocus &&
- (PWINDOW->m_iX11Type != 2 || (PWINDOW->m_bIsX11 && wlr_xwayland_or_surface_wants_focus(PWINDOW->m_uSurface.xwayland))) && !workspaceSilent &&
- (!PFORCEFOCUS || PFORCEFOCUS == PWINDOW)) {
+ (PWINDOW->m_iX11Type != 2 ||
+ (PWINDOW->m_bIsX11 && PWINDOW->m_uSurface.xwayland->window_type_len > 0 && wlr_xwayland_or_surface_wants_focus(PWINDOW->m_uSurface.xwayland))) &&
+ !workspaceSilent && (!PFORCEFOCUS || PFORCEFOCUS == PWINDOW) && !g_pInputManager->isConstrained()) {
g_pCompositor->focusWindow(PWINDOW);
PWINDOW->m_fActiveInactiveAlpha.setValueAndWarp(**PACTIVEALPHA);
PWINDOW->m_fDimPercent.setValueAndWarp(PWINDOW->m_sAdditionalConfigData.forceNoDim ? 0.f : **PDIMSTRENGTH);
@@ -645,7 +646,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
g_pCompositor->setPreferredScaleForSurface(PWINDOW->m_pWLSurface.wlr(), PMONITOR->scale);
g_pCompositor->setPreferredTransformForSurface(PWINDOW->m_pWLSurface.wlr(), PMONITOR->transform);
- if (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->constraintActive)
+ if (!g_pCompositor->m_sSeat.mouse || !g_pInputManager->isConstrained())
g_pInputManager->sendMotionEventsToFocused();
// fix some xwayland apps that don't behave nicely