forked from worron/redflat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.lua
More file actions
371 lines (320 loc) · 12.2 KB
/
common.lua
File metadata and controls
371 lines (320 loc) · 12.2 KB
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
-----------------------------------------------------------------------------------------------------------------------
-- RedFlat layout shared functions --
-----------------------------------------------------------------------------------------------------------------------
-- Hotkeys for layout manipulation
-- Handlers adapted for work with redflat navigator widget
-----------------------------------------------------------------------------------------------------------------------
-- Grab environment
-----------------------------------------------------------------------------------------------------------------------
local awful = require("awful")
local navigator = require("redflat.service.navigator")
local ipairs = ipairs
local layout = awful.layout
local redutil = require("redflat.util")
local redtip = require("redflat.float.hotkeys")
-- Initialize tables for module
-----------------------------------------------------------------------------------------------------------------------
local common = { handler = {}, last = {}, tips = {}, keys = {}, mouse = {} }
common.wfactstep = 0.05
-- default keys
common.keys.base = {
{
{ "Mod4" }, "c", function() common.action.kill() end,
{ description = "Kill application", group = "Action" }
},
{
{}, "Escape", function() common.action.exit() end,
{ description = "Exit navigation mode", group = "Action" }
},
{
{ "Mod4" }, "Escape", function() common.action.exit() end,
{} -- hidden key
},
{
{ "Mod4" }, "Super_L", function() common.action.exit() end,
{ description = "Exit navigation mode", group = "Action" }
},
{
{ "Mod4" }, "F1", function() redtip:show() end,
{ description = "Show hotkeys helper", group = "Action" }
},
}
common.keys.swap = {
{
{ "Mod4" }, "Up", function() awful.client.swap.bydirection("up") end,
{ description = "Move application up", group = "Movement" }
},
{
{ "Mod4" }, "Down", function() awful.client.swap.bydirection("down") end,
{ description = "Move application down", group = "Movement" }
},
{
{ "Mod4" }, "Left", function() awful.client.swap.bydirection("left") end,
{ description = "Move application left", group = "Movement" }
},
{
{ "Mod4" }, "Right", function() awful.client.swap.bydirection("right") end,
{ description = "Move application right", group = "Movement" }
},
}
common.keys.tile = {
{
{ "Mod4" }, "l", function () awful.tag.incmwfact( common.wfactstep) end,
{ description = "Increase master width factor", group = "Layout" }
},
{
{ "Mod4" }, "h", function () awful.tag.incmwfact(-common.wfactstep) end,
{ description = "Decrease master width factor", group = "Layout" }
},
{
{ "Mod4", "Shift" }, "h", function () awful.tag.incnmaster( 1, nil, true) end,
{ description = "Increase the number of master clients", group = "Layout" }
},
{
{ "Mod4", "Shift" }, "l", function () awful.tag.incnmaster(-1, nil, true) end,
{ description = "Decrease the number of master clients", group = "Layout" }
},
{
{ "Mod4", "Control" }, "h", function () awful.tag.incncol( 1, nil, true) end,
{ description = "Increase the number of columns", group = "Layout" }
},
{
{ "Mod4", "Control" }, "l", function () awful.tag.incncol(-1, nil, true) end,
{ description = "Decrease the number of columns", group = "Layout" }
},
}
common.keys.corner = {
{
{ "Mod4" }, "l", function () awful.tag.incmwfact( common.wfactstep) end,
{ description = "Increase master width factor", group = "Layout" }
},
{
{ "Mod4" }, "h", function () awful.tag.incmwfact(-common.wfactstep) end,
{ description = "Decrease master width factor", group = "Layout" }
},
{
{ "Mod4", "Shift" }, "h", function () awful.tag.incnmaster( 1, nil, true) end,
{ description = "Increase the number of master clients", group = "Layout" }
},
{
{ "Mod4", "Shift" }, "l", function () awful.tag.incnmaster(-1, nil, true) end,
{ description = "Decrease the number of master clients", group = "Layout" }
},
}
common.keys.magnifier = {
{
{ "Mod4" }, "l", function () awful.tag.incmwfact( common.wfactstep) end,
{ description = "Increase master width factor", group = "Layout" }
},
{
{ "Mod4" }, "h", function () awful.tag.incmwfact(-common.wfactstep) end,
{ description = "Decrease master width factor", group = "Layout" }
},
{
{ "Mod4" }, "g", function () awful.client.setmaster(client.focus) end,
{ description = "Set focused client as master", group = "Movement" }
},
}
-- TODO: set real keyset from navigator theme
common.keys._fake = {
{
{ "Mod4" }, "N1 N2", nil,
{
description = "Swap clients by key", group = "Movement",
keyset = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }
}
},
{
{ "Mod4" }, "N1 N1", nil,
{
description = "Focus client by key", group = "Action",
keyset = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }
}
},
}
-- Common handler actions
-----------------------------------------------------------------------------------------------------------------------
common.action = {}
function common.action.exit()
navigator:close()
common.last = {}
end
function common.action.kill()
client.focus:kill()
navigator:restart()
common.last.key = nil
end
-- Keys setup
-----------------------------------------------------------------------------------------------------------------------
-- Hotkey tips update functions
--------------------------------------------------------------------------------
common.updates = {}
local function build_base_tip()
return awful.util.table.join(common.keys.swap, common.keys.base, common.keys._fake)
end
local function build_tile_tip()
return awful.util.table.join(common.keys.swap, common.keys.tile, common.keys.base, common.keys._fake)
end
local function build_corner_tip()
return awful.util.table.join(common.keys.swap, common.keys.corner, common.keys.base, common.keys._fake)
end
local function build_magnifier_tip()
return awful.util.table.join(common.keys.magnifier, common.keys.base, common.keys._fake)
end
local function set_corner_tip()
common.tips[layout.suit.corner.nw] = build_corner_tip()
common.tips[layout.suit.corner.ne] = build_corner_tip()
common.tips[layout.suit.corner.sw] = build_corner_tip()
common.tips[layout.suit.corner.se] = build_corner_tip()
end
local function set_tile_tip()
common.tips[layout.suit.tile] = build_tile_tip()
common.tips[layout.suit.tile.right] = build_tile_tip()
common.tips[layout.suit.tile.left] = build_tile_tip()
common.tips[layout.suit.tile.top] = build_tile_tip()
common.tips[layout.suit.tile.bottom] = build_tile_tip()
end
common.updates.swap = function()
common.tips[layout.suit.fair] = build_base_tip()
common.tips[layout.suit.spiral] = build_base_tip()
common.tips[layout.suit.spiral.dwindle] = build_base_tip()
set_tile_tip()
set_corner_tip()
end
common.updates.base = function()
common.tips[layout.suit.fair] = build_base_tip()
common.tips[layout.suit.spiral] = build_base_tip()
common.tips[layout.suit.spiral.dwindle] = build_base_tip()
common.tips[layout.suit.magnifier] = build_magnifier_tip()
set_tile_tip()
set_corner_tip()
end
common.updates.magnifier = function()
common.tips[layout.suit.magnifier] = build_magnifier_tip()
end
common.updates.tile = function()
set_tile_tip()
end
common.updates.corner = function()
set_corner_tip()
end
-- Keys setup function
--------------------------------------------------------------------------------
function common:set_keys(keys, layout)
if keys then common.keys[layout] = keys end -- update keys
if self.updates[layout] then self.updates[layout]() end -- update tips
end
-- Shared keyboard handlers
-----------------------------------------------------------------------------------------------------------------------
common.grabbers = {}
-- Base grabbers
--------------------------------------------------------------------------------
common.grabbers.base = function(mod, key, event)
for _, k in ipairs(common.keys.base) do
if redutil.key.match_grabber(k, mod, key) then k[3](); return true end
end
-- if numkey pressed
local index = awful.util.table.hasitem(navigator.style.num, key)
-- swap or focus client
if index then
if navigator.data[index] and awful.util.table.hasitem(navigator.cls, navigator.data[index].client) then
if common.last.key then
if common.last.key == index then
client.focus = navigator.data[index].client
client.focus:raise()
else
redutil.client.swap(navigator.data[common.last.key].client, navigator.data[index].client)
end
common.last.key = nil
else
common.last.key = index
end
return true
end
end
end
common.grabbers.swap = function(mod, key, event)
for _, k in ipairs(common.keys.swap) do
if redutil.key.match_grabber(k, mod, key) then k[3](); return true end
end
end
common.grabbers.tile = function(mod, key, event)
for _, k in ipairs(common.keys.tile) do
if redutil.key.match_grabber(k, mod, key) then k[3](); return true end
end
end
common.grabbers.corner = function(mod, key, event)
for _, k in ipairs(common.keys.corner) do
if redutil.key.match_grabber(k, mod, key) then k[3](); return true end
end
end
common.grabbers.magnifier = function(mod, key, event)
for _, k in ipairs(common.keys.magnifier) do
if redutil.key.match_grabber(k, mod, key) then k[3](); return true end
end
end
-- Grabbers for awful layouts
--------------------------------------------------------------------------------
local function fair_handler(mod, key, event)
if event == "press" then return end
if common.grabbers.swap(mod, key, event) then return end
if common.grabbers.base(mod, key, event) then return end
end
local function magnifier_handler(mod, key, event)
if event == "press" then return end
if common.grabbers.magnifier(mod, key, event) then return end
if common.grabbers.base(mod, key, event) then return end
end
local function tile_handler(mod, key, event)
if event == "press" then return end
if common.grabbers.tile(mod, key, event) then return end
if common.grabbers.swap(mod, key, event) then return end
if common.grabbers.base(mod, key, event) then return end
end
local function corner_handler(mod, key, event)
if event == "press" then return end
if common.grabbers.corner(mod, key, event) then return end
if common.grabbers.swap(mod, key, event) then return end
if common.grabbers.base(mod, key, event) then return end
end
-- Handlers table
-----------------------------------------------------------------------------------------------------------------------
common.handler[layout.suit.fair] = fair_handler
common.handler[layout.suit.spiral] = fair_handler
common.handler[layout.suit.magnifier] = magnifier_handler
common.handler[layout.suit.tile] = tile_handler
common.handler[layout.suit.tile.right] = tile_handler
common.handler[layout.suit.tile.left] = tile_handler
common.handler[layout.suit.tile.top] = tile_handler
common.handler[layout.suit.tile.bottom] = tile_handler
common.handler[layout.suit.corner.nw] = corner_handler
common.handler[layout.suit.corner.ne] = corner_handler
common.handler[layout.suit.corner.se] = corner_handler
common.handler[layout.suit.corner.sw] = corner_handler
common.handler[layout.suit.spiral.dwindle] = fair_handler
-- tip dirty setup
common:set_keys(nil, "base")
-- Slightly changed awful mouse move handler
-----------------------------------------------------------------------------------------------------------------------
function common.mouse.move(c, context, hints)
-- Quit if it isn't a mouse.move on a tiled layout, that's handled elsewhere (WHERE?)
if c.floating then return end
if context ~= "mouse.move" then return end
-- move to screen with mouse
if mouse.screen ~= c.screen then c.screen = mouse.screen end
-- check if cutstom layout hadler availible
local l = c.screen.selected_tag and c.screen.selected_tag.layout or nil
if l == awful.layout.suit.floating then return end
if l and l.move_handler then
l.move_handler(c, context, hints)
return
end
-- general handler for tile layouts
local c_u_m = mouse.current_client
if c_u_m and not c_u_m.floating then
if c_u_m ~= c then c:swap(c_u_m) end
end
end
-- End
-----------------------------------------------------------------------------------------------------------------------
return common