Moving/Closing All Windows In Current Workspace

I would like to set a keybind that moves all windows contained in the current workspace to another workspace. The following example is wrong, but that is what I want to achieve.

function allWindowsToWorkspace(destination)
    local currentWorkspaceID = hl.get_active_workspace().id
    local windowsInCurrentWorkspace = hl.get_workspace_windows(currentWorkspaceID)

    for window, info in pairs(windowsInCurrentWorkspace) do
        return hl.dsp.window.move({ workspace = destination, window = info.id })
    end
end

for i = 1, 10 do
    local i = i % 10
    hl.bind( "SUPER + ALT + " .. i, allWindowsToWorkspace(i))
end

I remember having some keybinds for this in Sway:

bindsym $mod+shift+c [workspace=__focused__] kill

bindsym $mod+ctrl+alt+1 [workspace=__focused__] move to workspace number 1
bindsym $mod+ctrl+alt+2 [workspace=__focused__] move to workspace number 2

Just to be clear, I do not want to swap workspaces.

Any hints would be appreciated, thanks in advance.

The biggest issue will be to preserve positions, afaik hyprland doesn’t natively have a solution for that

I understand you want a one key shortcut but personally if I want to move my windows from one workspace to another I just press a few times SUPER+SHIFT+new_workspace_number and since it auto-select leftover windows then whole ordeal is done in around 0.69 seconds

I don’t mind the positions too much, but I do the same as you but only take 0.420 secs.

Thanks for replying :)

american-psycho-impressive

2 Likes