From 1c34c56d0b9c8fe5c2cd153c3b721330c143b041 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 29 Jun 2016 16:01:14 -0400 Subject: [PATCH] base: Remove setup_drawable callback As this was the last step in the base constructor, it could be done in each menu type without the callback and extra code. The only reason this existed was to allow menu "sub classes" that override this function. However, since this was rewritten, it was no longer used, so for the sake of simplicity, I remove this feature. --- bar.lua | 27 ++++++++++++--------------- base.lua | 2 -- context.lua | 30 +++++++++++++----------------- dock.lua | 37 +++++++++++++++++-------------------- embed.lua | 28 +++++++++++++--------------- 5 files changed, 55 insertions(+), 69 deletions(-) diff --git a/bar.lua b/bar.lua index 0a34779..5036b9c 100644 --- a/bar.lua +++ b/bar.lua @@ -8,7 +8,17 @@ local shape = require( "gears.shape" ) local module = {} -local function setup_drawable(data) +local function new(args) + args = args or {} + args.border_width = args.border_width or 0 + args.internal = args.internal or {} + args.internal.setup_item = args.internal.setup_item or common.setup_item + args.item_style = args.item_style or item_style + args.item_layout = args.item_layout or item_layout + args.sub_menu_on = args.sub_menu_on or base.event.BUTTON1 + + local data = base(args) + local internal = data._internal -- Use a background to make the border work @@ -46,21 +56,8 @@ local function setup_drawable(data) end common.setup_item_move_events(data) -end -local function new(args) - args = args or {} - args.border_width = args.border_width or 0 - args.internal = args.internal or {} - args.internal.setup_drawable = args.internal.setup_drawable or setup_drawable - args.internal.setup_item = args.internal.setup_item or common.setup_item - args.item_style = args.item_style or item_style - args.item_layout = args.item_layout or item_layout - args.sub_menu_on = args.sub_menu_on or base.event.BUTTON1 - - local ret = base(args) - - return ret,ret._internal.widget + return data, data._internal.widget end function module.flex(args) diff --git a/base.lua b/base.lua index 1599ab4..2cf3984 100644 --- a/base.lua +++ b/base.lua @@ -638,8 +638,6 @@ local function new(args) end end - data._internal.setup_drawable(data) - return data end return setmetatable(module, { __call = function(_, ...) return new(...) end }) diff --git a/context.lua b/context.lua index bc07779..62b075a 100644 --- a/context.lua +++ b/context.lua @@ -23,7 +23,17 @@ local function set_visible(i, value) end end -local function setup_drawable(data) +local function new(args) + args = args or {} + args.internal = args.internal or {} + args.internal.setup_item = args.internal.setup_item or common.setup_item + args.style = args.style or beautiful.menu_default_style or arrow_style + local data = base(args) + + data:connect_signal("parent_geometry::changed", function() + args.internal.w:move_by_parent(data.parent_geometry, "widget") + end) + local internal = data._internal -- Create the layout @@ -52,27 +62,13 @@ local function setup_drawable(data) data.get_margins = common.get_margins internal.set_visible = set_visible - -- Support remove, swap, insert, append... common.setup_item_move_events(data) -end - -local function new(args) - args = args or {} - args.internal = args.internal or {} - args.internal.setup_drawable = args.internal.setup_drawable or setup_drawable - args.internal.setup_item = args.internal.setup_item or common.setup_item - args.style = args.style or beautiful.menu_default_style or arrow_style - local ret = base(args) - - ret:connect_signal("parent_geometry::changed", function() - args.internal.w:move_by_parent(ret.parent_geometry, "widget") - end) -- Init the style - args.style(ret) + args.style(data) - return ret + return data end return setmetatable(module, { __call = function(_, ...) return new(...) end }) diff --git a/dock.lua b/dock.lua index eb3fc08..749d860 100644 --- a/dock.lua +++ b/dock.lua @@ -104,25 +104,6 @@ local function get_wibox(data, screen) return w end -local function setup_drawable(data) - local internal = data._internal - - -- Create the layout - internal.layout = data.layout(data) - - -- Getters - data.get_visible = function() return true end - data.get_margins = common.get_margins - - function data:set_visible(value) - if internal.w then - internal.w.visible = value or false - end - end - - common.setup_item_move_events(data) -end - local function new(args) args = args or {} local orientation = (not args.position or args.position == "left" or args.position == "right") and "vertical" or "horizontal" @@ -131,7 +112,6 @@ local function new(args) -- The the Radical arguments args.internal = args.internal or {} args.internal.orientation = orientation - args.internal.setup_drawable = args.internal.setup_drawable or setup_drawable args.internal.setup_item = args.internal.setup_item or common.setup_item args.item_style = args.item_style or item_style args.bg = color("#00000000") --Use the dock bg instead @@ -162,6 +142,23 @@ local function new(args) end) end + local internal = ret._internal + + -- Create the layout + internal.layout = ret.layout(ret) + + -- Getters + ret.get_visible = function() return true end + ret.get_margins = common.get_margins + + function ret:set_visible(value) + if internal.w then + internal.w.visible = value or false + end + end + + common.setup_item_move_events(ret) + return ret end diff --git a/embed.lua b/embed.lua index 261b59d..5875731 100644 --- a/embed.lua +++ b/embed.lua @@ -4,7 +4,18 @@ local layout = require( "radical.layout" ) local classic_style = require( "radical.style.classic" ) local common = require( "radical.common" ) -local function setup_drawable(data) +local function new(args) + args = args or {} + args.internal = args.internal or {} + args.internal.setup_item = args.internal.setup_item or common.setup_item + args.style = args.style or classic_style + local data = base(args) + + data:connect_signal("clear::menu",function(_,vis) + local l = data._internal.content_layout or data._internal.layout + l:reset() + end) + local internal = data._internal -- An embeded menu can only be visible if the parent is @@ -30,21 +41,8 @@ local function setup_drawable(data) -- Support remove, swap, insert, append... common.setup_item_move_events(data) -end -local function new(args) - args = args or {} - args.internal = args.internal or {} - args.internal.setup_drawable = args.internal.setup_drawable or setup_drawable - args.internal.setup_item = args.internal.setup_item or common.setup_item - args.style = args.style or classic_style - local ret = base(args) - ret:connect_signal("clear::menu",function(_,vis) - local l = ret._internal.content_layout or ret._internal.layout - l:reset() - end) - - return ret + return data end return setmetatable({}, { __call = function(_, ...) return new(...) end })