drawin: Turn `:buttons()` into a property.

This commit is contained in:
Emmanuel Lepage Vallee 2018-12-26 21:16:33 -05:00
parent 3d918258e2
commit 29e804a4f8
6 changed files with 28 additions and 6 deletions

View File

@ -1344,6 +1344,12 @@ function client.object.is_transient_for(self, c2)
return nil return nil
end end
object.properties._legacy_accessors(client, "buttons", "_buttons", true, function(new_btns)
return new_btns[1] and (
type(new_btns[1]) == "button" or new_btns[1]._is_capi_button
) or false
end, true)
--- Set the client shape. --- Set the client shape.
-- @property shape -- @property shape
-- @tparam gears.shape A gears.shape compatible function. -- @tparam gears.shape A gears.shape compatible function.

View File

@ -421,6 +421,8 @@ function awfulwibar.new(args)
w:connect_signal("property::visible", function() reattach(w) end) w:connect_signal("property::visible", function() reattach(w) end)
assert(w.buttons)
return w return w
end end

View File

@ -19,6 +19,7 @@ local beautiful = require("beautiful")
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local cairo = require("lgi").cairo local cairo = require("lgi").cairo
--- This provides widget box windows. Every wibox can also be used as if it were --- 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! -- a drawin. All drawin functions and properties are also available on wiboxes!
-- wibox -- wibox
@ -63,6 +64,10 @@ function wibox:find_widgets(x, y)
return self._drawable:find_widgets(x, y) return self._drawable:find_widgets(x, y)
end end
function wibox:_buttons(btns)
return self.drawin:_buttons(btns)
end
--- Create a widget that reflects the current state of this wibox. --- Create a widget that reflects the current state of this wibox.
-- @treturn widget A new widget. -- @treturn widget A new widget.
-- @method to_widget -- @method to_widget
@ -207,12 +212,18 @@ function wibox:get_children_by_id(name)
return {} return {}
end end
for _, k in pairs{ "buttons", "struts", "geometry", "get_xproperty", "set_xproperty" } do for _, k in pairs{ "struts", "geometry", "get_xproperty", "set_xproperty" } do
wibox[k] = function(self, ...) wibox[k] = function(self, ...)
return self.drawin[k](self.drawin, ...) return self.drawin[k](self.drawin, ...)
end end
end end
object.properties._legacy_accessors(wibox.object, "buttons", "_buttons", true, function(new_btns)
return new_btns[1] and (
type(new_btns[1]) == "button" or new_btns[1]._is_capi_button
) or false
end, true)
local function setup_signals(_wibox) local function setup_signals(_wibox)
local obj local obj
local function clone_signal(name) local function clone_signal(name)
@ -264,6 +275,7 @@ local function new(args)
return ret return ret
end end
w._private = {}
ret.drawin = w ret.drawin = w
ret._drawable = wibox.drawable(w.drawable, { wibox = ret }, ret._drawable = wibox.drawable(w.drawable, { wibox = ret },
"wibox drawable (" .. object.modulename(3) .. ")") "wibox drawable (" .. object.modulename(3) .. ")")
@ -365,6 +377,8 @@ object.properties(capi.drawin, {
auto_emit = true, auto_emit = true,
}) })
capi.drawin.object = wibox.object
return setmetatable(wibox, wibox.mt) return setmetatable(wibox, wibox.mt)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -949,9 +949,9 @@
/** Get or set mouse buttons bindings for a client. /** Get or set mouse buttons bindings for a client.
* *
* @param buttons_table An array of mouse button bindings objects, or nothing. * @property buttons
* @return A table with all buttons. * @param table
* @method buttons * @see awful.button
*/ */
/** Get the number of instances. /** Get the number of instances.

View File

@ -515,7 +515,7 @@ window_class_setup(lua_State *L)
static const struct luaL_Reg window_meta[] = static const struct luaL_Reg window_meta[] =
{ {
{ "struts", luaA_window_struts }, { "struts", luaA_window_struts },
{ "buttons", luaA_window_buttons }, { "_buttons", luaA_window_buttons },
{ "set_xproperty", luaA_window_set_xproperty }, { "set_xproperty", luaA_window_set_xproperty },
{ "get_xproperty", luaA_window_get_xproperty }, { "get_xproperty", luaA_window_get_xproperty },
{ NULL, NULL } { NULL, NULL }

View File

@ -37,7 +37,7 @@ local function new_drawin(_, args)
ret.data.drawable.refresh = function() end ret.data.drawable.refresh = function() end
ret.data._struts = { top = 0, right = 0, left = 0, bottom = 0 } ret.data._struts = { top = 0, right = 0, left = 0, bottom = 0 }
for _, k in pairs{ "buttons", "get_xproperty", "set_xproperty" } do for _, k in pairs{ "_buttons", "get_xproperty", "set_xproperty" } do
ret[k] = function() end ret[k] = function() end
end end