Skip to content

Commit

Permalink
xtra-dispatchers: add closeUnfocused
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jan 8, 2025
1 parent 948d70b commit b4c0fa3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion xtra-dispatchers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
| 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 |
15 changes: 15 additions & 0 deletions xtra-dispatchers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit b4c0fa3

Please sign in to comment.