forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua.in
More file actions
160 lines (138 loc) · 4.8 KB
/
Copy pathinit.lua.in
File metadata and controls
160 lines (138 loc) · 4.8 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
---------------------------------------------------------------------------
-- @author Uli Schlachter
-- @copyright 2010 Uli Schlachter
-- @release @AWESOME_VERSION@
---------------------------------------------------------------------------
local capi = {
drawin = drawin,
root = root,
awesome = awesome
}
local setmetatable = setmetatable
local pairs = pairs
local type = type
local table = table
local string_format = string.format
local color = require("gears.color")
local object = require("gears.object")
local sort = require("gears.sort")
local beautiful = require("beautiful")
local surface = require("gears.surface")
local cairo = require("lgi").cairo
--- This provides widget box windows. Every wibox can also be used as if it were
-- a drawin. All drawin functions and properties are also available on wiboxes!
-- wibox
local wibox = { mt = {} }
wibox.layout = require("wibox.layout")
wibox.widget = require("wibox.widget")
wibox.drawable = require("wibox.drawable")
--- Set the widget that the wibox displays
function wibox:set_widget(widget)
self._drawable:set_widget(widget)
end
--- Set the background of the wibox
-- @param c The background to use. This must either be a cairo pattern object,
-- nil or a string that gears.color() understands.
function wibox:set_bg(c)
self._drawable:set_bg(c)
end
--- Set the foreground of the wibox
-- @param c The foreground to use. This must either be a cairo pattern object,
-- nil or a string that gears.color() understands.
function wibox:set_fg(c)
self._drawable:set_fg(c)
end
--- Find a widget by a point.
-- The wibox must have drawn itself at least once for this to work.
-- @param x X coordinate of the point
-- @param y Y coordinate of the point
-- @return A sorted table with all widgets that contain the given point. The
-- widgets are sorted by relevance.
function wibox:find_widgets(x, y)
return self._drawable:find_widgets(x, y)
end
for _, k in pairs{ "buttons", "struts", "geometry", "get_xproperty", "set_xproperty" } do
wibox[k] = function(self, ...)
return self.drawin[k](self.drawin, ...)
end
end
local function setup_signals(_wibox)
local w = _wibox.drawin
local function clone_signal(name)
_wibox:add_signal(name)
-- When "name" is emitted on wibox.drawin, also emit it on wibox
w:connect_signal(name, function(_, ...)
_wibox:emit_signal(name, ...)
end)
end
clone_signal("property::border_color")
clone_signal("property::border_width")
clone_signal("property::buttons")
clone_signal("property::cursor")
clone_signal("property::height")
clone_signal("property::ontop")
clone_signal("property::opacity")
clone_signal("property::struts")
clone_signal("property::visible")
clone_signal("property::width")
clone_signal("property::x")
clone_signal("property::y")
local d = _wibox._drawable
local function clone_signal(name)
_wibox:add_signal(name)
-- When "name" is emitted on wibox.drawin, also emit it on wibox
d:connect_signal(name, function(_, ...)
_wibox:emit_signal(name, ...)
end)
end
clone_signal("button::press")
clone_signal("button::release")
clone_signal("mouse::enter")
clone_signal("mouse::leave")
clone_signal("mouse::move")
clone_signal("property::surface")
end
local function new(args)
local ret = object()
local w = capi.drawin(args)
ret.drawin = w
ret._drawable = wibox.drawable(w.drawable, ret)
for k, v in pairs(wibox) do
if type(v) == "function" then
ret[k] = v
end
end
setup_signals(ret)
ret.draw = ret._drawable.draw
ret.widget_at = function(_, widget, x, y, width, height)
return ret._drawable:widget_at(widget, x, y, width, height)
end
-- Set the default background
ret:set_bg(args.bg or beautiful.bg_normal)
ret:set_fg(args.fg or beautiful.fg_normal)
-- Make sure the wibox is drawn at least once
ret.draw()
-- Redirect all non-existing indexes to the "real" drawin
setmetatable(ret, {
__index = w,
__newindex = w
})
return ret
end
--- Redraw a wibox. You should never have to call this explicitely because it is
-- automatically called when needed.
-- @param wibox
-- @name draw
-- @class function
--- Widget box object.
-- Every wibox "inherits" from a drawin and you can use all of drawin's
-- functions directly on this as well. When creating a wibox, you can specify a
-- "fg" and a "bg" color as keys in the table that is passed to the constructor.
-- All other arguments will be passed to drawin's constructor.
-- @class table
-- @name drawin
function wibox.mt:__call(...)
return new(...)
end
return setmetatable(wibox, wibox.mt)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80