Merge pull request #1119 from Elv13/upstream_shape_api_p4.03
Upstream shape api p4.03
This commit is contained in:
commit
7f74c783cd
|
@ -84,7 +84,9 @@ function common.list_update(w, buttons, label, data, objects)
|
|||
}
|
||||
end
|
||||
|
||||
local text, bg, bg_image, icon = label(o, tb)
|
||||
local text, bg, bg_image, icon, args = label(o, tb)
|
||||
args = args or {}
|
||||
|
||||
-- The text might be invalid, so use pcall.
|
||||
if text == nil or text == "" then
|
||||
tbm:set_margins(0)
|
||||
|
@ -104,6 +106,11 @@ function common.list_update(w, buttons, label, data, objects)
|
|||
else
|
||||
ibm:set_margins(0)
|
||||
end
|
||||
|
||||
bgb.shape = args.shape
|
||||
bgb.shape_border_width = args.shape_border_width
|
||||
bgb.shape_border_color = args.shape_border_color
|
||||
|
||||
w:add(bgb)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,6 +30,143 @@ end
|
|||
local taglist = { mt = {} }
|
||||
taglist.filter = {}
|
||||
|
||||
--- The tag list main foreground (text) color.
|
||||
-- @beautiful beautiful.taglist_fg_focus
|
||||
-- @param[opt=fg_focus] color
|
||||
-- @see gears.color
|
||||
|
||||
--- The tag list main background color.
|
||||
-- @beautiful beautiful.taglist_bg_focus
|
||||
-- @param[opt=bg_focus] color
|
||||
-- @see gears.color
|
||||
|
||||
--- The tag list urgent elements foreground (text) color.
|
||||
-- @beautiful beautiful.taglist_fg_urgent
|
||||
-- @param[opt=fg_urgent] color
|
||||
-- @see gears.color
|
||||
|
||||
--- The tag list urgent elements background color.
|
||||
-- @beautiful beautiful.taglist_bg_urgent
|
||||
-- @param[opt=bg_urgent] color
|
||||
-- @see gears.color
|
||||
|
||||
--- The tag list occupied elements background color.
|
||||
-- @beautiful beautiful.taglist_bg_occupied
|
||||
-- @param color
|
||||
-- @see gears.color
|
||||
|
||||
--- The tag list occupied elements foreground (text) color.
|
||||
-- @beautiful beautiful.taglist_fg_occupied
|
||||
-- @param color
|
||||
-- @see gears.color
|
||||
|
||||
--- The tag list empty elements background color.
|
||||
-- @beautiful beautiful.taglist_bg_empty
|
||||
-- @param color
|
||||
-- @see gears.color
|
||||
|
||||
--- The tag list empty elements foreground (text) color.
|
||||
-- @beautiful beautiful.taglist_fg_empty
|
||||
-- @param color
|
||||
-- @see gears.color
|
||||
|
||||
--- The selected elements background image.
|
||||
-- @beautiful beautiful.taglist_squares_sel
|
||||
-- @param surface
|
||||
-- @see gears.surface
|
||||
|
||||
--- The unselected elements background image.
|
||||
-- @beautiful beautiful.taglist_squares_unsel
|
||||
-- @param surface
|
||||
-- @see gears.surface
|
||||
|
||||
--- The selected empty elements background image.
|
||||
-- @beautiful beautiful.taglist_squares_sel_empty
|
||||
-- @param surface
|
||||
-- @see gears.surface
|
||||
|
||||
--- The unselected empty elements background image.
|
||||
-- @beautiful beautiful.taglist_squares_unsel_empty
|
||||
-- @param surface
|
||||
-- @see gears.surface
|
||||
|
||||
--- If the background images can be resized.
|
||||
-- @beautiful beautiful.taglist_squares_resize
|
||||
-- @param boolean
|
||||
|
||||
--- Do not display the tag icons, even if they are set.
|
||||
-- @beautiful beautiful.taglist_disable_icon
|
||||
-- @param boolean
|
||||
|
||||
--- The taglist font.
|
||||
-- @beautiful beautiful.taglist_font
|
||||
-- @param string
|
||||
|
||||
--- The main shape used for the elements.
|
||||
-- This will be the fallback for state specific shapes.
|
||||
-- To get a shape for the whole taglist, use `wibox.container.background`.
|
||||
-- @beautiful beautiful.taglist_shape
|
||||
-- @param[opt=rectangle] gears.shape
|
||||
-- @see gears.shape
|
||||
-- @see beautiful.taglist_shape_empty
|
||||
-- @see beautiful.taglist_shape_focus
|
||||
-- @see beautiful.taglist_shape_urgent
|
||||
|
||||
--- The shape elements border width.
|
||||
-- @beautiful beautiful.taglist_shape_border_width
|
||||
-- @param[opt=0] number
|
||||
-- @see wibox.container.background
|
||||
|
||||
--- The elements shape border color.
|
||||
-- @beautiful beautiful.taglist_shape_border_color
|
||||
-- @param color
|
||||
-- @see gears.color
|
||||
|
||||
--- The shape used for the empty elements.
|
||||
-- @beautiful beautiful.taglist_shape_empty
|
||||
-- @param[opt=rectangle] gears.shape
|
||||
-- @see gears.shape
|
||||
|
||||
--- The shape used for the empty elements border width.
|
||||
-- @beautiful beautiful.taglist_shape_border_width_empty
|
||||
-- @param[opt=0] number
|
||||
-- @see wibox.container.background
|
||||
|
||||
--- The empty elements shape border color.
|
||||
-- @beautiful beautiful.taglist_shape_border_color_empty
|
||||
-- @param color
|
||||
-- @see gears.color
|
||||
|
||||
--- The shape used for the selected elements.
|
||||
-- @beautiful beautiful.taglist_shape_focus
|
||||
-- @param[opt=rectangle] gears.shape
|
||||
-- @see gears.shape
|
||||
|
||||
--- The shape used for the selected elements border width.
|
||||
-- @beautiful beautiful.taglist_shape_border_width_focus
|
||||
-- @param[opt=0] number
|
||||
-- @see wibox.container.background
|
||||
|
||||
--- The selected elements shape border color.
|
||||
-- @beautiful beautiful.taglist_shape_border_color_focus
|
||||
-- @param color
|
||||
-- @see gears.color
|
||||
|
||||
--- The shape used for the urgent elements.
|
||||
-- @beautiful beautiful.taglist_shape_urgent
|
||||
-- @param[opt=rectangle] gears.shape
|
||||
-- @see gears.shape
|
||||
|
||||
--- The shape used for the urgent elements border width.
|
||||
-- @beautiful beautiful.taglist_shape_border_width_urgent
|
||||
-- @param[opt=0] number
|
||||
-- @see wibox.container.background
|
||||
|
||||
--- The urgents elements shape border color.
|
||||
-- @beautiful beautiful.taglist_shape_border_color_urgent
|
||||
-- @param color
|
||||
-- @see gears.color
|
||||
|
||||
local instances = nil
|
||||
|
||||
function taglist.taglist_label(t, args)
|
||||
|
@ -56,6 +193,9 @@ function taglist.taglist_label(t, args)
|
|||
local fg_color = nil
|
||||
local bg_image
|
||||
local icon
|
||||
local shape = args.shape or theme.taglist_shape
|
||||
local shape_border_width = args.shape_border_width or theme.taglist_shape_border_width
|
||||
local shape_border_color = args.shape_border_color or theme.taglist_shape_border_color
|
||||
-- TODO: Re-implement bg_resize
|
||||
local bg_resize = false -- luacheck: ignore
|
||||
local is_selected = false
|
||||
|
@ -91,15 +231,53 @@ function taglist.taglist_label(t, args)
|
|||
end
|
||||
if bg_empty then bg_color = bg_empty end
|
||||
if fg_empty then fg_color = fg_empty end
|
||||
|
||||
if args.shape_empty or theme.taglist_shape_empty then
|
||||
shape = args.shape_empty or theme.taglist_shape_empty
|
||||
end
|
||||
|
||||
if args.shape_border_width_empty or theme.taglist_shape_border_width_empty then
|
||||
shape_border_width = args.shape_border_width_empty or theme.taglist_shape_border_width_empty
|
||||
end
|
||||
|
||||
if args.shape_border_color_empty or theme.taglist_shape_border_color_empty then
|
||||
shape_border_color = args.shape_border_color_empty or theme.taglist_shape_border_color_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
if t.selected then
|
||||
bg_color = bg_focus
|
||||
fg_color = fg_focus
|
||||
|
||||
if args.shape_focus or theme.taglist_shape_focus then
|
||||
shape = args.shape_focus or theme.taglist_shape_focus
|
||||
end
|
||||
|
||||
if args.shape_border_width_focus or theme.taglist_shape_border_width_focus then
|
||||
shape = args.shape_border_width_focus or theme.taglist_shape_border_width_focus
|
||||
end
|
||||
|
||||
if args.shape_border_color_focus or theme.taglist_shape_border_color_focus then
|
||||
shape = args.shape_border_color_focus or theme.taglist_shape_border_color_focus
|
||||
end
|
||||
|
||||
elseif tag.getproperty(t, "urgent") then
|
||||
if bg_urgent then bg_color = bg_urgent end
|
||||
if fg_urgent then fg_color = fg_urgent end
|
||||
|
||||
if args.shape_urgent or theme.taglist_shape_urgent then
|
||||
shape = args.shape_urgent or theme.taglist_shape_urgent
|
||||
end
|
||||
|
||||
if args.shape_border_width_urgent or theme.taglist_shape_border_width_urgent then
|
||||
shape_border_width = args.shape_border_width_urgent or theme.taglist_shape_border_width_urgent
|
||||
end
|
||||
|
||||
if args.shape_border_color_urgent or theme.taglist_shape_border_color_urgent then
|
||||
shape_border_color = args.shape_border_color_urgent or theme.taglist_shape_border_color_urgent
|
||||
end
|
||||
end
|
||||
|
||||
if not tag.getproperty(t, "icon_only") then
|
||||
text = "<span font_desc='"..font.."'>"
|
||||
if fg_color then
|
||||
|
@ -116,7 +294,13 @@ function taglist.taglist_label(t, args)
|
|||
end
|
||||
end
|
||||
|
||||
return text, bg_color, bg_image, not taglist_disable_icon and icon or nil
|
||||
local other_args = {
|
||||
shape = shape,
|
||||
shape_border_width = shape_border_width,
|
||||
shape_border_color = shape_border_color,
|
||||
}
|
||||
|
||||
return text, bg_color, bg_image, not taglist_disable_icon and icon or nil, other_args
|
||||
end
|
||||
|
||||
local function taglist_update(s, w, buttons, filter, data, style, update_function)
|
||||
|
@ -172,11 +356,16 @@ end
|
|||
-- @param[opt] base_widget.squares_unsel_empty A user provided image for unselected squares for empty tags.
|
||||
-- @param[opt] base_widget.squares_resize True or false to resize squares.
|
||||
-- @param base_widget.font The font.
|
||||
-- @function awful.taglist
|
||||
function taglist.new(screen, filter, buttons, style, update_function, base_widget)
|
||||
screen = get_screen(screen)
|
||||
local uf = update_function or common.list_update
|
||||
local w = base_widget or fixed.horizontal()
|
||||
|
||||
if w.set_spacing and (style and style.spacing or beautiful.taglist_spacing) then
|
||||
w:set_spacing(style and style.spacing or beautiful.taglist_spacing)
|
||||
end
|
||||
|
||||
local data = setmetatable({}, { __mode = 'k' })
|
||||
|
||||
local queued_update = {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---------------------------------------------------------------------------
|
||||
--- Tasklist widget module for awful
|
||||
--- Tasklist widget module for awful.
|
||||
--
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2008-2009 Julien Danjou
|
||||
|
@ -28,6 +28,142 @@ local tasklist = { mt = {} }
|
|||
|
||||
local instances
|
||||
|
||||
--- The default foreground (text) color.
|
||||
-- @beautiful beautiful.tasklist_fg_normal
|
||||
-- @tparam[opt=nil] string|pattern fg_normal
|
||||
-- @see gears.color
|
||||
|
||||
--- The default background color.
|
||||
-- @beautiful beautiful.tasklist_bg_normal
|
||||
-- @tparam[opt=nil] string|pattern bg_normal
|
||||
-- @see gears.color
|
||||
|
||||
--- The focused client foreground (text) color.
|
||||
-- @beautiful beautiful.tasklist_fg_focus
|
||||
-- @tparam[opt=nil] string|pattern fg_focus
|
||||
-- @see gears.color
|
||||
|
||||
--- The focused client background color.
|
||||
-- @beautiful beautiful.tasklist_bg_focus
|
||||
-- @tparam[opt=nil] string|pattern bg_focus
|
||||
-- @see gears.color
|
||||
|
||||
--- The urgent clients foreground (text) color.
|
||||
-- @beautiful beautiful.tasklist_fg_urgent
|
||||
-- @tparam[opt=nil] string|pattern fg_urgent
|
||||
-- @see gears.color
|
||||
|
||||
--- The urgent clients background color.
|
||||
-- @beautiful beautiful.tasklist_bg_urgent
|
||||
-- @tparam[opt=nil] string|pattern bg_urgent
|
||||
-- @see gears.color
|
||||
|
||||
--- The minimized clients foreground (text) color.
|
||||
-- @beautiful beautiful.tasklist_fg_minimize
|
||||
-- @tparam[opt=nil] string|pattern fg_minimize
|
||||
-- @see gears.color
|
||||
|
||||
--- The minimized clients background color.
|
||||
-- @beautiful beautiful.tasklist_bg_minimize
|
||||
-- @tparam[opt=nil] string|pattern bg_minimize
|
||||
-- @see gears.color
|
||||
|
||||
--- The elements default background image.
|
||||
-- @beautiful beautiful.tasklist_bg_image_normal
|
||||
-- @tparam[opt=nil] string bg_image_normal
|
||||
|
||||
--- The focused client background image.
|
||||
-- @beautiful beautiful.tasklist_bg_image_focus
|
||||
-- @tparam[opt=nil] string bg_image_focus
|
||||
|
||||
--- The urgent clients background image.
|
||||
-- @beautiful beautiful.tasklist_bg_image_urgent
|
||||
-- @tparam[opt=nil] string bg_image_urgent
|
||||
|
||||
--- The minimized clients background image.
|
||||
-- @beautiful beautiful.tasklist_bg_image_minimize
|
||||
-- @tparam[opt=nil] string bg_image_minimize
|
||||
|
||||
-- Disable the tasklist clients icons.
|
||||
-- @beautiful beautiful.tasklist_tasklist_disable_icon
|
||||
-- @tparam[opt=false] boolean tasklist_disable_icon
|
||||
|
||||
--- The tasklist font.
|
||||
-- @beautiful beautiful.tasklist_font
|
||||
-- @tparam[opt=nil] string font
|
||||
|
||||
--- The focused client alignment.
|
||||
-- @beautiful beautiful.tasklist_align
|
||||
-- @tparam[opt=left] string align *left*, *right* or *center*
|
||||
|
||||
--- The focused client title alignment.
|
||||
-- @beautiful beautiful.tasklist_font_focus
|
||||
-- @tparam[opt=nil] string font_focus
|
||||
|
||||
--- The minimized clients font.
|
||||
-- @beautiful beautiful.tasklist_font_minimized
|
||||
-- @tparam[opt=nil] string font_minimized
|
||||
|
||||
--- The urgent clients font.
|
||||
-- @beautiful beautiful.tasklist_font_urgent
|
||||
-- @tparam[opt=nil] string font_urgent
|
||||
|
||||
--- The space between the tasklist elements.
|
||||
-- @beautiful beautiful.tasklist_spacing
|
||||
-- @tparam[opt=0] number spacing The spacing between tags.
|
||||
|
||||
--- The default tasklist elements shape.
|
||||
-- @beautiful beautiful.tasklist_shape
|
||||
-- @tparam[opt=nil] gears.shape shape
|
||||
|
||||
--- The default tasklist elements border width.
|
||||
-- @beautiful beautiful.tasklist_shape_border_width
|
||||
-- @tparam[opt=0] number shape_border_width
|
||||
|
||||
--- The default tasklist elements border color.
|
||||
-- @beautiful beautiful.tasklist_shape_border_color
|
||||
-- @tparam[opt=nil] string|color shape_border_color
|
||||
-- @see gears.color
|
||||
|
||||
--- The focused client shape.
|
||||
-- @beautiful beautiful.tasklist_shape_focus
|
||||
-- @tparam[opt=nil] gears.shape shape_focus
|
||||
|
||||
--- The focused client border width.
|
||||
-- @beautiful beautiful.tasklist_shape_border_width_focus
|
||||
-- @tparam[opt=0] number shape_border_width_focus
|
||||
|
||||
--- The focused client border color.
|
||||
-- @beautiful beautiful.tasklist_shape_border_color_focus
|
||||
-- @tparam[opt=nil] string|color shape_border_color_focus
|
||||
-- @see gears.color
|
||||
|
||||
--- The minimized clients shape.
|
||||
-- @beautiful beautiful.tasklist_shape_minimized
|
||||
-- @tparam[opt=nil] gears.shape shape_minimized
|
||||
|
||||
--- The minimized clients border width.
|
||||
-- @beautiful beautiful.tasklist_shape_border_width_minimized
|
||||
-- @tparam[opt=0] number shape_border_width_minimized
|
||||
|
||||
--- The minimized clients border color.
|
||||
-- @beautiful beautiful.tasklist_shape_border_color_minimized
|
||||
-- @tparam[opt=nil] string|color shape_border_color_minimized
|
||||
-- @see gears.color
|
||||
|
||||
--- The urgent clients shape.
|
||||
-- @beautiful beautiful.tasklist_shape_urgent
|
||||
-- @tparam[opt=nil] gears.shape shape_urgent
|
||||
|
||||
--- The urgent clients border width.
|
||||
-- @beautiful beautiful.tasklist_shape_border_width_urgent
|
||||
-- @tparam[opt=0] number shape_border_width_urgent
|
||||
|
||||
--- The urgent clients border color.
|
||||
-- @beautiful beautiful.tasklist_shape_border_color_urgent
|
||||
-- @tparam[opt=nil] string|color shape_border_color_urgent
|
||||
-- @see gears.color
|
||||
|
||||
-- Public structures
|
||||
tasklist.filter = {}
|
||||
|
||||
|
@ -56,6 +192,9 @@ local function tasklist_label(c, args, tb)
|
|||
local name = ""
|
||||
local bg
|
||||
local bg_image
|
||||
local shape = args.shape or theme.tasklist_shape
|
||||
local shape_border_width = args.shape_border_width or theme.tasklist_shape_border_width
|
||||
local shape_border_color = args.shape_border_color or theme.tasklist_shape_border_color
|
||||
|
||||
-- symbol to use to indicate certain client properties
|
||||
local sticky = args.sticky or theme.tasklist_sticky or "▪"
|
||||
|
@ -106,23 +245,66 @@ local function tasklist_label(c, args, tb)
|
|||
text = text .. "<span color='"..fg_focus.."'>"..name.."</span>"
|
||||
bg_image = bg_image_focus
|
||||
font = font_focus
|
||||
|
||||
if args.shape_focus or theme.tasklist_shape_focus then
|
||||
shape = args.shape_focus or theme.tasklist_shape_focus
|
||||
end
|
||||
|
||||
if args.shape_border_width_focus or theme.tasklist_shape_border_width_focus then
|
||||
shape_border_width = args.shape_border_width_focus or theme.tasklist_shape_border_width_focus
|
||||
end
|
||||
|
||||
if args.shape_border_color_focus or theme.tasklist_shape_border_color_focus then
|
||||
shape_border_color = args.shape_border_color_focus or theme.tasklist_shape_border_color_focus
|
||||
end
|
||||
elseif c.urgent then
|
||||
bg = bg_urgent
|
||||
text = text .. "<span color='"..fg_urgent.."'>"..name.."</span>"
|
||||
bg_image = bg_image_urgent
|
||||
font = font_urgent
|
||||
|
||||
if args.shape_urgent or theme.tasklist_shape_urgent then
|
||||
shape = args.shape_urgent or theme.tasklist_shape_urgent
|
||||
end
|
||||
|
||||
if args.shape_border_width_urgent or theme.tasklist_shape_border_width_urgent then
|
||||
shape_border_width = args.shape_border_width_urgent or theme.tasklist_shape_border_width_urgent
|
||||
end
|
||||
|
||||
if args.shape_border_color_urgent or theme.tasklist_shape_border_color_urgent then
|
||||
shape_border_color = args.shape_border_color_urgent or theme.tasklist_shape_border_color_urgent
|
||||
end
|
||||
elseif c.minimized then
|
||||
bg = bg_minimize
|
||||
text = text .. "<span color='"..fg_minimize.."'>"..name.."</span>"
|
||||
bg_image = bg_image_minimize
|
||||
font = font_minimized
|
||||
|
||||
if args.shape_minimized or theme.tasklist_shape_minimized then
|
||||
shape = args.shape_minimized or theme.tasklist_shape_minimized
|
||||
end
|
||||
|
||||
if args.shape_border_width_minimized or theme.tasklist_shape_border_width_minimized then
|
||||
shape_border_width = args.shape_border_width_minimized or theme.tasklist_shape_border_width_minimized
|
||||
end
|
||||
|
||||
if args.shape_border_color_minimized or theme.tasklist_shape_border_color_minimized then
|
||||
shape_border_color = args.shape_border_color_minimized or theme.tasklist_shape_border_color_minimized
|
||||
end
|
||||
else
|
||||
bg = bg_normal
|
||||
text = text .. "<span color='"..fg_normal.."'>"..name.."</span>"
|
||||
bg_image = bg_image_normal
|
||||
end
|
||||
tb:set_font(font)
|
||||
return text, bg, bg_image, not tasklist_disable_icon and c.icon or nil
|
||||
|
||||
local other_args = {
|
||||
shape = shape,
|
||||
shape_border_width = shape_border_width,
|
||||
shape_border_color = shape_border_color,
|
||||
}
|
||||
|
||||
return text, bg, bg_image, not tasklist_disable_icon and c.icon or nil, other_args
|
||||
end
|
||||
|
||||
local function tasklist_update(s, w, buttons, filter, data, style, update_function)
|
||||
|
@ -164,9 +346,23 @@ end
|
|||
-- @tparam[opt=nil] string style.bg_image_minimize
|
||||
-- @tparam[opt=nil] boolean style.tasklist_disable_icon
|
||||
-- @tparam[opt=nil] string style.font
|
||||
-- @tparam[opt=left] string style.align *left*, *right* or *center*
|
||||
-- @tparam[opt=nil] string style.font_focus
|
||||
-- @tparam[opt=nil] string style.font_minimized
|
||||
-- @tparam[opt=nil] string style.font_urgent
|
||||
-- @tparam[opt=nil] number style.spacing The spacing between tags.
|
||||
-- @tparam[opt=nil] gears.shape style.shape
|
||||
-- @tparam[opt=nil] number style.shape_border_width
|
||||
-- @tparam[opt=nil] string|color style.shape_border_color
|
||||
-- @tparam[opt=nil] gears.shape style.shape_focus
|
||||
-- @tparam[opt=nil] number style.shape_border_width_focus
|
||||
-- @tparam[opt=nil] string|color style.shape_border_color_focus
|
||||
-- @tparam[opt=nil] gears.shape style.shape_minimized
|
||||
-- @tparam[opt=nil] number style.shape_border_width_minimized
|
||||
-- @tparam[opt=nil] string|color style.shape_border_color_minimized
|
||||
-- @tparam[opt=nil] gears.shape style.shape_urgent
|
||||
-- @tparam[opt=nil] number style.shape_border_width_urgent
|
||||
-- @tparam[opt=nil] string|color style.shape_border_color_urgent
|
||||
-- @param[opt] update_function Function to create a tag widget on each
|
||||
-- update. See `awful.widget.common.list_update`.
|
||||
-- @tparam[opt] table base_widget Container widget for tag widgets. Default
|
||||
|
@ -179,6 +375,10 @@ function tasklist.new(screen, filter, buttons, style, update_function, base_widg
|
|||
|
||||
local data = setmetatable({}, { __mode = 'k' })
|
||||
|
||||
if w.set_spacing and (style and style.spacing or beautiful.taglist_spacing) then
|
||||
w:set_spacing(style and style.spacing or beautiful.taglist_spacing)
|
||||
end
|
||||
|
||||
local queued_update = false
|
||||
function w._do_tasklist_update()
|
||||
-- Add a delayed callback for the first update.
|
||||
|
|
|
@ -14,7 +14,27 @@
|
|||
-- In many case, it is necessary to apply the shape using a transformation
|
||||
-- such as a rotation. The preferred way to do this is to wrap the function
|
||||
-- in another function calling `cr:rotate()` (or any other transformation
|
||||
-- matrix)
|
||||
-- matrix).
|
||||
--
|
||||
-- To specialize a shape where the API doesn't allows extra arguments to be
|
||||
-- passed, it is possible to wrap the shape function like:
|
||||
--
|
||||
-- local new_shape = function(cr, width, height)
|
||||
-- gears.shape.rounded_rect(cr, width, height, 2)
|
||||
-- end
|
||||
--
|
||||
-- Many elements can be shaped. This include:
|
||||
--
|
||||
-- * `client`s (see `gears.surface.apply_shape_bounding`)
|
||||
-- * `wibox`es (see `wibox.shape`)
|
||||
-- * All widgets (see `wibox.container.background`)
|
||||
-- * The progressbar (see `wibox.widget.progressbar.bar_shape`)
|
||||
-- * The graph (see `wibox.widget.graph.step_shape`)
|
||||
-- * The checkboxes (see `wibox.widget.checkbox.check_shape`)
|
||||
-- * Images (see `wibox.widget.imagebox.clip_shape`)
|
||||
-- * The taglist tags (see `awful.widget.taglist`)
|
||||
-- * The tasklist clients (see `awful.widget.tasklist`)
|
||||
-- * The tooltips (see `awful.tooltip`)
|
||||
--
|
||||
-- @author Emmanuel Lepage Vallee
|
||||
-- @copyright 2011-2016 Emmanuel Lepage Vallee
|
||||
|
|
|
@ -185,6 +185,10 @@ end
|
|||
-- @see gears.shape
|
||||
-- @see shape
|
||||
function background:set_shape(shape, ...)
|
||||
local args = {...}
|
||||
|
||||
if shape == self._private.shape and #args == 0 then return end
|
||||
|
||||
self._private.shape = shape
|
||||
self._private.shape_args = {...}
|
||||
self:emit_signal("widget::redraw_needed")
|
||||
|
@ -201,6 +205,8 @@ end
|
|||
-- @tparam number width The border width
|
||||
|
||||
function background:set_shape_border_width(width)
|
||||
if self._private.shape_border_width == width then return end
|
||||
|
||||
self._private.shape_border_width = width
|
||||
self:emit_signal("widget::redraw_needed")
|
||||
end
|
||||
|
@ -217,6 +223,8 @@ end
|
|||
-- @see gears.color
|
||||
|
||||
function background:set_shape_border_color(fg)
|
||||
if self._private.shape_border_color == fg then return end
|
||||
|
||||
self._private.shape_border_color = fg
|
||||
self:emit_signal("widget::redraw_needed")
|
||||
end
|
||||
|
@ -231,6 +239,8 @@ end
|
|||
-- @tparam boolean value If the shape clip is enable
|
||||
|
||||
function background:set_shape_clip(value)
|
||||
if self._private.shape_clip == value then return end
|
||||
|
||||
self._private.shape_clip = value
|
||||
self:emit_signal("widget::redraw_needed")
|
||||
end
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
---------------------------------------------------------------------------
|
||||
--- A graph widget.
|
||||
--
|
||||
-- The graph goes from left to right. To change this to right to left, use
|
||||
-- a `wibox.container.mirror` widget. This can also be used to have data
|
||||
-- shown from top to bottom.
|
||||
--
|
||||
-- To add text on top of the graph, use a `wibox.layout.stack` and a
|
||||
-- `wibox.container.align` widgets.
|
||||
--
|
||||
-- To display the graph vertically, use a `wibox.container.rotate` widget.
|
||||
--
|
||||
--@DOC_wibox_widget_defaults_graph_EXAMPLE@
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2009 Julien Danjou
|
||||
|
@ -43,11 +52,38 @@ local graph = { mt = {} }
|
|||
-- @property max_value
|
||||
-- @param number
|
||||
|
||||
--- The minimum value.
|
||||
-- Note that the min_value is not supported when used along with the stack
|
||||
-- property.
|
||||
-- @property min_value
|
||||
-- @param number
|
||||
|
||||
--- Set the graph to automatically scale its values. Default is false.
|
||||
--
|
||||
-- @property scale
|
||||
-- @param boolean
|
||||
|
||||
--- Set the width or the individual steps.
|
||||
--
|
||||
-- Note that it isn't supported when used along with stacked graphs.
|
||||
--
|
||||
--@DOC_wibox_widget_graph_step_EXAMPLE@
|
||||
--
|
||||
-- @property step_width
|
||||
-- @param[opt=1] number
|
||||
|
||||
--- Set the spacing between the steps.
|
||||
--
|
||||
-- Note that it isn't supported when used along with stacked graphs.
|
||||
--
|
||||
-- @property step_spacing
|
||||
-- @param[opt=0] number
|
||||
|
||||
--- The step shape.
|
||||
-- @property step_shape
|
||||
-- @param[opt=rectangle] shape
|
||||
-- @see gears.shape
|
||||
|
||||
--- Set the graph to draw stacks. Default is false.
|
||||
--
|
||||
-- @property stack
|
||||
|
@ -69,12 +105,19 @@ local graph = { mt = {} }
|
|||
|
||||
local properties = { "width", "height", "border_color", "stack",
|
||||
"stack_colors", "color", "background_color",
|
||||
"max_value", "scale" }
|
||||
"max_value", "scale", "min_value", "step_shape",
|
||||
"step_spacing", "step_width" }
|
||||
|
||||
function graph.draw(_graph, _, cr, width, height)
|
||||
local max_value = _graph._private.max_value
|
||||
local min_value = _graph._private.min_value or (
|
||||
_graph._private.scale and math.huge or 0)
|
||||
local values = _graph._private.values
|
||||
|
||||
local step_shape = _graph._private.step_shape
|
||||
local step_spacing = _graph._private.step_spacing or 0
|
||||
local step_width = _graph._private.step_width or 1
|
||||
|
||||
cr:set_line_width(1)
|
||||
|
||||
-- Draw the background first
|
||||
|
@ -97,6 +140,9 @@ function graph.draw(_graph, _, cr, width, height)
|
|||
if sv > max_value then
|
||||
max_value = sv
|
||||
end
|
||||
if min_value > sv then
|
||||
min_value = sv
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -125,6 +171,9 @@ function graph.draw(_graph, _, cr, width, height)
|
|||
if v > max_value then
|
||||
max_value = v
|
||||
end
|
||||
if min_value > v then
|
||||
min_value = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -134,18 +183,33 @@ function graph.draw(_graph, _, cr, width, height)
|
|||
for i = 0, #values - 1 do
|
||||
local value = values[#values - i]
|
||||
if value >= 0 then
|
||||
value = value / max_value
|
||||
cr:move_to(i + 0.5, height * (1 - value))
|
||||
cr:line_to(i + 0.5, height)
|
||||
local x = i*step_width + ((i-1)*step_spacing) + 0.5
|
||||
value = (value - min_value) / max_value
|
||||
cr:move_to(x, height * (1 - value))
|
||||
|
||||
if step_shape then
|
||||
cr:translate(step_width + (i>1 and step_spacing or 0), height * (1 - value))
|
||||
step_shape(cr, step_width, height)
|
||||
cr:translate(0, -(height * (1 - value)))
|
||||
elseif step_width > 1 then
|
||||
cr:rectangle(x, height * (1 - value), step_width, height)
|
||||
else
|
||||
cr:line_to(x, height)
|
||||
end
|
||||
end
|
||||
end
|
||||
cr:set_source(color(_graph._private.color or beautiful.graph_fg or "#ff0000"))
|
||||
cr:stroke()
|
||||
|
||||
if step_shape or step_width > 1 then
|
||||
cr:fill()
|
||||
else
|
||||
cr:stroke()
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Undo the cr:translate() for the border
|
||||
-- Undo the cr:translate() for the border and step shapes
|
||||
cr:restore()
|
||||
|
||||
-- Draw the border last so that it overlaps already drawn values
|
||||
|
|
|
@ -1,7 +1,20 @@
|
|||
---------------------------------------------------------------------------
|
||||
--- A progressbar widget.
|
||||
--
|
||||
-- To add text on top of the progressbar, a `wibox.layout.stack` can be used:
|
||||
--
|
||||
--@DOC_wibox_widget_progressbar_text_EXAMPLE@
|
||||
--
|
||||
-- To display the progressbar vertically, use a `wibox.container.rotate` widget:
|
||||
--
|
||||
--@DOC_wibox_widget_progressbar_vertical_EXAMPLE@
|
||||
--
|
||||
-- By default, this widget will take all the available size. To prevent this,
|
||||
-- a `wibox.container.constraint` widget or the `forced_width`/`forced_height`
|
||||
-- properties have to be used.
|
||||
--
|
||||
--@DOC_wibox_widget_defaults_progressbar_EXAMPLE@
|
||||
--
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2009 Julien Danjou
|
||||
-- @release @AWESOME_VERSION@
|
||||
|
@ -11,62 +24,89 @@
|
|||
local setmetatable = setmetatable
|
||||
local ipairs = ipairs
|
||||
local math = math
|
||||
local util = require("awful.util")
|
||||
local base = require("wibox.widget.base")
|
||||
local color = require("gears.color")
|
||||
local beautiful = require("beautiful")
|
||||
local shape = require("gears.shape")
|
||||
|
||||
local progressbar = { mt = {} }
|
||||
|
||||
local data = setmetatable({}, { __mode = "k" })
|
||||
|
||||
--- Set the progressbar border color.
|
||||
--- The progressbar border color.
|
||||
-- If the value is nil, no border will be drawn.
|
||||
--
|
||||
-- @function set_border_color
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param color The border color to set.
|
||||
-- @property border_color
|
||||
-- @tparam gears.color color The border color to set.
|
||||
|
||||
--- Set the progressbar foreground color.
|
||||
--
|
||||
-- @function set_color
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param color The progressbar color.
|
||||
--- The progressbar border width.
|
||||
-- @property border_width
|
||||
|
||||
--- Set the progressbar background color.
|
||||
--- The progressbar inner border color.
|
||||
-- If the value is nil, no border will be drawn.
|
||||
--
|
||||
-- @function set_background_color
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param color The progressbar background color.
|
||||
-- @property bar_border_color
|
||||
-- @tparam gears.color color The border color to set.
|
||||
|
||||
--- Set the progressbar to draw vertically. Default is false.
|
||||
--
|
||||
-- @function set_vertical
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param vertical A boolean value.
|
||||
--- The progressbar inner border width.
|
||||
-- @property bar_border_width
|
||||
|
||||
--- Set the progressbar to draw ticks. Default is false.
|
||||
--- The progressbar foreground color.
|
||||
--
|
||||
-- @function set_ticks
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param ticks A boolean value.
|
||||
-- @property color
|
||||
-- @tparam gears.color color The progressbar color.
|
||||
|
||||
--- Set the progressbar ticks gap.
|
||||
--- The progressbar background color.
|
||||
--
|
||||
-- @function set_ticks_gap
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param value The value.
|
||||
-- @property background_color
|
||||
-- @tparam gears.color color The progressbar background color.
|
||||
|
||||
--- Set the progressbar ticks size.
|
||||
--- The progressbar inner shape.
|
||||
--
|
||||
-- @function set_ticks_size
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param value The value.
|
||||
--@DOC_wibox_widget_progressbar_bar_shape_EXAMPLE@
|
||||
--
|
||||
-- @property bar_shape
|
||||
-- @tparam[opt=gears.shape.rectangle] gears.shape shape
|
||||
-- @see gears.shape
|
||||
|
||||
--- Set the maximum value the progressbar should handle.
|
||||
--- The progressbar shape.
|
||||
--
|
||||
-- @function set_max_value
|
||||
-- @param progressbar The progressbar.
|
||||
-- @param value The value.
|
||||
--@DOC_wibox_widget_progressbar_shape_EXAMPLE@
|
||||
--
|
||||
-- @property shape
|
||||
-- @tparam[opt=gears.shape.rectangle] gears.shape shape
|
||||
-- @see gears.shape
|
||||
|
||||
--- Set the progressbar to draw vertically.
|
||||
-- This doesn't do anything anymore, use a `wibox.container.rotate` widget.
|
||||
-- @deprecated set_vertical
|
||||
-- @tparam boolean vertical
|
||||
|
||||
--- Force the inner part (the bar) to fit in the background shape.
|
||||
--
|
||||
--@DOC_wibox_widget_progressbar_clip_EXAMPLE@
|
||||
--
|
||||
-- @property clip
|
||||
-- @tparam[opt=true] boolean clip
|
||||
|
||||
--- The progressbar to draw ticks. Default is false.
|
||||
--
|
||||
-- @property ticks
|
||||
-- @param boolean
|
||||
|
||||
--- The progressbar ticks gap.
|
||||
--
|
||||
-- @property ticks_gap
|
||||
-- @param number
|
||||
|
||||
--- The progressbar ticks size.
|
||||
--
|
||||
-- @property ticks_size
|
||||
-- @param number
|
||||
|
||||
--- The maximum value the progressbar should handle.
|
||||
--
|
||||
-- @property max_value
|
||||
-- @param number
|
||||
|
||||
--- The progressbar background color.
|
||||
-- @beautiful beautiful.progressbar_bg
|
||||
|
@ -74,139 +114,307 @@ local data = setmetatable({}, { __mode = "k" })
|
|||
--- The progressbar foreground color.
|
||||
-- @beautiful beautiful.progressbar_fg
|
||||
|
||||
--- The progressbar shape.
|
||||
-- @beautiful beautiful.progressbar_shape
|
||||
-- @see gears.shape
|
||||
|
||||
--- The progressbar border color.
|
||||
-- @beautiful beautiful.progressbar_border_color
|
||||
|
||||
local properties = { "width", "height", "border_color",
|
||||
"color", "background_color",
|
||||
"vertical", "value", "max_value",
|
||||
"ticks", "ticks_gap", "ticks_size" }
|
||||
--- The progressbar outer border width.
|
||||
-- @beautiful beautiful.progressbar_border_width
|
||||
|
||||
--- The progressbar inner shape.
|
||||
-- @beautiful beautiful.progressbar_bar_shape
|
||||
-- @see gears.shape
|
||||
|
||||
--- The progressbar bar border width.
|
||||
-- @beautiful beautiful.progressbar_bar_border_width
|
||||
|
||||
--- The progressbar bar border color.
|
||||
-- @beautiful beautiful.progressbar_bar_border_color
|
||||
|
||||
--- The progressbar margins.
|
||||
-- Note that if the `clip` is disabled, this allows the background to be smaller
|
||||
-- than the bar.
|
||||
--
|
||||
-- See the `clip` example.
|
||||
--
|
||||
-- @tparam[opt=0] (table|number|nil) margins A table for each side or a number
|
||||
-- @tparam[opt=0] number margins.top
|
||||
-- @tparam[opt=0] number margins.bottom
|
||||
-- @tparam[opt=0] number margins.left
|
||||
-- @tparam[opt=0] number margins.right
|
||||
-- @property margins
|
||||
-- @see clip
|
||||
|
||||
--- The progressbar padding.
|
||||
-- Note that if the `clip` is disabled, this allows the bar to be taller
|
||||
-- than the background.
|
||||
--
|
||||
-- See the `clip` example.
|
||||
--
|
||||
-- @tparam[opt=0] (table|number|nil) padding A table for each side or a number
|
||||
-- @tparam[opt=0] number padding.top
|
||||
-- @tparam[opt=0] number padding.bottom
|
||||
-- @tparam[opt=0] number padding.left
|
||||
-- @tparam[opt=0] number padding.right
|
||||
-- @property paddings
|
||||
-- @see clip
|
||||
|
||||
--- The progressbar margins.
|
||||
-- Note that if the `clip` is disabled, this allows the background to be smaller
|
||||
-- than the bar.
|
||||
-- @tparam[opt=0] (table|number|nil) margins A table for each side or a number
|
||||
-- @tparam[opt=0] number margins.top
|
||||
-- @tparam[opt=0] number margins.bottom
|
||||
-- @tparam[opt=0] number margins.left
|
||||
-- @tparam[opt=0] number margins.right
|
||||
-- @beautiful beautiful.progressbar_margins
|
||||
-- @see clip
|
||||
|
||||
--- The progressbar padding.
|
||||
-- Note that if the `clip` is disabled, this allows the bar to be taller
|
||||
-- than the background.
|
||||
-- @tparam[opt=0] (table|number|nil) padding A table for each side or a number
|
||||
-- @tparam[opt=0] number padding.top
|
||||
-- @tparam[opt=0] number padding.bottom
|
||||
-- @tparam[opt=0] number padding.left
|
||||
-- @tparam[opt=0] number padding.right
|
||||
-- @beautiful beautiful.progressbar_paddings
|
||||
-- @see clip
|
||||
|
||||
local properties = { "border_color", "color" , "background_color",
|
||||
"value" , "max_value" , "ticks",
|
||||
"ticks_gap" , "ticks_size", "border_width",
|
||||
"shape" , "bar_shape" , "bar_border_width",
|
||||
"clip" , "margins" , "bar_border_color",
|
||||
"paddings",
|
||||
}
|
||||
|
||||
function progressbar.draw(pbar, _, cr, width, height)
|
||||
local ticks_gap = data[pbar].ticks_gap or 1
|
||||
local ticks_size = data[pbar].ticks_size or 4
|
||||
local ticks_gap = pbar._private.ticks_gap or 1
|
||||
local ticks_size = pbar._private.ticks_size or 4
|
||||
|
||||
-- We want one pixel wide lines
|
||||
cr:set_line_width(1)
|
||||
|
||||
local value = data[pbar].value
|
||||
local max_value = data[pbar].max_value
|
||||
local max_value = pbar._private.max_value
|
||||
|
||||
local value = math.min(max_value, math.max(0, pbar._private.value))
|
||||
|
||||
if value >= 0 then
|
||||
value = value / max_value
|
||||
end
|
||||
local border_width = pbar._private.border_width
|
||||
or beautiful.progressbar_border_width or 0
|
||||
|
||||
local over_drawn_width = width
|
||||
local over_drawn_height = height
|
||||
local border_width = 0
|
||||
local col = data[pbar].border_color or beautiful.progressbar_border_color
|
||||
if col then
|
||||
-- Draw border
|
||||
cr:rectangle(0.5, 0.5, width - 1, height - 1)
|
||||
cr:set_source(color(col))
|
||||
cr:stroke()
|
||||
local bcol = pbar._private.border_color or beautiful.progressbar_border_color
|
||||
|
||||
over_drawn_width = width - 2 -- remove 2 for borders
|
||||
over_drawn_height = height - 2 -- remove 2 for borders
|
||||
border_width = 1
|
||||
border_width = bcol and border_width or 0
|
||||
|
||||
local bg = pbar._private.background_color or
|
||||
beautiful.progressbar_bg or "#ff0000aa"
|
||||
|
||||
local bg_width, bg_height = width, height
|
||||
|
||||
local clip = pbar._private.clip ~= false and beautiful.progressbar_clip ~= false
|
||||
|
||||
-- Apply the margins
|
||||
local margin = pbar._private.margins or beautiful.progressbar_margins
|
||||
|
||||
if margin then
|
||||
if type(margin) == "number" then
|
||||
cr:translate(margin, margin)
|
||||
bg_width, bg_height = bg_width - 2*margin, bg_height - 2*margin
|
||||
else
|
||||
cr:translate(margin.left or 0, margin.top or 0)
|
||||
bg_height = bg_height -
|
||||
(margin.top or 0) - (margin.bottom or 0)
|
||||
bg_width = bg_width -
|
||||
(margin.left or 0) - (margin.right or 0)
|
||||
end
|
||||
end
|
||||
|
||||
cr:rectangle(border_width, border_width,
|
||||
over_drawn_width, over_drawn_height)
|
||||
cr:set_source(color(data[pbar].color or beautiful.progressbar_fg or "#ff0000"))
|
||||
cr:fill()
|
||||
-- Draw the background shape
|
||||
if border_width > 0 then
|
||||
-- Cairo draw half of the border outside of the path area
|
||||
cr:translate(border_width/2, border_width/2)
|
||||
bg_width, bg_height = bg_width - border_width, bg_height - border_width
|
||||
cr:set_line_width(border_width)
|
||||
end
|
||||
|
||||
-- Cover the part that is not set with a rectangle
|
||||
if data[pbar].vertical then
|
||||
local rel_height = over_drawn_height * (1 - value)
|
||||
cr:rectangle(border_width,
|
||||
border_width,
|
||||
over_drawn_width,
|
||||
rel_height)
|
||||
cr:set_source(color(data[pbar].background_color or beautiful.progressbar_bg or "#000000aa"))
|
||||
cr:fill()
|
||||
local background_shape = pbar._private.shape or
|
||||
beautiful.progressbar_shape or shape.rectangle
|
||||
|
||||
-- Place smaller pieces over the gradient if ticks are enabled
|
||||
if data[pbar].ticks then
|
||||
for i=0, height / (ticks_size+ticks_gap)-border_width do
|
||||
local rel_offset = over_drawn_height / 1 - (ticks_size+ticks_gap) * i
|
||||
background_shape(cr, bg_width, bg_height)
|
||||
|
||||
if rel_offset >= rel_height then
|
||||
cr:rectangle(border_width,
|
||||
rel_offset,
|
||||
over_drawn_width,
|
||||
ticks_gap)
|
||||
end
|
||||
end
|
||||
cr:set_source(color(data[pbar].background_color or beautiful.progressbar_bg or "#000000aa"))
|
||||
cr:fill()
|
||||
end
|
||||
cr:set_source(color(bg))
|
||||
|
||||
local over_drawn_width = bg_width + border_width
|
||||
local over_drawn_height = bg_height + border_width
|
||||
|
||||
if border_width > 0 then
|
||||
cr:fill_preserve()
|
||||
|
||||
-- Draw the border
|
||||
cr:set_source(color(bcol))
|
||||
|
||||
cr:stroke()
|
||||
|
||||
over_drawn_width = over_drawn_width - 2*border_width
|
||||
over_drawn_height = over_drawn_height - 2*border_width
|
||||
else
|
||||
local rel_x = over_drawn_width * value
|
||||
cr:rectangle(border_width + rel_x,
|
||||
border_width,
|
||||
over_drawn_width - rel_x,
|
||||
over_drawn_height)
|
||||
cr:set_source(color(data[pbar].background_color or "#000000aa"))
|
||||
cr:fill()
|
||||
end
|
||||
|
||||
if data[pbar].ticks then
|
||||
for i=0, width / (ticks_size+ticks_gap)-border_width do
|
||||
local rel_offset = over_drawn_width / 1 - (ticks_size+ticks_gap) * i
|
||||
-- Undo the translation
|
||||
cr:translate(-border_width/2, -border_width/2)
|
||||
|
||||
if rel_offset <= rel_x then
|
||||
cr:rectangle(rel_offset,
|
||||
border_width,
|
||||
ticks_gap,
|
||||
over_drawn_height)
|
||||
end
|
||||
end
|
||||
cr:set_source(color(data[pbar].background_color or "#000000aa"))
|
||||
cr:fill()
|
||||
-- Make sure the bar stay in the shape
|
||||
if clip then
|
||||
background_shape(cr, bg_width, bg_height)
|
||||
cr:clip()
|
||||
cr:translate(border_width, border_width)
|
||||
else
|
||||
-- Assume the background size is irrelevant to the bar itself
|
||||
if type(margin) == "number" then
|
||||
cr:translate(-margin, -margin)
|
||||
else
|
||||
cr:translate(-(margin.left or 0), -(margin.top or 0))
|
||||
end
|
||||
|
||||
over_drawn_height = height
|
||||
over_drawn_width = width
|
||||
end
|
||||
|
||||
-- Apply the padding
|
||||
local padding = pbar._private.paddings or beautiful.progressbar_paddings
|
||||
|
||||
if padding then
|
||||
if type(padding) == "number" then
|
||||
cr:translate(padding, padding)
|
||||
over_drawn_height = over_drawn_height - 2*padding
|
||||
over_drawn_width = over_drawn_width - 2*padding
|
||||
else
|
||||
cr:translate(padding.left or 0, padding.top or 0)
|
||||
|
||||
over_drawn_height = over_drawn_height -
|
||||
(padding.top or 0) - (padding.bottom or 0)
|
||||
over_drawn_width = over_drawn_width -
|
||||
(padding.left or 0) - (padding.right or 0)
|
||||
end
|
||||
end
|
||||
|
||||
over_drawn_width = math.max(over_drawn_width , 0)
|
||||
over_drawn_height = math.max(over_drawn_height, 0)
|
||||
|
||||
local rel_x = over_drawn_width * value
|
||||
|
||||
|
||||
-- Draw the progressbar shape
|
||||
|
||||
local bar_shape = pbar._private.bar_shape or
|
||||
beautiful.progressbar_bar_shape or shape.rectangle
|
||||
|
||||
local bar_border_width = pbar._private.bar_border_width or
|
||||
beautiful.progressbar_bar_border_width or pbar._private.border_width or
|
||||
beautiful.progressbar_border_width or 0
|
||||
|
||||
local bar_border_color = pbar._private.bar_border_color or
|
||||
beautiful.progressbar_bar_border_color
|
||||
|
||||
bar_border_width = bar_border_color and bar_border_width or 0
|
||||
|
||||
over_drawn_width = over_drawn_width - bar_border_width
|
||||
over_drawn_height = over_drawn_height - bar_border_width
|
||||
cr:translate(bar_border_width/2, bar_border_width/2)
|
||||
|
||||
bar_shape(cr, rel_x, over_drawn_height)
|
||||
|
||||
cr:set_source(color(pbar._private.color or beautiful.progressbar_fg or "#ff0000"))
|
||||
|
||||
if bar_border_width > 0 then
|
||||
cr:fill_preserve()
|
||||
cr:set_source(color(bar_border_color))
|
||||
cr:set_line_width(bar_border_width)
|
||||
cr:stroke()
|
||||
else
|
||||
cr:fill()
|
||||
end
|
||||
|
||||
if pbar._private.ticks then
|
||||
for i=0, width / (ticks_size+ticks_gap)-border_width do
|
||||
local rel_offset = over_drawn_width / 1 - (ticks_size+ticks_gap) * i
|
||||
|
||||
if rel_offset <= rel_x then
|
||||
cr:rectangle(rel_offset,
|
||||
border_width,
|
||||
ticks_gap,
|
||||
over_drawn_height)
|
||||
end
|
||||
end
|
||||
cr:set_source(color(pbar._private.background_color or "#000000aa"))
|
||||
cr:fill()
|
||||
end
|
||||
end
|
||||
|
||||
function progressbar.fit(pbar)
|
||||
return data[pbar].width, data[pbar].height
|
||||
function progressbar:fit(_, width, height)
|
||||
return width, height
|
||||
end
|
||||
|
||||
--- Set the progressbar value.
|
||||
-- @param value The progress bar value between 0 and 1.
|
||||
function progressbar:set_value(value)
|
||||
value = value or 0
|
||||
local max_value = data[self].max_value
|
||||
data[self].value = math.min(max_value, math.max(0, value))
|
||||
|
||||
self._private.value = value
|
||||
|
||||
self:emit_signal("widget::redraw_needed")
|
||||
return self
|
||||
end
|
||||
|
||||
function progressbar:set_max_value(max_value)
|
||||
|
||||
self._private.max_value = max_value
|
||||
|
||||
self:emit_signal("widget::redraw_needed")
|
||||
end
|
||||
|
||||
--- Set the progressbar height.
|
||||
-- This method is deprecated, it no longer do anything.
|
||||
-- Use a `wibox.container.constraint` widget or `forced_height`.
|
||||
-- @param height The height to set.
|
||||
function progressbar:set_height(height)
|
||||
data[self].height = height
|
||||
self:emit_signal("widget::layout_changed")
|
||||
return self
|
||||
-- @deprecated set_height
|
||||
function progressbar:set_height(height) --luacheck: no unused_args
|
||||
util.deprecate("Use a `wibox.container.constraint` widget or forced_height")
|
||||
end
|
||||
|
||||
--- Set the progressbar width.
|
||||
-- This method is deprecated, it no longer do anything.
|
||||
-- Use a `wibox.container.constraint` widget or `forced_width`.
|
||||
-- @param width The width to set.
|
||||
function progressbar:set_width(width)
|
||||
data[self].width = width
|
||||
self:emit_signal("widget::layout_changed")
|
||||
return self
|
||||
-- @deprecated set_width
|
||||
function progressbar:set_width(width) --luacheck: no unused_args
|
||||
util.deprecate("Use a `wibox.container.constraint` widget or forced_width")
|
||||
end
|
||||
|
||||
-- Build properties function
|
||||
for _, prop in ipairs(properties) do
|
||||
if not progressbar["set_" .. prop] then
|
||||
progressbar["set_" .. prop] = function(pbar, value)
|
||||
data[pbar][prop] = value
|
||||
pbar._private[prop] = value
|
||||
pbar:emit_signal("widget::redraw_needed")
|
||||
return pbar
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function progressbar:set_vertical(value) --luacheck: no unused_args
|
||||
util.deprecate("Use a `wibox.container.rotate` widget")
|
||||
end
|
||||
|
||||
|
||||
--- Create a progressbar widget.
|
||||
-- @param args Standard widget() arguments. You should add width and height
|
||||
-- key to set progressbar geometry.
|
||||
|
@ -214,22 +422,17 @@ end
|
|||
-- @function wibox.widget.progressbar
|
||||
function progressbar.new(args)
|
||||
args = args or {}
|
||||
local width = args.width or 100
|
||||
local height = args.height or 20
|
||||
|
||||
args.type = "imagebox"
|
||||
local pbar = base.make_widget(nil, nil, {
|
||||
enable_properties = true,
|
||||
})
|
||||
|
||||
local pbar = base.make_widget()
|
||||
pbar._private.width = args.width or 100
|
||||
pbar._private.height = args.height or 20
|
||||
pbar._private.value = 0
|
||||
pbar._private.max_value = 1
|
||||
|
||||
data[pbar] = { width = width, height = height, value = 0, max_value = 1 }
|
||||
|
||||
-- Set methods
|
||||
for _, prop in ipairs(properties) do
|
||||
pbar["set_" .. prop] = progressbar["set_" .. prop]
|
||||
end
|
||||
|
||||
pbar.draw = progressbar.draw
|
||||
pbar.fit = progressbar.fit
|
||||
util.table.crush(pbar, progressbar, true)
|
||||
|
||||
return pbar
|
||||
end
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
local parent = ... --DOC_HIDE
|
||||
local wibox = require("wibox") --DOC_HIDE
|
||||
local gears = {shape = require("gears.shape") } --DOC_HIDE
|
||||
local beautiful = require("beautiful") --DOC_HIDE
|
||||
|
||||
parent:add( --DOC_HIDE
|
||||
|
||||
wibox.widget {
|
||||
max_value = 1,
|
||||
value = 0.33,
|
||||
widget = wibox.widget.progressbar
|
||||
max_value = 1,
|
||||
value = 0.33,
|
||||
forced_height = 20,
|
||||
forced_width = 100,
|
||||
shape = gears.shape.rounded_bar,
|
||||
border_width = 2,
|
||||
border_color = beautiful.border_color,
|
||||
widget = wibox.widget.progressbar,
|
||||
}
|
||||
|
||||
) --DOC_HIDE
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
local parent = ... --DOC_HIDE
|
||||
local wibox = require("wibox") --DOC_HIDE
|
||||
local gears = {shape = require("gears.shape")} --DOC_HIDE
|
||||
|
||||
local data = { --DOC_HIDE
|
||||
3, 5, 6,4, 11,15,19,29,17,17,14,0,0,3,1,0,0, 22, 17,7, 1,0,0,5, --DOC_HIDE
|
||||
3, 5, 6,4, 11,15,19,29,17,17,14,0,0,3,1,0,0, 22, 17,7, 1,0,0,5, --DOC_HIDE
|
||||
3, 5, 6,4, 11,15,19,29,17,17,14,0,0,3,1,0,0, 22, 17,7, 1,0,0,5, --DOC_HIDE
|
||||
3, 5, 6,4, 11,15,19,29,17,17,14,0,0,3,1,0,0, 22, 17,7, 1,0,0,5, --DOC_HIDE
|
||||
3, 5, 6,4, 11,15,19,29,17,17,14,0,0,3,1,0,0, 22, 17,7, 1,0,0,5, --DOC_HIDE
|
||||
} --DOC_HIDE
|
||||
|
||||
local w = --DOC_HIDE
|
||||
wibox.widget {
|
||||
max_value = 29,
|
||||
step_width = 3,
|
||||
step_spacing = 1,
|
||||
step_shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 2)
|
||||
end,
|
||||
widget = wibox.widget.graph
|
||||
}
|
||||
|
||||
parent:add( w ) --DOC_HIDE
|
||||
|
||||
for _, v in ipairs(data) do --DOC_HIDE
|
||||
w:add_value(v) --DOC_HIDE
|
||||
end --DOC_HIDE
|
|
@ -0,0 +1,27 @@
|
|||
local parent = ... --DOC_HIDE
|
||||
local wibox = require("wibox") --DOC_HIDE
|
||||
local gears = {shape = require("gears.shape") } --DOC_HIDE
|
||||
local beautiful = require("beautiful") --DOC_HIDE
|
||||
|
||||
|
||||
local l = wibox.layout { --DOC_HIDE
|
||||
forced_height = 120, --DOC_HIDE
|
||||
forced_width = 100, --DOC_HIDE
|
||||
layout = wibox.layout.flex.vertical --DOC_HIDE
|
||||
} --DOC_HIDE
|
||||
|
||||
for _, shape in ipairs {"rounded_bar", "octogon", "hexagon", "powerline" } do
|
||||
l:add(wibox.widget {
|
||||
value = 0.33,
|
||||
bar_shape = gears.shape[shape],
|
||||
bar_border_color = beautiful.border_color,
|
||||
bar_border_width = 1,
|
||||
border_width = 2,
|
||||
border_color = beautiful.border_color,
|
||||
margins = 5, --DOC_HIDE
|
||||
paddings = 1,
|
||||
widget = wibox.widget.progressbar,
|
||||
})
|
||||
end
|
||||
|
||||
parent:add(l) --DOC_HIDE
|
|
@ -0,0 +1,27 @@
|
|||
local parent = ... --DOC_HIDE
|
||||
local wibox = require("wibox") --DOC_HIDE
|
||||
local gears = {shape = require("gears.shape") } --DOC_HIDE
|
||||
local beautiful = require("beautiful") --DOC_HIDE
|
||||
|
||||
parent:add( --DOC_HIDE
|
||||
|
||||
wibox.widget {
|
||||
value = 75,
|
||||
max_value = 100,
|
||||
border_width = 2,
|
||||
border_color = beautiful.border_color,
|
||||
color = beautiful.border_color,
|
||||
shape = gears.shape.rounded_bar,
|
||||
bar_shape = gears.shape.rounded_bar,
|
||||
clip = false,
|
||||
forced_height = 30,
|
||||
forced_width = 100,
|
||||
paddings = 5,
|
||||
margins = {
|
||||
top = 12,
|
||||
bottom = 12,
|
||||
},
|
||||
widget = wibox.widget.progressbar,
|
||||
}
|
||||
|
||||
) --DOC_HIDE
|
|
@ -0,0 +1,24 @@
|
|||
local parent = ... --DOC_HIDE
|
||||
local wibox = require("wibox") --DOC_HIDE
|
||||
local gears = {shape = require("gears.shape") } --DOC_HIDE
|
||||
local beautiful = require("beautiful") --DOC_HIDE
|
||||
|
||||
|
||||
local l = wibox.layout { --DOC_HIDE
|
||||
forced_height = 100, --DOC_HIDE
|
||||
forced_width = 100, --DOC_HIDE
|
||||
layout = wibox.layout.flex.vertical --DOC_HIDE
|
||||
} --DOC_HIDE
|
||||
|
||||
for _, shape in ipairs {"rounded_bar", "octogon", "hexagon", "powerline" } do
|
||||
l:add(wibox.widget {
|
||||
value = 0.33,
|
||||
shape = gears.shape[shape],
|
||||
border_width = 2,
|
||||
border_color = beautiful.border_color,
|
||||
margins = 5, --DOC_HIDE
|
||||
widget = wibox.widget.progressbar,
|
||||
})
|
||||
end
|
||||
|
||||
parent:add(l) --DOC_HIDE
|
|
@ -0,0 +1,25 @@
|
|||
local parent = ... --DOC_NO_USAGE --DOC_HIDE
|
||||
local wibox = require("wibox") --DOC_HIDE
|
||||
local beautiful = require("beautiful") --DOC_HIDE
|
||||
|
||||
parent:add( --DOC_HIDE
|
||||
|
||||
wibox.widget {
|
||||
{
|
||||
max_value = 1,
|
||||
value = 0.5,
|
||||
forced_height = 20,
|
||||
forced_width = 100,
|
||||
paddings = 1,
|
||||
border_width = 1,
|
||||
border_color = beautiful.border_color,
|
||||
widget = wibox.widget.progressbar,
|
||||
},
|
||||
{
|
||||
text = "50%",
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
layout = wibox.layout.stack
|
||||
}
|
||||
|
||||
) --DOC_HIDE
|
|
@ -0,0 +1,18 @@
|
|||
local parent = ... --DOC_NO_USAGE --DOC_HIDE
|
||||
local wibox = require("wibox") --DOC_HIDE
|
||||
|
||||
parent:add( --DOC_HIDE
|
||||
|
||||
wibox.widget {
|
||||
{
|
||||
max_value = 1,
|
||||
value = 0.33,
|
||||
widget = wibox.widget.progressbar,
|
||||
},
|
||||
forced_height = 100,
|
||||
forced_width = 20,
|
||||
direction = "east",
|
||||
layout = wibox.container.rotate,
|
||||
}
|
||||
|
||||
) --DOC_HIDE
|
Loading…
Reference in New Issue