Created
August 2, 2024 20:50
-
-
Save wenjie1991/4cb700da4cbef612fb498e7445be878b to your computer and use it in GitHub Desktop.
Hyprland Group all windows in a workspace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get the active workspace ID | |
active_workspace=$(hyprctl activeworkspace -j | jq '.id') | |
# Get addresses of all windows in the active workspace | |
windows=$(hyprctl clients -j | jq -r ".[] | select(.workspace.id == $active_workspace) | .address") | |
# Focus the first window | |
hyprctl dispatch focuswindow address:$(echo "$windows" | head -n 1) | |
# Check if the first window is already in a group | |
first_window_grouped=$(hyprctl clients -j | jq -r ".[] | select(.address == \"$(echo "$windows" | head -n 1)\") | .grouped | .[]") | |
# If NOT grouped and there are multiple windows, create a group and add others | |
if [[ -z "$first_window_grouped" && $(echo "$windows" | wc -l) -gt 1 ]]; then | |
# Create a group | |
hyprctl dispatch togglegroup | |
# Iterate over remaining windows (skipping the first) | |
for window in $(echo "$windows" | tail -n +2); do | |
hyprctl dispatch focuswindow address:"$window" | |
sleep 0.2 # Briefly pause (mimics R's Sys.sleep) | |
hyprctl dispatch moveintogroup r | |
hyprctl dispatch moveintogroup l | |
hyprctl dispatch moveintogroup u | |
hyprctl dispatch moveintogroup d | |
done | |
else | |
# If already grouped or only one window, toggle group (ungroup if needed) | |
hyprctl dispatch togglegroup | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment