From 5b635e96e5e70ae88907475d69804b8c6815ddf5 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Thu, 16 Jan 2014 00:25:50 -0500 Subject: [PATCH] Move upderlay widget to Radical --- README.md | 33 ++++++++++++++-------------- bar.lua | 6 +++++ base.lua | 9 ++++---- impl/alttab.lua | 2 +- item_style/arrow_prefix.lua | 4 ++-- layout/vertical.lua | 8 ++++--- widgets/underlay.lua | 44 +++++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 26 deletions(-) create mode 100644 widgets/underlay.lua diff --git a/README.md b/README.md index d0d3183..d53d641 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ Multiple items can have multiple sets of options. | selected | Select this item | boolean | | checkable | Is the item dual state (a checkbox) | boolean | | checked | Is the item checked or not | boolean | -| underlay | Text to render at the far-right of the item | string | +| underlay | Text to render at the far-right of the item | [array of] string | | prefix_widget | Widget to append at the begenning of the item| widget | | suffix_widget | Widget to append at the end of the item | widget | | tooltip | A tooltip shown on the side or bottom | string | @@ -219,18 +219,19 @@ here is the list: Radical also use the some of the same theme options as awful.menu, plus some: - * menu_height - * menu_width - * menu_border_width - * menu_border_color - * border_width - * border_color - * menu_fg_normal - * menu_bg_focus - * menu_bg_header - * menu_bg_alternate - * menu_bg_normal - * menu_bg_highlight - * menu_submenu_icon - * menu_separator_color - * menu_submenu_icon +| Name | Description | Type | +| ---------------------------- | ------------------------------------- | ---------------------- | +| menu_height | Menu height | String/Gradient/Pattern | +| menu_width | Menu default/minimum width | Number | +| menu_border_width | Border width | Number | +| menu_border_color | Border color | String/Gradient/Pattern | +| menu_fg_normal | Text/Foreground color | String/Gradient/Pattern | +| menu_bg_focus | Selected item color | String/Gradient/Pattern | +| menu_bg_header | Header widget background color | String/Gradient/Pattern | +| menu_bg_alternate | Scrollbar and other widget color | String/Gradient/Pattern | +| menu_bg_normal | Default background | String/Gradient/Pattern | +| menu_bg_highlight | Highlighted item background | String/Gradient/Pattern | +| menu_submenu_icon | Sub menu pixmap (aka >) | Path/Pattern | +| menu_separator_color | Menu separator color | String/Gradient/Pattern | +| draw_underlay | Function returning the underlay pixmap | Function | + diff --git a/bar.lua b/bar.lua index 7f1e8ab..5b1d86e 100644 --- a/bar.lua +++ b/bar.lua @@ -106,6 +106,12 @@ local function create_item(item,data,args) -- Text local tb = wibox.widget.textbox() tb.fit = textbox_fit + tb.draw = function(self,w, cr, width, height) + if item.underlay then + vertical.paint_underlay(data,item,cr,width,height) + end + wibox.widget.textbox.draw(self,w, cr, width, height) + end item.widget = bg tb:set_text(item.text) diff --git a/base.lua b/base.lua index f9a5ee3..7cbee2f 100644 --- a/base.lua +++ b/base.lua @@ -2,10 +2,11 @@ local setmetatable = setmetatable local pairs,ipairs = pairs, ipairs local type,string = type,string local print,unpack = print, unpack -local beautiful = require( "beautiful" ) -local util = require( "awful.util" ) -local aw_key = require( "awful.key" ) -local object = require( "radical.object" ) +local beautiful = require( "beautiful" ) +local util = require( "awful.util" ) +local aw_key = require( "awful.key" ) +local object = require( "radical.object" ) +local vertical = require( "radical.layout.vertical" ) local capi = { mouse = mouse, screen = screen , keygrabber = keygrabber, root=root, } diff --git a/impl/alttab.lua b/impl/alttab.lua index a927333..52b52cb 100644 --- a/impl/alttab.lua +++ b/impl/alttab.lua @@ -100,7 +100,7 @@ local function new(args) icon = module.icon_transform and module.icon_transform(v.icon or module.default_icon) or v.icon or module.default_icon, suffix_widget = not auto_release and l or nil, selected = capi.client.focus and capi.client.focus == v, - underlay = v:tags()[1] and draw_underlay(v:tags()[1].name), + underlay = v:tags()[1] and v:tags()[1].name, checkable = not auto_release, checked = not auto_release and is_in_tag(t,v) or nil, button1 = function() diff --git a/item_style/arrow_prefix.lua b/item_style/arrow_prefix.lua index 6866461..d93dbcf 100644 --- a/item_style/arrow_prefix.lua +++ b/item_style/arrow_prefix.lua @@ -12,8 +12,8 @@ local wibox = require("wibox") local module = { margins = { - TOP = 2, - BOTTOM = 2, + TOP = 0, + BOTTOM = 0, RIGHT = 20, LEFT = 3 } diff --git a/layout/vertical.lua b/layout/vertical.lua index 7f38249..d17f059 100644 --- a/layout/vertical.lua +++ b/layout/vertical.lua @@ -6,6 +6,7 @@ local checkbox = require( "radical.widgets.checkbox" ) local scroll = require( "radical.widgets.scroll" ) local filter = require( "radical.widgets.filter" ) local fkey = require( "radical.widgets.fkey" ) +local underlay = require( "radical.widgets.underlay" ) local beautiful = require("beautiful" ) local wibox = require( "wibox" ) local color = require( "gears.color" ) @@ -65,9 +66,10 @@ local function item_fit(data,item,...) end -- Like an overlay, but under -local function paint_underlay(data,item,cr,width,height) +function module.paint_underlay(data,item,cr,width,height) cr:save() - cr:set_source_surface(item.underlay,width-item.underlay:get_width()-3) + local udl = underlay.draw(item.underlay) + cr:set_source_surface(udl,width-udl:get_width()-3) cr:paint_with_alpha(data.underlay_alpha) cr:restore() end @@ -148,7 +150,7 @@ function module:setup_text(item,data) text_w.draw = function(self,w, cr, width, height) if item.underlay then - paint_underlay(data,item,cr,width,height) + module.paint_underlay(data,item,cr,width,height) end wibox.widget.textbox.draw(self,w, cr, width, height) end diff --git a/widgets/underlay.lua b/widgets/underlay.lua new file mode 100644 index 0000000..155fbe9 --- /dev/null +++ b/widgets/underlay.lua @@ -0,0 +1,44 @@ +local type = type +local color = require("gears.color") +local gsurface = require("gears.surface") +local cairo = require("lgi").cairo +local pango = require("lgi").Pango +local pangocairo = require("lgi").PangoCairo +local beautiful = require("beautiful") + +local module = {} + +local pango_l,pango_crx = {},{} + +function module.draw(text,args) + local args = args or {} + local padding = beautiful.default_height/3 + local height = args.height or (beautiful.menu_height) + if not pango_l[height] then + local pango_crx = pangocairo.font_map_get_default():create_context() + pango_l[height] = 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[height]:set_font_description(desc) + end + pango_l[height].text = text + local width = pango_l[height]:get_pixel_extents().width + height + padding + local img = cairo.ImageSurface.create(cairo.Format.ARGB32, width+(args.padding_right or 0), height+padding) + cr = cairo.Context(img) + cr:set_source(color(args.bg or beautiful.bg_alternate)) + cr:arc((height-padding)/2 + 2, (height-padding)/2 + padding/4 + (args.margins or 0), (height-padding)/2+(args.padding or 0)/2,0,2*math.pi) + cr:fill() + cr:arc(width - (height-padding)/2 - 2, (height-padding)/2 + padding/4 + (args.margins or 0), (height-padding)/2+(args.padding or 0)/2,0,2*math.pi) + cr:rectangle((height-padding)/2+2,padding/4 + (args.margins or 0)-(args.padding or 0)/2,width - (height),(height-padding)+(args.padding or 0)) + cr:fill() + cr:set_source(color(args.fg or beautiful.bg_normal)) + cr:set_operator(cairo.Operator.CLEAR) + cr:move_to(height/2 + 2,padding/4 + (args.margins or 0)-(args.padding or 0)/2) + cr:show_layout(pango_l[height]) + return img +end + +return setmetatable(module, { __call = function(_, ...) return new(...) end }) +-- kate: space-indent on; indent-width 2; replace-tabs on; \ No newline at end of file