Fix issue #11, break API, may cause regressions

This commit is contained in:
Emmanuel Lepage Vallee 2014-03-22 17:35:43 -04:00
parent 9b9c96be1b
commit bee04c14bc
7 changed files with 69 additions and 54 deletions

View File

@ -85,15 +85,15 @@ local function filter(data)
local fs,visible_counter = data.filter_string:lower(),0 local fs,visible_counter = data.filter_string:lower(),0
data._internal.visible_item_count = 0 data._internal.visible_item_count = 0
for k,v in pairs(data.items) do for k,v in pairs(data.items) do
local tmp = v[1]._filter_out local tmp = v._filter_out
v[1]._filter_out = (v[1].text:lower():find(fs) == nil)-- or (fs ~= "") v._filter_out = (v.text:lower():find(fs) == nil)-- or (fs ~= "")
if tmp ~= v[1]._filter_out then if tmp ~= v._filter_out then
v[1].widget:emit_signal("widget::updated") v.widget:emit_signal("widget::updated")
end end
if (not v[1]._filter_out) and (not v[1]._hidden) then if (not v._filter_out) and (not v._hidden) then
visible_counter = visible_counter + v[1].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[1].f_key = data._internal.visible_item_count v.f_key = data._internal.visible_item_count
end end
end end
data._total_item_height = visible_counter data._total_item_height = visible_counter
@ -314,7 +314,6 @@ local function new(args)
data.get_margin = function(_) return {left=0,bottom=0,right=0,left=0} end data.get_margin = function(_) return {left=0,bottom=0,right=0,left=0} end
data.get_items = function(_) return internal.items end data.get_items = function(_) return internal.items end
data.get_rowcount = function(_) return #internal.items end data.get_rowcount = function(_) return #internal.items end
data.get_columncount = function(_) return (#internal.items > 0) and #(internal.items[1]) or 0 end
-- Setters -- Setters
data.set_auto_resize = function(_,val) private_data[""] = val end data.set_auto_resize = function(_,val) private_data[""] = val end
@ -372,10 +371,8 @@ local function new(args)
data.get_current_index = function(_) data.get_current_index = function(_)
if data._current_item then if data._current_item then
for k,v in ipairs(internal.items) do --rows for k,v in ipairs(internal.items) do --rows
for k2,v2 in ipairs(v) do --columns if data._current_item == v then
if data._current_item == v2 then return k
return k,k2 --row, column as row is expected in most configurations
end
end end
end end
end end
@ -383,17 +380,17 @@ 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[1]._hidden or candidate[1]._filter_out) and idx > 0 do while candidate and (candidate._hidden 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])[1] 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[1]._hidden or candidate[1]._filter_out) and idx <= data.rowcount do while candidate and (candidate._hidden 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])[1] return (candidate or internal.items)
end end
--Repaint when appearance properties change --Repaint when appearance properties change
@ -456,7 +453,7 @@ local function new(args)
if not item or not idx then return end if not item or not idx then return end
local idx1 = nil local idx1 = nil
for k,v in ipairs(internal.items) do --rows for k,v in ipairs(internal.items) do --rows
if item == v[1] then if item == v then
idx1 = k idx1 = k
break break
end end
@ -473,7 +470,7 @@ local function new(args)
item.index = idx item.index = idx
data:emit_signal("item::moved",item,idx,idx1) data:emit_signal("item::moved",item,idx,idx1)
for i=idx,idx1 do for i=idx,idx1 do
internal.items[i][1].index = i internal.items[i].index = i
end end
end end
end end
@ -483,7 +480,7 @@ local function new(args)
if not item then return end if not item then return end
local idx1 = nil local idx1 = nil
for k,v in ipairs(internal.items) do --rows for k,v in ipairs(internal.items) do --rows
if item == v[1] then if item == v then
idx1 = k idx1 = k
break break
end end
@ -492,7 +489,7 @@ local function new(args)
table.remove(internal.items,idx1) table.remove(internal.items,idx1)
data:emit_signal("item::removed",item,idx1) data:emit_signal("item::removed",item,idx1)
for i=idx1,#internal.items do for i=idx1,#internal.items do
internal.items[i][1].index = i internal.items[i].index = i
end end
end end
end end
@ -510,10 +507,10 @@ 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 = false internal.items[data._start_at]._hidden = false
data:emit_signal("_hidden::changed",internal.items[data._start_at][1]) data:emit_signal("_hidden::changed",internal.items[data._start_at])
internal.items[data._start_at+data.max_items][1]._hidden = true internal.items[data._start_at+data.max_items]._hidden = true
data:emit_signal("_hidden::changed",internal.items[data._start_at+data.max_items][1]) data:emit_signal("_hidden::changed",internal.items[data._start_at+data.max_items])
filter(data) filter(data)
end end
end end
@ -525,10 +522,10 @@ 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][1]._hidden = true internal.items[data._start_at-1]._hidden = true
data:emit_signal("_hidden::changed",internal.items[data._start_at-1][1]) data:emit_signal("_hidden::changed",internal.items[data._start_at-1])
internal.items[data._start_at-1+data.max_items][1]._hidden = false internal.items[data._start_at-1+data.max_items]._hidden = false
data:emit_signal("_hidden::changed",internal.items[data._start_at-1+data.max_items][1]) data:emit_signal("_hidden::changed",internal.items[data._start_at-1+data.max_items])
filter(data) filter(data)
end end
end end

View File

@ -4,18 +4,13 @@ local button = require( "awful.button" )
local beautiful = require( "beautiful" ) local beautiful = require( "beautiful" )
local tag = require( "awful.tag" ) local tag = require( "awful.tag" )
local client2 = require( "awful.client" ) local client2 = require( "awful.client" )
local menu = require( "radical.box" ) local radical = require( "radical" )
local util = require( "awful.util" ) local util = require( "awful.util" )
local wibox = require( "wibox" ) local wibox = require( "wibox" )
local capi = { client = client, mouse = mouse, screen = screen} local capi = { client = client, mouse = mouse, screen = screen}
local module,pause_monitoring = {},false local module,pause_monitoring = {},false
local function draw_underlay(text)
-- If blind is installed, it can be used to draw the tag(s) name in the background
return beautiful.draw_underlay and beautiful.draw_underlay(text) or nil
end
-- Keep its own history instead of using awful.client.focus.history -- Keep its own history instead of using awful.client.focus.history
local focusIdx,focusTable = 1,setmetatable({}, { __mode = 'v' }) local focusIdx,focusTable = 1,setmetatable({}, { __mode = 'v' })
local function push_focus(c) local function push_focus(c)
@ -78,10 +73,33 @@ local function new(args)
end end
local t,auto_release = tag.selected(capi.client.focus and capi.client.focus.screen or capi.mouse.screen),args.auto_release local t,auto_release = tag.selected(capi.client.focus and capi.client.focus.screen or capi.mouse.screen),args.auto_release
local currentMenu = menu({filter = true, show_filter=true, autodiscard = true, local currentMenu = radical.box({filter = true, show_filter=true, autodiscard = true,
disable_markup=true,fkeys_prefix=not auto_release,width=(((capi.screen[capi.client.focus and capi.client.focus.screen or capi.mouse.screen]).geometry.width)/2), disable_markup=true,fkeys_prefix=not auto_release,width=(((capi.screen[capi.client.focus and capi.client.focus.screen or capi.mouse.screen]).geometry.width)/2),
icon_transformation = beautiful.alttab_icon_transformation}) icon_transformation = beautiful.alttab_icon_transformation,filter_underlay="Use [Shift] to toggle clients",filter_underlay_color=beautiful.menu_bg_normal,
filter_placeholder="<span fgcolor='".. (beautiful.menu_fg_disabled or beautiful.fg_disabled or "#777777") .."'>Type to filter</span>"})
local pref_bg = wibox.widget.background()
local pref_l = wibox.layout.align.horizontal()
pref_bg.fit = function(s,w,h)
local w2,h2 = wibox.widget.background.fit(s,w,h)
return w2,currentMenu.item_height
end
pref_bg:set_bg(currentMenu.bg_alternate)
local tb2= wibox.widget.textbox()
tb2:set_text("foo!!!!")
pref_l:set_first(tb2)
pref_bg:set_widget(pref_l)
local pref_menu,pref_menu_l = radical.bar{item_style=radical.item.style.basic}
pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL))
pref_menu:add_item{text="Exclusive"}
pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL))
pref_menu:add_item{text="12 clients"}
pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL))
pref_menu:add_item{text="Screen 1"}
pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL))
pref_l:set_third(pref_menu_l)
currentMenu:add_prefix_widget(pref_bg)
currentMenu:add_key_hook({}, "Tab", "press", select_next) currentMenu:add_key_hook({}, "Tab", "press", select_next)
currentMenu:add_key_hook({}, "Shift_L", "press", function() currentMenu:add_key_hook({}, "Shift_L", "press", function()

View File

@ -132,7 +132,7 @@ local function new_item(data,args)
-- Need to be done before painting -- Need to be done before painting
data._internal.items[#data._internal.items+1] = {} data._internal.items[#data._internal.items+1] = {}
data._internal.items[#data._internal.items][1] = item data._internal.items[#data._internal.items] = item
-- Setters -- Setters
item.set_selected = function(_,value,force) item.set_selected = function(_,value,force)

View File

@ -91,11 +91,11 @@ end
local function get_prev(data,item) local function get_prev(data,item)
for k,v in ipairs(data.items) do for k,v in ipairs(data.items) do
if v[1] == item then if v == item then
while k > 0 do while k > 0 do
k = k - 1 k = k - 1
if k > 0 and (not data.items[k][1].hidden) and data.items[k][1]._internal.f_key == item._internal.f_key - 1 then if k > 0 and (not data.items[k].hidden) and data.items[k]._internal.f_key == item._internal.f_key - 1 then
return data.items[k][1] return data.items[k]
end end
end end
return nil return nil

View File

@ -20,7 +20,7 @@ local function up(data)
if idx <= 0 then if idx <= 0 then
idx = rc + idx + 1 idx = rc + idx + 1
end end
data.items[idx][1].selected = true data.items[idx].selected = true
end end
local function down(data) local function down(data)
@ -29,7 +29,7 @@ local function down(data)
if idx > rc then if idx > rc then
idx = idx - rc - 1 idx = idx - rc - 1
end end
data.items[idx][1].selected = true data.items[idx].selected = true
end end
function module:setup_key_hooks(data) function module:setup_key_hooks(data)
@ -69,7 +69,7 @@ local function new(data)
end end
local rc = data.rowcount+1 local rc = data.rowcount+1
for i=1,rc do for i=1,rc do
rows[((i-1)%constraint)+1]:add((rc == i and item.widget or data.items[i][1].widget)) rows[((i-1)%constraint)+1]:add((rc == i and item.widget or data.items[i].widget))
end end
return true return true
end end

View File

@ -13,7 +13,7 @@ local module = {}
local function left(data) local function left(data)
if data._current_item._tmp_menu then if data._current_item._tmp_menu then
data = data._current_item._tmp_menu data = data._current_item._tmp_menu
data.items[1][1].selected = true data.items.selected = true
return true,data return true,data
end end
end end
@ -21,8 +21,8 @@ end
local function right(data) local function right(data)
if data.parent_geometry.is_menu then if data.parent_geometry.is_menu then
for k,v in ipairs(data.items) do for k,v in ipairs(data.items) do
if v[1]._tmp_menu == data or v[1].sub_menu_m == data then if v._tmp_menu == data or v.sub_menu_m == data then
v[1].selected = true v.selected = true
end end
end end
data.visible = false data.visible = false

View File

@ -12,7 +12,7 @@ local module = {}
local function left(data) local function left(data)
if data._current_item._tmp_menu then if data._current_item._tmp_menu then
data = data._current_item._tmp_menu data = data._current_item._tmp_menu
data.items[1][1].selected = true data.items[1].selected = true
return true,data return true,data
end end
end end
@ -20,8 +20,8 @@ end
local function right(data) local function right(data)
if data.parent_geometry and data.parent_geometry.is_menu then if data.parent_geometry and data.parent_geometry.is_menu then
for k,v in ipairs(data.items) do for k,v in ipairs(data.items) do
if v[1]._tmp_menu == data or v[1].sub_menu_m == data then if v._tmp_menu == data or v.sub_menu_m == data then
v[1].selected = true v.selected = true
end end
end end
data.visible = false data.visible = false
@ -202,8 +202,8 @@ local function compute_geo(data)
visblerow = data.max_items visblerow = data.max_items
if data.filter_string ~= "" then if data.filter_string ~= "" then
local cur,vis = (data._start_at or 1),0 local cur,vis = (data._start_at or 1),0
while (data._internal.items[cur] and data._internal.items[cur][1]) and cur < data.max_items + (data._start_at or 1) do while (data._internal.items[cur] and data._internal.items[cur]) and cur < data.max_items + (data._start_at or 1) do
vis = vis + (data._internal.items[cur][1]._filter_out and 0 or 1) vis = vis + (data._internal.items[cur]._filter_out and 0 or 1)
cur = cur +1 cur = cur +1
end end
visblerow = vis visblerow = vis