Skip to content
Custom layouts

Custom layouts

You can create custom layouts in the Lua config directly. For this, define your layout with hl.layout.register(name, { recalculate, layout_msg? }) then use it as lua:name.

A simple example layout:

hl.layout.register("columns", {
    recalculate = function(ctx)
        local n = #ctx.targets
        if n == 0 then
            return
        end

        for i, target in ipairs(ctx.targets) do
            target:place(ctx:column(i, n))
        end
    end,
})

This can then be used as lua:columns.

There are some example layouts in the Hyprland repo here.

ctx has some convenience functions for you, like grid_cell, column, row and split. It also provides area and targets, for the work area and target list respectively.

You can get the window from a target by accessing its .window field, but please do note that it doesn’t always have to be there, and that some layout targets might have multiple, and only expose the “main” one (e.g. group).

Note

Please prefer :place() over :set_box() unless necessary. :place() will calculate the gaps, pseudotiling, reserved space, and more, for you. :set_box() is only to be used if full manual positioning is absolutely necessary.

Last updated on