1 ---------------------------------------------------------------------------
2 -- @author Uli Schlachter
3 -- @copyright 2010 Uli Schlachter
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
12 local setmetatable
= setmetatable
16 local string_format
= string.format
17 local color
= require("gears.color")
18 local object
= require("gears.object")
19 local sort = require("gears.sort")
20 local beautiful
= require("beautiful")
21 local surface
= require("gears.surface")
22 local cairo
= require("lgi").cairo
24 --- This provides widget box windows. Every wibox can also be used as if it were
25 -- a drawin. All drawin functions and properties are also available on wiboxes!
27 local wibox
= { mt
= {} }
28 wibox
.layout
= require("wibox.layout")
29 wibox
.widget
= require("wibox.widget")
30 wibox
.drawable
= require("wibox.drawable")
32 --- Set the widget that the wibox displays
33 function wibox
.set_widget(_wibox
, widget
)
34 _wibox
._drawable
:set_widget(widget
)
37 --- Set the background of the wibox
38 -- @param wibox The wibox to use
39 -- @param c The background to use. This must either be a cairo pattern object,
40 -- nil or a string that gears.color() understands.
41 function wibox
.set_bg(_wibox
, c
)
42 _wibox
._drawable
:set_bg(c
)
45 --- Set the foreground of the wibox
46 -- @param wibox The wibox to use
47 -- @param c The foreground to use. This must either be a cairo pattern object,
48 -- nil or a string that gears.color() understands.
49 function wibox
.set_fg(_wibox
, c
)
50 _wibox
._drawable
:set_fg(c
)
53 --- Helper function to make wibox:buttons() work as expected
54 function wibox
.buttons(box
, ...)
55 return box
.drawin
:buttons(...)
58 --- Helper function to make wibox:struts() work as expected
59 function wibox
.struts(box
, ...)
60 return box
.drawin
:struts(...)
63 --- Helper function to make wibox:geometry() work as expected
64 function wibox
.geometry(box
, ...)
65 return box
.drawin
:geometry(...)
68 local function setup_signals(_wibox
)
69 local w
= _wibox
.drawin
71 local function clone_signal(name
)
72 _wibox
:add_signal(name
)
73 -- When "name" is emitted on wibox.drawin, also emit it on wibox
74 w
:connect_signal(name
, function(_
, ...)
75 _wibox
:emit_signal(name
, ...)
78 clone_signal("property::border_color")
79 clone_signal("property::border_width")
80 clone_signal("property::buttons")
81 clone_signal("property::cursor")
82 clone_signal("property::height")
83 clone_signal("property::ontop")
84 clone_signal("property::opacity")
85 clone_signal("property::struts")
86 clone_signal("property::visible")
87 clone_signal("property::widgets")
88 clone_signal("property::width")
89 clone_signal("property::x")
90 clone_signal("property::y")
92 local d
= _wibox
._drawable
93 local function clone_signal(name
)
94 _wibox
:add_signal(name
)
95 -- When "name" is emitted on wibox.drawin, also emit it on wibox
96 d
:connect_signal(name
, function(_
, ...)
97 _wibox
:emit_signal(name
, ...)
100 clone_signal("button::press")
101 clone_signal("button::release")
102 clone_signal("mouse::enter")
103 clone_signal("mouse::leave")
104 clone_signal("mouse::move")
105 clone_signal("property::surface")
108 local function new(args
)
110 local w
= capi
.drawin(args
)
112 ret
._drawable
= wibox
.drawable(w
.drawable
, ret
)
114 for k
, v
in pairs(wibox
) do
115 if type(v
) == "function" then
121 ret
.draw
= ret
._drawable
.draw
122 ret
.widget_at
= function(_
, widget
, x
, y
, width
, height
)
123 return ret
._drawable
:widget_at(widget
, x
, y
, width
, height
)
126 -- Set the default background
127 ret
:set_bg(args
.bg
or beautiful
.bg_normal
)
128 ret
:set_fg(args
.fg
or beautiful
.fg_normal
)
130 -- Make sure the wibox is drawn at least once
133 -- Redirect all non-existing indexes to the "real" drawin
142 --- Redraw a wibox. You should never have to call this explicitely because it is
143 -- automatically called when needed.
148 --- Widget box object.
149 -- Every wibox "inherits" from a drawin and you can use all of drawin's
150 -- functions directly on this as well. When creating a wibox, you can specify a
151 -- "fg" and a "bg" color as keys in the table that is passed to the constructor.
152 -- All other arguments will be passed to drawin's constructor.
156 function wibox
.mt
:__call(...)
160 return setmetatable(wibox
, wibox
.mt
)
162 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80