Add hy3:killactive dispatcher for killing the focused node

This commit is contained in:
outfoxxed 2023-06-25 15:29:02 -07:00
parent f32db7247e
commit ee8c49357f
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
4 changed files with 35 additions and 0 deletions

View file

@ -95,6 +95,7 @@ plugin {
- `visible` - only move between visible nodes, not hidden tabs
- `hy3:movewindow, <l | u | d | r | left | down | up | right>, [once]` - move a window left, up, down, or right
- `once` - only move directly to the neighboring group, without moving into any of its subgroups
- `hy3:killactive` - close all windows in the focused node
- `hy3:changefocus, <top | bottom | raise | lower | tab | tabnode>`
- `top` - focus all nodes in the workspace
- `bottom` - focus the single root selection window

View file

@ -302,6 +302,17 @@ std::string Hy3Node::getTitle() {
return "";
}
void Hy3Node::appendAllWindows(std::vector<CWindow*>& list) {
switch (this->data.type) {
case Hy3NodeData::Window: list.push_back(this->data.as_window); break;
case Hy3NodeData::Group:
for (auto* child: this->data.as_group.children) {
child->appendAllWindows(list);
}
break;
}
}
void markGroupFocusedRecursive(Hy3GroupData& group) {
group.group_focused = true;
for (auto& child: group.children) {
@ -1855,6 +1866,19 @@ hastab:
tab_node->recalcSizePosRecursive();
}
void Hy3Layout::killFocusedNode(int workspace) {
auto* node = this->getWorkspaceFocusedNode(workspace);
if (node == nullptr) return;
std::vector<CWindow*> windows;
node->appendAllWindows(windows);
for (auto* window: windows) {
window->setHidden(false);
g_pCompositor->closeWindow(window);
}
}
bool Hy3Layout::shouldRenderSelected(CWindow* window) {
if (window == nullptr) return false;
auto* root = this->getWorkspaceRootGroup(window->m_iWorkspaceID);

View file

@ -113,6 +113,7 @@ struct Hy3Node {
bool isIndirectlyFocused();
Hy3Node* findNodeForTabGroup(Hy3TabGroup&);
std::string getTitle();
void appendAllWindows(std::vector<CWindow*>&);
bool operator==(const Hy3Node&) const;
@ -159,6 +160,7 @@ public:
void shiftFocus(int, ShiftDirection, bool);
void changeFocus(int, FocusShift);
void focusTab(int, TabFocus, TabFocusMousePriority, bool);
void killFocusedNode(int);
bool shouldRenderSelected(CWindow*);

View file

@ -126,6 +126,13 @@ void dispatch_focustab(std::string value) {
g_Hy3Layout->focusTab(workspace, focus, mouse, wrap_scroll);
}
void dispatch_killactive(std::string value) {
int workspace = workspace_for_action();
if (workspace == -1) return;
g_Hy3Layout->killFocusedNode(workspace);
}
void dispatch_debug(std::string arg) {
int workspace = workspace_for_action();
if (workspace == -1) return;
@ -204,6 +211,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addDispatcher(PHANDLE, "hy3:movewindow", dispatch_movewindow);
HyprlandAPI::addDispatcher(PHANDLE, "hy3:changefocus", dispatch_changefocus);
HyprlandAPI::addDispatcher(PHANDLE, "hy3:focustab", dispatch_focustab);
HyprlandAPI::addDispatcher(PHANDLE, "hy3:killactive", dispatch_killactive);
HyprlandAPI::addDispatcher(PHANDLE, "hy3:debugnodes", dispatch_debug);
return {"hy3", "i3 like layout for hyprland", "outfoxxed", "0.1"};