]> 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:

Merge branch 'master' of https://github.com/copycat-killer/lain
[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     wa.x = wa.x + global_border
43     wa.y = wa.y + global_border
44
45     -- Width of main column?
46     local t = awful.tag.selected(p.screen)
47     local mwfact = awful.tag.getmwfact(t)
48
49     if #cls > 0
50     then
51         -- Main column, fixed width and height.
52         local c = cls[1]
53         local g = {}
54         local mainwid = math.floor(wa.width * mwfact)
55         local slavewid = wa.width - mainwid
56         local slaveLwid = math.floor(slavewid / 2)
57         local slaveRwid = slavewid - slaveLwid
58         local slaveThei = math.floor(wa.height / 2)
59         local slaveBhei = wa.height - slaveThei
60
61         g.height = wa.height - 2*useless_gap - 2*c.border_width
62         g.width = mainwid - 2*c.border_width
63         if g.width < 1 then g.width = 1 end
64         if g.height < 1 then g.height = 1 end
65         g.x = wa.x + slaveLwid
66         g.y = wa.y + useless_gap
67
68         c:geometry(g)
69
70         -- Auxiliary windows.
71         if #cls > 1
72         then
73             local at = 0
74             for i = 2,#cls
75             do
76                 -- It's all fixed. If there are more than 5 clients,
77                 -- those additional clients will float. This is
78                 -- intentional.
79                 if at == 4
80                 then
81                     break
82                 end
83
84                 c = cls[i]
85                 g = {}
86
87                 if i - 2 == centerwork.top_left
88                 then
89                     -- top left
90                     g.x = wa.x + useless_gap
91                     g.y = wa.y + useless_gap
92                     g.width = slaveLwid - 2*useless_gap - 2*c.border_width
93                     g.height = slaveThei - useless_gap - 2*c.border_width
94                 elseif i - 2 == centerwork.top_right
95                 then
96                     -- top right
97                     g.x = wa.x + slaveLwid + mainwid + useless_gap
98                     g.y = wa.y + useless_gap
99                     g.width = slaveRwid - 2*useless_gap - 2*c.border_width
100                     g.height = slaveThei - useless_gap - 2*c.border_width
101                 elseif i - 2 == centerwork.bottom_left
102                 then
103                     -- bottom left
104                     g.x = wa.x + useless_gap
105                     g.y = wa.y + slaveThei + useless_gap
106                     g.width = slaveLwid - 2*useless_gap - 2*c.border_width
107                     g.height = slaveBhei - 2*useless_gap - 2*c.border_width
108                 elseif i - 2 == centerwork.bottom_right
109                 then
110                     -- bottom right
111                     g.x = wa.x + slaveLwid + mainwid + useless_gap
112                     g.y = wa.y + slaveThei + useless_gap
113                     g.width = slaveRwid - 2*useless_gap - 2*c.border_width
114                     g.height = slaveBhei - 2*useless_gap - 2*c.border_width
115                 end
116
117                 if g.width < 1 then g.width = 1 end
118                 if g.height < 1 then g.height = 1 end
119                 c:geometry(g)
120
121                 at = at + 1
122             end
123
124             -- Set remaining clients to floating.
125             for i = (#cls - 1 - 4),1,-1
126             do
127                 c = cls[i]
128                 awful.client.floating.set(c, true)
129             end
130         end
131     end
132 end
133
134 return centerwork