-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientactions.lua
346 lines (318 loc) · 9.5 KB
/
clientactions.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
-- required packages (made global)
-- local awful = require("awful")
-- initialize return value
local _M = {}
_M.tables_overlap = function(aa, bb)
for _, a in pairs(aa) do
for _, b in pairs(bb) do
if (a == b) then
return true
end
end
end
return false
end
_M.is_tagged_on_screen = function(c,s)
-- tags on screen
local stt = s.selected_tags
-- tags on client
local ctt = c:tags()
return _M.tables_overlap(stt,ctt)
end
_M.is_showing_on_screen = function(c, s)
if (c.screen ~= s) then
return false
end
if ((c.minimized) or (c.hidden)) then
return false
end
return _M.is_tagged_on_screen(c, s)
end
_M.is_showing_current_screen = function(c)
local s = awful.screen.focused()
return _M.is_showing_on_screen(c,s)
end
_M.make_only_on_screen = function(c, s)
-- make sure unminimized
c.minimized = false
-- bring it to selected tag on screen
if not (_M.is_showing_on_screen(c,s)) then
c:move_to_screen(s)
c:move_to_tag(s.selected_tag)
return
end
-- minimize everything else
local numminimized = 0
for _,t in pairs(s.selected_tags) do
for _,o in pairs(t:clients()) do
-- skip the client in question
if (o ~= c) and not (o.sticky) and not (o.ontop) and
not (o.skip_taskbar) then
-- check if showing
if (_M.is_showing_on_screen(o, s)) then
o.minimized = true
numminimized = numminimized + 1
end
end
end
end
-- activate client
c:emit_signal("request::activate", "tasklist", { raise = true } )
return numminimized
end
_M.unminimize_all_peers = function(c)
local s = c.screen
for _, t in pairs(s.selected_tags) do
for _, o in pairs(t:clients()) do
o.minimized = false
end
end
end
_M.toggle_showing = function(c)
-- if sticky or on top, then jump to it
if ((c.sticky) or (c.ontop)) then
if (c.minimized) then
c.minimized = false
end
c:jump_to(false)
return
end
-- if not showing on current screen, then add current tag
-- and activate
if not (_M.is_showing_current_screen(c)) then
c:move_to_screen(awful.screen.focused())
c:move_to_tag(awful.screen.focused().selected_tag)
c.minimized = false
c:emit_signal("request::activate", "tasklist", { raise = true })
return
end
-- if minimized, then unminimize and activate
if (c.minimized) then
c.minimized = false
c:emit_signal("request::activate", "tasklist", { raise = true })
return
end
-- check if only visible thing on window
local isonly = true
local s = c.screen
for _, o in pairs(s.all_clients) do
if (
(o ~= c) and
(_M.is_showing_on_screen(o,s))
) then
isonly = false
break
end
end
-- if only thing on screen then unminimize all peers
if (isonly) then
_M.unminimize_all_peers(c)
return
end
-- showing but the only thing on screen => just minimize
c.minimized = true
end
_M.smart_screen_next = function(c, inc)
-- want it to take place on screen of client in question
local s = c.screen
-- get visible clients on that screen
local vv = s:get_clients(false)
-- do nothing if nothing is invisible
if (#vv == 0) then
return
end
-- if more than one is showing, go to next showing one
if (#vv > 1) then
-- find index of focused on
local focused_index = 0
local target_index = 0
for i, v in ipairs(vv) do
if (v == client.focus) then
focused_index = i
end
if (v == c) then
target_index = i
end
-- both have been found, can break loop
if (target_index > 0) and (focused_index > 0) then
break
end
end
-- use target if focus not found
if (focused_index == 0) then focused_index = target_index end
-- want to go to next one; notice if focused_index = 0,
-- this will still give 1
local next_index = focused_index + inc
-- cycle around
if (next_index > #vv) then
next_index = 1
end
if (next_index < 1) then
next_index = #vv
end
-- jump to that client
vv[next_index]:jump_to(false)
return
end
-- only one was found; let's also include minimized ones
vv = s:get_all_clients(false)
-- if still only one, do nothing
if (#vv < 2) then
return
end
-- find index in new list
local focused_index = 0
local target_index = 0
for i, v in ipairs(vv) do
if (v == client.focus) then
focused_index = i
end
if (v == c) then
target_index = 0
end
-- both have been found, can break loop
if (target_index > 0) and (focused_index > 0) then
break
end
end
-- use target if focus not found
if (focused_index == 0) then focused_index = target_index end
-- loop around until we find an appropriate one
local search_index = focused_index + inc
while (search_index ~= focused_index) do
-- wrap around if need be
if (search_index < 1) then
search_index = #vv
end
if (search_index > #vv) then
search_index = 1
end
local sc = vv[search_index]
-- check if has right properties
if (not (sc.hidden) and not (sc.skip_taskbar) and
not (sc.below) and (sc.focusable) and (sc.valid) and
(_M.is_tagged_on_screen(sc,s))) then
-- if so, make it only focus, like previous one
_M.make_only_on_screen(sc, s)
return
end
-- increment!
search_index = search_index + inc
end
-- shouldn't really be here, but fine to do nothing
end
_M.makeshape = function(shapename)
c = _M.context_menu_target
if not(c) then return end
local shape = gears.shape[shapename]
if (shape) then
c.shape = shape
c.isshaped = true
end
end
_M.myshape = function(c, w, h)
return gears.shape.partially_rounded_rect(
c, w, h, true, false, true, false, 50
)
end
_M.shapemenu = {
{ "rounded", function() _M.makeshape("rounded_rect") end },
{ "circle", function() _M.makeshape("circle") end },
{ "arrow", function() _M.makeshape("arrow") end },
{ "triangle", function() _M.makeshape("isosceles_triangle") end },
{ "hexagon", function() _M.makeshape("hexagon") end },
{ "octagon", function() _M.makeshape("octogon") end },
{ "parallelogram", function() _M.makeshape("parallelogram") end },
{ "diamond", function() _M.makeshape("losange") end },
{ "myshape", function()
c = _M.context_menu_target
if not(c) then return end
c.shape = _M.myshape
c.isshaped = true
end
}
}
_M.the_context_menu = awful.menu({ items = {
{ "(un)set show only", function()
c = _M.context_menu_target
if not(c) then return end
local numminimized =
_M.make_only_on_screen(c,
c.screen
)
if (numminimized == 0) then
_M.unminimize_all_peers(c)
end
end },
{ "swap with master", function()
c = _M.context_menu_target
if (c) then _M.swap_with_master(c) end
end },
{ "(un)minimize", function()
if (_M.context_menu_target) then
_M.context_menu_target.minimized =
not (_M.context_menu_target.minimized)
end
end },
{ "(un)maximize", function()
if (_M.context_menu_target) then
_M.context_menu_target.maximized =
not (_M.context_menu_target.maximized)
end
end },
{ "(un)set floating", function()
if (_M.context_menu_target) then
_M.context_menu_target.floating =
not (_M.context_menu_target.floating)
end
end },
{ "(un)set fullscreen", function()
if (_M.context_menu_target) then
_M.context_menu_target.fullscreen =
not (_M.context_menu_target.fullscreen)
end
end },
{ "(un)set sticky", function()
if (_M.context_menu_target) then
_M.context_menu_target.sticky =
not (_M.context_menu_target.sticky)
end
end },
{ "(un)set ontop", function()
if (_M.context_menu_target) then
_M.context_menu_target.ontop =
not (_M.context_menu_target.ontop)
end
end },
{ "put on next screen", function()
if (_M.context_menu_target) then
_M.context_menu_target:move_to_screen()
end
end },
{ "make shape", _M.shapemenu },
{ "revert shape", function()
c = _M.context_menu_target
if (c) then
c.shape = nil
end
end },
{ "close", function()
if (_M.context_menu_target) then
_M.context_menu_target:kill()
end
end },
{ "cancel", function() end }
}})
_M.context_menu = function(c)
_M.context_menu_target = c
_M.the_context_menu:toggle()
end
_M.swap_with_master = function(c)
local m = awful.client.getmaster(c.screen)
if (m ~= c) then
c:swap(m)
else
awful.client.swap.byidx(1,c)
end
end
return _M