-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathhot_corner.lua
More file actions
132 lines (106 loc) · 3.21 KB
/
Copy pathhot_corner.lua
File metadata and controls
132 lines (106 loc) · 3.21 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
local capi = {screen = screen}
local wibox = require( "wibox" )
local util = require( "awful.util" )
local timer = require( "gears.timer" )
local placement = require( "awful.placement" )
local module = {}
--TODO add "wrap cursor mode"
local wibox_to_req = {}
local corners_geo = {
-- Corners
top_left = function(geo, wa) return {width = 1, height = 1} end,
top_right = function(geo, wa) return {width = 1, height = 1} end,
bottom_left = function(geo, wa) return {width = 1, height = 1} end,
bottom_right = function(geo, wa) return {width = 1, height = 1} end,
-- Sides
left = function(geo, wa) return {width = 1 , height = wa.height } end,
right = function(geo, wa) return {width = 1 , height = wa.height } end,
top = function(geo, wa) return {width = wa.width, height = 1 } end,
bottom = function(geo, wa) return {width = wa.width, height = 1 } end,
}
local function mouse_enter(w)
local req = wibox_to_req[w]
if req and req.enter then
req:enter()
end
end
local function mouse_leave(w)
local req = wibox_to_req[w]
if req and req.leave then
req:leave()
end
end
local function create_hot_corner(corner, s)
s = s or 1
local size = corners_geo[corner] (
capi.screen[s].geometry,
capi.screen[s].workarea
)
local w = wibox(util.table.crush(size, {ontop=true, opacity = 0, visible=true}))
placement[corner](w, {
parent = capi.screen[s],
attach = true,
})
local req = {wibox = w, screen = s, corner = corner}
w:connect_signal("mouse::enter", mouse_enter)
wibox_to_req[w] = req
return req
end
local function create_visible_timer(w, time, req)
local t = timer{}
t.timeout = time
t:connect_signal("timeout", function()
w.visible = false
req.wibox.visible = true
t:stop()
end)
t:start()
end
function module.register_function(corner, f, s)
if not f then return end
local req = create_hot_corner(corner, s)
req.enter = f
return req
end
--- Show a wibox when `corner` is hit.
--
-- Valid corners are:
--
-- * left
-- * right
-- * top
-- * bottom
-- * top_left
-- * top_right
-- * bottom_left
-- * bottom_right
--
-- @tparam string corner A corner name
-- @param w The wibox or a function returning a wibox in case lazy loading is
-- desirable
-- @tparam[opt=all] number s The screen
-- @tparam[opt=0] number timeout The timeout (in seconds)
-- @return A request handler
function module.register_wibox(corner, w, s, timeout)
if not w then return end
local req = create_hot_corner(corner, s)
local connected = false
function req.enter()
if type(w) == "function" then
w = w(req)
end
if not connected then
w:connect_signal("mouse::leave", mouse_leave)
wibox_to_req[w] = req --FIXME leak
connected = true
end
w.visible = true
end
if not timeout then
function req.leave() w.visible = false; req.wibox.visible = true end
else
function req.leave() create_visible_timer(w, timeout, req) end
end
return req
end
return module