Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. ---------------------------------------------------------------------------
  2. -- @author Josh Komoroske
  3. -- @copyright 2012 Josh Komoroske
  4. -- @release v3.5.5
  5. ---------------------------------------------------------------------------
  6.  
  7. -- Grab environment we need
  8. local ipairs = ipairs
  9. local math = math
  10.  
  11. --- Fair layouts module for awful
  12. -- awful.layout.suit.fair
  13. local fair = {}
  14.  
  15. local function do_fair(p, orientation)
  16. local wa = p.workarea
  17. local cls = p.clients
  18.  
  19. -- Swap workarea dimensions, if our orientation is "east"
  20. if orientation == 'east' then
  21. wa.width, wa.height = wa.height, wa.width
  22. wa.x, wa.y = wa.y, wa.x
  23. end
  24.  
  25. if #cls > 0 then
  26. local rows, cols = 0, 0
  27. if #cls == 2 then
  28. rows, cols = 1, 2
  29. else
  30. rows = math.ceil(math.sqrt(#cls))
  31. cols = math.ceil(#cls / rows)
  32. end
  33.  
  34. for k, c in ipairs(cls) do
  35. k = k - 1
  36. local g = {}
  37.  
  38. local row, col = 0, 0
  39. row = k % rows
  40. col = math.floor(k / rows)
  41.  
  42. local lrows, lcols = 0, 0
  43. if k >= rows * cols - rows then
  44. lrows = #cls - (rows * cols - rows)
  45. lcols = cols
  46. else
  47. lrows = rows
  48. lcols = cols
  49. end
  50.  
  51. if row == lrows - 1 then
  52. g.height = wa.height - math.ceil(wa.height / lrows) * row
  53. g.y = wa.height - g.height
  54. else
  55. g.height = math.ceil(wa.height / lrows)
  56. g.y = g.height * row
  57. end
  58.  
  59. if col == lcols - 1 then
  60. g.width = wa.width - math.ceil(wa.width / lcols) * col
  61. g.x = wa.width - g.width
  62. else
  63. g.width = math.ceil(wa.width / lcols)
  64. g.x = g.width * col
  65. end
  66.  
  67. g.height = g.height - c.border_width * 2
  68. g.width = g.width - c.border_width * 2
  69. g.y = g.y + wa.y
  70. g.x = g.x + wa.x
  71.  
  72. -- Swap window dimensions, if our orientation is "east"
  73. if orientation == 'east' then
  74. g.width, g.height = g.height, g.width
  75. g.x, g.y = g.y, g.x
  76. end
  77.  
  78. -- Useless gap.
  79. useless_gap = 8
  80. if useless_gap > 0
  81. then
  82. -- Top and left clients are shrinked by two steps and
  83. -- get moved away from the border. Other clients just
  84. -- get shrinked in one direction.
  85.  
  86. top = false
  87. left = false
  88.  
  89. if g.x == wa.x then
  90. top = true
  91. end
  92.  
  93. if g.y == wa.y then
  94. left = true
  95. end
  96.  
  97. if top then
  98. g.width = g.width - 2 * useless_gap
  99. g.x = g.x + useless_gap
  100. else
  101. g.width = g.width - useless_gap
  102. end
  103.  
  104. if left then
  105. g.height = g.height - 2 * useless_gap
  106. g.y = g.y + useless_gap
  107. else
  108. g.height = g.height - useless_gap
  109. end
  110. end
  111. -- End of useless gap.
  112.  
  113. c:geometry(g)
  114. end
  115. end
  116. end
  117.  
  118. --- Horizontal fair layout.
  119. -- @param screen The screen to arrange.
  120. fair.horizontal = {}
  121. fair.horizontal.name = "fairh"
  122. function fair.horizontal.arrange(p)
  123. return do_fair(p, "east")
  124. end
  125.  
  126. -- Vertical fair layout.
  127. -- @param screen The screen to arrange.
  128. fair.name = "fairv"
  129. function fair.arrange(p)
  130. return do_fair(p, "south")
  131. end
  132.  
  133. return fair
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement