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 object = require("gears.object")
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2016-05-03 05:27:00 +02:00
|
|
|
-- Import some drawin documentation
|
|
|
|
|
|
|
|
--- Border width.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::border_width*
|
|
|
|
--
|
|
|
|
-- @property border_width
|
|
|
|
-- @param integer
|
|
|
|
|
|
|
|
--- Border color.
|
|
|
|
--
|
|
|
|
-- Please note that this property only support string based 24 bit or 32 bit
|
|
|
|
-- colors:
|
|
|
|
--
|
|
|
|
-- Red Blue
|
|
|
|
-- _| _|
|
|
|
|
-- #FF00FF
|
|
|
|
-- T‾
|
|
|
|
-- Green
|
|
|
|
--
|
|
|
|
--
|
|
|
|
-- Red Blue
|
|
|
|
-- _| _|
|
|
|
|
-- #FF00FF00
|
|
|
|
-- T‾ ‾T
|
|
|
|
-- Green Alpha
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::border_color*
|
|
|
|
--
|
|
|
|
-- @property border_color
|
|
|
|
-- @param string
|
|
|
|
|
|
|
|
--- On top of other windows.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::ontop*
|
|
|
|
--
|
|
|
|
-- @property ontop
|
|
|
|
-- @param boolean
|
|
|
|
|
|
|
|
--- The mouse cursor.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::cursor*
|
|
|
|
--
|
|
|
|
-- @property cursor
|
|
|
|
-- @param string
|
|
|
|
-- @see mouse
|
|
|
|
|
|
|
|
--- Visibility.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::visible*
|
|
|
|
--
|
|
|
|
-- @property visible
|
|
|
|
-- @param boolean
|
|
|
|
|
|
|
|
--- The opacity of the wibox, between 0 and 1.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::opacity*
|
|
|
|
--
|
|
|
|
-- @property opacity
|
|
|
|
-- @tparam number opacity (between 0 and 1)
|
|
|
|
|
|
|
|
--- The window type (desktop, normal, dock, ...).
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::type*
|
|
|
|
--
|
|
|
|
-- @property type
|
|
|
|
-- @param string
|
|
|
|
-- @see client.type
|
|
|
|
|
|
|
|
--- The x coordinates.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::x*
|
|
|
|
--
|
|
|
|
-- @property x
|
|
|
|
-- @param integer
|
|
|
|
|
|
|
|
--- The y coordinates.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::y*
|
|
|
|
--
|
|
|
|
-- @property y
|
|
|
|
-- @param integer
|
|
|
|
|
|
|
|
--- The width of the wibox.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::width*
|
|
|
|
--
|
|
|
|
-- @property width
|
|
|
|
-- @param width
|
|
|
|
|
|
|
|
--- The height of the wibox.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::height*
|
|
|
|
--
|
|
|
|
-- @property height
|
|
|
|
-- @param height
|
|
|
|
|
|
|
|
--- The wibox's `drawable`.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::drawable*
|
|
|
|
--
|
|
|
|
-- @property drawable
|
|
|
|
-- @tparam drawable drawable
|
|
|
|
|
|
|
|
--- The X window id.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::window*
|
|
|
|
--
|
|
|
|
-- @property window
|
|
|
|
-- @param string
|
|
|
|
-- @see client.window
|
|
|
|
|
|
|
|
--- The wibox's bounding shape as a (native) cairo surface.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::shape_bounding*
|
|
|
|
--
|
|
|
|
-- @property shape_bounding
|
|
|
|
-- @param surface._native
|
|
|
|
|
|
|
|
--- The wibox's clip shape as a (native) cairo surface.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * *property::shape_clip*
|
|
|
|
--
|
|
|
|
-- @property shape_clip
|
|
|
|
-- @param surface._native
|
|
|
|
|
|
|
|
--- Get or set mouse buttons bindings to a wibox.
|
|
|
|
--
|
|
|
|
-- @param buttons_table A table of buttons objects, or nothing.
|
|
|
|
-- @function wibox.buttons
|
|
|
|
|
|
|
|
--- Get or set wibox geometry. That's the same as accessing or setting the x,
|
|
|
|
-- y, width or height properties of a wibox.
|
|
|
|
--
|
|
|
|
-- @param A table with coordinates to modify.
|
|
|
|
-- @return A table with wibox coordinates and geometry.
|
|
|
|
-- @function wibox.geometry
|
|
|
|
|
|
|
|
--- Get or set wibox struts.
|
|
|
|
--
|
|
|
|
-- @param strut A table with new strut, or nothing
|
|
|
|
-- @return The wibox strut in a table.
|
|
|
|
-- @function wibox.struts
|
|
|
|
-- @see client.struts
|
|
|
|
|
|
|
|
--- The default background color.
|
|
|
|
-- @beautiful beautiful.bg_normal
|
|
|
|
-- @see set_bg
|
|
|
|
|
|
|
|
--- The default foreground (text) color.
|
|
|
|
-- @beautiful beautiful.fg_normal
|
|
|
|
-- @see set_fg
|
|
|
|
|
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.
|
2016-05-03 07:18:08 +02:00
|
|
|
-- @tparam number x X coordinate of the point
|
|
|
|
-- @tparam number y Y coordinate of the point
|
|
|
|
-- @treturn table A sorted table of widgets positions. The first element is the biggest
|
|
|
|
-- container while the last is the topmost widget. The table contains *x*, *y*,
|
|
|
|
-- *width*, *height* and *widget*.
|
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)
|
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, {
|
|
|
|
__index = w,
|
2016-05-08 05:46:57 +02:00
|
|
|
__newindex = function(self, k,v)
|
|
|
|
if wibox["set_"..k] then
|
|
|
|
wibox["set_"..k](v)
|
|
|
|
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
|