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.
This commit is contained in:
Emmanuel Lepage Vallee 2016-02-28 05:00:44 -05:00
parent a1abd2f57a
commit f48ede52f9
7 changed files with 24 additions and 29 deletions

View File

@ -91,7 +91,7 @@ local function filter(data)
if tmp ~= v._filter_out then if tmp ~= v._filter_out then
v.widget:emit_signal("widget::updated") v.widget:emit_signal("widget::updated")
end 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 visible_counter = visible_counter + v.height
data._internal.visible_item_count = data._internal.visible_item_count +1 data._internal.visible_item_count = data._internal.visible_item_count +1
v.f_key = data._internal.visible_item_count v.f_key = data._internal.visible_item_count
@ -475,14 +475,14 @@ local function new(args)
data.get_previous_item = function(_) data.get_previous_item = function(_)
local candidate,idx = internal.items[(data.current_index or 0)-1],(data.current_index or 0)-1 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 candidate,idx = internal.items[idx - 1],idx-1
end end
return (candidate or internal.items[data.rowcount]) return (candidate or internal.items[data.rowcount])
end end
data.get_next_item = function(_) data.get_next_item = function(_)
local candidate,idx = internal.items[(data.current_index or 0)+1],(data.current_index or 0)+1 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 candidate,idx = internal.items[idx + 1],idx+1
end end
return (candidate or internal.items[1]) return (candidate or internal.items[1])
@ -602,9 +602,9 @@ local function new(args)
current_item:set_selected(false,true) current_item:set_selected(false,true)
end end
data._start_at = (data._start_at or 1) - 1 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]) 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]) data:emit_signal("_hidden::changed",internal.items[data._start_at+data.max_items])
filter(data) filter(data)
@ -623,9 +623,9 @@ local function new(args)
current_item:set_selected(false,true) current_item:set_selected(false,true)
end end
data._start_at = (data._start_at or 1) + 1 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]) 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]) data:emit_signal("_hidden::changed",internal.items[data._start_at-1+data.max_items])
filter(data) filter(data)

View File

@ -164,10 +164,6 @@ function module.setup_item_move_events(data)
l:reset() l:reset()
end) end)
data:connect_signal("_hidden::changed",function(_,item)
item.widget:emit_signal("widget::updated")
end)
end end
function module.setup_state_events(data, item) function module.setup_state_events(data, item)
@ -218,6 +214,11 @@ function module.setup_item(data,item,args)
item.infoshapes = item._internal.infoshapes item.infoshapes = item._internal.infoshapes
end 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") item.widget:emit_signal("widget::updated")
end end

View File

@ -56,9 +56,6 @@ local function new(args)
local l = ret._internal.content_layout or ret._internal.layout local l = ret._internal.content_layout or ret._internal.layout
l:reset() l:reset()
end) end)
ret:connect_signal("_hidden::changed",function(_,item)
item.widget:emit_signal("widget::updated")
end)
return ret return ret
end end

View File

@ -135,9 +135,9 @@ local function new_item(data,args)
item._private_data = private_data item._private_data = private_data
item._internal = args._internal or {} item._internal = args._internal or {}
theme.setup_item_colors(data,item,args) theme.setup_item_colors(data,item,args)
item.get_y = function() -- 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 -- 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 -- end
item.get_height = function() item.get_height = function()
return args.height or data.item_height or beautiful.menu_height or 30 return args.height or data.item_height or beautiful.menu_height or 30
end end
@ -154,10 +154,6 @@ local function new_item(data,args)
item["button"..i] = args["button"..i] item["button"..i] = args["button"..i]
end 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 -- Use _internal to avoid the radical.object trigger
data._internal.visible_item_count = (data._internal.visible_item_count or 0) + 1 data._internal.visible_item_count = (data._internal.visible_item_count or 0) + 1
item._internal.f_key = data._internal.visible_item_count item._internal.f_key = data._internal.visible_item_count

View File

@ -23,7 +23,7 @@ function module:setup_item(data,item,args)
item._private_data._fit = wibox.widget.background.fit item._private_data._fit = wibox.widget.background.fit
if item._internal.margin_w then if item._internal.margin_w then
item._internal.margin_w.fit = function(...) 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 return 0,0
end end
return item_fit(data,item,...) return item_fit(data,item,...)
@ -129,8 +129,6 @@ local function new(data)
-- Set the overloaded methods -- Set the overloaded methods
real_l.fit = real_fit real_l.fit = real_fit
local l = data._internal.content_layout
return real_l return real_l
end end

View File

@ -13,9 +13,9 @@ local function return_data(tab, key)
end end
-- Common method to set foreground and background color dependeing on state -- 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 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] local state_name = base.colors_by_id[current_state]

View File

@ -8,6 +8,8 @@ local button = require( "awful.button" )
local beautiful = require( "beautiful" ) local beautiful = require( "beautiful" )
local shape = require( "gears.shape" ) local shape = require( "gears.shape" )
local surface = require( "gears.surface" ) local surface = require( "gears.surface" )
local theme = require( "radical.theme" )
local rad_item = require( "radical.item" )
local module = {} local module = {}
@ -66,10 +68,11 @@ local function new(data)
scroll_w[v].visible = true scroll_w[v].visible = true
data.item_style({widget=scroll_w[v]},{color=data.bg_highlight}) data.item_style({widget=scroll_w[v]},{color=data.bg_highlight})
scroll_w[v]:connect_signal("mouse::enter",function() 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) end)
scroll_w[v]:connect_signal("mouse::leave",function() 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) end)
scroll_w[v]:buttons( util.table.join( button({ }, 1, function() scroll_w[v]:buttons( util.table.join( button({ }, 1, function()
data["scroll_"..v](data) data["scroll_"..v](data)