399a7b26dc88182a40c294f37367272b1824316a

Author
outfoxxed <outfoxxed@outfoxxed.me>
Committer
outfoxxed <outfoxxed@outfoxxed.me>
Date

Message

ensure cursor warps update pointer focus

Diff

  1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
  2index baf31510449e7af5915c8575dd046d2bda4cdb2c..f37464773ff82a297c81067ce49048230bd64587 100644
  3--- a/src/Hy3Layout.cpp
  4+++ b/src/Hy3Layout.cpp
  5@@ -14,6 +14,7 @@
  6 #include <hyprland/src/managers/input/InputManager.hpp>
  7 #include <hyprland/src/plugins/PluginAPI.hpp>
  8 #include <hyprland/src/plugins/PluginSystem.hpp>
  9+#include <hyprutils/math/Vector2D.hpp>
 10 #include <ranges>
 11 
 12 #include "Hy3Layout.hpp"
 13@@ -954,6 +955,7 @@ void Hy3Layout::shiftFocus(
 14 			    g_pCompositor->getWindowInDirection(current_window, getShiftDirectionChar(direction));
 15 
 16 			if (next_window != nullptr) {
 17+				g_pInputManager->unconstrainMouse();
 18 				g_pCompositor->focusWindow(next_window);
 19 				if (warp) Hy3Layout::warpCursorToBox(next_window->m_vPosition, next_window->m_vSize);
 20 			}
 21@@ -1003,8 +1005,9 @@ Hy3Node* Hy3Layout::focusMonitor(ShiftDirection direction) {
 22 				}
 23 			}
 24 		}
 25+
 26 		if (!found) {
 27-			g_pCompositor->warpCursorTo(next_monitor->vecPosition + next_monitor->vecSize / 2);
 28+			Hy3Layout::warpCursorWithFocus(next_monitor->vecPosition + next_monitor->vecSize / 2);
 29 		}
 30 	}
 31 	return nullptr;
 32@@ -1040,7 +1043,7 @@ void Hy3Layout::toggleFocusLayer(const PHLWORKSPACE& workspace, bool warp) {
 33 	g_pCompositor->focusWindow(target);
 34 
 35 	if (warp) {
 36-		g_pCompositor->warpCursorTo(target->middle());
 37+		Hy3Layout::warpCursorWithFocus(target->middle());
 38 	}
 39 }
 40 
 41@@ -1049,13 +1052,13 @@ void Hy3Layout::warpCursor() {
 42 
 43 	if (current_window != nullptr) {
 44 		if (current_window != nullptr) {
 45-			g_pCompositor->warpCursorTo(current_window->middle(), true);
 46+			Hy3Layout::warpCursorWithFocus(current_window->middle(), true);
 47 		}
 48 	} else {
 49 		auto* node = this->getWorkspaceFocusedNode(g_pCompositor->m_pLastMonitor->activeWorkspace);
 50 
 51 		if (node != nullptr) {
 52-			g_pCompositor->warpCursorTo(node->position + node->size / 2);
 53+			Hy3Layout::warpCursorWithFocus(node->position + node->size / 2);
 54 		}
 55 	}
 56 }
 57@@ -1503,7 +1506,20 @@ void Hy3Layout::warpCursorToBox(const Vector2D& pos, const Vector2D& size) {
 58 	if (cursorpos.x < pos.x || cursorpos.x >= pos.x + size.x || cursorpos.y < pos.y
 59 	    || cursorpos.y >= pos.y + size.y)
 60 	{
 61-		g_pCompositor->warpCursorTo(pos + size / 2, true);
 62+		Hy3Layout::warpCursorWithFocus(pos + size / 2, true);
 63+	}
 64+}
 65+
 66+void Hy3Layout::warpCursorWithFocus(const Vector2D& target, bool force) {
 67+	static const auto input_follows_mouse = ConfigValue<Hyprlang::INT>("input:follow_mouse");
 68+	static const auto no_warps = ConfigValue<Hyprlang::INT>("cursor:no_warps");
 69+
 70+	g_pCompositor->warpCursorTo(target, force);
 71+
 72+	if (*no_warps && !force) return;
 73+
 74+	if (*input_follows_mouse) {
 75+		g_pInputManager->simulateMouseMovement();
 76 	}
 77 }
 78 
 79diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
 80index 81c99d3f3cb1d398e378f92277bc367afb006a43..4785533fb0b5336efd5b97181e7d49aef4cb1cc5 100644
 81--- a/src/Hy3Layout.hpp
 82+++ b/src/Hy3Layout.hpp
 83@@ -141,6 +141,7 @@ public:
 84 	void killFocusedNode(const PHLWORKSPACE& workspace);
 85 	void expand(const PHLWORKSPACE& workspace, ExpandOption, ExpandFullscreenOption);
 86 	static void warpCursorToBox(const Vector2D& pos, const Vector2D& size);
 87+	static void warpCursorWithFocus(const Vector2D& pos, bool force = false);
 88 
 89 	bool shouldRenderSelected(const PHLWINDOW&);
 90 	PHLWINDOW findTiledWindowCandidate(const PHLWINDOW& from);
 91diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp
 92index 9e477c90ae221cba9ac1d72156edab07d3b41373..bd84350e56e5ccce03a9ed3183237dcd9f738c50 100644
 93--- a/src/Hy3Node.cpp
 94+++ b/src/Hy3Node.cpp
 95@@ -12,6 +12,7 @@
 96 #include "Hy3Layout.hpp"
 97 #include "Hy3Node.hpp"
 98 #include "globals.hpp"
 99+#include "src/managers/input/InputManager.hpp"
100 
101 const float MIN_RATIO = 0.0f;
102 
103@@ -168,6 +169,8 @@ bool Hy3Node::operator==(const Hy3Node& rhs) const { return this->data == rhs.da
104 void Hy3Node::focus(bool warp) {
105 	this->markFocused();
106 
107+	g_pInputManager->unconstrainMouse();
108+
109 	switch (this->data.type()) {
110 	case Hy3NodeType::Window: {
111 		auto window = this->data.as_window();