From 2c620468f01384d39215ce3b31872fc9dfffc920 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 23 Jul 2016 18:32:37 -0400 Subject: [PATCH 01/25] progressbar: Deprecate width, height and vertical properties. --- lib/wibox/widget/progressbar.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index ddf1b151..e52e323a 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -11,6 +11,7 @@ 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") @@ -40,7 +41,7 @@ local data = setmetatable({}, { __mode = "k" }) --- Set the progressbar to draw vertically. Default is false. -- --- @function set_vertical +-- @deprecated set_vertical -- @param progressbar The progressbar. -- @param vertical A boolean value. @@ -181,16 +182,24 @@ function progressbar:set_value(value) end --- Set the progressbar height. +-- This method is deprecated. +-- Use a `wibox.container.constraint` widget or `forced_height`. -- @param height The height to set. -function progressbar:set_height(height) +-- @deprecated set_height +function progressbar:set_height(height) --luacheck: no unused_args + util.deprecate("Use a `wibox.container.constraint` widget or forced_height") data[self].height = height self:emit_signal("widget::layout_changed") return self end --- Set the progressbar width. +-- This method is deprecated. +-- Use a `wibox.container.constraint` widget or `forced_width`. -- @param width The width to set. -function progressbar:set_width(width) +-- @deprecated set_width +function progressbar:set_width(width) --luacheck: no unused_args + util.deprecate("Use a `wibox.container.constraint` widget or forced_width") data[self].width = width self:emit_signal("widget::layout_changed") return self @@ -207,6 +216,13 @@ for _, prop in ipairs(properties) do end end +local set_vertical = progressbar.set_vertical +function progressbar:set_vertical(value) --luacheck: no unused_args + util.deprecate("Use a `wibox.container.rotate` widget") + set_vertical(self, value) +end + + --- Create a progressbar widget. -- @param args Standard widget() arguments. You should add width and height -- key to set progressbar geometry. From 7cbcc800bca9e27bf42099153bd113a22b908330 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 23 Jul 2016 18:35:38 -0400 Subject: [PATCH 02/25] progressbar: Remove dead code. --- lib/wibox/widget/progressbar.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index e52e323a..89617c0d 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -233,8 +233,6 @@ function progressbar.new(args) local width = args.width or 100 local height = args.height or 20 - args.type = "imagebox" - local pbar = base.make_widget() data[pbar] = { width = width, height = height, value = 0, max_value = 1 } From 8d7f228301a4fc613310f03225377a945dce43b2 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 23 Jul 2016 18:39:29 -0400 Subject: [PATCH 03/25] progressbar: Conform to the new widget conventions. It is not Awesome 3.2 anymore, progressbars are no longer userdata. --- lib/wibox/widget/progressbar.lua | 59 +++++++++++++++----------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index 89617c0d..34590b52 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -18,8 +18,6 @@ local beautiful = require("beautiful") local progressbar = { mt = {} } -local data = setmetatable({}, { __mode = "k" }) - --- Set the progressbar border color. -- If the value is nil, no border will be drawn. -- @@ -84,14 +82,14 @@ local properties = { "width", "height", "border_color", "ticks", "ticks_gap", "ticks_size" } 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 value = pbar._private.value + local max_value = pbar._private.max_value if value >= 0 then value = value / max_value end @@ -99,7 +97,7 @@ function progressbar.draw(pbar, _, cr, width, height) 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 + local col = pbar._private.border_color or beautiful.progressbar_border_color if col then -- Draw border cr:rectangle(0.5, 0.5, width - 1, height - 1) @@ -113,21 +111,21 @@ function progressbar.draw(pbar, _, cr, width, height) 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:set_source(color(pbar._private.color or beautiful.progressbar_fg or "#ff0000")) cr:fill() -- Cover the part that is not set with a rectangle - if data[pbar].vertical then + if pbar._private.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:set_source(color(pbar._private.background_color or beautiful.progressbar_bg or "#000000aa")) cr:fill() -- Place smaller pieces over the gradient if ticks are enabled - if data[pbar].ticks then + if pbar._private.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 @@ -138,7 +136,7 @@ function progressbar.draw(pbar, _, cr, width, height) ticks_gap) end end - cr:set_source(color(data[pbar].background_color or beautiful.progressbar_bg or "#000000aa")) + cr:set_source(color(pbar._private.background_color or beautiful.progressbar_bg or "#000000aa")) cr:fill() end else @@ -147,10 +145,10 @@ function progressbar.draw(pbar, _, cr, width, height) border_width, over_drawn_width - rel_x, over_drawn_height) - cr:set_source(color(data[pbar].background_color or "#000000aa")) + cr:set_source(color(pbar._private.background_color or "#000000aa")) cr:fill() - if data[pbar].ticks then + 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 @@ -161,22 +159,22 @@ function progressbar.draw(pbar, _, cr, width, height) over_drawn_height) end end - cr:set_source(color(data[pbar].background_color or "#000000aa")) + cr:set_source(color(pbar._private.background_color or "#000000aa")) cr:fill() end end end function progressbar.fit(pbar) - return data[pbar].width, data[pbar].height + return pbar._private.width, pbar._private.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)) + local max_value = self._private.max_value + self._private.value = math.min(max_value, math.max(0, value)) self:emit_signal("widget::redraw_needed") return self end @@ -188,7 +186,7 @@ end -- @deprecated set_height function progressbar:set_height(height) --luacheck: no unused_args util.deprecate("Use a `wibox.container.constraint` widget or forced_height") - data[self].height = height + self._private.height = height self:emit_signal("widget::layout_changed") return self end @@ -200,7 +198,7 @@ end -- @deprecated set_width function progressbar:set_width(width) --luacheck: no unused_args util.deprecate("Use a `wibox.container.constraint` widget or forced_width") - data[self].width = width + self._private.width = width self:emit_signal("widget::layout_changed") return self end @@ -209,7 +207,7 @@ end 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 @@ -230,20 +228,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 - local pbar = base.make_widget() + local pbar = base.make_widget(nil, nil, { + enable_properties = true, + }) - data[pbar] = { width = width, height = height, value = 0, max_value = 1 } + pbar._private.width = args.width or 100 + pbar._private.height = args.height or 20 + pbar._private.value = 0 + pbar._private.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 From e28b79944f29e07e22c00378c3b426cdf923db76 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 23 Jul 2016 19:02:00 -0400 Subject: [PATCH 04/25] doc: Use @property for the progressbar doc. --- lib/wibox/widget/progressbar.lua | 52 ++++++++++++++------------------ 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index 34590b52..5f4315e7 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -18,54 +18,46 @@ local beautiful = require("beautiful") local progressbar = { mt = {} } ---- 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. +--- The progressbar foreground color. -- --- @function set_color --- @param progressbar The progressbar. --- @param color The progressbar color. +-- @property color +-- @tparam gears.color color The progressbar color. ---- Set the progressbar background color. +--- The progressbar background color. -- --- @function set_background_color --- @param progressbar The progressbar. --- @param color The progressbar background color. +-- @property background_color +-- @tparam gears.color color The progressbar background color. --- Set the progressbar to draw vertically. Default is false. -- -- @deprecated set_vertical --- @param progressbar The progressbar. --- @param vertical A boolean value. +-- @tparam boolean vertical ---- Set the progressbar to draw ticks. Default is false. +--- The progressbar to draw ticks. Default is false. -- --- @function set_ticks --- @param progressbar The progressbar. --- @param ticks A boolean value. +-- @property ticks +-- @param boolean ---- Set the progressbar ticks gap. +--- The progressbar ticks gap. -- --- @function set_ticks_gap --- @param progressbar The progressbar. --- @param value The value. +-- @property ticks_gap +-- @param number ---- Set the progressbar ticks size. +--- The progressbar ticks size. -- --- @function set_ticks_size --- @param progressbar The progressbar. --- @param value The value. +-- @property ticks_size +-- @param number ---- Set the maximum value the progressbar should handle. +--- The maximum value the progressbar should handle. -- --- @function set_max_value --- @param progressbar The progressbar. --- @param value The value. +-- @property max_value +-- @param number --- The progressbar background color. -- @beautiful beautiful.progressbar_bg From e5d4c188f1729d07da7bc0beb6f7491902b29d8f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 23 Jul 2016 19:21:15 -0400 Subject: [PATCH 05/25] progressbar: Remove vertical/width/height code The deprecation message should be enough. This doesn't remove the functionalities themselves. --- lib/wibox/widget/progressbar.lua | 87 ++++++++++---------------------- 1 file changed, 28 insertions(+), 59 deletions(-) diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index 5f4315e7..277c2683 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -1,6 +1,10 @@ --------------------------------------------------------------------------- --- A progressbar widget. -- +-- 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 @@ -34,8 +38,8 @@ local progressbar = { mt = {} } -- @property background_color -- @tparam gears.color color The progressbar background color. ---- Set the progressbar to draw vertically. Default is false. --- +--- Set the progressbar to draw vertically. +-- This doesn't do anything anymore, use a `wibox.container.rotate` widget. -- @deprecated set_vertical -- @tparam boolean vertical @@ -68,10 +72,9 @@ local progressbar = { mt = {} } --- 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" } +local properties = { "border_color", "color" , "background_color", + "value" , "max_value", "ticks", + "ticks_gap" , "ticks_size" } function progressbar.draw(pbar, _, cr, width, height) local ticks_gap = pbar._private.ticks_gap or 1 @@ -107,58 +110,32 @@ function progressbar.draw(pbar, _, cr, width, height) cr:fill() -- Cover the part that is not set with a rectangle - if pbar._private.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(pbar._private.background_color or beautiful.progressbar_bg or "#000000aa")) - cr:fill() + 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(pbar._private.background_color or "#000000aa")) + cr:fill() - -- Place smaller pieces over the gradient if ticks are enabled - if pbar._private.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 + 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_height then - cr:rectangle(border_width, - rel_offset, - over_drawn_width, - ticks_gap) - end + if rel_offset <= rel_x then + cr:rectangle(rel_offset, + border_width, + ticks_gap, + over_drawn_height) end - cr:set_source(color(pbar._private.background_color or beautiful.progressbar_bg or "#000000aa")) - cr:fill() end - 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(pbar._private.background_color or "#000000aa")) cr:fill() - - 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 end -function progressbar.fit(pbar) - return pbar._private.width, pbar._private.height +function progressbar:fit(_, width, height) + return width, height end --- Set the progressbar value. @@ -172,27 +149,21 @@ function progressbar:set_value(value) end --- Set the progressbar height. --- This method is deprecated. +-- This method is deprecated, it no longer do anything. -- Use a `wibox.container.constraint` widget or `forced_height`. -- @param height The height to set. -- @deprecated set_height function progressbar:set_height(height) --luacheck: no unused_args util.deprecate("Use a `wibox.container.constraint` widget or forced_height") - self._private.height = height - self:emit_signal("widget::layout_changed") - return self end --- Set the progressbar width. --- This method is deprecated. +-- This method is deprecated, it no longer do anything. -- Use a `wibox.container.constraint` widget or `forced_width`. -- @param width The width to set. -- @deprecated set_width function progressbar:set_width(width) --luacheck: no unused_args util.deprecate("Use a `wibox.container.constraint` widget or forced_width") - self._private.width = width - self:emit_signal("widget::layout_changed") - return self end -- Build properties function @@ -206,10 +177,8 @@ for _, prop in ipairs(properties) do end end -local set_vertical = progressbar.set_vertical function progressbar:set_vertical(value) --luacheck: no unused_args util.deprecate("Use a `wibox.container.rotate` widget") - set_vertical(self, value) end From 8ec53c827b0ad7518ee2715a9cef38e18fa1ebe0 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 24 Jul 2016 16:25:19 -0400 Subject: [PATCH 06/25] progressbar: Fix a race condition When created using the declarative syntax, set_value could be called before set_max_value, this trimmed the value. --- lib/wibox/widget/progressbar.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index 277c2683..94541397 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -83,8 +83,10 @@ function progressbar.draw(pbar, _, cr, width, height) -- We want one pixel wide lines cr:set_line_width(1) - local value = pbar._private.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 @@ -142,12 +144,20 @@ end -- @param value The progress bar value between 0 and 1. function progressbar:set_value(value) value = value or 0 - local max_value = self._private.max_value - self._private.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`. From 915c10b1f87753f73abaa19c0bcc7857f3a4f2f4 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 24 Jul 2016 18:05:00 -0400 Subject: [PATCH 07/25] progressbar: Add shape support The current progressbar code dates from a time when Awesome had a very limited drawing API. This commit first re-write the algorithm to remove the workaround used to draw the border using full rectangles only. It then add support for outer and inner shapes with their respective border settings. This commit also add clip support. This is enabled by default, but could be disabled to have the bar taller than the background. --- lib/wibox/widget/progressbar.lua | 156 ++++++++++++++++++++++++++----- 1 file changed, 132 insertions(+), 24 deletions(-) diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index 94541397..0c66c17e 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -19,6 +19,7 @@ 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 = {} } @@ -28,6 +29,18 @@ local progressbar = { mt = {} } -- @property border_color -- @tparam gears.color color The border color to set. +--- The progressbar border width. +-- @property border_width + +--- The progressbar inner border color. +-- If the value is nil, no border will be drawn. +-- +-- @property bar_border_color +-- @tparam gears.color color The border color to set. + +--- The progressbar inner border width. +-- @property bar_border_width + --- The progressbar foreground color. -- -- @property color @@ -38,11 +51,26 @@ local progressbar = { mt = {} } -- @property background_color -- @tparam gears.color color The progressbar background color. +--- The progressbar inner shape. +-- @property bar_shape +-- @tparam[opt=gears.shape.rectangle] gears.shape shape +-- @see gears.shape + +--- The progressbar shape. +-- @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. +-- +-- @property clip +-- @tparam[opt=true] boolean clip + --- The progressbar to draw ticks. Default is false. -- -- @property ticks @@ -69,12 +97,32 @@ local progressbar = { mt = {} } --- 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 = { "border_color", "color" , "background_color", - "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 + +local properties = { "border_color", "color" , "background_color", + "value" , "max_value" , "ticks", + "ticks_gap" , "ticks_size", "border_width", + "shape" , "bar_shape" , "bar_border_width", + "clip" , "bar_border_color" + } function progressbar.draw(pbar, _, cr, width, height) local ticks_gap = pbar._private.ticks_gap or 1 @@ -93,32 +141,92 @@ function progressbar.draw(pbar, _, cr, width, height) local over_drawn_width = width local over_drawn_height = height - local border_width = 0 - local col = pbar._private.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 border_width = pbar._private.border_width + or beautiful.progressbar_border_width or 0 - over_drawn_width = width - 2 -- remove 2 for borders - over_drawn_height = height - 2 -- remove 2 for borders - border_width = 1 + local bcol = pbar._private.border_color or beautiful.progressbar_border_color + + 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 + + -- 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 - cr:rectangle(border_width, border_width, - over_drawn_width, over_drawn_height) - cr:set_source(color(pbar._private.color or beautiful.progressbar_fg or "#ff0000")) - cr:fill() + local background_shape = pbar._private.shape or + beautiful.progressbar_shape or shape.rectangle + + background_shape(cr, bg_width, bg_height) + + cr:set_source(color(bg)) + + if border_width > 0 then + cr:fill_preserve() + + -- Draw the border + cr:set_source(color(bcol)) + + cr:stroke() + + over_drawn_width = width - 2*border_width + over_drawn_height = height - 2*border_width + else + cr:fill() + end + + -- Undo the translation + if border_width > 0 then + cr:translate(-border_width/2, -border_width/2) + end - -- Cover the part that is not set with a rectangle 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(pbar._private.background_color or "#000000aa")) - cr:fill() + + cr:translate(border_width, border_width) + + -- Make sure the bar stay in the shape + if pbar._private.clip ~= false and beautiful.progressbar_clip ~= false then + background_shape(cr, over_drawn_width, over_drawn_height) + cr:clip() + end + + -- 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 From e1733dd37aabb72f7ae7e57a140c0bf77c2a70c8 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 24 Jul 2016 20:11:40 -0400 Subject: [PATCH 08/25] progressbar: Add paddings and margins properties This restore a feature that was available in Awesome 2.1-3.2. The reason margin is implemented rather than use a container is to be able to make the background smaller than the bar. --- lib/wibox/widget/progressbar.lua | 122 +++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 15 deletions(-) diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index 0c66c17e..568777a5 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -117,11 +117,56 @@ local progressbar = { mt = {} } --- 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. +-- @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. +-- @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" , "bar_border_color" + "clip" , "margins" , "bar_border_color", + "paddings", } function progressbar.draw(pbar, _, cr, width, height) @@ -138,9 +183,6 @@ function progressbar.draw(pbar, _, cr, width, height) if value >= 0 then value = value / max_value end - - local over_drawn_width = width - local over_drawn_height = height local border_width = pbar._private.border_width or beautiful.progressbar_border_width or 0 @@ -153,6 +195,24 @@ function progressbar.draw(pbar, _, cr, width, height) 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 + -- Draw the background shape if border_width > 0 then -- Cairo draw half of the border outside of the path area @@ -168,6 +228,9 @@ function progressbar.draw(pbar, _, cr, width, height) 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() @@ -176,26 +239,55 @@ function progressbar.draw(pbar, _, cr, width, height) cr:stroke() - over_drawn_width = width - 2*border_width - over_drawn_height = height - 2*border_width + over_drawn_width = over_drawn_width - 2*border_width + over_drawn_height = over_drawn_height - 2*border_width else cr:fill() end -- Undo the translation - if border_width > 0 then - cr:translate(-border_width/2, -border_width/2) + cr:translate(-border_width/2, -border_width/2) + + -- 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 - cr:translate(border_width, border_width) - - -- Make sure the bar stay in the shape - if pbar._private.clip ~= false and beautiful.progressbar_clip ~= false then - background_shape(cr, over_drawn_width, over_drawn_height) - cr:clip() - end -- Draw the progressbar shape From b49b859fac1fedf25b74e9d9cfd9ac2dfc470fbf Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 24 Jul 2016 21:46:37 -0400 Subject: [PATCH 09/25] tests: Use the new progressbar features in the default test. --- .../examples/wibox/widget/defaults/progressbar.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/examples/wibox/widget/defaults/progressbar.lua b/tests/examples/wibox/widget/defaults/progressbar.lua index c82957ff..f833edc8 100644 --- a/tests/examples/wibox/widget/defaults/progressbar.lua +++ b/tests/examples/wibox/widget/defaults/progressbar.lua @@ -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 From a8568eb969a7aa500a8e4de35ec2f1fb6a8e886e Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 24 Jul 2016 22:06:11 -0400 Subject: [PATCH 10/25] doc: Add examples for vertical and labelled progressbar --- lib/wibox/widget/progressbar.lua | 9 +++++++ .../wibox/widget/progressbar/text.lua | 25 +++++++++++++++++++ .../wibox/widget/progressbar/vertical.lua | 18 +++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 tests/examples/wibox/widget/progressbar/text.lua create mode 100644 tests/examples/wibox/widget/progressbar/vertical.lua diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index 568777a5..ef4e0729 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -1,11 +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@ diff --git a/tests/examples/wibox/widget/progressbar/text.lua b/tests/examples/wibox/widget/progressbar/text.lua new file mode 100644 index 00000000..f502939e --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/text.lua @@ -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 diff --git a/tests/examples/wibox/widget/progressbar/vertical.lua b/tests/examples/wibox/widget/progressbar/vertical.lua new file mode 100644 index 00000000..eb0d060f --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/vertical.lua @@ -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 From 7b11f1c1b4c759f4a15357d4e72861f2fff29b15 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 24 Jul 2016 22:18:12 -0400 Subject: [PATCH 11/25] tests: Test progressbat paddings, margins and clip --- lib/wibox/widget/progressbar.lua | 8 ++++++ .../wibox/widget/progressbar/clip.lua | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/examples/wibox/widget/progressbar/clip.lua diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index ef4e0729..f7f9d314 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -77,6 +77,8 @@ local progressbar = { mt = {} } --- 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 @@ -129,6 +131,9 @@ local progressbar = { mt = {} } --- 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 @@ -140,6 +145,9 @@ local progressbar = { mt = {} } --- 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 diff --git a/tests/examples/wibox/widget/progressbar/clip.lua b/tests/examples/wibox/widget/progressbar/clip.lua new file mode 100644 index 00000000..08f48466 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/clip.lua @@ -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 From 549d68dcc526680d428faf04f516f3339b49c912 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 24 Jul 2016 22:35:58 -0400 Subject: [PATCH 12/25] doc: Add more progressbar shape examples --- lib/wibox/widget/progressbar.lua | 6 +++++ .../wibox/widget/progressbar/bar_shape.lua | 27 +++++++++++++++++++ .../wibox/widget/progressbar/shape.lua | 24 +++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 tests/examples/wibox/widget/progressbar/bar_shape.lua create mode 100644 tests/examples/wibox/widget/progressbar/shape.lua diff --git a/lib/wibox/widget/progressbar.lua b/lib/wibox/widget/progressbar.lua index f7f9d314..833656ae 100644 --- a/lib/wibox/widget/progressbar.lua +++ b/lib/wibox/widget/progressbar.lua @@ -61,11 +61,17 @@ local progressbar = { mt = {} } -- @tparam gears.color color The progressbar background color. --- The progressbar inner shape. +-- +--@DOC_wibox_widget_progressbar_bar_shape_EXAMPLE@ +-- -- @property bar_shape -- @tparam[opt=gears.shape.rectangle] gears.shape shape -- @see gears.shape --- The progressbar shape. +-- +--@DOC_wibox_widget_progressbar_shape_EXAMPLE@ +-- -- @property shape -- @tparam[opt=gears.shape.rectangle] gears.shape shape -- @see gears.shape diff --git a/tests/examples/wibox/widget/progressbar/bar_shape.lua b/tests/examples/wibox/widget/progressbar/bar_shape.lua new file mode 100644 index 00000000..8b6ba991 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/bar_shape.lua @@ -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 diff --git a/tests/examples/wibox/widget/progressbar/shape.lua b/tests/examples/wibox/widget/progressbar/shape.lua new file mode 100644 index 00000000..59603429 --- /dev/null +++ b/tests/examples/wibox/widget/progressbar/shape.lua @@ -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 From 00ee99851bee6b23ccd7da904475a2d9ba56615a Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 5 Aug 2016 00:46:19 -0400 Subject: [PATCH 13/25] taglist: Add spacing support --- lib/awful/widget/taglist.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/awful/widget/taglist.lua b/lib/awful/widget/taglist.lua index 38a39434..cfc290e0 100644 --- a/lib/awful/widget/taglist.lua +++ b/lib/awful/widget/taglist.lua @@ -177,6 +177,10 @@ function taglist.new(screen, filter, buttons, style, update_function, base_widge 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 = {} From f517538b6a4e9f8ea92f22209ced86897c196074 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 5 Aug 2016 01:13:20 -0400 Subject: [PATCH 14/25] background: Avoid some redraw --- lib/wibox/container/background.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/wibox/container/background.lua b/lib/wibox/container/background.lua index 6b52e986..589a3697 100644 --- a/lib/wibox/container/background.lua +++ b/lib/wibox/container/background.lua @@ -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 From da47357ae7f0c370a2dc0c693c90445eae28e8e3 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 5 Aug 2016 01:13:39 -0400 Subject: [PATCH 15/25] widget.common: Add shape support --- lib/awful/widget/common.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/awful/widget/common.lua b/lib/awful/widget/common.lua index 78f57172..bd46fa66 100644 --- a/lib/awful/widget/common.lua +++ b/lib/awful/widget/common.lua @@ -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 From 967fc87a92e6202814334f10aff931b7e08ce591 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 5 Aug 2016 01:13:58 -0400 Subject: [PATCH 16/25] taglist: Add shape support --- lib/awful/widget/taglist.lua | 49 +++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/awful/widget/taglist.lua b/lib/awful/widget/taglist.lua index cfc290e0..e3c4d053 100644 --- a/lib/awful/widget/taglist.lua +++ b/lib/awful/widget/taglist.lua @@ -56,6 +56,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 +94,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 = "" if fg_color then @@ -116,7 +157,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) From 520bd024162817255f26add5cd72b9d5af929432 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 5 Aug 2016 01:34:55 -0400 Subject: [PATCH 17/25] tasklist: Add spacing support --- lib/awful/widget/tasklist.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/awful/widget/tasklist.lua b/lib/awful/widget/tasklist.lua index ae749273..cff5ef4e 100644 --- a/lib/awful/widget/tasklist.lua +++ b/lib/awful/widget/tasklist.lua @@ -167,6 +167,7 @@ end -- @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. -- @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 +180,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. From 6e829ce1047e35e73805deb36f307ef9a3c69a80 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 5 Aug 2016 01:47:14 -0400 Subject: [PATCH 18/25] tasklist: Add shape support --- lib/awful/widget/tasklist.lua | 60 ++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/awful/widget/tasklist.lua b/lib/awful/widget/tasklist.lua index cff5ef4e..db3244a6 100644 --- a/lib/awful/widget/tasklist.lua +++ b/lib/awful/widget/tasklist.lua @@ -56,6 +56,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 +109,66 @@ local function tasklist_label(c, args, tb) text = text .. ""..name.."" 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 .. ""..name.."" 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 .. ""..name.."" 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 .. ""..name.."" 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) @@ -168,6 +214,18 @@ end -- @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 From 9e8c4a71e34f630b150812f774dac5b24a5a9c44 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 13 Aug 2016 17:39:36 -0400 Subject: [PATCH 19/25] doc: Document taglist theme variables --- lib/awful/widget/taglist.lua | 138 +++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/lib/awful/widget/taglist.lua b/lib/awful/widget/taglist.lua index e3c4d053..143804b1 100644 --- a/lib/awful/widget/taglist.lua +++ b/lib/awful/widget/taglist.lua @@ -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) @@ -219,6 +356,7 @@ 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 From bbb3d1482261aa4fc44cf9917fde94d860f99ba4 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 14 Aug 2016 00:25:50 -0400 Subject: [PATCH 20/25] doc: Document the tasklist variables. --- lib/awful/widget/tasklist.lua | 139 +++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/lib/awful/widget/tasklist.lua b/lib/awful/widget/tasklist.lua index db3244a6..3c42755f 100644 --- a/lib/awful/widget/tasklist.lua +++ b/lib/awful/widget/tasklist.lua @@ -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 = {} @@ -210,6 +346,7 @@ 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 From 68999f4a86df5f8d23d7bf06939d45985f052411 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 16 Aug 2016 00:59:37 -0400 Subject: [PATCH 21/25] graph: Add min_value Fix #277 --- lib/wibox/widget/graph.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/wibox/widget/graph.lua b/lib/wibox/widget/graph.lua index 802cc0c9..ca27409f 100644 --- a/lib/wibox/widget/graph.lua +++ b/lib/wibox/widget/graph.lua @@ -43,6 +43,12 @@ 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 @@ -69,10 +75,12 @@ local graph = { mt = {} } local properties = { "width", "height", "border_color", "stack", "stack_colors", "color", "background_color", - "max_value", "scale" } + "max_value", "scale", "min_value" } 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 cr:set_line_width(1) @@ -97,6 +105,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 +136,9 @@ function graph.draw(_graph, _, cr, width, height) if v > max_value then max_value = v end + if min_value > sv then + min_value = v + end end end @@ -134,7 +148,7 @@ 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 + value = (value - min_value) / max_value cr:move_to(i + 0.5, height * (1 - value)) cr:line_to(i + 0.5, height) end From 5ef9b64b40eaa15ca4459c1d41a8d08f48a891c6 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 16 Aug 2016 01:38:42 -0400 Subject: [PATCH 22/25] graph: Add shape support This complete the shape API. Now, everything support shapes. --- lib/wibox/widget/graph.lua | 53 +++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/lib/wibox/widget/graph.lua b/lib/wibox/widget/graph.lua index ca27409f..6d720073 100644 --- a/lib/wibox/widget/graph.lua +++ b/lib/wibox/widget/graph.lua @@ -54,6 +54,27 @@ local graph = { mt = {} } -- @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 @@ -75,7 +96,8 @@ local graph = { mt = {} } local properties = { "width", "height", "border_color", "stack", "stack_colors", "color", "background_color", - "max_value", "scale", "min_value" } + "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 @@ -83,6 +105,10 @@ function graph.draw(_graph, _, cr, width, height) _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 @@ -136,7 +162,7 @@ function graph.draw(_graph, _, cr, width, height) if v > max_value then max_value = v end - if min_value > sv then + if min_value > v then min_value = v end end @@ -148,18 +174,33 @@ function graph.draw(_graph, _, cr, width, height) for i = 0, #values - 1 do local value = values[#values - i] if value >= 0 then + local x = i*step_width + ((i-1)*step_spacing) + 0.5 value = (value - min_value) / max_value - cr:move_to(i + 0.5, height * (1 - value)) - cr:line_to(i + 0.5, height) + 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 From f25621c94c227a1314ca4cccae2337907d10cc7f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 16 Aug 2016 01:39:28 -0400 Subject: [PATCH 23/25] tests: Test the graph shape. --- tests/examples/wibox/widget/graph/step.lua | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/examples/wibox/widget/graph/step.lua diff --git a/tests/examples/wibox/widget/graph/step.lua b/tests/examples/wibox/widget/graph/step.lua new file mode 100644 index 00000000..9b5d0210 --- /dev/null +++ b/tests/examples/wibox/widget/graph/step.lua @@ -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 From b6421699da257480dc76d98da118bb8cfb76cae4 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 16 Aug 2016 01:43:42 -0400 Subject: [PATCH 24/25] doc: Add more graph documentation. --- lib/wibox/widget/graph.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/wibox/widget/graph.lua b/lib/wibox/widget/graph.lua index 6d720073..635dccb9 100644 --- a/lib/wibox/widget/graph.lua +++ b/lib/wibox/widget/graph.lua @@ -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 From fb4a48b744d145ecdcc8b4356a1f46e29fe814b7 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 16 Aug 2016 01:54:49 -0400 Subject: [PATCH 25/25] doc: Document where gears.shape can be used. --- lib/gears/shape.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/gears/shape.lua b/lib/gears/shape.lua index 3307d429..148c228f 100644 --- a/lib/gears/shape.lua +++ b/lib/gears/shape.lua @@ -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