-
Notifications
You must be signed in to change notification settings - Fork 11
/
resize.lua
231 lines (189 loc) · 7.79 KB
/
resize.lua
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
local capi = { client = client }
local wibox = require( "wibox" )
local beautiful = require( "beautiful" )
local awful = require( "awful" )
local surface = require( "gears.surface" )
local shape = require( "gears.shape" )
local module, indicators, cur_c, sizeboxes = {},nil,nil, {}
local values = {"top" , "top_right" , "right" , "bottom_right" ,
"bottom" , "bottom_left", "left" , "top_left" }
local invert = {
left = "right",
right = "left" ,
up = "down" ,
down = "up" ,
}
local r_ajust = {
left = function(c, d) return { x = c.x - d, width = c.width + d } end,
right = function(c, d) return { width = c.width + d, } end,
up = function(c, d) return { y = c.y - d, height = c.height + d } end,
down = function(c, d) return { height = c.height + d, } end,
}
-- Resize tiled using the keyboard
local layouts_all = {
[awful.layout.suit.floating] = { right = "" },
[awful.layout.suit.tile] = { right = {mwfact= 0.05}, left = {mwfact=-0.05}, up ={wfact=-0.1 }, down = {wfact = 0.1 } },
[awful.layout.suit.tile.left] = { right = {mwfact=-0.05}, left = {mwfact= 0.05}, up ={wfact= 0.1 }, down = {wfact =-0.1 } },
[awful.layout.suit.tile.bottom] = { right = {wfact=-0.1 }, left = {wfact= 0.1 }, up ={mwfact=-0.05}, down = {mwfact= 0.05} },
[awful.layout.suit.tile.top] = { right = {wfact=-0.1 }, left = {wfact= 0.1 }, up ={mwfact= 0.05}, down = {mwfact=-0.05} },
[awful.layout.suit.spiral] = { right = {wfact=-0.1 }, left = {wfact= 0.1 }, up ={mwfact= 0.05}, down = {mwfact=-0.05} },
[awful.layout.suit.magnifier] = { right = {mwfact= 0.05}, left = {mwfact=-0.05}, up ={mwfact= 0.05}, down = {mwfact=-0.05} },
-- The other layouts cannot be resized using variables
}
local function update_size_boxes(c, float_only)
if not awful.popup then return end
if not beautiful.collision_resize_size then return end
local clients = c and {c} or awful.client.visible()
if c and float_only then
for c2, wb in pairs(sizeboxes) do
if c2 ~= c and not c2.floating then
wb.visible = false
end
end
end
for _, c in ipairs(clients) do
if (not float_only) or c.floating then
local wb = sizeboxes[c]
if not wb then
sizeboxes[c] = awful.popup {
widget = {
{
id = "tb",
text = "0x0",
font = beautiful.collision_resize_size_font,
widget = wibox.widget.textbox
},
margins = beautiful.collision_resize_size_padding or 4,
widget = wibox.container.margin
},
visible = false,
ontop = true,
bg = beautiful.collision_resize_size_bg or beautiful.bg_normal,
fg = beautiful.collision_resize_size_fg or beautiful.fg_normal,
border_width = beautiful.collision_resize_size_border_width,
border_color = beautiful.collision_resize_size_border_color,
shape = beautiful.collision_resize_shape,
placement = function(o)
return awful.placement.centered(o, {parent = c})
end,
}
wb = sizeboxes[c]
end
local geo = c:geometry()
sizeboxes[c].visible = true
sizeboxes[c].widget.tb.text = geo.width .. "x" .. geo.height
end
end
end
local function create_indicators()
local ret = {}
local angle = -((2*math.pi)/8)
-- Get the parameters
local size = beautiful.collision_resize_width or 40
local s = beautiful.collision_resize_shape or shape.circle
local bw = beautiful.collision_resize_border_width
local bc = beautiful.collision_resize_border_color
local padding = beautiful.collision_resize_padding or 7
local bg = beautiful.collision_resize_bg or beautiful.bg_alternate or "#ff0000"
local fg = beautiful.collision_resize_fg or beautiful.fg_normal or "#0000ff"
local arrow_bc = beautiful.collision_resize_arrow_border_color
local arrow_bw = beautiful.collision_resize_arrow_border_width or 0
for k,v in ipairs(values) do
local w = wibox {
width = size,
height = size,
ontop = true,
visible = true
}
angle = angle + (2*math.pi)/8
local tr = (size - 2*arrow_bw - 2*padding) / 2
w:setup {
{
{
{
widget = wibox.widget.imagebox
},
shape = shape.transform(shape.arrow)
: translate( tr,tr )
: rotate ( angle )
: translate( -tr,-tr ),
bg = fg,
border_color = arrow_bc,
border_width = arrow_bw,
widget = wibox.container.background
},
margins = padding,
widget = wibox.container.margin,
},
bg = bg,
shape = s,
shape_border_width = bw,
shape_border_color = bc,
widget = wibox.container.background
}
if awesome.version >= "v4.1" then
w.shape = s
else
surface.apply_shape_bounding(w, s)
end
ret[v] = w
end
return ret
end
function module.hide()
if not indicators then return end
for k, v in ipairs(values) do indicators[v].visible = false end
for _, wb in pairs(sizeboxes) do wb.visible = false end
if not cur_c then return end
cur_c:disconnect_signal("property::geometry", module.display)
cur_c = nil
sizeboxes = {}
end
function module.display(c,toggle)
if type(c) ~= "client" then --HACK
c = capi.client.focus
end
if not c then return end
indicators = indicators or create_indicators()
if c ~= cur_c then
if cur_c then
cur_c:disconnect_signal("property::geometry", module.display)
end
c:connect_signal("property::geometry", module.display)
cur_c = c
elseif toggle == true then
module.hide()
end
for k,v in ipairs(values) do
local w = indicators[v]
awful.placement[v](w, {parent=c})
w.visible = true
end
update_size_boxes(c.floating and c or nil, c.floating)
end
function module.resize(mod,key,event,direction,is_swap,is_max)
local c = capi.client.focus
if not c then return true end
local del = is_swap and -100 or 100
direction = is_swap and invert[direction] or direction
local lay = awful.layout.get(c.screen)
if c.floating or lay == awful.layout.suit.floating then
c:emit_signal("request::geometry", "mouse.resize", r_ajust[direction](c, del))
update_size_boxes(c, true)
elseif layouts_all[lay] then
local ret = layouts_all[lay][direction]
if ret.mwfact then
awful.tag.incmwfact(ret.mwfact)
end
if ret.wfact then
awful.client.incwfact(ret.wfact, c)
end
update_size_boxes()
end
return true
end
-- Always display the arrows when resizing
awful.mouse.resize.add_enter_callback(module.display, "mouse.resize")
awful.mouse.resize.add_leave_callback(module.hide , "mouse.resize")
return module
-- kate: space-indent on; indent-width 4; replace-tabs on;