29293bf7d509cd18e25a59e15841538fcdef580a

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

Message

move hyprsplit compatibility code to Hy3Layout

Diff

 1diff --git a/CHANGELOG.md b/CHANGELOG.md
 2index 04607000d11d8b9972449b91eaa434c972c7d746..ffc3e97e13117642bdcd24b6e74796e2a669cdf8 100644
 3--- a/CHANGELOG.md
 4+++ b/CHANGELOG.md
 5@@ -1,5 +1,9 @@
 6 # Changelog
 7 
 8+# Upcoming
 9+
10+- Added hyprsplit compatibility for hy3:movetoworkspace
11+
12 # hl0.44.0 and before
13 
14 - Fixed tab bars on root node not respecting outer gaps
15diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
16index 7e65574341d4a970a7e154caace1ea114cc179fc..5488fa77184bfa6f5c105ae05def21af946b6ce1 100644
17--- a/src/Hy3Layout.cpp
18+++ b/src/Hy3Layout.cpp
19@@ -1,5 +1,6 @@
20 #include <regex>
21 #include <set>
22+#include <dlfcn.h>
23 
24 #include <hyprland/src/Compositor.hpp>
25 #include <hyprland/src/desktop/DesktopTypes.hpp>
26@@ -14,6 +15,25 @@
27 #include "globals.hpp"
28 #include "src/desktop/Window.hpp"
29 
30+std::string operationWorkspaceForName(const std::string& workspace) {
31+	typedef std::string (*PHYPRSPLIT_GET_WORKSPACE_FN)(const std::string& workspace);
32+
33+	static auto* hyprsplitTransformer = []() {
34+		for (auto& p: g_pPluginSystem->getAllPlugins()) {
35+			if (p->name == "hyprsplit") {
36+				return reinterpret_cast<PHYPRSPLIT_GET_WORKSPACE_FN>(
37+				    dlsym(p->m_pHandle, "hyprsplitGetWorkspace")
38+				);
39+			}
40+		}
41+
42+		return reinterpret_cast<PHYPRSPLIT_GET_WORKSPACE_FN>(0);
43+	}();
44+
45+	if (hyprsplitTransformer != 0) return hyprsplitTransformer(workspace);
46+	return workspace;
47+}
48+
49 SP<HOOK_CALLBACK_FN> renderHookPtr;
50 SP<HOOK_CALLBACK_FN> windowTitleHookPtr;
51 SP<HOOK_CALLBACK_FN> urgentHookPtr;
52@@ -985,7 +1005,7 @@ void changeNodeWorkspaceRecursive(Hy3Node& node, const PHLWORKSPACE& workspace)
53 }
54 
55 void Hy3Layout::moveNodeToWorkspace(const PHLWORKSPACE& origin, std::string wsname, bool follow) {
56-	auto target = getWorkspaceIDNameFromString(wsname);
57+	auto target = getWorkspaceIDNameFromString(operationWorkspaceForName(wsname));
58 
59 	if (target.id == WORKSPACE_INVALID) {
60 		hy3_log(ERR, "moveNodeToWorkspace called with invalid workspace {}", wsname);
61diff --git a/src/dispatchers.cpp b/src/dispatchers.cpp
62index 08c188731d030eb917e4199b239aeeaa6d8f16c5..ba152a7c0c51328ccec426da5ed3b3b312e9deaf 100644
63--- a/src/dispatchers.cpp
64+++ b/src/dispatchers.cpp
65@@ -1,6 +1,5 @@
66 #include <optional>
67 
68-#include <dlfcn.h>
69 #include <hyprland/src/Compositor.hpp>
70 #include <hyprland/src/desktop/DesktopTypes.hpp>
71 #include <hyprland/src/plugins/PluginAPI.hpp>
72@@ -9,8 +8,6 @@
73 #include "dispatchers.hpp"
74 #include "globals.hpp"
75 
76-typedef std::string (*PHYPRSPLIT_GET_WORKSPACE_FN)(const std::string& workspace);
77-
78 PHLWORKSPACE workspace_for_action(bool allow_fullscreen = false) {
79 	if (g_pLayoutManager->getCurrentLayout() != g_Hy3Layout.get()) return nullptr;
80 
81@@ -151,15 +148,6 @@ void dispatch_move_to_workspace(std::string value) {
82 	auto workspace = args[0];
83 	if (workspace == "") return;
84 
85-	for (auto& p: g_pPluginSystem->getAllPlugins()) {
86-		if (p->name == "hyprsplit") {
87-			PHYPRSPLIT_GET_WORKSPACE_FN hyprsplitGetWorkspace =
88-			    (PHYPRSPLIT_GET_WORKSPACE_FN) dlsym(p->m_pHandle, "hyprsplitGetWorkspace");
89-			if (hyprsplitGetWorkspace) workspace = hyprsplitGetWorkspace(workspace);
90-			break;
91-		}
92-	}
93-
94 	bool follow = args[1] == "follow";
95 
96 	g_Hy3Layout->moveNodeToWorkspace(origin_workspace, workspace, follow);