Add a bunch of skining options

This commit is contained in:
Emmanuel Lepage Vallee 2014-11-14 23:46:06 -05:00
parent e72323441d
commit 03090fa2ec
16 changed files with 165 additions and 35 deletions

View File

@ -352,6 +352,8 @@ Radical also use the some of the same theme options as awful.menu, plus some:
| menu_draw_underlay | Function returning the underlay pixmap | function(array,width) |
| menu_icon_transformation | The function used to draw the icon | function(image,data,item) |
| underlay_alpha | Alpha for underlays | Number (0 to 1) |
| menu_corner_radius | Arrow based menu corner radius | Number (default = 10) |
| dock_corner_radius | The dock menu type corner radius | Number (default 10) |
Styling can also be done using the icon_transformation option. This feature

View File

@ -53,6 +53,10 @@ local function setup_drawable(data)
internal.layout.draw = bg_draw
internal.layout._data = data
if internal.layout.set_spacing and data.spacing then
internal.layout:set_spacing(data.spacing)
end
--Getters
data.get_x = function() return 0 end
data.get_y = function() return 0 end

View File

@ -332,6 +332,7 @@ local function new(args)
select_on = args.select_on or module.event.HOVER,
overlay = args.overlay or nil,
opacity = args.opacity or beautiful.menu_opacity or 1,
spacing = args.spacing or nil, --TODO add to README once merged upstream
default_margins = args.default_margins or {},
default_item_margins = args.default_item_margins or {},
icon_transformation = args.icon_transformation or nil,

View File

@ -20,6 +20,8 @@ local margins2 = require("radical.margins" )
local capi,module = { mouse = mouse , screen = screen, keygrabber = keygrabber },{}
local max_size = {height={},width={}}
local default_radius = 10
local dir_to_deg = {left=0,bottom=math.pi/2,right=math.pi,top=3*(math.pi/2)}
local function get_direction(data)
@ -81,7 +83,7 @@ local function dock_draw(self, w, cr, width, height)
-- Generate the border surface
if not self.mask or self.mask_hash ~= width*1000+height then
local dir,rotation = get_direction(self.data)
self.mask = mask(rotation,w.width,w.height,8,1,0,color(self.data.border_color or seld.data.fg),color("#FF000000"))
self.mask = mask(rotation,w.width,w.height,(beautiful.dock_corner_radius or default_radius) - 2,1,0,color(self.data.border_color or seld.data.fg),color("#FF000000"))
self.mask_hash = width*1000+height
end
cr:save()
@ -220,11 +222,11 @@ local function get_wibox(data, screen)
data._internal.w = w
-- Create the rounded corner mask
w:set_bg(cairo.Pattern.create_for_surface(mask(rotation,w.width,w.height,8,1,0,color(beautiful.fg_normal),color(beautiful.bg_dock or beautiful.bg_normal))))
w.shape_bounding = mask(rotation,w.width,w.height,10,0,1,color("#00000000"),color("#FFFFFFFF"))._native
w:set_bg(cairo.Pattern.create_for_surface(mask(rotation,w.width,w.height,(beautiful.dock_corner_radius or default_radius)-2,1,0,color(beautiful.fg_normal),color(beautiful.bg_dock or beautiful.bg_normal))))
w.shape_bounding = mask(rotation,w.width,w.height,beautiful.dock_corner_radius or default_radius,0,1,color("#00000000"),color("#FFFFFFFF"))._native
local function prop_change()
w:set_bg(cairo.Pattern.create_for_surface(mask(rotation,w.width,w.height,8,1,0,color(beautiful.fg_normal),color(beautiful.bg_dock or beautiful.bg_normal))))
w.shape_bounding = mask(rotation,w.width,w.height,10,0,1,color("#00000000"),color("#FFFFFFFF"))._native
w:set_bg(cairo.Pattern.create_for_surface(mask(rotation,w.width,w.height,(beautiful.dock_corner_radius or default_radius) -2,1,0,color(beautiful.fg_normal),color(beautiful.bg_dock or beautiful.bg_normal))))
w.shape_bounding = mask(rotation,w.width,w.height,beautiful.dock_corner_radius or default_radius,0,1,color("#00000000"),color("#FFFFFFFF"))._native
end
w:connect_signal("property::height",prop_change)
w:connect_signal("property::width" ,prop_change)

View File

@ -27,10 +27,12 @@ local function createTagList(aScreen,args)
tag_list = require("radical.impl.taglist")
end
local tagList = radical.context {}
local ret = {}
for _, v in ipairs(awful.tag.gettags(aScreen)) do
args.text,args.icon = v.name,awful.tag.geticon(v)
local i = tagList:add_item(args)
i._tag = v
ret[v] = i
i:connect_signal("mouse::enter",function()
tag_list.highlight(v)
end)
@ -40,7 +42,7 @@ local function createTagList(aScreen,args)
tag_list.highlight(nil)
end
end)
return tagList
return tagList,ret
end
function module.listTags(args)

View File

@ -38,4 +38,17 @@ taglist_fg_urgent
taglist_bg_cloned
taglist_fg_cloned
taglist_bg_changed
taglist_fg_changed
taglist_fg_changed
taglist_default_icon
taglist_style
taglist_default_item_margins
taglist_default_margins
taglist_disable_index
taglist_fg_prefix
taglist_disable_icon
taglist_icon_transformation
States:
empty
cloned
highlight

View File

@ -18,11 +18,15 @@ local theme = require( "radical.theme")
local tracker = require( "radical.impl.taglist.tracker" )
local tag_menu = require( "radical.impl.taglist.tag_menu" )
local CLONED = 100
local CLONED = 100
local HIGHLIGHTED = -2
local EMPTY = 412345
local last_idx = EMPTY
theme.register_color(CLONED , "cloned" , "cloned" , true )
theme.register_color(HIGHLIGHTED , "highlight" , "highlight" , true )
theme.register_color(EMPTY , "empty" , "empty" , true )
local module,instances = {},{}
@ -54,20 +58,28 @@ local function index_draw(self,w, cr, width, height)
end
local function create_item(t,s)
local menu = instances[s]
local menu,ib = instances[s],nil
if not menu or not t then return end
local w = wibox.layout.fixed.horizontal()
local icon = tag.geticon(t)
local ib = wibox.widget.imagebox()
ib:set_image(icon)
w:add(ib)
local tw = wibox.widget.textbox()
tw.draw = index_draw
local index = tag.getidx(t)
tw:set_markup(" <b>"..(index).."</b> ")
w:add(tw)
if beautiful.taglist_disable_icon ~= true then
local icon = tag.geticon(t)
if icon and beautiful.taglist_icon_transformation then
icon = beautiful.taglist_icon_transformation(icon,menu,nil)
end
ib = wibox.widget.imagebox()
ib:set_image(icon)
w:add(ib)
end
if beautiful.taglist_disable_index ~= true then
local tw = wibox.widget.textbox()
tw.draw = index_draw
local index = tag.getproperty(t,"index") or tag.getidx(t)
tw:set_markup(" <b>"..(index).."</b> ")
w:add(tw)
end
local suf_w = wibox.layout.fixed.horizontal()
local item = menu:add_item { text = t.name, prefix_widget = w,suffix_widget=suf_w}
local item = menu:add_item { text = t.name, prefix_widget = w,suffix_widget=suf_w,bg_normal="#ff0000"--[[beautiful.taglist_bg_unused]]}
item.state[EMPTY] = true
item._internal.icon_w = ib
-- item:connect_signal("index::changed",function(_,value)
-- tw:set_markup(" <b>"..(index).."</b> ")
@ -235,8 +247,11 @@ local function new(s)
bg = beautiful.taglist_bg or beautiful.bg_normal,
bg_focus = beautiful.taglist_bg_selected,
fg_focus = beautiful.taglist_fg_selected,
bg_empty = beautiful.taglist_bg_empty,
fg_empty = beautiful.taglist_fg_empty,
spacing = beautiful.taglist_spacing,
default_item_margins = beautiful.taglist_default_item_margins,
default_margins = beautiful.taglist_default_margins ,
default_margins = beautiful.taglist_default_margins ,
-- fkeys_prefix = true,
}
for k,v in ipairs {"hover","used","urgent","cloned","changed","highlight"} do
@ -268,7 +283,7 @@ end
capi.tag.connect_signal("property::selected" , select)
capi.tag.connect_signal("property::index2",function(t,i)
if t then
if t and not beautiful.taglist_disable_index then
local s = tag.getscreen(t)
local item = cache[t]
if item then
@ -282,6 +297,15 @@ function module.item(t)
return cache[t]
end
function module.register_color(col)
last_idx = last_idx - 1
theme.register_color(last_idx , "color_"..last_idx , "color_"..last_idx , true )
for k,v in pairs(instances) do
v["bg_color_"..last_idx] = col
end
return last_idx,"color_"..last_idx
end
return setmetatable(module, { __call = function(_, ...) return new(...) end })
-- kate: space-indent on; indent-width 2; replace-tabs on;

View File

@ -3,11 +3,15 @@ local io = io
local ipairs = ipairs
local tag = require( "awful.tag" )
local menu = require( "radical.context" )
local beautiful = require( "beautiful" )
local com_tag = require( "radical.impl.common.tag" )
local awful = require("awful")
local radical = require("radical")
local extensions = require("radical.impl.taglist.extensions")
local capi = { screen = screen }
local cairo = require("lgi" ).cairo
local color = require("gears.color" )
local tag_list = nil
local module = {}
@ -15,6 +19,55 @@ local aTagMenu = nil
local aTag = nil
local radius = 3
local function gen_icon(col,height)
local img = cairo.ImageSurface.create(cairo.Format.ARGB32, height, height)--target:create_similar(target:get_content(),width,height)
local cr = cairo.Context(img)
cr:move_to(1,radius+1)
cr:arc(1+radius,radius+1,radius,math.pi,3*(math.pi/2))
cr:arc(height-radius-2,radius+1,radius,3*(math.pi/2),math.pi*2)
cr:arc(height-radius-2,height-radius-2,radius,math.pi*2,math.pi/2)
cr:arc(2+radius,height-radius-2,radius,math.pi/2,math.pi)
cr:close_path()
cr:set_source(color(beautiful.menu_fg or beautiful.fg_normal))
cr:set_line_width(2)
cr:stroke_preserve()
cr:set_source(color(col))
cr:fill()
return img
end
local function set_color(aTag,col)
local pat = col
if beautiful.taglist_custom_color then
pat = beautiful.taglist_custom_color(pat)
end
local idx,name = tag_list.register_color(pat)
local item = tag_list.item(aTag)
item["bg_"..name] = pat
item.state[idx] = true
end
local function color_menu(aTag)
if not tag_list then
tag_list = require("radical.impl.taglist")
end
local m = radical.context {layout=radical.layout.grid,column=6}
m:add_item{icon=gen_icon("#ff0000",m.item_height-4), item_layout = radical.item.layout.icon, button1 = function() set_color(aTag,"#ff0000") end}
m:add_item{icon=gen_icon("#00ff00",m.item_height-4), item_layout = radical.item.layout.icon, button1 = function() set_color(aTag,"#00ff00") end}
m:add_item{icon=gen_icon("#0000ff",m.item_height-4), item_layout = radical.item.layout.icon}
m:add_item{icon=gen_icon("#ff00ff",m.item_height-4), item_layout = radical.item.layout.icon}
m:add_item{icon=gen_icon("#ffff00",m.item_height-4), item_layout = radical.item.layout.icon}
m:add_item{icon=gen_icon("#00ffff",m.item_height-4), item_layout = radical.item.layout.icon}
m:add_item{icon=gen_icon("#ff0000",m.item_height-4), item_layout = radical.item.layout.icon}
m:add_item{icon=gen_icon("#00ff00",m.item_height-4), item_layout = radical.item.layout.icon}
m:add_item{icon=gen_icon("#0000ff",m.item_height-4), item_layout = radical.item.layout.icon}
m:add_item{icon=gen_icon("#ff00ff",m.item_height-4), item_layout = radical.item.layout.icon}
m:add_item{icon=gen_icon("#ffff00",m.item_height-4), item_layout = radical.item.layout.icon}
m:add_item{icon=gen_icon("#00ffff",m.item_height-4), item_layout = radical.item.layout.icon}
return m
end
-- My config has an icon directory path stored there, change as you like
local config = nil
@ -48,7 +101,9 @@ local function new(t)
end
end
aTagMenu:add_item({text = "Merge With", sub_menu = com_tag.listTags})
aTagMenu:add_item({text = "Set color", sub_menu = function() return color_menu(aTag) end})
aTagMenu:add_item({text = "Merge With", sub_menu = function() return com_tag.listTags() end})
function createTagList(aScreen)
local tagList = menu()

View File

@ -137,7 +137,9 @@ end
local function reload_content(c,b,a)
local item = _cache[c]
if item then
item.icon = surface(c.icon) or beautiful.tasklist_default_icon
if not beautiful.tasklist_disable_icon then
item.icon = surface(c.icon) or beautiful.tasklist_default_icon
end
item.text = c.name or "N/A"
end
end
@ -154,7 +156,7 @@ local function create_client_item(c,screen)
-- Too bad, let's create a new one
local suf_w = wibox.layout.fixed.horizontal()
item = menu:add_item{text=c.name,icon=surface(c.icon),suffix_widget=suf_w}
item = menu:add_item{text=c.name,icon=(not beautiful.tasklist_disable_icon) and surface(c.icon),suffix_widget=suf_w}
item.add_suffix = function(w,w2)
suf_w:add(w2)
end
@ -251,6 +253,7 @@ local function new(screen)
default_margins = beautiful.tasklist_default_margins ,
item_style = beautiful.tasklist_item_style ,
style = beautiful.tasklist_style ,
spacing = beautiful.tasklist_spacing ,
}
for k,v in ipairs {"hover","urgent","minimized","focus"} do
args["bg_"..v] = beautiful["tasklist_bg_"..v]

View File

@ -69,7 +69,7 @@ function module:setup_checked(item,data)
if item.checkable then
item.get_checked = function()
if type(item._private_data.checked) == "function" then
return item._private_data.checked()
return item._private_data.checked(data,item)
else
return item._private_data.checked
end

View File

@ -87,7 +87,7 @@ local function create_item(item,data,args)
return data._internal.layout.item_fit(data,item,box,w,h)
end
if item.checkable then
item.get_checked = function()
item.get_checked = function(data,item)
if type(item._private_data.checked) == "function" then
return item._private_data.checked()
else

View File

@ -42,7 +42,7 @@ end
-- Show the checkbox
function module:setup_checked(item,data)
if item.checkable then
item.get_checked = function()
item.get_checked = function(data,item)
if type(item._private_data.checked) == "function" then
return item._private_data.checked()
else

View File

@ -16,12 +16,18 @@ local module = {
local state_cache = {}
local function gen(width,height,bg_color,border_color)
local default_height = 3
local rect = {
bottom = function(x,y,width,height) return 0, height-default_height, width , default_height end,
top = function(x,y,width,height) return 0, 0, width , 3 end,
}
local function gen(width,height,bg_color,border_color, pos)
local img = cairo.ImageSurface(cairo.Format.ARGB32, width,height)
local cr = cairo.Context(img)
local rad = corner_radius or 3
cr:set_source(color(bg_color))
cr:rectangle(0,height -4, width , 4)
cr:rectangle(rect[pos](0,0,width,height))
cr:fill()
return cairo.Pattern.create_for_surface(img)
end
@ -41,7 +47,7 @@ local function widget_draw(self, w, cr, width, height)
--Generate the pixmap
if not cached then
local state_name = current_state == "" and "bg" or "bg_"..(base.colors_by_id[current_state] or "")
cached = gen(width,height,self._item[state_name],bc)
cached = gen(width,height,self._item[state_name],bc,self.holo_pos)
cache[hash] = cached
end
@ -65,6 +71,7 @@ local function draw(item,args)
item.widget.draw = widget_draw
item.widget._overlay_init = true
item.widget._item = item
item.widget.holo_pos = args.pos or "bottom"
end
local state = item.state or {}
@ -80,5 +87,19 @@ local function draw(item,args)
end
end
local function draw_top(item,args)
return draw(item,{pos="top"})
end
-- Create an identical module for holo_top
module.top = setmetatable({
draw = draw_top,
margins = module.margins
},
{
__call = function(_, ...) return draw_top(...) end
}
)
return setmetatable(module, { __call = function(_, ...) return draw(...) end })
-- kate: space-indent on; indent-width 2; replace-tabs on;

View File

@ -1,9 +1,12 @@
local holo = require("radical.item.style.holo")
return {
basic = require("radical.item.style.basic" ),
classic = require("radical.item.style.classic" ),
subtle = require("radical.item.style.subtle" ),
rounded = require("radical.item.style.rounded" ),
holo = require("radical.item.style.holo" ),
holo = holo ,
holo_top = holo.top ,
arrow_alt = require("radical.item.style.arrow_alt" ),
arrow_prefix = require("radical.item.style.arrow_prefix" ),
arrow_single = require("radical.item.style.arrow_single" ),

View File

@ -89,7 +89,7 @@ local function do_gen_menu_top(data, width, height, radius,padding,args)
cr:set_source( color(args.fg) )
-- Generate the path
draw_roundedrect_path(cr, data, width, height, radius,padding,args)
draw_roundedrect_path(cr, data, width, height, beautiful.menu_corner_radius or radius,padding,args)
-- Apply
cr:fill()
@ -200,7 +200,7 @@ local function draw_border(self,w, cr, width, height)
cr:set_matrix(matrix)
-- Generate the path
draw_roundedrect_path(cr, data, width, height, radius,data.border_width/2)
draw_roundedrect_path(cr, data, width, height, beautiful.menu_corner_radius or radius,data.border_width/2)
cr:set_source(color(beautiful.fg_normal))
cr:set_line_width(data.border_width)
cr:stroke()

View File

@ -28,7 +28,7 @@ local function new(menu,direction)
local bg = wibox.widget.base.make_widget()
bg.direction = direction or module.HORIZONTAL
bg.fit = fit
bg._color = color( menu and menu.separator_color or beautiful.border_color or beautiful.fg_normal)
bg._color = color( menu and menu.separator_color or beautiful.menu_border_color or beautiful.menu_fg or beautiful.fg_normal)
bg.draw = draw
bg._force_fit = true
return bg