Restore full F-keys support for vertical menus

This commit is contained in:
Emmanuel Lepage Vallee 2013-07-05 00:57:30 -04:00
parent 7bad049fab
commit f47d527649
2 changed files with 43 additions and 3 deletions

View File

@ -18,6 +18,7 @@ local module = {
local function filter(data)
local fs,visible_counter = data.filter_string:lower(),0
data._internal.visible_item_count = 0
for k,v in pairs(data.items) do
local tmp = v[1]._filter_out
v[1]._filter_out = (v[1].text:lower():find(fs) == nil)-- or (fs ~= "")
@ -26,6 +27,8 @@ local function filter(data)
end
if not v[1]._filter_out then
visible_counter = visible_counter + v[1].height
data._internal.visible_item_count = data._internal.visible_item_count +1
v[1].f_key = data._internal.visible_item_count
end
end
data._total_item_height = visible_counter
@ -171,6 +174,8 @@ local function add_item(data,args)
if args.selected == true then
item.selected = true
end
data._internal.visible_item_count = (data._internal.visible_item_count or 0) + 1
item.f_key = data._internal.visible_item_count
return item
end
@ -362,6 +367,15 @@ local function new(args)
end
end
function data:remove_key_hook(key)
for k,v in pairs(internal.filter_hooks) do
if k.key == key then
internal.filter_hooks[k] = nil
break
end
end
end
function data:clear()
internal.items = {}
data:emit_signal("clear::menu")

View File

@ -1,6 +1,7 @@
local setmetatable = setmetatable
local print,pairs = print,pairs
local unpack=unpack
local math = math
local util = require( "awful.util" )
local button = require( "awful.button" )
local checkbox = require( "radical.widgets.checkbox" )
@ -68,6 +69,7 @@ local function cache_pixmap(item)
item._internal.pix_cache = {}
item.widget._draw = item.widget.draw
item.widget.draw = function(self,wibox, cr, width, height)
if not wibox.visible then return end
if item._internal.pix_cache[10*width+7*height+(item.selected and 8888 or 999)] then
cr:set_source_surface(item._internal.pix_cache[10*width+7*height+(item.selected and 8888 or 999)])
cr:paint()
@ -142,12 +144,24 @@ function module:setup_item(data,item,args)
return data._internal.layout.item_fit(data,item,...)
end
local pref
if data.fkeys_prefix == true then
local pref = wibox.widget.textbox()
pref = wibox.widget.textbox()
pref.draw = function(self,w, cr, width, height)
cr:set_source(color(beautiful.fg_normal))
cr:paint()
wibox.widget.textbox.draw(self,w, cr, width, height)
cr:arc((height-4)/2 + 2, (height-4)/2 + 2, (height-4)/2,0,2*math.pi)
cr:arc(width - (height-4)/2 - 2, (height-4)/2 + 2, (height-4)/2,0,2*math.pi)
cr:rectangle((height-4)/2+2,2,width - (height),(height-4))
cr:fill()
cr:select_font_face("Verdana", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
cr:set_font_size(height-6)
cr:move_to(height/2,height-4)
cr:set_source(color(beautiful.bg_normal))
local text = (item._internal.f_key and item._internal.f_key <= 12) and ("F"..(item._internal.f_key)) or "---"
cr:show_text(text)
end
pref.fit = function(...)
return 35,data.item_height
end
pref:set_markup("<span fgcolor='".. beautiful.bg_normal .."'><tt><b>F11</b></tt></span>")
l:add(pref)
@ -222,6 +236,18 @@ function module:setup_item(data,item,args)
-- end
end
end
item._internal.set_map.f_key = function(value)
item._internal.has_changed = true
item._internal.f_key = value
data:remove_key_hook("F"..value)
data:add_key_hook({}, "F"..value , "press", function()
item.button1()
data.visible = false
end)
end
item._internal.get_map.f_key = function() return item._internal.f_key end
item._internal.set_map.icon = function (value)
icon:set_image(value)
end