fkey: Rewrite (with some more sanity)

This commit is contained in:
Emmanuel Lepage Vallee 2016-06-27 02:12:48 -04:00
parent eaa389bd5f
commit 1ca9bb2f26
2 changed files with 34 additions and 58 deletions

View File

@ -38,6 +38,7 @@ function module.setup_fkey(item,data)
item.button1(data) item.button1(data)
data.visible = false data.visible = false
end) end)
item:emit_signal("f_key::changed", value)
end end
item.get_f_key = function() return item._internal.f_key end item.get_f_key = function() return item._internal.f_key end

View File

@ -5,67 +5,42 @@ local pango = require( "lgi" ).Pango
local pangocairo = require( "lgi" ).PangoCairo local pangocairo = require( "lgi" ).PangoCairo
local wibox = require( "wibox" ) local wibox = require( "wibox" )
local beautiful = require( "beautiful" ) local beautiful = require( "beautiful" )
local constrainedtext = require("radical.widgets.constrainedtext")
local pango_l,pango_crx,max_width,keys = nil,nil,0,{} local shape = require("gears.shape")
local function create_pango(height)
local padding = height/4
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)
desc:set_size((height-padding*2) * pango.SCALE)
pango_l:set_font_description(desc)
pango_l.text = "F88"
max_width = pango_l:get_pixel_extents().width + height + 4
end
local function new(data,item) local function new(data,item)
local pref = wibox.widget.textbox() local pref = wibox.widget {
pref.draw = function(self, context, cr, width, height) {
local padding = height/4 {
local key = item._internal.f_key {
if not keys[height] then padding = 1,
pref:emit_signal("widget::updated") width_for_text = "F99",
create_pango(height) text = item._internal.f_key or "F1",
keys[height] = {} widget = constrainedtext,
end id = "textbox",
if key and key > 12 and keys[height][0] then },
cr:set_source_surface(keys[height][0]) left = data.item_height / 2 - 2*2,
cr:paint() right = data.item_height / 2 - 2*2,
elseif not keys[height] or not keys[height][key] then widget = wibox.container.margin
if not pango_l then },
create_pango(height) shape = shape.rounded_bar,
end bg = color(beautiful.fg_normal),
local img = cairo.ImageSurface(cairo.Format.ARGB32, max_width,beautiful.menu_height) fg = color(beautiful.bg_normal),
local cr2 = cairo.Context(img) widget = wibox.container.background
cr2:set_source(color(beautiful.fg_normal)) },
cr2:arc((height-padding)/2 + 2, (height-padding)/2 + padding/2, (height-padding)/2,0,2*math.pi) margins = 2,
cr2:arc(max_width - (height-padding)/2 - 2, (height-padding)/2 + padding/2, (height-padding)/2,0,2*math.pi) widget = wibox.container.margin
cr2:rectangle((height-padding)/2+2,padding/2,max_width - (height),(height-padding)) }
cr2:fill()
cr2:move_to(height/2 + padding/2,padding/4)
cr2:set_source(color(beautiful.bg_normal))
pango_l.text = (key and key <= 12) and ("F"..(key)) or " ---"
cr2:show_layout(pango_l)
keys[height][key > 12 and 0 or key] = img
end
cr:set_source_surface((key and key > 12 and keys[height][0]) and keys[height][0] or keys[height][key])
cr:paint()
end
pref.fit = function(self,context,width,height)
if not keys[height] then
pref:emit_signal("widget::updated")
create_pango(height)
keys[height] = {}
end
return max_width,data.item_height local tb = pref:get_children_by_id("textbox")[1]
end assert(tb)
pref:set_markup("<span fgcolor='".. beautiful.bg_normal .."'><tt><b>F11</b></tt></span>")
return pref item:connect_signal("f_key::changed" , function()
tb:set_text("F"..item._internal.f_key)
end)
return pref
end end
return setmetatable({}, { __call = function(_, ...) return new(...) end }) return setmetatable({}, { __call = function(_, ...) return new(...) end })
-- kate: space-indent on; indent-width 2; replace-tabs on; -- kate: space-indent on; indent-width 4; replace-tabs on;