mirror of
				https://github.com/hyprwm/hyprland-plugins.git
				synced 2025-10-30 04:12:43 +00:00 
			
		
		
		
	xtra-dispatchers: init new plugin
This commit is contained in:
		
							parent
							
								
									b8293c3608
								
							
						
					
					
						commit
						d4525d5aa9
					
				| @ -77,3 +77,12 @@ build = [ | ||||
|     "make -C hyprexpo all", | ||||
| ] | ||||
| since_hyprland = 4364 | ||||
| 
 | ||||
| [xtra-dispatchers] | ||||
| description = "A plugin to add some extra dispatchers" | ||||
| authors = ["Vaxry"] | ||||
| output = "xtra-dispatchers/xtra-dispatchers.so" | ||||
| build = [ | ||||
|     "make -C xtra-dispatchers all", | ||||
| ] | ||||
| since_hyprland = 5573 | ||||
|  | ||||
							
								
								
									
										27
									
								
								xtra-dispatchers/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								xtra-dispatchers/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| cmake_minimum_required(VERSION 3.27) | ||||
| 
 | ||||
| project(xtra-dispatchers | ||||
|     DESCRIPTION "xtra-dispatchers plugin for Hyprland" | ||||
|     VERSION 0.1 | ||||
| ) | ||||
| 
 | ||||
| set(CMAKE_CXX_STANDARD 23) | ||||
| 
 | ||||
| file(GLOB_RECURSE SRC "*.cpp") | ||||
| 
 | ||||
| add_library(xtra-dispatchers SHARED ${SRC}) | ||||
| 
 | ||||
| find_package(PkgConfig REQUIRED) | ||||
| pkg_check_modules(deps REQUIRED IMPORTED_TARGET | ||||
|     hyprland | ||||
|     libdrm | ||||
|     libinput | ||||
|     libudev | ||||
|     pangocairo | ||||
|     pixman-1 | ||||
|     wayland-server | ||||
|     xkbcommon | ||||
| ) | ||||
| target_link_libraries(xtra-dispatchers PRIVATE rt PkgConfig::deps) | ||||
| 
 | ||||
| install(TARGETS xtra-dispatchers) | ||||
							
								
								
									
										4
									
								
								xtra-dispatchers/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								xtra-dispatchers/Makefile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| all: | ||||
| 	$(CXX) -shared -fPIC --no-gnu-unique main.cpp -o xtra-dispatchers.so -g `pkg-config --cflags pixman-1 libdrm hyprland pangocairo libinput libudev wayland-server xkbcommon` -std=c++2b -O2 | ||||
| clean: | ||||
| 	rm ./xtra-dispatchers.so | ||||
							
								
								
									
										11
									
								
								xtra-dispatchers/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								xtra-dispatchers/README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| # xtra-dispatchers | ||||
| 
 | ||||
| Adds some additional dispatchers to Hyprland. | ||||
| 
 | ||||
| ## Dispatchers | ||||
| 
 | ||||
| | name | description | params | | ||||
| | -- | -- | -- | | ||||
| | moveorexec | moves window to the current workspace, or executes if it's not found. `WINDOW` cannot contain commas | `WINDOW,CMD` | | ||||
| | throwunfocused | throws all unfocused windows on the current workspace to the given workspace | `WORKSPACE` | | ||||
| | bringallfrom | kinda inverse of throwunfocused. Bring all windows from a given workspace to the current one. | `WORKSPACE` | | ||||
							
								
								
									
										5
									
								
								xtra-dispatchers/globals.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								xtra-dispatchers/globals.hpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #include <hyprland/src/plugins/PluginAPI.hpp> | ||||
| 
 | ||||
| inline HANDLE PHANDLE = nullptr; | ||||
							
								
								
									
										130
									
								
								xtra-dispatchers/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								xtra-dispatchers/main.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,130 @@ | ||||
| #define WLR_USE_UNSTABLE | ||||
| 
 | ||||
| #include <unistd.h> | ||||
| 
 | ||||
| #include <hyprland/src/includes.hpp> | ||||
| #include <sstream> | ||||
| 
 | ||||
| #define private public | ||||
| #include <hyprland/src/Compositor.hpp> | ||||
| #include <hyprland/src/desktop/Window.hpp> | ||||
| #include <hyprland/src/config/ConfigManager.hpp> | ||||
| #include <hyprland/src/render/Renderer.hpp> | ||||
| #include <hyprland/src/managers/KeybindManager.hpp> | ||||
| #undef private | ||||
| 
 | ||||
| #include <hyprutils/string/VarList.hpp> | ||||
| using namespace Hyprutils::String; | ||||
| 
 | ||||
| #include "globals.hpp" | ||||
| 
 | ||||
| // Do NOT change this function.
 | ||||
| APICALL EXPORT std::string PLUGIN_API_VERSION() { | ||||
|     return HYPRLAND_API_VERSION; | ||||
| } | ||||
| 
 | ||||
| //
 | ||||
| 
 | ||||
| static SDispatchResult moveOrExec(std::string in) { | ||||
|     CVarList vars(in, 0, ','); | ||||
| 
 | ||||
|     if (!g_pCompositor->m_pLastMonitor || !g_pCompositor->m_pLastMonitor->activeWorkspace) | ||||
|         return SDispatchResult{.success = false, .error = "No active workspace"}; | ||||
| 
 | ||||
|     const auto PWINDOW = g_pCompositor->getWindowByRegex(vars[0]); | ||||
| 
 | ||||
|     if (!PWINDOW) | ||||
|         g_pKeybindManager->spawn(vars[1]); | ||||
|     else { | ||||
|         if (g_pCompositor->m_pLastMonitor->activeWorkspace != PWINDOW->m_pWorkspace) | ||||
|             g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, g_pCompositor->m_pLastMonitor->activeWorkspace); | ||||
|         else | ||||
|             g_pCompositor->warpCursorTo(PWINDOW->middle()); | ||||
|         g_pCompositor->focusWindow(PWINDOW); | ||||
|     } | ||||
| 
 | ||||
|     return SDispatchResult{}; | ||||
| } | ||||
| 
 | ||||
| static SDispatchResult throwUnfocused(std::string in) { | ||||
|     const auto [id, name] = getWorkspaceIDNameFromString(in); | ||||
| 
 | ||||
|     if (id == WORKSPACE_INVALID) | ||||
|         return SDispatchResult{.success = false, .error = "Failed to find workspace"}; | ||||
| 
 | ||||
|     if (!g_pCompositor->m_pLastWindow || !g_pCompositor->m_pLastWindow->m_pWorkspace) | ||||
|         return SDispatchResult{.success = false, .error = "No valid last window"}; | ||||
| 
 | ||||
|     auto pWorkspace = g_pCompositor->getWorkspaceByID(id); | ||||
|     if (!pWorkspace) | ||||
|         pWorkspace = g_pCompositor->createNewWorkspace(id, g_pCompositor->m_pLastWindow->m_pWorkspace->monitorID(), name, false); | ||||
| 
 | ||||
|     for (const auto& w : g_pCompositor->m_vWindows) { | ||||
|         if (w == g_pCompositor->m_pLastWindow || w->m_pWorkspace != g_pCompositor->m_pLastWindow->m_pWorkspace) | ||||
|             continue; | ||||
| 
 | ||||
|         g_pCompositor->moveWindowToWorkspaceSafe(w, pWorkspace); | ||||
|     } | ||||
| 
 | ||||
|     return SDispatchResult{}; | ||||
| } | ||||
| 
 | ||||
| static SDispatchResult bringAllFrom(std::string in) { | ||||
|     const auto [id, name] = getWorkspaceIDNameFromString(in); | ||||
| 
 | ||||
|     if (id == WORKSPACE_INVALID) | ||||
|         return SDispatchResult{.success = false, .error = "Failed to find workspace"}; | ||||
| 
 | ||||
|     if (!g_pCompositor->m_pLastMonitor || !g_pCompositor->m_pLastMonitor->activeWorkspace) | ||||
|         return SDispatchResult{.success = false, .error = "No active monitor"}; | ||||
| 
 | ||||
|     auto pWorkspace = g_pCompositor->getWorkspaceByID(id); | ||||
|     if (!pWorkspace) | ||||
|         return SDispatchResult{.success = false, .error = "Workspace isnt open"}; | ||||
| 
 | ||||
|     const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); | ||||
| 
 | ||||
|     for (const auto& w : g_pCompositor->m_vWindows) { | ||||
|         if (w->m_pWorkspace != pWorkspace) | ||||
|             continue; | ||||
| 
 | ||||
|         g_pCompositor->moveWindowToWorkspaceSafe(w, g_pCompositor->m_pLastMonitor->activeWorkspace); | ||||
|     } | ||||
| 
 | ||||
|     if (PLASTWINDOW) { | ||||
|         g_pCompositor->focusWindow(PLASTWINDOW); | ||||
|         g_pCompositor->warpCursorTo(PLASTWINDOW->middle()); | ||||
|     } | ||||
| 
 | ||||
|     return SDispatchResult{}; | ||||
| } | ||||
| 
 | ||||
| APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { | ||||
|     PHANDLE = handle; | ||||
| 
 | ||||
|     const std::string HASH = __hyprland_api_get_hash(); | ||||
| 
 | ||||
|     if (HASH != GIT_COMMIT_HASH) { | ||||
|         HyprlandAPI::addNotification(PHANDLE, "[xtra-dispatchers] Failure in initialization: Version mismatch (headers ver is not equal to running hyprland ver)", | ||||
|                                      CHyprColor{1.0, 0.2, 0.2, 1.0}, 5000); | ||||
|         throw std::runtime_error("[xtd] Version mismatch"); | ||||
|     } | ||||
| 
 | ||||
|     bool success = true; | ||||
|     success      = success && HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:xtd:moveorexec", ::moveOrExec); | ||||
|     success      = success && HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:xtd:throwunfocused", ::throwUnfocused); | ||||
|     success      = success && HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:xtd:bringallfrom", ::bringAllFrom); | ||||
| 
 | ||||
|     if (success) | ||||
|         HyprlandAPI::addNotification(PHANDLE, "[xtra-dispatchers] Initialized successfully!", CHyprColor{0.2, 1.0, 0.2, 1.0}, 5000); | ||||
|     else { | ||||
|         HyprlandAPI::addNotification(PHANDLE, "[xtra-dispatchers] Failure in initialization: failed to register dispatchers", CHyprColor{1.0, 0.2, 0.2, 1.0}, 5000); | ||||
|         throw std::runtime_error("[xtd] Dispatchers failed"); | ||||
|     } | ||||
| 
 | ||||
|     return {"xtra-dispatchers", "A plugin to add some extra dispatchers to hyprland", "Vaxry", "1.0"}; | ||||
| } | ||||
| 
 | ||||
| APICALL EXPORT void PLUGIN_EXIT() { | ||||
|     ; | ||||
| } | ||||
							
								
								
									
										30
									
								
								xtra-dispatchers/meson.build
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								xtra-dispatchers/meson.build
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| project('xtra-dispatchers', 'cpp', | ||||
|   version: '0.1', | ||||
|   default_options: ['buildtype=release'], | ||||
| ) | ||||
| 
 | ||||
| cpp_compiler = meson.get_compiler('cpp') | ||||
| if cpp_compiler.has_argument('-std=c++23') | ||||
|   add_global_arguments('-std=c++23', language: 'cpp') | ||||
| elif cpp_compiler.has_argument('-std=c++2b') | ||||
|   add_global_arguments('-std=c++2b', language: 'cpp') | ||||
| else | ||||
|   error('Could not configure current C++ compiler (' + cpp_compiler.get_id() + ' ' + cpp_compiler.version() + ') with required C++ standard (C++23)') | ||||
| endif | ||||
| 
 | ||||
| globber = run_command('find', '.', '-name', '*.cpp', check: true) | ||||
| src = globber.stdout().strip().split('\n') | ||||
| 
 | ||||
| shared_module(meson.project_name(), src, | ||||
|   dependencies: [ | ||||
|     dependency('hyprland'), | ||||
|     dependency('pixman-1'), | ||||
|     dependency('libdrm'), | ||||
|     dependency('pangocairo'), | ||||
|     dependency('libinput'), | ||||
|     dependency('libudev'), | ||||
|     dependency('wayland-server'), | ||||
|     dependency('xkbcommon'), | ||||
|   ], | ||||
|   install: true, | ||||
| ) | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user