1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
---------------------------------------------------------------------------
--- Magnifier layout module for awful
--
-- @author Julien Danjou <julien@danjou.info>
-- @copyright 2008 Julien Danjou
-- @module awful.layout
---------------------------------------------------------------------------
-- Grab environment we need
local ipairs = ipairs
local math = math
local capi =
{
client = client,
screen = screen,
mouse = mouse,
mousegrabber = mousegrabber
}
--- The magnifier layout layoutbox icon.
-- @beautiful beautiful.layout_magnifier
-- @param surface
-- @see gears.surface
local magnifier = {}
function magnifier.mouse_resize_handler(c, corner, x, y)
capi.mouse.coords({ x = x, y = y })
local wa = c.screen.workarea
local center_x = wa.x + wa.width / 2
local center_y = wa.y + wa.height / 2
local maxdist_pow = (wa.width^2 + wa.height^2) / 4
local prev_coords = {}
capi.mousegrabber.run(function (_mouse)
if not c.valid then return false end
for _, v in ipairs(_mouse.buttons) do
if v then
prev_coords = { x =_mouse.x, y = _mouse.y }
local dx = center_x - _mouse.x
local dy = center_y - _mouse.y
local dist = dx^2 + dy^2
-- New master width factor
local mwfact = dist / maxdist_pow
c.screen.selected_tag.master_width_factor
= math.min(math.max(0.01, mwfact), 0.99)
return true
end
end
return prev_coords.x == _mouse.x and prev_coords.y == _mouse.y
end, corner .. "_corner")
end
function magnifier.arrange(p)
-- Fullscreen?
local area = p.workarea
local cls = p.clients
local focus = p.focus or capi.client.focus
local t = p.tag or capi.screen[p.screen].selected_tag
local mwfact = t.master_width_factor
local fidx
-- Check that the focused window is on the right screen
if focus and focus.screen ~= p.screen then focus = nil end
-- If no window is focused or focused window is not tiled, take the first tiled one.
if (not focus or focus.floating) and #cls > 0 then
focus = cls[1]
fidx = 1
end
-- Abort if no clients are present
if not focus then return end
local geometry = {}
if #cls > 1 then
geometry.width = area.width * math.sqrt(mwfact)
geometry.height = area.height * math.sqrt(mwfact)
geometry.x = area.x + (area.width - geometry.width) / 2
geometry.y = area.y + (area.height - geometry.height) /2
else
geometry.x = area.x
geometry.y = area.y
geometry.width = area.width
geometry.height = area.height
end
local g = {
x = geometry.x,
y = geometry.y,
width = geometry.width,
height = geometry.height
}
p.geometries[focus] = g
if #cls > 1 then
geometry.x = area.x
geometry.y = area.y
geometry.height = area.height / (#cls - 1)
geometry.width = area.width
-- We don't know the focus window index. Try to find it.
if not fidx then
for k, c in ipairs(cls) do
if c == focus then
fidx = k
break
end
end
end
-- First move clients that are before focused client.
for k = fidx + 1, #cls do
p.geometries[cls[k]] = {
x = geometry.x,
y = geometry.y,
width = geometry.width,
height = geometry.height
}
geometry.y = geometry.y + geometry.height
end
-- Then move clients that are after focused client.
-- So the next focused window will be the one at the top of the screen.
for k = 1, fidx - 1 do
p.geometries[cls[k]] = {
x = geometry.x,
y = geometry.y,
width = geometry.width,
height = geometry.height
}
geometry.y = geometry.y + geometry.height
end
end
end
--- The magnifier layout.
-- @clientlayout awful.layout.suit.magnifier
magnifier.name = "magnifier"
return magnifier
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|