2013-07-07 06:39:17 +02:00
|
|
|
local setmetatable = setmetatable
|
2013-07-09 03:31:33 +02:00
|
|
|
local print = print
|
|
|
|
local color = require( "gears.color" )
|
|
|
|
local cairo = require( "lgi" ).cairo
|
|
|
|
local pango = require( "lgi" ).Pango
|
|
|
|
local pangocairo = require( "lgi" ).PangoCairo
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local beautiful = require( "beautiful" )
|
2013-07-07 06:39:17 +02:00
|
|
|
|
2014-01-06 04:51:42 +01:00
|
|
|
local pango_l,pango_crx,max_width,keys = nil,nil,0,{}
|
2013-07-07 06:39:17 +02:00
|
|
|
|
2014-01-05 07:04:40 +01:00
|
|
|
local function create_pango(height)
|
2014-01-06 04:51:42 +01:00
|
|
|
local padding = height/4
|
2013-07-09 03:31:33 +02:00
|
|
|
pango_crx = pangocairo.font_map_get_default():create_context()
|
|
|
|
pango_l = pango.Layout.new(pango_crx)
|
|
|
|
local desc = pango.FontDescription()
|
|
|
|
desc:set_family("Verdana")
|
|
|
|
desc:set_weight(pango.Weight.BOLD)
|
2014-01-05 07:04:40 +01:00
|
|
|
desc:set_size((height-padding*2) * pango.SCALE)
|
2013-07-09 03:31:33 +02:00
|
|
|
pango_l:set_font_description(desc)
|
|
|
|
pango_l.text = "F88"
|
2014-01-05 07:04:40 +01:00
|
|
|
max_width = pango_l:get_pixel_extents().width + height + 4
|
2013-07-09 03:31:33 +02:00
|
|
|
end
|
|
|
|
|
2013-07-07 06:39:17 +02:00
|
|
|
local function new(data,item)
|
|
|
|
local pref = wibox.widget.textbox()
|
|
|
|
pref.draw = function(self,w, cr, width, height)
|
2014-01-06 04:51:42 +01:00
|
|
|
local padding = height/4
|
2013-07-09 03:31:33 +02:00
|
|
|
local key = item._internal.f_key
|
2014-01-05 07:04:40 +01:00
|
|
|
if not keys[height] then
|
2013-07-09 03:31:33 +02:00
|
|
|
pref:emit_signal("widget::updated")
|
2014-01-05 07:04:40 +01:00
|
|
|
create_pango(height)
|
|
|
|
keys[height] = {}
|
2013-07-09 03:31:33 +02:00
|
|
|
end
|
2014-01-05 07:04:40 +01:00
|
|
|
if key and key > 12 and keys[height][0] then
|
|
|
|
cr:set_source_surface(keys[height][0])
|
2013-07-09 03:31:33 +02:00
|
|
|
cr:paint()
|
2014-01-05 07:04:40 +01:00
|
|
|
elseif not keys[height] or not keys[height][key] then
|
2013-07-09 03:31:33 +02:00
|
|
|
if not pango_l then
|
2014-01-05 07:04:40 +01:00
|
|
|
create_pango(height)
|
2013-07-09 03:31:33 +02:00
|
|
|
end
|
|
|
|
local img = cairo.ImageSurface(cairo.Format.ARGB32, max_width,beautiful.menu_height)
|
|
|
|
local cr2 = cairo.Context(img)
|
|
|
|
cr2:set_source(color(beautiful.fg_normal))
|
2013-11-11 05:18:23 +01:00
|
|
|
cr2:arc((height-padding)/2 + 2, (height-padding)/2 + padding/2, (height-padding)/2,0,2*math.pi)
|
|
|
|
cr2:arc(max_width - (height-padding)/2 - 2, (height-padding)/2 + padding/2, (height-padding)/2,0,2*math.pi)
|
|
|
|
cr2:rectangle((height-padding)/2+2,padding/2,max_width - (height),(height-padding))
|
2013-07-09 03:31:33 +02:00
|
|
|
cr2:fill()
|
2013-11-11 05:18:23 +01:00
|
|
|
cr2:move_to(height/2 + padding/2,padding/4)
|
2013-07-09 03:31:33 +02:00
|
|
|
cr2:set_source(color(beautiful.bg_normal))
|
2014-01-06 04:51:42 +01:00
|
|
|
pango_l.text = (key and key <= 12) and ("F"..(key)) or " ---"
|
2013-07-09 03:31:33 +02:00
|
|
|
cr2:show_layout(pango_l)
|
2014-01-06 04:51:42 +01:00
|
|
|
keys[height][key > 12 and 0 or key] = img
|
2013-07-09 03:31:33 +02:00
|
|
|
end
|
2014-01-06 04:51:42 +01:00
|
|
|
cr:set_source_surface((key and key > 12 and keys[height][0]) and keys[height][0] or keys[height][key])
|
|
|
|
cr:paint()
|
2013-07-07 06:39:17 +02:00
|
|
|
end
|
2013-07-09 03:31:33 +02:00
|
|
|
pref.fit = function(self,width,height)
|
|
|
|
return max_width,data.item_height
|
2013-07-07 06:39:17 +02:00
|
|
|
end
|
|
|
|
pref:set_markup("<span fgcolor='".. beautiful.bg_normal .."'><tt><b>F11</b></tt></span>")
|
|
|
|
return pref
|
|
|
|
end
|
|
|
|
|
2014-01-06 04:51:42 +01:00
|
|
|
return setmetatable({}, { __call = function(_, ...) return new(...) end })
|
2013-07-07 06:39:17 +02:00
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|