]> git.madduck.net Git - etc/awesome.git/blobdiff - layout/termfair.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix bugs with v4 API update
[etc/awesome.git] / layout / termfair.lua
index ec127e2efbc080975b3b806e49c0f4572d64f3af..26a71308f1788e8f93364c8f70ca83d7976685a6 100644 (file)
@@ -9,11 +9,11 @@
                                                   
 --]]
 
-local tag       = require("awful.tag")
-local math      = { ceil  = math.ceil,
-                    floor = math.floor,
-                    max   = math.max }
-local tonumber  = tonumber
+local scr      = require("awful.screen")
+local math     = { ceil  = math.ceil,
+                   floor = math.floor,
+                   max   = math.max }
+local tonumber = tonumber
 
 local termfair  = { name = "termfair" }
 termfair.center = { name = "centerfair" }
@@ -22,11 +22,14 @@ local function do_fair(p, orientation)
     -- Screen.
     local wa  = p.workarea
     local cls = p.clients
+    local ta = scr.focused().selected_tag
+
+    if not ta then return end
 
     if #cls <= 0 then return end
 
     -- Useless gaps.
-    local useless_gap = tag.gap or 0
+    local useless_gap = p.useless_gap or 0
 
     if orientation == "west" then
         -- Layout with fixed number of vertical columns (read from nmaster).
@@ -50,12 +53,12 @@ local function do_fair(p, orientation)
         if #cls <= 0 then return end
 
         -- How many vertical columns? Read from nmaster on the tag.
-        local num_x = tonumber(termfair.nmaster) or tag.master_count
-        local ncol  = tonumber(termfair.ncol) or tag.column_count
-        local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x)
+        local num_x = tonumber(termfair.nmaster) or ta.master_count
+        local ncol  = tonumber(termfair.ncol) or ta.column_count
 
         if num_x <= 2 then num_x = 2 end
         if ncol  <= 1 then ncol  = 1 end
+        local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x)
 
         local num_y     = math.max(math.ceil(#cls / num_x), ncol)
         local height    = math.floor((wa.height - (num_y + 1)*useless_gap) / num_y)
@@ -143,13 +146,14 @@ local function do_fair(p, orientation)
         --   +---+---+---+      +---+---+---+
 
         -- How many vertical columns? Read from nmaster on the tag.
-        local num_x = tonumber(termfair.center.nmaster) or tag.master_count
-        local ncol  = tonumber(termfair.center.ncol) or tag.column_count
-        local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x)
+        local num_x = tonumber(termfair.center.nmaster) or ta.master_count
+        local ncol  = tonumber(termfair.center.ncol) or ta.column_count
 
         if num_x <= 2 then num_x = 2 end
         if ncol  <= 1 then ncol  = 1 end
 
+        local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x)
+
         if #cls < num_x then
             -- Less clients than the number of columns, let's center it!
             local offset_x = wa.x + (wa.width - #cls*width - (#cls - 1)*useless_gap) / 2