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

calendar: fixed typos
[etc/awesome.git] / layout / centerhwork.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2015,      Joerg Jaspert              
6       * (c) 2014,      projektile                 
7       * (c) 2013,      Luke Bonham                
8       * (c) 2010-2012, Peter Hofmann              
9                                                   
10 --]]
11
12 local awful     = require("awful")
13 local beautiful = require("beautiful")
14 local tonumber  = tonumber
15
16 local centerhwork =
17 {
18     name         = "centerhwork",
19     top_left     = 0,
20     top_right    = 1,
21     bottom_left  = 2,
22     bottom_right = 3
23 }
24
25 function centerhwork.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 mainhei  = math.floor(wa.height * mwfact)
55         local slaveLwid = math.floor(wa.width / 2 )
56         local slaveRwid = wa.width - slaveLwid
57         local slavehei = wa.height - mainhei
58         local slaveThei = math.floor(slavehei / 2)
59         local slaveBhei = slavehei - slaveThei
60         local Lhalfgap = math.floor(useless_gap / 2)
61         local Rhalfgap = useless_gap - Lhalfgap
62
63         g.height = mainhei - 2*c.border_width
64         g.width  = wa.width - 2*useless_gap - 2*c.border_width
65         g.x = wa.x + useless_gap
66         g.y = wa.y + slaveThei
67
68         if g.width < 1 then g.width = 1 end
69         if g.height < 1 then g.height = 1 end
70         c:geometry(g)
71
72         -- Auxiliary windows.
73         if #cls > 1
74         then
75             local at = 0
76             for i = 2,#cls
77             do
78                 -- It's all fixed. If there are more than 5 clients,
79                 -- those additional clients will float. This is
80                 -- intentional.
81                 if at == 4
82                 then
83                     break
84                 end
85
86                 c = cls[i]
87                 g = {}
88
89                 if i - 2 == centerhwork.top_left
90                 then
91                     -- top left
92                     g.x = wa.x + useless_gap
93                     g.y = wa.y + useless_gap
94                     g.width = slaveLwid - useless_gap - Lhalfgap - 2*c.border_width
95                     g.height = slaveThei - 2*useless_gap - 2*c.border_width
96                 elseif i - 2 == centerhwork.top_right
97                 then
98                     -- top right
99                     g.x = wa.x + slaveLwid + Rhalfgap
100                     g.y = wa.y + useless_gap
101                     g.width = slaveRwid - useless_gap - Rhalfgap - 2*c.border_width
102                     g.height = slaveThei - 2*useless_gap - 2*c.border_width
103                 elseif i - 2 == centerhwork.bottom_left
104                 then
105                     -- bottom left
106                     g.x = wa.x + useless_gap
107                     g.y = wa.y + mainhei + slaveThei + useless_gap
108                     g.width = slaveLwid - useless_gap - Lhalfgap - 2*c.border_width
109                     g.height = slaveBhei - 2*useless_gap - 2*c.border_width
110                 elseif i - 2 == centerhwork.bottom_right
111                 then
112                     -- bottom right
113                     g.x = wa.x + slaveLwid + Rhalfgap
114                     g.y = wa.y + mainhei + slaveThei + useless_gap
115                     g.width = slaveRwid - useless_gap - Rhalfgap - 2*c.border_width
116                     g.height = slaveBhei - 2*useless_gap - 2*c.border_width
117                 end
118
119                 if g.width < 1 then g.width = 1 end
120                 if g.height < 1 then g.height = 1 end
121                 c:geometry(g)
122
123                 at = at + 1
124             end
125
126             -- Set remaining clients to floating.
127             for i = (#cls - 1 - 4),1,-1
128             do
129                 c = cls[i]
130                 awful.client.floating.set(c, true)
131             end
132         end
133     end
134 end
135
136 return centerhwork