cosmic-comp icon indicating copy to clipboard operation
cosmic-comp copied to clipboard

Add smart window gaps feature

Open JCapucho opened this issue 6 months ago • 10 comments

This PR implements the smart gaps feature like what is present in i3 and sway https://i3wm.org/docs/userguide.html#gaps

Smart window gaps only add the external and internal gaps when it aids in visually separating the top levels (when using the tiling mode).

This is done by only adding the outer gap when more than one toplevel exists in the output and only adding the inner gap when an adjacent toplevel exists in the given direction.

I don't know if this is a wanted feature but it's absence was really bugging me (I previously used sway), so I implemented it and have been using it so I thought I might as well contribute it upstream :)

Screenshots

One window (no gaps) One window

Two windows (outer and inner gaps) Two windows

Notes

Requires a change in libcosmic, if the feature is wanted I will open the PR (Didn't want to spam two repositories for this feature), the changes are here https://github.com/JCapucho/libcosmic/tree/smart-window-gaps

I also think the inner gap calculations are wrong, currently they are:

if TilingLayout::has_adjacent_node(tree, &node_id, dir) {
    inner / 2
} else if is_smart_gaps {
    0
} else {
    inner
}

I have kept the previous version where if smart gaps isn't enabled and there are no adjacent windows a inner gap is added, but this seems wrong because it leads to windows having both an outer and inner gap when they are at the edge of the output. This should instead be:

if TilingLayout::has_adjacent_node(tree, &node_id, dir) {
    inner / 2
} else {
    0
}

I think this hasn't been a problem because by default the outer gap is 0 and there's no way to change it in the settings app, but if it's changed in the file directly it leads to a double border.

Further work

I have also a similar change to only add the active window hint when there's more than one window in the output, but that one still has some problems.

JCapucho avatar Aug 19 '24 12:08 JCapucho