From 059572956e68696ada96c29259834a272bc8db43 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 22 Mar 2014 00:11:03 -0400 Subject: [PATCH] Change the way position is computed The old way was a hack arounf an Awesome 3.5.0 limitation. The newer should be more reliable. Please report any regressions. --- base.lua | 4 ++-- context.lua | 4 ++-- embed.lua | 14 +++++--------- item/init.lua | 4 ++-- item/layout/horizontal.lua | 6 ------ layout/vertical.lua | 18 ++++++++++++++---- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/base.lua b/base.lua index bf8a4dd..73c22eb 100644 --- a/base.lua +++ b/base.lua @@ -507,7 +507,7 @@ local function new(args) if data.max_items ~= nil and data.rowcount >= data.max_items and (data._start_at or 1) > 1 then local current_item = data._current_item if current_item then - current_item.selected = false + current_item:set_selected(false,true) end data._start_at = (data._start_at or 1) - 1 internal.items[data._start_at][1]._hidden = false @@ -522,7 +522,7 @@ local function new(args) if data.max_items ~= nil and data.rowcount >= data.max_items and (data._start_at or 1)+data.max_items <= data.rowcount then local current_item = data._current_item if current_item then - current_item.selected = false + current_item:set_selected(false,true) end data._start_at = (data._start_at or 1) + 1 internal.items[data._start_at-1][1]._hidden = true diff --git a/context.lua b/context.lua index 4f23774..868cefc 100644 --- a/context.lua +++ b/context.lua @@ -45,7 +45,7 @@ local function set_position(self) if parent.direction == "right" then ret={x=parent.x-self.width,y=parent.y+(self.parent_item.y)} else - ret={x=parent.x+parent.width,y=parent.y+(self.parent_item.y)- (parent.show_filter and parent.item_height or 0)} + ret={x=parent.x+parent.width,y=parent.y+(self.parent_item.y)-self.style.margins.TOP} --Handle when the menu doesn't fit in the srceen horizontally if ret.x+self.width > src_geo.x + src_geo.width then @@ -54,7 +54,7 @@ local function set_position(self) -- Handle when the menu doesn't fit on the screen vertically if ret.y+self.height > src_geo.y + src_geo.height then - ret.y = ret.y - self.height + self.item_height + ret.y = ret.y - self.height + self.item_height + 2*self.style.margins.TOP end end elseif parent then diff --git a/embed.lua b/embed.lua index 03c142b..11bbcc4 100644 --- a/embed.lua +++ b/embed.lua @@ -26,9 +26,9 @@ local function setup_drawable(data) data.set_visible = function(_,v) if data._embeded_parent then data._embeded_parent.visible = v end end -- Enumate geometry --BUG this is fake, but better than nothing - data.get_width = function() return data._embeded_parent and (data._embeded_parent.width --[[+ (internal.current_width or 0)]])end - data.get_y = function() return data._embeded_parent and (data._embeded_parent.y--[[ + (internal.current_y or 0)]]) end - data.get_x = function() return data._embeded_parent and (data._embeded_parent.x--[[ + (internal.current_x or 0)]]) end + data.get_width = function() return data._embeded_parent and (data._embeded_parent.width)end + data.get_y = function() return data._embeded_parent and (data._embeded_parent.y) end + data.get_x = function() return data._embeded_parent and (data._embeded_parent.x) end if not data.layout then data.layout = layout.vertical end @@ -36,9 +36,6 @@ local function setup_drawable(data) data.width,data.height = data._internal.layout:fit() data.margins={left=0,right=0,bottom=0,top=0} internal.layout:connect_signal("mouse::enter",function(_,geo) --- internal.current_x = geo.x --- internal.current_y = geo.y --- internal.current_width = geo.width if data._embeded_parent._current_item then data._embeded_parent._current_item.state[base.item_flags.SELECTED] = nil data._embeded_parent._current_item.selected = false @@ -53,6 +50,8 @@ local function setup_drawable(data) end local function setup_item(data,item,args) + + -- Create the layout local f = (data._internal.layout.setup_item) or (layout.vertical.setup_item) f(data._internal.layout,data,item,args) local buttons = {} @@ -86,9 +85,6 @@ local function setup_item(data,item,args) end end) - item.widget:connect_signal("mouse::enter",function(_,geo) - item.y = geo.y - end) end local function new(args) diff --git a/item/init.lua b/item/init.lua index f35156b..420cbd4 100644 --- a/item/init.lua +++ b/item/init.lua @@ -135,12 +135,12 @@ local function new_item(data,args) data._internal.items[#data._internal.items][1] = item -- Setters - item.set_selected = function(_,value) + item.set_selected = function(_,value,force) private_data.selected = value -- Hide the sub-menu local current_item = data._current_item - if current_item and current_item ~= item or not value then + if current_item and current_item ~= item or force then current_item.state[module.item_flags.SELECTED] = nil if current_item._tmp_menu then current_item._tmp_menu.visible = false diff --git a/item/layout/horizontal.lua b/item/layout/horizontal.lua index 0f4c5f9..29eeecd 100644 --- a/item/layout/horizontal.lua +++ b/item/layout/horizontal.lua @@ -156,12 +156,6 @@ local function create_item(item,data,args) -- Background local bg = wibox.widget.background() - --Cache item height - bg.fit = function(box,w,h,...) - args.y = data.height-h-data.margins.top - return wibox.widget.background.fit(box,w,h) - end - -- Margins local m = wibox.layout.margin(la) m:set_margins (0) diff --git a/layout/vertical.lua b/layout/vertical.lua index 2a22330..6e4a78c 100644 --- a/layout/vertical.lua +++ b/layout/vertical.lua @@ -129,11 +129,21 @@ function module:setup_item(data,item,args) --Event handling if data.select_on == base.event.HOVER then - item.widget:connect_signal("mouse::enter", function() item.selected = true end) - item.widget:connect_signal("mouse::leave", function() item.selected = false end) + item.widget:connect_signal("mouse::enter", function(_,geo) + item.y = geo.y + item.selected = true + end) + item.widget:connect_signal("mouse::leave", function() + item.selected = false + end) else - item.widget:connect_signal("mouse::enter", function() item.hover = true end) - item.widget:connect_signal("mouse::leave", function() item.hover = false end) + item.widget:connect_signal("mouse::enter", function(_,geo) + item.y = geo.y + item.hover = true + end) + item.widget:connect_signal("mouse::leave", function() + item.hover = false + end) end data._internal.layout:add(item)