Skip to content

Instantly share code, notes, and snippets.

@MartinRamm
Last active July 6, 2025 23:45
Show Gist options
  • Save MartinRamm/fd91dbaa9744e9301ec8e617416ccc49 to your computer and use it in GitHub Desktop.
Save MartinRamm/fd91dbaa9744e9301ec8e617416ccc49 to your computer and use it in GitHub Desktop.
AwesomeWM: Spiral layout with changable width

AwesomeWM: Spiral layout with changable width

The built-in layout spiral.dwindle is my preferred layout. Unfortunately, unlike other layouts (like tile) it doesn't listen to the master_width_factor to change the width of the primary (leftmost) window (by default, changable via Mod+L and Mod+H). This custom layout does this now.

How to use it:

  1. Copy the above file to your rc.local file
  2. Add/Replace it to the awful.layout.layouts table:
awful.layout.layouts = {
--  ...
    spiralWithChangableWidth,
--    awful.layout.spiral.swindle,
--  ...
}

If you want to use this layout by default, make sure it is the first element in this list.

-- as seen on https://gist.github.com/MartinRamm/fd91dbaa9744e9301ec8e617416ccc49
local spiralWithChangableWidth = {}
spiralWithChangableWidth.name = "dwindle"
function spiralWithChangableWidth.arrange(p)
local fullWidth = p.workarea.width
local fullHeight = p.workarea.height
local tag = p.tag or screen[p.screen].selected_tag
--number between 0 and 1, by default changable via Mod+L and Mod+H. Defaults to 0.5
local rawFactor = tag.master_width_factor
local factor = math.ceil((fullWidth / 2) * (rawFactor - 0.5))
local x = p.workarea.x
local y = p.workarea.y
local windows = p.clients
local numberOfWindows = #windows
for i, window in ipairs(windows) do
--this coordinate
local thisX = x
local thisY = y
--i is a 1 based index of the windows
local isFirst = i == 1
local isLast = i == numberOfWindows
local isEven = i % 2 == 0
--next coordinates
if isEven then
y = math.ceil(y + (fullHeight / (2^(i/2))))
else
x = math.ceil(x + (fullWidth / (2^((i+1)/2))) - (isFirst and (0-factor) or (factor/(i-1))))
end
local g = {
x = thisX,
y = thisY,
--if last, fill the area.
width = (isLast or x == thisX) and (fullWidth - thisX + p.workarea.x) or (x - thisX),
height = (isLast or y == thisY) and (fullHeight - thisY + p.workarea.y) or (y - thisY),
}
p.geometries[window] = g
end
end
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment