2010-10-06 12:42:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2010 Uli Schlachter
|
|
|
|
-- @release @AWESOME_VERSION@
|
2015-02-25 11:18:53 +01:00
|
|
|
-- @classmod wibox
|
2010-10-06 12:42:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local capi = {
|
|
|
|
drawin = drawin,
|
2012-04-07 21:54:51 +02:00
|
|
|
root = root,
|
2016-05-10 06:01:35 +02:00
|
|
|
awesome = awesome,
|
|
|
|
screen = screen
|
2010-10-06 12:42:56 +02:00
|
|
|
}
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local pairs = pairs
|
|
|
|
local type = type
|
|
|
|
local object = require("gears.object")
|
2016-05-16 05:46:11 +02:00
|
|
|
local grect = require("gears.geometry").rectangle
|
2010-10-06 12:42:56 +02:00
|
|
|
local beautiful = require("beautiful")
|
2015-09-27 17:00:01 +02:00
|
|
|
local base = require("wibox.widget.base")
|
2010-10-06 12:42:56 +02:00
|
|
|
|
2010-12-12 21:45:54 +01:00
|
|
|
--- 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!
|
2012-06-12 14:14:57 +02:00
|
|
|
-- wibox
|
2016-05-03 05:57:33 +02:00
|
|
|
local wibox = { mt = {}, object = {} }
|
2012-06-12 14:14:57 +02:00
|
|
|
wibox.layout = require("wibox.layout")
|
|
|
|
wibox.widget = require("wibox.widget")
|
2012-10-14 17:20:24 +02:00
|
|
|
wibox.drawable = require("wibox.drawable")
|
2015-08-12 11:53:01 +02:00
|
|
|
wibox.hierarchy = require("wibox.hierarchy")
|
2010-10-06 12:42:56 +02:00
|
|
|
|
2016-05-08 05:46:57 +02:00
|
|
|
local force_forward = {
|
|
|
|
shape_bounding = true,
|
|
|
|
shape_clip = true,
|
|
|
|
}
|
|
|
|
|
2016-05-10 03:35:02 +02:00
|
|
|
--@DOC_wibox_COMMON@
|
|
|
|
|
2012-11-18 20:44:03 +01:00
|
|
|
function wibox:set_widget(widget)
|
|
|
|
self._drawable:set_widget(widget)
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
2016-05-10 03:35:02 +02:00
|
|
|
function wibox:get_widget()
|
|
|
|
return self._drawable.widget
|
|
|
|
end
|
2016-05-03 05:27:00 +02:00
|
|
|
|
2015-09-27 17:00:01 +02:00
|
|
|
wibox.setup = base.widget.setup
|
|
|
|
|
2012-11-18 20:44:03 +01:00
|
|
|
function wibox:set_bg(c)
|
|
|
|
self._drawable:set_bg(c)
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
2016-02-08 09:37:37 +01:00
|
|
|
function wibox:set_bgimage(image, ...)
|
|
|
|
self._drawable:set_bgimage(image, ...)
|
|
|
|
end
|
|
|
|
|
2012-11-18 20:44:03 +01:00
|
|
|
function wibox:set_fg(c)
|
|
|
|
self._drawable:set_fg(c)
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
2014-08-20 11:26:09 +02:00
|
|
|
function wibox:find_widgets(x, y)
|
|
|
|
return self._drawable:find_widgets(x, y)
|
|
|
|
end
|
|
|
|
|
2016-05-10 06:01:35 +02:00
|
|
|
function wibox:get_screen()
|
2016-05-16 05:46:11 +02:00
|
|
|
local sgeos = {}
|
|
|
|
|
|
|
|
for s in capi.screen do
|
|
|
|
sgeos[s] = s.geometry
|
|
|
|
end
|
|
|
|
|
|
|
|
return grect.get_closest_by_coord(sgeos, self.x, self.y)
|
2016-05-10 06:01:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function wibox:set_screen(s)
|
|
|
|
s = capi.screen[s or 1]
|
|
|
|
if s ~= self:get_screen() then
|
|
|
|
self.x = s.geometry.x
|
|
|
|
self.y = s.geometry.y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-07 13:49:24 +01:00
|
|
|
for _, k in pairs{ "buttons", "struts", "geometry", "get_xproperty", "set_xproperty" } do
|
|
|
|
wibox[k] = function(self, ...)
|
|
|
|
return self.drawin[k](self.drawin, ...)
|
|
|
|
end
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
2012-06-12 14:14:57 +02:00
|
|
|
local function setup_signals(_wibox)
|
2016-02-07 14:13:43 +01:00
|
|
|
local obj
|
2010-10-06 12:42:56 +02:00
|
|
|
local function clone_signal(name)
|
2012-06-12 14:14:57 +02:00
|
|
|
_wibox:add_signal(name)
|
2010-10-06 12:42:56 +02:00
|
|
|
-- When "name" is emitted on wibox.drawin, also emit it on wibox
|
2016-02-07 14:13:43 +01:00
|
|
|
obj:connect_signal(name, function(_, ...)
|
2012-06-12 14:14:57 +02:00
|
|
|
_wibox:emit_signal(name, ...)
|
2010-10-06 12:42:56 +02:00
|
|
|
end)
|
|
|
|
end
|
2016-02-07 14:13:43 +01:00
|
|
|
|
|
|
|
obj = _wibox.drawin
|
2010-10-06 12:42:56 +02:00
|
|
|
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")
|
2016-03-13 03:14:09 +01:00
|
|
|
clone_signal("property::geometry")
|
|
|
|
clone_signal("property::shape_bounding")
|
|
|
|
clone_signal("property::shape_clip")
|
2012-10-31 22:12:30 +01:00
|
|
|
|
2016-02-07 14:13:43 +01:00
|
|
|
obj = _wibox._drawable
|
2012-10-31 22:12:30 +01:00
|
|
|
clone_signal("button::press")
|
|
|
|
clone_signal("button::release")
|
|
|
|
clone_signal("mouse::enter")
|
|
|
|
clone_signal("mouse::leave")
|
|
|
|
clone_signal("mouse::move")
|
|
|
|
clone_signal("property::surface")
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function new(args)
|
2016-05-15 07:10:11 +02:00
|
|
|
args = args or {}
|
2010-10-06 12:42:56 +02:00
|
|
|
local ret = object()
|
|
|
|
local w = capi.drawin(args)
|
2016-05-03 05:57:33 +02:00
|
|
|
|
2016-05-03 05:57:33 +02:00
|
|
|
-- lua 5.1 and luajit have issues with self referencing loops
|
|
|
|
local avoid_leak = setmetatable({ret},{__mode="v"})
|
|
|
|
|
|
|
|
function w.get_wibox()
|
|
|
|
return avoid_leak[1]
|
|
|
|
end
|
|
|
|
|
2010-10-06 12:42:56 +02:00
|
|
|
ret.drawin = w
|
2015-08-08 13:13:47 +02:00
|
|
|
ret._drawable = wibox.drawable(w.drawable, { wibox = ret },
|
2015-07-29 21:12:41 +02:00
|
|
|
"wibox drawable (" .. object.modulename(3) .. ")")
|
2010-10-06 12:42:56 +02:00
|
|
|
|
2012-06-12 14:14:57 +02:00
|
|
|
for k, v in pairs(wibox) do
|
2010-10-06 12:42:56 +02:00
|
|
|
if type(v) == "function" then
|
|
|
|
ret[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
setup_signals(ret)
|
2012-10-14 17:20:24 +02:00
|
|
|
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
|
2010-10-06 12:42:56 +02:00
|
|
|
|
|
|
|
-- Set the default background
|
|
|
|
ret:set_bg(args.bg or beautiful.bg_normal)
|
|
|
|
ret:set_fg(args.fg or beautiful.fg_normal)
|
|
|
|
|
2015-07-29 21:14:40 +02:00
|
|
|
-- Add __tostring method to metatable.
|
|
|
|
local mt = {}
|
|
|
|
local orig_string = tostring(ret)
|
2016-02-07 14:13:43 +01:00
|
|
|
mt.__tostring = function()
|
2015-07-29 21:14:40 +02:00
|
|
|
return string.format("wibox: %s (%s)",
|
|
|
|
tostring(ret._drawable), orig_string)
|
|
|
|
end
|
|
|
|
ret = setmetatable(ret, mt)
|
|
|
|
|
2010-10-06 12:42:56 +02:00
|
|
|
-- Make sure the wibox is drawn at least once
|
|
|
|
ret.draw()
|
|
|
|
|
2016-05-08 05:46:57 +02:00
|
|
|
-- If a value is not found, look in the drawin
|
2010-10-06 12:42:56 +02:00
|
|
|
setmetatable(ret, {
|
2016-05-08 07:41:19 +02:00
|
|
|
__index = function(self, k)
|
|
|
|
if rawget(self, "get_"..k) then
|
|
|
|
return self["get_"..k](self)
|
|
|
|
else
|
|
|
|
return w[k]
|
|
|
|
end
|
|
|
|
end,
|
2016-05-08 05:46:57 +02:00
|
|
|
__newindex = function(self, k,v)
|
2016-05-08 07:41:19 +02:00
|
|
|
if rawget(self, "set_"..k) then
|
|
|
|
self["set_"..k](self, v)
|
2016-05-08 05:46:57 +02:00
|
|
|
elseif w[k] ~= nil or force_forward[k] then
|
|
|
|
w[k] = v
|
|
|
|
else
|
|
|
|
rawset(self, k, v)
|
|
|
|
end
|
|
|
|
end
|
2010-10-06 12:42:56 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2016-05-03 05:57:33 +02:00
|
|
|
capi.drawin.add_signal("property::get_wibox")
|
|
|
|
|
2010-12-12 21:45:54 +01:00
|
|
|
--- Redraw a wibox. You should never have to call this explicitely because it is
|
|
|
|
-- automatically called when needed.
|
|
|
|
-- @param wibox
|
2014-05-20 13:02:13 +02:00
|
|
|
-- @function draw
|
2010-12-12 21:45:54 +01:00
|
|
|
|
2012-06-12 14:14:57 +02:00
|
|
|
function wibox.mt:__call(...)
|
|
|
|
return new(...)
|
|
|
|
end
|
|
|
|
|
2016-05-03 05:57:33 +02:00
|
|
|
-- Extend the luaobject
|
|
|
|
object.properties(capi.drawin, {
|
|
|
|
getter_class = wibox.object,
|
|
|
|
setter_class = wibox.object,
|
|
|
|
auto_emit = true,
|
|
|
|
})
|
|
|
|
|
2012-06-12 14:14:57 +02:00
|
|
|
return setmetatable(wibox, wibox.mt)
|
2010-10-06 12:42:56 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|