Add global underlay support
This commit is contained in:
parent
ad20d9e2be
commit
231eef25bc
|
@ -132,6 +132,13 @@ mytextbox:set_tooltip("foo bar")
|
|||
|
||||
```
|
||||
|
||||
### "Underlay"
|
||||
|
||||
The "underlay" is the opposite of an overlay. Think of it as a background label.
|
||||
Radical add this option to all Awesome widget by calling the `set_underlay`
|
||||
method. The first argument is the text (or table of string) and the second is
|
||||
an array with the `style` and `alpha` keys.
|
||||
|
||||
## Options
|
||||
|
||||
Radical offer a (very, very) wide range of options to allow the creation of rich
|
||||
|
@ -304,6 +311,8 @@ Radical also use the some of the same theme options as awful.menu, plus some:
|
|||
| menu_opacity | Use your favorite compositor | Number (0=0%, 1=100%) |
|
||||
| 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) |
|
||||
|
||||
|
||||
Styling can also be done using the icon_transformation option. This feature
|
||||
allow masks such as desaturation, tinting, invert or some matrix to be applied
|
||||
|
|
48
bar.lua
48
bar.lua
|
@ -24,39 +24,43 @@ local function set_position(self)
|
|||
end
|
||||
|
||||
-- Draw the menu background
|
||||
local function bg_draw(self, w, cr, width, height)
|
||||
cr:save()
|
||||
cr:set_source(color(self._data.bg))
|
||||
cr:rectangle(0,0,width,height)
|
||||
cr:fill()
|
||||
cr:restore()
|
||||
wibox.layout.margin.draw(self, w, cr, width, height)
|
||||
-- local function bg_draw(self, w, cr, width, height)
|
||||
-- cr:save()
|
||||
-- cr:set_source(color(self._data.bg))
|
||||
-- cr:rectangle(0,0,width,height)
|
||||
-- cr:fill()
|
||||
-- cr:restore()
|
||||
-- wibox.layout.margin.draw(self, w, cr, width, height)
|
||||
-- end
|
||||
|
||||
local function proxy_draw(_,...)
|
||||
local l = _._internal and _._internal.layout or _
|
||||
return wibox.layout.fixed.draw(l,...)
|
||||
end
|
||||
|
||||
local function proxy_fit(_,...)
|
||||
local l = _._internal and _._internal.layout or _
|
||||
return wibox.layout.fixed.fit(l,...)
|
||||
end
|
||||
|
||||
local function setup_drawable(data)
|
||||
local internal = data._internal
|
||||
local private_data = internal.private_data
|
||||
|
||||
--Init
|
||||
internal.margin = wibox.layout.margin()
|
||||
internal.margin._data = data
|
||||
internal.margin.draw = bg_draw
|
||||
|
||||
internal.layout = internal.layout_func or wibox.layout.fixed.horizontal()
|
||||
internal.margin:set_widget(internal.layout)
|
||||
|
||||
--Getters
|
||||
data.get_x = function() return 0 end
|
||||
data.get_y = function() return 0 end
|
||||
data.get_width = function() return internal.margin.fix(internal.margin,9999,99) end
|
||||
data.get_width = function() return internal.layout.fit(internal.layout,9999,99) end
|
||||
data.get_height = function() return beautiful.default_height end
|
||||
data.get_visible = function() return true end
|
||||
data.get_direction = function() return "left" end
|
||||
data.get_margins = function() return {left=0,right=0,top=0,bottom=0} end
|
||||
|
||||
-- This widget do not use wibox, so setup correct widget interface
|
||||
data.fit = internal.margin.fit
|
||||
data.draw = internal.margin.draw
|
||||
data.fit = internal.layout
|
||||
data.draw = internal.layout
|
||||
|
||||
-- Swap / Move / Remove
|
||||
data:connect_signal("item::swapped",function(_,item1,item2,index1,index2)
|
||||
|
@ -76,6 +80,10 @@ local function setup_drawable(data)
|
|||
internal.layout:add(item.widget)
|
||||
internal.layout:emit_signal("widget::updated")
|
||||
end)
|
||||
data:connect_signal("widget::added",function(_,item,widget)
|
||||
internal.layout:add(widget)
|
||||
internal.layout:emit_signal("widget::updated")
|
||||
end)
|
||||
end
|
||||
|
||||
local function setup_buttons(data,item,args)
|
||||
|
@ -143,6 +151,14 @@ local function new(args)
|
|||
ret:connect_signal("_hidden::changed",function(_,item)
|
||||
item.widget:emit_signal("widget::updated")
|
||||
end)
|
||||
|
||||
-- rawset(ret,"fit", proxy_fit)
|
||||
-- rawset(ret,"draw", proxy_draw)
|
||||
-- rawset(ret,"_fit_geometry_cache", ret._internal.layout._fit_geometry_cache)
|
||||
-- rawset(ret,"add_signal", function()end)
|
||||
-- ret._internal.layout:connect_signal("widget::updated",function()
|
||||
-- ret:emit_signal("widget::updated")
|
||||
-- end)
|
||||
return ret,ret._internal.layout
|
||||
end
|
||||
|
||||
|
|
7
base.lua
7
base.lua
|
@ -199,9 +199,9 @@ local function add_widget(data,widget,args)
|
|||
|
||||
data._internal.widgets[#data._internal.widgets+1] = item
|
||||
data._internal.items[#data._internal.items+1] = {item}
|
||||
data._internal.layout:add(item)
|
||||
data:emit_signal("widget::added",item,widget)
|
||||
if data.visible then
|
||||
local fit_w,fit_h = data._internal.layout:fit()
|
||||
local fit_w,fit_h = data._internal.layout:fit(9999,9999)
|
||||
data.width = data._internal.width or fit_w
|
||||
data.height = fit_h
|
||||
end
|
||||
|
@ -274,7 +274,8 @@ local function new(args)
|
|||
suffix_widget = args.suffix_widget or nil,
|
||||
prefix_widget = args.prefix_widget or nil,
|
||||
fkeys_prefix = args.fkeys_prefix or false,
|
||||
underlay_alpha = args.underlay_alpha or 0.7,
|
||||
underlay_alpha = args.underlay_alpha or beautiful.underlay_alpha or 0.7,
|
||||
underlay_style = args.underlay_style or nil,
|
||||
filter_prefix = args.filter_prefix or "Filter:",
|
||||
enable_keyboard = (args.enable_keyboard ~= false),
|
||||
max_items = args.max_items or nil,
|
||||
|
|
|
@ -160,6 +160,7 @@ local function new(screen)
|
|||
bg_urgent = beautiful.taglist_bg_image_urgent2,
|
||||
bg_hover = beautiful.menu_bg_focus,
|
||||
disable_markup = true,
|
||||
underlay_style = radical.widgets.underlay.draw_arrow,
|
||||
overlay = function(data,item,cd,w,h)
|
||||
-- print("foo!")
|
||||
end,
|
||||
|
|
28
init.lua
28
init.lua
|
@ -1,7 +1,9 @@
|
|||
local type = type
|
||||
local base = require( "wibox.widget.base" )
|
||||
local tooltip = require( "radical.tooltip" )
|
||||
local underlay = require( "radical.widgets.underlay")
|
||||
local aw_button = require( "awful.button" )
|
||||
local beautiful = require( "beautiful" )
|
||||
|
||||
-- Define some wibox.widget extensions
|
||||
local function set_tooltip(self, text)
|
||||
|
@ -33,12 +35,34 @@ local function set_menu(self,menu,button)
|
|||
return bt
|
||||
end
|
||||
|
||||
local function _underlay_draw(self,w, cr, width, height)
|
||||
cr:save()
|
||||
local udl = underlay.draw(self._underlay,{height=height,style = self._underlay_style})
|
||||
cr:set_source_surface(udl,width-udl:get_width()-3)
|
||||
cr:paint_with_alpha(self._underlay_alpha or beautiful.underlay_alpha or 0.7)
|
||||
cr:restore()
|
||||
self._draw_underlay(self,w, cr, width, height)
|
||||
end
|
||||
|
||||
local function set_underlay(self,udl,args)
|
||||
local args = args or {}
|
||||
if not self._draw_underlay then
|
||||
self._draw_underlay = self.draw
|
||||
self.draw = _underlay_draw
|
||||
end
|
||||
self._underlay = udl
|
||||
self._underlay_style = args.style
|
||||
self._underlay_alpha = args.alpha
|
||||
self:emit_signal("widget::updated")
|
||||
end
|
||||
|
||||
-- Do some monkey patching to extend all wibox.widget
|
||||
base._make_widget =base.make_widget
|
||||
base.make_widget = function(...)
|
||||
local ret = base._make_widget(...)
|
||||
ret.set_tooltip = set_tooltip
|
||||
ret.set_menu = set_menu
|
||||
ret.set_tooltip = set_tooltip
|
||||
ret.set_menu = set_menu
|
||||
ret.set_underlay = set_underlay
|
||||
return ret
|
||||
end
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ end
|
|||
-- Like an overlay, but under
|
||||
function module.paint_underlay(data,item,cr,width,height)
|
||||
cr:save()
|
||||
local udl = underlay.draw(item.underlay)
|
||||
local udl = underlay.draw(item.underlay,{style=data.underlay_style,height=height})
|
||||
cr:set_source_surface(udl,width-udl:get_width()-3)
|
||||
cr:paint_with_alpha(data.underlay_alpha)
|
||||
cr:restore()
|
||||
|
|
|
@ -155,6 +155,11 @@ local function new(data)
|
|||
l.item_fit = item_fit
|
||||
l.setup_key_hooks = module.setup_key_hooks
|
||||
l.setup_item = module.setup_item
|
||||
|
||||
data:connect_signal("widget::added",function(_,item,widget)
|
||||
wibox.layout.fixed.add(l,item.widget)
|
||||
l:emit_signal("widget::updated")
|
||||
end)
|
||||
return l
|
||||
end
|
||||
|
||||
|
|
|
@ -271,6 +271,10 @@ local function new(data)
|
|||
l.widgets[#l.widgets+1] = item.widget
|
||||
l:emit_signal("widget::updated")
|
||||
end)
|
||||
data:connect_signal("widget::added",function(_,item,widget)
|
||||
wibox.layout.fixed.add(l,item.widget)
|
||||
l:emit_signal("widget::updated")
|
||||
end)
|
||||
data:connect_signal("prefix_widget::added",function(_,widget,args)
|
||||
table.insert(pref_l.widgets,1,widget)
|
||||
pref_l:emit_signal("widget::updated")
|
||||
|
|
|
@ -7,4 +7,5 @@ return {
|
|||
header = require( "radical.widgets.header" ),
|
||||
piechart = require( "radical.widgets.piechart" ),
|
||||
separator= require( "radical.widgets.separator"),
|
||||
underlay = require( "radical.widgets.underlay" )
|
||||
}
|
|
@ -5,20 +5,27 @@ local cairo = require( "lgi" ).cairo
|
|||
local wibox = require( "wibox" )
|
||||
local beautiful = require( "beautiful" )
|
||||
|
||||
local module = {HORIZONTAL=1,VERTICAL=2}
|
||||
|
||||
local function draw(self, w, cr, width, height)
|
||||
cr:save()
|
||||
cr:set_source(self._color)
|
||||
cr:rectangle(5,2,width-10,1)
|
||||
if self.direction == module.VERTICAL then
|
||||
cr:rectangle(2,2,1,height-4)
|
||||
else
|
||||
cr:rectangle(5,2,width-10,1)
|
||||
end
|
||||
cr:fill()
|
||||
cr:restore()
|
||||
end
|
||||
|
||||
local function fit(box, w, h)
|
||||
return w,5
|
||||
return box.direction == module.VERTICAL and 5 or w,box.direction == module.VERTICAL and h or 5
|
||||
end
|
||||
|
||||
local function new(menu)
|
||||
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.draw = draw
|
||||
|
@ -26,5 +33,5 @@ local function new(menu)
|
|||
return bg
|
||||
end
|
||||
|
||||
return setmetatable({}, { __call = function(_, ...) return new(...) end })
|
||||
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
||||
-- kate: space-indent on; indent-width 2; replace-tabs on;
|
||||
|
|
|
@ -28,10 +28,33 @@ local function draw_item(cr,x,y,width,height,padding,args)
|
|||
cr:restore()
|
||||
end
|
||||
|
||||
function module.draw_arrow(cr,x,y,width,height,padding,args)
|
||||
cr:save()
|
||||
cr:rectangle(x,y,width+padding,height+padding)
|
||||
cr:clip()
|
||||
padding=padding/2
|
||||
local mid = (height-2*padding)/2
|
||||
cr:move_to(x+mid ,padding)
|
||||
cr:line_to(x+width-mid,padding)
|
||||
cr:line_to(x+width ,mid+padding)
|
||||
cr:line_to(x+width-mid,height-padding)
|
||||
cr:line_to(x+mid ,height-padding)
|
||||
cr:line_to(x+0 ,mid+padding)
|
||||
cr:line_to(x+mid ,padding)
|
||||
cr:close_path()
|
||||
cr:set_source(color(args.bg or beautiful.bg_alternate))
|
||||
cr:fill()
|
||||
cr:set_source(color(args.fg or beautiful.bg_normal))
|
||||
cr:set_operator(cairo.Operator.CLEAR)
|
||||
cr:move_to(x+height/2+2,y+padding/2)
|
||||
cr:show_layout(pango_l[height])
|
||||
cr:restore()
|
||||
end
|
||||
|
||||
function module.draw(text,args)
|
||||
local args = args or {}
|
||||
local padding = beautiful.default_height/3
|
||||
local height = args.height or (beautiful.menu_height)
|
||||
local padding = height/4--beautiful.default_height/3
|
||||
|
||||
-- Get text height
|
||||
if not pango_l[height] then
|
||||
|
@ -59,7 +82,8 @@ function module.draw(text,args)
|
|||
local x = 0
|
||||
for k,v in ipairs(type(text) == "table" and text or {text}) do
|
||||
pango_l[height].text = v
|
||||
draw_item(cr,x,0,ret[k],height,padding,args)
|
||||
local draw_f = args.style or draw_item
|
||||
draw_f(cr,x,0,ret[k],height,padding,args)
|
||||
x = x + ret[k]
|
||||
end
|
||||
return img
|
||||
|
|
Loading…
Reference in New Issue