2010-10-06 12:42:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2010 Uli Schlachter
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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 sort = require("gears.sort")
|
|
|
|
local beautiful = require("beautiful")
|
2012-05-27 19:20:34 +02:00
|
|
|
local surface = require("gears.surface")
|
|
|
|
local cairo = require("lgi").cairo
|
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")
|
2010-10-06 12:42:56 +02:00
|
|
|
|
|
|
|
--- Set the widget that the wibox displays
|
2012-06-12 14:14:57 +02:00
|
|
|
function wibox.set_widget(_wibox, widget)
|
2012-10-14 17:20:24 +02:00
|
|
|
_wibox._drawable:set_widget(widget)
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Set the background of the wibox
|
|
|
|
-- @param wibox The wibox to use
|
|
|
|
-- @param c The background to use. This must either be a cairo pattern object,
|
|
|
|
-- nil or a string that gears.color() understands.
|
2012-06-12 14:14:57 +02:00
|
|
|
function wibox.set_bg(_wibox, c)
|
2012-10-14 17:20:24 +02:00
|
|
|
_wibox._drawable:set_bg(c)
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Set the foreground of the wibox
|
|
|
|
-- @param wibox The wibox to use
|
|
|
|
-- @param c The foreground to use. This must either be a cairo pattern object,
|
|
|
|
-- nil or a string that gears.color() understands.
|
2012-06-12 14:14:57 +02:00
|
|
|
function wibox.set_fg(_wibox, c)
|
2012-10-14 17:20:24 +02:00
|
|
|
_wibox._drawable:set_fg(c)
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Helper function to make wibox:buttons() work as expected
|
2012-06-12 14:14:57 +02:00
|
|
|
function wibox.buttons(box, ...)
|
2010-10-06 12:42:56 +02:00
|
|
|
return box.drawin:buttons(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Helper function to make wibox:struts() work as expected
|
2012-06-12 14:14:57 +02:00
|
|
|
function wibox.struts(box, ...)
|
2010-10-06 12:42:56 +02:00
|
|
|
return box.drawin:struts(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Helper function to make wibox:geometry() work as expected
|
2012-06-12 14:14:57 +02:00
|
|
|
function wibox.geometry(box, ...)
|
2010-10-06 12:42:56 +02:00
|
|
|
return box.drawin:geometry(...)
|
|
|
|
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
|
2012-10-14 17:20:24 +02:00
|
|
|
ret._drawable = wibox.drawable(w.drawable, ret)
|
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)
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
-- @name draw
|
|
|
|
-- @class function
|
|
|
|
|
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.
|
|
|
|
-- @class table
|
|
|
|
-- @name drawin
|
|
|
|
|
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
|