From 1f5d7f427852aca2041d976f1c863aa09ecd15cd Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 28 Feb 2016 05:00:44 -0500 Subject: [PATCH] cleanup: Port scrolling to Awesome 3.6 visible widget API It still doesn't work, but at least there is no logic duplication with Awesome anymore. --- base.lua | 14 +++++++------- common.lua | 9 +++++---- embed.lua | 5 +---- item/init.lua | 10 +++------- layout/vertical.lua | 4 +--- theme/init.lua | 4 ++-- widgets/scroll.lua | 7 +++++-- 7 files changed, 24 insertions(+), 29 deletions(-) diff --git a/base.lua b/base.lua index 45295fe..313b85a 100644 --- a/base.lua +++ b/base.lua @@ -91,7 +91,7 @@ local function filter(data) if tmp ~= v._filter_out then v.widget:emit_signal("widget::updated") end - if (not v._filter_out) and (not v._hidden) then + if (not v._filter_out) and (not v.widget.visible == false) then visible_counter = visible_counter + v.height data._internal.visible_item_count = data._internal.visible_item_count +1 v.f_key = data._internal.visible_item_count @@ -475,14 +475,14 @@ local function new(args) data.get_previous_item = function(_) local candidate,idx = internal.items[(data.current_index or 0)-1],(data.current_index or 0)-1 - while candidate and (candidate._hidden or candidate._filter_out) and idx > 0 do + while candidate and (candidate.widget.visible == false or candidate._filter_out) and idx > 0 do candidate,idx = internal.items[idx - 1],idx-1 end return (candidate or internal.items[data.rowcount]) end data.get_next_item = function(_) local candidate,idx = internal.items[(data.current_index or 0)+1],(data.current_index or 0)+1 - while candidate and (candidate._hidden or candidate._filter_out) and idx <= data.rowcount do + while candidate and (candidate.widget.visible == false or candidate._filter_out) and idx <= data.rowcount do candidate,idx = internal.items[idx + 1],idx+1 end return (candidate or internal.items[1]) @@ -602,9 +602,9 @@ local function new(args) current_item:set_selected(false,true) end data._start_at = (data._start_at or 1) - 1 - internal.items[data._start_at]._hidden = false + internal.items[data._start_at].widget:set_visible(false) data:emit_signal("_hidden::changed",internal.items[data._start_at]) - internal.items[data._start_at+data.max_items]._hidden = true + internal.items[data._start_at+data.max_items].widget:set_visible(true) data:emit_signal("_hidden::changed",internal.items[data._start_at+data.max_items]) filter(data) @@ -623,9 +623,9 @@ local function new(args) current_item:set_selected(false,true) end data._start_at = (data._start_at or 1) + 1 - internal.items[data._start_at-1]._hidden = true + internal.items[data._start_at-1].widget:set_visible(true) data:emit_signal("_hidden::changed",internal.items[data._start_at-1]) - internal.items[data._start_at-1+data.max_items]._hidden = false + internal.items[data._start_at-1+data.max_items].widget:set_visible(false) data:emit_signal("_hidden::changed",internal.items[data._start_at-1+data.max_items]) filter(data) diff --git a/common.lua b/common.lua index 1bc3a82..5985b33 100644 --- a/common.lua +++ b/common.lua @@ -164,10 +164,6 @@ function module.setup_item_move_events(data) l:reset() end) - data:connect_signal("_hidden::changed",function(_,item) - item.widget:emit_signal("widget::updated") - end) - end function module.setup_state_events(data, item) @@ -218,6 +214,11 @@ function module.setup_item(data,item,args) item.infoshapes = item._internal.infoshapes end + -- Hide items after the maximum is reached + if data.max_items ~= nil and data.rowcount > data.max_items then-- and (data._start_at or 0) + item.widget:set_visible(false) + end + item.widget:emit_signal("widget::updated") end diff --git a/embed.lua b/embed.lua index d0d3a03..8d2bd33 100644 --- a/embed.lua +++ b/embed.lua @@ -56,11 +56,8 @@ local function new(args) local l = ret._internal.content_layout or ret._internal.layout l:reset() end) - ret:connect_signal("_hidden::changed",function(_,item) - item.widget:emit_signal("widget::updated") - end) return ret end return setmetatable(module, { __call = function(_, ...) return new(...) end }) --- kate: space-indent on; indent-width 2; replace-tabs on; \ No newline at end of file +-- kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/item/init.lua b/item/init.lua index 7c0be97..53664e9 100644 --- a/item/init.lua +++ b/item/init.lua @@ -135,9 +135,9 @@ local function new_item(data,args) item._private_data = private_data item._internal = args._internal or {} theme.setup_item_colors(data,item,args) - item.get_y = function() - return (args.y and args.y >= 0) and args.y or data.height - (data.margins.top or data.border_width) - data.item_height --Hack around missing :fit call for last item - end +-- item.get_y = function() +-- return (args.y and args.y >= 0) and args.y or data.height - (data.margins.top or data.border_width) - data.item_height --Hack around missing :fit call for last item +-- end item.get_height = function() return args.height or data.item_height or beautiful.menu_height or 30 end @@ -154,10 +154,6 @@ local function new_item(data,args) item["button"..i] = args["button"..i] end - if data.max_items ~= nil and data.rowcount >= data.max_items then-- and (data._start_at or 0) - item._hidden = true - end - -- Use _internal to avoid the radical.object trigger data._internal.visible_item_count = (data._internal.visible_item_count or 0) + 1 item._internal.f_key = data._internal.visible_item_count diff --git a/layout/vertical.lua b/layout/vertical.lua index 96c41f1..3523083 100644 --- a/layout/vertical.lua +++ b/layout/vertical.lua @@ -23,7 +23,7 @@ function module:setup_item(data,item,args) item._private_data._fit = wibox.widget.background.fit if item._internal.margin_w then item._internal.margin_w.fit = function(...) - if (item.visible == false or item._filter_out == true or item._hidden == true) then + if (item.visible == false or item._filter_out == true or item.widget.visible == false) then return 0,0 end return item_fit(data,item,...) @@ -129,8 +129,6 @@ local function new(data) -- Set the overloaded methods real_l.fit = real_fit - local l = data._internal.content_layout - return real_l end diff --git a/theme/init.lua b/theme/init.lua index b120dea..9aa67ed 100644 --- a/theme/init.lua +++ b/theme/init.lua @@ -13,9 +13,9 @@ local function return_data(tab, key) end -- Common method to set foreground and background color dependeing on state -function module.update_colors(item) +function module.update_colors(item, current_state_override) local state = item.state or {} - local current_state = state._current_key or nil + local current_state = current_state_override or state._current_key or nil local state_name = base.colors_by_id[current_state] diff --git a/widgets/scroll.lua b/widgets/scroll.lua index eeccce5..09e6529 100644 --- a/widgets/scroll.lua +++ b/widgets/scroll.lua @@ -8,6 +8,8 @@ local button = require( "awful.button" ) local beautiful = require( "beautiful" ) local shape = require( "gears.shape" ) local surface = require( "gears.surface" ) +local theme = require( "radical.theme" ) +local rad_item = require( "radical.item" ) local module = {} @@ -66,10 +68,11 @@ local function new(data) scroll_w[v].visible = true data.item_style({widget=scroll_w[v]},{color=data.bg_highlight}) scroll_w[v]:connect_signal("mouse::enter",function() - data.item_style({widget=scroll_w[v]},{color=data.bg_alternate or beautiful.bg_focus}) + --FIXME once the theme use a metatable chain, this should start working again + theme.update_colors({widget=scroll_w[v]},rad_item.item_flags.HOVER) end) scroll_w[v]:connect_signal("mouse::leave",function() - data.item_style({widget=scroll_w[v]},{color=data.bg_highlight}) + theme.update_colors({widget=scroll_w[v]},rad_item.item_flags.NONE) end) scroll_w[v]:buttons( util.table.join( button({ }, 1, function() data["scroll_"..v](data)