]> git.madduck.net Git - etc/awesome.git/blob - layout/centerwork.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:

Stopped assuming all clients use theme.border_width
[etc/awesome.git] / layout / centerwork.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2014,      projektile                 
6       * (c) 2013,      Luke Bonham                
7       * (c) 2010-2012, Peter Hofmann              
8                                                   
9 --]]
10
11 local awful     = require("awful")
12 local beautiful = require("beautiful")
13 local tonumber  = tonumber
14 local math      = { floor = math.floor }
15
16 local centerwork =
17 {
18     name         = "centerwork",
19     top_right    = 0,
20     bottom_right = 1,
21     bottom_left  = 2,
22     top_left     = 3
23 }
24
25 function centerwork.arrange(p)
26     -- A useless gap (like the dwm patch) can be defined with
27     -- beautiful.useless_gap_width .
28     local useless_gap = tonumber(beautiful.useless_gap_width) or 0
29
30     -- A global border can be defined with
31     -- beautiful.global_border_width
32     local global_border = tonumber(beautiful.global_border_width) or 0
33     if global_border < 0 then global_border = 0 end
34
35     -- Screen.
36     local wa = p.workarea
37     local cls = p.clients
38
39     -- Borders are factored in.
40     wa.height = wa.height - (global_border * 2)
41     wa.width = wa.width - (global_border * 2)
42
43     -- Width of main column?
44     local t = awful.tag.selected(p.screen)
45     local mwfact = awful.tag.getmwfact(t)
46
47     if #cls > 0
48     then
49         -- Main column, fixed width and height.
50         local c = cls[1]
51         local g = {}
52         local mainwid = math.floor(wa.width * mwfact)
53         local slavewid = wa.width - mainwid
54         local slaveLwid = math.floor(slavewid / 2)
55         local slaveRwid = slavewid - slaveLwid
56         local slaveThei = math.floor(wa.height / 2)
57         local slaveBhei = wa.height - slaveThei
58
59         g.height = wa.height - 2*useless_gap - 2*c.border_width
60         g.width = mainwid - 2*c.border_width
61         g.x = wa.x + slaveLwid + global_border
62         g.y = wa.y + useless_gap + global_border
63
64         c:geometry(g)
65
66         -- Auxiliary windows.
67         if #cls > 1
68         then
69             local at = 0
70             for i = 2,#cls
71             do
72                 -- It's all fixed. If there are more than 5 clients,
73                 -- those additional clients will float. This is
74                 -- intentional.
75                 if at == 4
76                 then
77                     break
78                 end
79
80                 c = cls[i]
81                 g = {}
82
83                 if i - 2 == centerwork.top_left
84                 then
85                     -- top left
86                     g.x = wa.x + useless_gap + global_border
87                     g.y = wa.y + useless_gap + global_border
88                     g.width = slaveLwid - 2*useless_gap - 2*c.border_width
89                     g.height = slaveThei - useless_gap - 2*c.border_width
90                 elseif i - 2 == centerwork.top_right
91                 then
92                     -- top right
93                     g.x = wa.x + slaveLwid + mainwid + useless_gap + global_border
94                     g.y = wa.y + useless_gap + global_border
95                     g.width = slaveRwid - 2*useless_gap - 2*c.border_width
96                     g.height = slaveThei - useless_gap - 2*c.border_width
97                 elseif i - 2 == centerwork.bottom_left
98                 then
99                     -- bottom left
100                     g.x = wa.x + useless_gap + global_border
101                     g.y = wa.y + slaveThei + useless_gap + global_border
102                     g.width = slaveLwid - 2*useless_gap - 2*c.border_width
103                     g.height = slaveBhei - 2*useless_gap - 2*c.border_width
104                 elseif i - 2 == centerwork.bottom_right
105                 then
106                     -- bottom right
107                     g.x = wa.x + slaveLwid + mainwid + useless_gap + global_border
108                     g.y = wa.y + slaveThei + useless_gap + global_border
109                     g.width = slaveRwid - 2*useless_gap - 2*c.border_width
110                     g.height = slaveBhei - 2*useless_gap - 2*c.border_width
111                 end
112
113                 c:geometry(g)
114
115                 at = at + 1
116             end
117
118             -- Set remaining clients to floating.
119             for i = (#cls - 1 - 4),1,-1
120             do
121                 c = cls[i]
122                 awful.client.floating.set(c, true)
123             end
124         end
125     end
126 end
127
128 return centerwork