diff --git a/xtra-dispatchers/README.md b/xtra-dispatchers/README.md index c7b98ba..da5e62b 100644 --- a/xtra-dispatchers/README.md +++ b/xtra-dispatchers/README.md @@ -4,8 +4,11 @@ Adds some additional dispatchers to Hyprland. ## Dispatchers +All dispatchers here are called `plugin:xtd:name` e.g. `plugin:xtd:moveorexec`. + | 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` | \ No newline at end of file +| bringallfrom | kinda inverse of throwunfocused. Bring all windows from a given workspace to the current one. | `WORKSPACE` | +| closeunfocused | close all unfocused windows on the current workspace. | none | diff --git a/xtra-dispatchers/main.cpp b/xtra-dispatchers/main.cpp index 6f2b79e..dd12ed4 100644 --- a/xtra-dispatchers/main.cpp +++ b/xtra-dispatchers/main.cpp @@ -99,6 +99,20 @@ static SDispatchResult bringAllFrom(std::string in) { return SDispatchResult{}; } +static SDispatchResult closeUnfocused(std::string in) { + if (!g_pCompositor->m_pLastMonitor) + return SDispatchResult{.success = false, .error = "No focused monitor"}; + + for (const auto& w : g_pCompositor->m_vWindows) { + if (w->m_pWorkspace != g_pCompositor->m_pLastMonitor->activeWorkspace || w->m_pMonitor != g_pCompositor->m_pLastMonitor || !w->m_bIsMapped) + continue; + + g_pCompositor->closeWindow(w); + } + + return SDispatchResult{}; +} + APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { PHANDLE = handle; @@ -114,6 +128,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { 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); + success = success && HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:xtd:closeunfocused", ::closeUnfocused); if (success) HyprlandAPI::addNotification(PHANDLE, "[xtra-dispatchers] Initialized successfully!", CHyprColor{0.2, 1.0, 0.2, 1.0}, 5000);