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,
|
2010-10-15 18:57:50 +02:00
|
|
|
awesome = awesome
|
2010-10-06 12:42:56 +02:00
|
|
|
}
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local pairs = pairs
|
|
|
|
local type = type
|
|
|
|
local table = table
|
2012-05-27 19:20:34 +02:00
|
|
|
local string_format = string.format
|
2010-10-06 12:42:56 +02:00
|
|
|
local color = require("gears.color")
|
|
|
|
local object = require("gears.object")
|
|
|
|
local beautiful = require("beautiful")
|
2012-05-27 19:20:34 +02:00
|
|
|
local surface = require("gears.surface")
|
|
|
|
local cairo = require("lgi").cairo
|
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
|
|
|
|
local wibox = { mt = {} }
|
|
|
|
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
|
|
|
|
|
|
|
--- Set the widget that the wibox displays
|
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
|
|
|
|
|
2015-09-27 17:00:01 +02:00
|
|
|
--- Set a declarative widget hierarchy description.
|
|
|
|
-- See [The declarative layout system](../documentation/03-declarative-layout.md.html)
|
|
|
|
-- @param args An array containing the widgets disposition
|
|
|
|
-- @name setup
|
|
|
|
-- @class function
|
|
|
|
wibox.setup = base.widget.setup
|
|
|
|
|
2010-10-06 12:42:56 +02:00
|
|
|
--- Set the background of the wibox
|
|
|
|
-- @param c The background to use. This must either be a cairo pattern object,
|
2014-05-20 13:02:13 +02:00
|
|
|
-- nil or a string that gears.color() understands.
|
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
|
|
|
--- Set the background image of the drawable
|
|
|
|
-- If `image` is a function, it will be called with `(context, cr, width, height)`
|
|
|
|
-- as arguments. Any other arguments passed to this method will be appended.
|
|
|
|
-- @param image A background image or a function
|
|
|
|
function wibox:set_bgimage(image, ...)
|
|
|
|
self._drawable:set_bgimage(image, ...)
|
|
|
|
end
|
|
|
|
|
2010-10-06 12:42:56 +02:00
|
|
|
--- Set the foreground of the wibox
|
|
|
|
-- @param c The foreground to use. This must either be a cairo pattern object,
|
2014-05-20 13:02:13 +02:00
|
|
|
-- nil or a string that gears.color() understands.
|
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
|
|
|
--- 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
|
2015-10-14 00:21:29 +02:00
|
|
|
-- widgets are sorted by relevance.
|
2014-08-20 11:26:09 +02:00
|
|
|
function wibox:find_widgets(x, y)
|
|
|
|
return self._drawable:find_widgets(x, y)
|
|
|
|
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)
|
|
|
|
local w = _wibox.drawin
|
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
|
|
|
|
w: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
|
|
|
|
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")
|
2012-10-31 22:12:30 +01:00
|
|
|
|
|
|
|
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")
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function new(args)
|
|
|
|
local ret = object()
|
|
|
|
local w = capi.drawin(args)
|
|
|
|
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)
|
|
|
|
mt.__tostring = function(o)
|
|
|
|
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()
|
|
|
|
|
|
|
|
-- Redirect all non-existing indexes to the "real" drawin
|
|
|
|
setmetatable(ret, {
|
|
|
|
__index = w,
|
|
|
|
__newindex = w
|
|
|
|
})
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
2010-12-14 21:07:04 +01:00
|
|
|
--- 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.
|
2014-05-20 13:02:13 +02:00
|
|
|
-- @table drawin
|
2010-12-14 21:07:04 +01:00
|
|
|
|
2012-06-12 14:14:57 +02:00
|
|
|
function wibox.mt:__call(...)
|
|
|
|
return new(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|