diff options
author | ache <ache@ache.one> | 2017-04-25 02:24:15 +0000 |
---|---|---|
committer | ache <ache@ache.one> | 2017-04-25 02:24:15 +0000 |
commit | 9a8809f5d7fb61db02f5fbd90edd927d61006455 (patch) | |
tree | a023e3f37460df5f25e6dc97f8f8465e81433874 /awesome/lib/wibox/widget | |
parent | Change theme colors (diff) |
Big clean up of the config directory
Diffstat (limited to 'awesome/lib/wibox/widget')
-rw-r--r-- | awesome/lib/wibox/widget/background.lua | 16 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/base.lua | 694 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/checkbox.lua | 530 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/graph.lua | 575 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/imagebox.lua | 395 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/init.lua | 22 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/piechart.lua | 467 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/progressbar.lua | 754 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/slider.lua | 709 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/systray.lua | 186 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/textbox.lua | 507 | ||||
-rw-r--r-- | awesome/lib/wibox/widget/textclock.lua | 254 |
12 files changed, 0 insertions, 5109 deletions
diff --git a/awesome/lib/wibox/widget/background.lua b/awesome/lib/wibox/widget/background.lua deleted file mode 100644 index 3c35a0b..0000000 --- a/awesome/lib/wibox/widget/background.lua +++ /dev/null @@ -1,16 +0,0 @@ ---------------------------------------------------------------------------- --- This class has been moved to `wibox.container.background` --- --- @author Uli Schlachter --- @copyright 2010 Uli Schlachter --- @classmod wibox.widget.background ---------------------------------------------------------------------------- -local util = require("awful.util") - -return util.deprecate_class( - require("wibox.container.background"), - "wibox.widget.background", - "wibox.container.background" -) - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/base.lua b/awesome/lib/wibox/widget/base.lua deleted file mode 100644 index dd80ec7..0000000 --- a/awesome/lib/wibox/widget/base.lua +++ /dev/null @@ -1,694 +0,0 @@ ---------------------------------------------------------------------------- --- @author Uli Schlachter --- @copyright 2010 Uli Schlachter --- @classmod wibox.widget.base ---------------------------------------------------------------------------- - -local object = require("gears.object") -local cache = require("gears.cache") -local matrix = require("gears.matrix") -local protected_call = require("gears.protected_call") -local util = require("awful.util") -local setmetatable = setmetatable -local pairs = pairs -local type = type -local table = table - -local base = {} - --- {{{ Functions on widgets - ---- Functions available on all widgets. -base.widget = {} - ---- Set/get a widget's buttons. --- @tab _buttons The table of buttons that is bound to the widget. --- @function buttons -function base.widget:buttons(_buttons) - if _buttons then - self._private.widget_buttons = _buttons - end - return self._private.widget_buttons -end - ---- Set a widget's visibility. --- @tparam boolean b Whether the widget is visible. --- @function set_visible -function base.widget:set_visible(b) - if b ~= self._private.visible then - self._private.visible = b - self:emit_signal("widget::layout_changed") - -- In case something ignored fit and drew the widget anyway. - self:emit_signal("widget::redraw_needed") - end -end - ---- Is the widget visible? --- @treturn boolean --- @function get_visible -function base.widget:get_visible() - return self._private.visible or false -end - ---- Set a widget's opacity. --- @tparam number o The opacity to use (a number from 0 (transparent) to 1 --- (opaque)). --- @function set_opacity -function base.widget:set_opacity(o) - if o ~= self._private.opacity then - self._private.opacity = o - self:emit_signal("widget::redraw") - end -end - ---- Get the widget's opacity. --- @treturn number The opacity (between 0 (transparent) and 1 (opaque)). --- @function get_opacity -function base.widget:get_opacity() - return self._private.opacity -end - ---- Set the widget's forced width. --- @tparam[opt] number width With `nil` the default mechanism of calling the --- `:fit` method is used. --- @see fit_widget --- @function set_forced_width -function base.widget:set_forced_width(width) - if width ~= self._private.forced_width then - self._private.forced_width = width - self:emit_signal("widget::layout_changed") - end -end - ---- Get the widget's forced width. --- --- Note that widget instances can be used in different places simultaneously, --- and therefore can have multiple dimensions. --- If there is no forced width/height, then the only way to get the widget's --- actual size is during a `mouse::enter`, `mouse::leave` or button event. --- @treturn[opt] number The forced width (nil if automatic). --- @see fit_widget --- @function get_forced_width -function base.widget:get_forced_width() - return self._private.forced_width -end - ---- Set the widget's forced height. --- @tparam[opt] number height With `nil` the default mechanism of calling the --- `:fit` method is used. --- @see fit_widget --- @function set_height -function base.widget:set_forced_height(height) - if height ~= self._private.forced_height then - self._private.forced_height = height - self:emit_signal("widget::layout_changed") - end -end - ---- Get the widget's forced height. --- --- Note that widget instances can be used in different places simultaneously, --- and therefore can have multiple dimensions. --- If there is no forced width/height, then the only way to get the widget's --- actual size is during a `mouse::enter`, `mouse::leave` or button event. --- @treturn[opt] number The forced height (nil if automatic). --- @function get_forced_height -function base.widget:get_forced_height() - return self._private.forced_height -end - ---- Get the widget's direct children widgets. --- --- This method should be re-implemented by the relevant widgets. --- @treturn table The children --- @function get_children -function base.widget:get_children() - return {} -end - ---- Replace the layout children. --- --- The default implementation does nothing, this must be re-implemented by --- all layout and container widgets. --- @tab children A table composed of valid widgets. --- @function set_children -function base.widget:set_children(children) -- luacheck: no unused - -- Nothing on purpose -end - --- It could have been merged into `get_all_children`, but it's not necessary. -local function digg_children(ret, tlw) - for _, w in ipairs(tlw:get_children()) do - table.insert(ret, w) - digg_children(ret, w) - end -end - ---- Get all direct and indirect children widgets. --- --- This will scan all containers recursively to find widgets. --- --- *Warning*: This method it prone to stack overflow if the widget, or any of --- its children, contains (directly or indirectly) itself. --- @treturn table The children --- @function get_all_children -function base.widget:get_all_children() - local ret = {} - digg_children(ret, self) - return ret -end - ---- Emit a signal and ensure all parent widgets in the hierarchies also --- forward the signal. This is useful to track signals when there is a dynamic --- set of containers and layouts wrapping the widget. --- --- Note that this function has two flaws: --- --- 1. The signal is only forwarded once the widget tree has been built. This --- happens after all currently scheduled functions have been executed. --- Therefore, it will not start to work right away. --- 2. In case the widget is present multiple times in a single widget tree, --- this function will also forward the signal multiple time (one per upward --- tree path). --- --- @tparam string signal_name --- @param ... Other arguments --- @function emit_signal_recursive -function base.widget:emit_signal_recursive(signal_name, ...) - -- This is a convenience wrapper, the real implementation is in the - -- hierarchy. - - self:emit_signal("widget::emit_recursive", signal_name, ...) -end - ---- Get the index of a widget. --- @tparam widget widget The widget to look for. --- @tparam[opt] boolean recursive Also check sub-widgets? --- @tparam[opt] widget ... Additional widgets to add at the end of the "path" --- @treturn number The index. --- @treturn widget The parent widget. --- @treturn table The path between "self" and "widget". --- @function index -function base.widget:index(widget, recursive, ...) - local widgets = self:get_children() - for idx, w in ipairs(widgets) do - if w == widget then - return idx, self, {...} - elseif recursive then - local child_idx, l, path = w:index(widget, true, self, ...) - if child_idx and l then - return child_idx, l, path - end - end - end - return nil, self, {} -end --- }}} - --- {{{ Caches - --- Indexes are widgets, allow them to be garbage-collected. -local widget_dependencies = setmetatable({}, { __mode = "kv" }) - --- Get the cache of the given kind for this widget. This returns a gears.cache --- that calls the callback of kind `kind` on the widget. -local function get_cache(widget, kind) - if not widget._private.widget_caches[kind] then - widget._private.widget_caches[kind] = cache.new(function(...) - return protected_call(widget[kind], widget, ...) - end) - end - return widget._private.widget_caches[kind] -end - --- Special value to skip the dependency recording that is normally done by --- base.fit_widget() and base.layout_widget(). The caller must ensure that no --- caches depend on the result of the call and/or must handle the children's --- widget::layout_changed signal correctly when using this. -base.no_parent_I_know_what_I_am_doing = {} - --- Record a dependency from parent to child: The layout of `parent` depends on --- the layout of `child`. -local function record_dependency(parent, child) - if parent == base.no_parent_I_know_what_I_am_doing then - return - end - - base.check_widget(parent) - base.check_widget(child) - - local deps = widget_dependencies[child] or {} - deps[parent] = true - widget_dependencies[child] = deps -end - --- Clear the caches for `widget` and all widgets that depend on it. -local clear_caches -function clear_caches(widget) - local deps = widget_dependencies[widget] or {} - widget_dependencies[widget] = {} - widget._private.widget_caches = {} - for w in pairs(deps) do - clear_caches(w) - end -end - --- }}} - ---- Figure out the geometry in the device coordinate space. --- --- This gives only tight bounds if no rotations by non-multiples of 90° are --- used. --- @function wibox.widget.base.rect_to_device_geometry -function base.rect_to_device_geometry(cr, x, y, width, height) - return matrix.transform_rectangle(cr.matrix, x, y, width, height) -end - ---- Fit a widget for the given available width and height. --- --- This calls the widget's `:fit` callback and caches the result for later use. --- Never call `:fit` directly, but always through this function! --- @tparam widget parent The parent widget which requests this information. --- @tab context The context in which we are fit. --- @tparam widget widget The widget to fit (this uses --- `widget:fit(context, width, height)`). --- @tparam number width The available width for the widget. --- @tparam number height The available height for the widget. --- @treturn number The width that the widget wants to use. --- @treturn number The height that the widget wants to use. --- @function wibox.widget.base.fit_widget -function base.fit_widget(parent, context, widget, width, height) - record_dependency(parent, widget) - - if not widget._private.visible then - return 0, 0 - end - - -- Sanitize the input. This also filters out e.g. NaN. - width = math.max(0, width) - height = math.max(0, height) - - local w, h = 0, 0 - if widget.fit then - w, h = get_cache(widget, "fit"):get(context, width, height) - else - -- If it has no fit method, calculate based on the size of children - local children = base.layout_widget(parent, context, widget, width, height) - for _, info in ipairs(children or {}) do - local x, y, w2, h2 = matrix.transform_rectangle(info._matrix, - 0, 0, info._width, info._height) - w, h = math.max(w, x + w2), math.max(h, y + h2) - end - end - - -- Apply forced size and handle nil's - w = widget._private.forced_width or w or 0 - h = widget._private.forced_height or h or 0 - - -- Also sanitize the output. - w = math.max(0, math.min(w, width)) - h = math.max(0, math.min(h, height)) - return w, h -end - ---- Lay out a widget for the given available width and height. --- --- This calls the widget's `:layout` callback and caches the result for later --- use. Never call `:layout` directly, but always through this function! --- However, normally there shouldn't be any reason why you need to use this --- function. --- @tparam widget parent The parent widget which requests this information. --- @tab context The context in which we are laid out. --- @tparam widget widget The widget to layout (this uses --- `widget:layout(context, width, height)`). --- @tparam number width The available width for the widget. --- @tparam number height The available height for the widget. --- @treturn[opt] table The result from the widget's `:layout` callback. --- @function wibox.widget.base.layout_widget -function base.layout_widget(parent, context, widget, width, height) - record_dependency(parent, widget) - - if not widget._private.visible then - return - end - - -- Sanitize the input. This also filters out e.g. NaN. - width = math.max(0, width) - height = math.max(0, height) - - if widget.layout then - return get_cache(widget, "layout"):get(context, width, height) - end -end - ---- Handle a button event on a widget. --- --- This is used internally and should not be called directly. --- @function wibox.widget.base.handle_button -function base.handle_button(event, widget, x, y, button, modifiers, geometry) - x = x or y -- luacheck: no unused - local function is_any(mod) - return #mod == 1 and mod[1] == "Any" - end - - local function tables_equal(a, b) - if #a ~= #b then - return false - end - for k, v in pairs(b) do - if a[k] ~= v then - return false - end - end - return true - end - - -- Find all matching button objects. - local matches = {} - for _, v in pairs(widget._private.widget_buttons) do - local match = true - -- Is it the right button? - if v.button ~= 0 and v.button ~= button then match = false end - -- Are the correct modifiers pressed? - if (not is_any(v.modifiers)) and (not tables_equal(v.modifiers, modifiers)) then match = false end - if match then - table.insert(matches, v) - end - end - - -- Emit the signals. - for _, v in pairs(matches) do - v:emit_signal(event,geometry) - end -end - ---- Create widget placement information. This should be used in a widget's --- `:layout()` callback. --- @tparam widget widget The widget that should be placed. --- @param mat A matrix transforming from the parent widget's coordinate --- system. For example, use matrix.create_translate(1, 2) to draw a --- widget at position (1, 2) relative to the parent widget. --- @tparam number width The width of the widget in its own coordinate system. --- That is, after applying the transformation matrix. --- @tparam number height The height of the widget in its own coordinate system. --- That is, after applying the transformation matrix. --- @treturn table An opaque object that can be returned from `:layout()`. --- @function wibox.widget.base.place_widget_via_matrix -function base.place_widget_via_matrix(widget, mat, width, height) - return { - _widget = widget, - _width = width, - _height = height, - _matrix = mat - } -end - ---- Create widget placement information. This should be used for a widget's --- `:layout()` callback. --- @tparam widget widget The widget that should be placed. --- @tparam number x The x coordinate for the widget. --- @tparam number y The y coordinate for the widget. --- @tparam number width The width of the widget in its own coordinate system. --- That is, after applying the transformation matrix. --- @tparam number height The height of the widget in its own coordinate system. --- That is, after applying the transformation matrix. --- @treturn table An opaque object that can be returned from `:layout()`. --- @function wibox.widget.base.place_widget_at -function base.place_widget_at(widget, x, y, width, height) - return base.place_widget_via_matrix(widget, matrix.create_translate(x, y), width, height) -end - --- Read the table, separate attributes from widgets. -local function parse_table(t, leave_empty) - local max = 0 - local attributes, widgets = {}, {} - for k,v in pairs(t) do - if type(k) == "number" then - if v then - -- Since `ipairs` doesn't always work on sparse tables, update - -- the maximum. - if k > max then - max = k - end - - widgets[k] = v - end - else - attributes[k] = v - end - end - - -- Pack the sparse table, if the container doesn't support sparse tables. - if not leave_empty then - widgets = util.table.from_sparse(widgets) - max = #widgets - end - - return max, attributes, widgets -end - --- Recursively build a container from a declarative table. -local function drill(ids, content) - if not content then return end - - -- Alias `widget` to `layout` as they are handled the same way. - content.layout = content.layout or content.widget - - -- Make sure the layout is not indexed on a function. - local layout = type(content.layout) == "function" and content.layout() or content.layout - - -- Create layouts based on metatable's __call. - local l = layout.is_widget and layout or layout() - - -- Get the number of children widgets (including nil widgets). - local max, attributes, widgets = parse_table(content, l.allow_empty_widget) - - -- Get the optional identifier to create a virtual widget tree to place - -- in an "access table" to be able to retrieve the widget. - local id = attributes.id - - -- Clear the internal attributes. - attributes.id, attributes.layout, attributes.widget = nil, nil, nil - - -- Set layout attributes. - -- This has to be done before the widgets are added because it might affect - -- the output. - for attr, val in pairs(attributes) do - if l["set_"..attr] then - l["set_"..attr](l, val) - elseif type(l[attr]) == "function" then - l[attr](l, val) - else - l[attr] = val - end - end - - -- Add all widgets. - for k = 1, max do - -- ipairs cannot be used on sparse tables. - local v, id2, e = widgets[k], id, nil - if v then - -- It is another declarative container, parse it. - if not v.is_widget then - e, id2 = drill(ids, v) - widgets[k] = e - end - base.check_widget(widgets[k]) - - -- Place the widget in the access table. - if id2 then - l [id2] = e - ids[id2] = ids[id2] or {} - table.insert(ids[id2], e) - end - end - end - -- Replace all children (if any) with the new ones. - l:set_children(widgets) - return l, id -end - --- Only available when the declarative system is used. -local function get_children_by_id(self, name) - if rawget(self, "_private") then - return self._private.by_id[name] or {} - else - return rawget(self, "_by_id")[name] or {} - end -end - ---- Set a declarative widget hierarchy description. --- --- See [The declarative layout system](../documentation/03-declarative-layout.md.html). --- @tab args A table containing the widget's disposition. --- @function setup -function base.widget:setup(args) - local f,ids = self.set_widget or self.add or self.set_first,{} - local w, id = drill(ids, args) - f(self,w) - if id then - -- Avoid being dropped by wibox metatable -> drawin - rawset(self, id, w) - ids[id] = ids[id] or {} - table.insert(ids[id], 1, w) - end - - if rawget(self, "_private") then - self._private.by_id = ids - else - rawset(self, "_by_id", ids) - end - - rawset(self, "get_children_by_id", get_children_by_id) -end - ---- Create a widget from a declarative description. --- --- See [The declarative layout system](../documentation/03-declarative-layout.md.html). --- @tab args A table containing the widgets disposition. --- @function wibox.widget.base.make_widget_declarative -function base.make_widget_declarative(args) - local ids = {} - - if (not args.layout) and (not args.widget) then - args.widget = base.make_widget(nil, args.id) - end - - local w, id = drill(ids, args) - - local mt = getmetatable(w) or {} - local orig_string = tostring(w) - - -- Add the main id (if any) - if id then - ids[id] = ids[id] or {} - table.insert(ids[id], 1, w) - end - - if rawget(w, "_private") then - w._private.by_id = ids - else - rawset(w, "_by_id", ids) - end - - rawset(w, "get_children_by_id", get_children_by_id) - - mt.__tostring = function() - return string.format("%s (%s)", id or w.widget_name or "N/A", orig_string) - end - - return setmetatable(w, mt) -end - ---- Create an empty widget skeleton. --- --- See [Creating new widgets](../documentation/04-new-widget.md.html). --- @tparam[opt] widget proxy If this is set, the returned widget will be a --- proxy for this widget. It will be equivalent to this widget. --- This means it looks the same on the screen. --- @tparam[opt] string widget_name Name of the widget. If not set, it will be --- set automatically via @{gears.object.modulename}. --- @tparam[opt={}] table args Widget settings --- @tparam[opt=false] boolean args.enable_properties Enable automatic getter --- and setter methods. --- @tparam[opt=nil] table args.class The widget class --- @see fit_widget --- @function wibox.widget.base.make_widget -function base.make_widget(proxy, widget_name, args) - args = args or {} - local ret = object { - enable_properties = args.enable_properties, - class = args.class, - } - - -- Backwards compatibility. - -- TODO: Remove this - ret:connect_signal("widget::updated", function() - ret:emit_signal("widget::layout_changed") - ret:emit_signal("widget::redraw_needed") - end) - - -- Create a table used to store the widgets internal data. - rawset(ret, "_private", {}) - - -- No buttons yet. - ret._private.widget_buttons = {} - - -- Widget is visible. - ret._private.visible = true - - -- Widget is fully opaque. - ret._private.opacity = 1 - - -- Differentiate tables from widgets. - rawset(ret, "is_widget", true) - - -- Size is not restricted/forced. - ret._private.forced_width = nil - ret._private.forced_height = nil - - -- Make buttons work. - ret:connect_signal("button::press", function(...) - return base.handle_button("press", ...) - end) - ret:connect_signal("button::release", function(...) - return base.handle_button("release", ...) - end) - - if proxy then - rawset(ret, "fit", function(_, context, width, height) - return base.fit_widget(ret, context, proxy, width, height) - end) - rawset(ret, "layout", function(_, _, width, height) - return { base.place_widget_at(proxy, 0, 0, width, height) } - end) - proxy:connect_signal("widget::layout_changed", function() - ret:emit_signal("widget::layout_changed") - end) - proxy:connect_signal("widget::redraw_needed", function() - ret:emit_signal("widget::redraw_needed") - end) - end - - -- Set up caches. - clear_caches(ret) - ret:connect_signal("widget::layout_changed", function() - clear_caches(ret) - end) - - -- Add functions. - for k, v in pairs(base.widget) do - rawset(ret, k, v) - end - - -- Add __tostring method to metatable. - rawset(ret, "widget_name", widget_name or object.modulename(3)) - local mt = getmetatable(ret) or {} - local orig_string = tostring(ret) - mt.__tostring = function() - return string.format("%s (%s)", ret.widget_name, orig_string) - end - return setmetatable(ret, mt) -end - ---- Generate an empty widget which takes no space and displays nothing. --- @function wibox.widget.base.empty_widget -function base.empty_widget() - return base.make_widget() -end - ---- Do some sanity checking on a widget. --- --- This function raises an error if the widget is not valid. --- @function wibox.widget.base.check_widget -function base.check_widget(widget) - assert(type(widget) == "table", "Type should be table, but is " .. tostring(type(widget))) - assert(widget.is_widget, "Argument is not a widget!") - for _, func in pairs({ "connect_signal", "disconnect_signal" }) do - assert(type(widget[func]) == "function", func .. " is not a function") - end -end - -return base - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/checkbox.lua b/awesome/lib/wibox/widget/checkbox.lua deleted file mode 100644 index 57bdaa3..0000000 --- a/awesome/lib/wibox/widget/checkbox.lua +++ /dev/null @@ -1,530 +0,0 @@ ---------------------------------------------------------------------------- --- A boolean display widget. --- --- If necessary, themes can implement custom shape: --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_checkbox_custom.svg) --- --- --- wibox.widget { --- checked = true, --- color = beautiful.bg_normal, --- paddings = 2, --- check_shape = function(cr, width, height) --- local rs = math.min(width, height) --- cr:move_to( 0 , 0 ) --- cr:line_to( rs , 0 ) --- cr:move_to( 0 , 0 ) --- cr:line_to( 0 , rs ) --- cr:move_to( 0 , rs ) --- cr:line_to( rs , rs ) --- cr:move_to( rs , 0 ) --- cr:line_to( rs , rs ) --- cr:move_to( 0 , 0 ) --- cr:line_to( rs , rs ) --- cr:move_to( 0 , rs ) --- cr:line_to( rs , 0 ) --- end, --- check_border_color = '#ff0000', --- check_color = '#00000000', --- check_border_width = 1, --- widget = wibox.widget.checkbox --- } --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_defaults_checkbox.svg) --- --- @usage ---wibox.widget { --- checked = true, --- color = beautiful.bg_normal, --- paddings = 2, --- shape = gears.shape.circle, --- widget = wibox.widget.checkbox ---} --- @author Emmanuel Lepage Valle --- @copyright 2010 Emmanuel Lepage Vallee --- @classmod wibox.widget.checkbox ---------------------------------------------------------------------------- - -local color = require( "gears.color" ) -local base = require( "wibox.widget.base" ) -local beautiful = require( "beautiful" ) -local shape = require( "gears.shape" ) -local util = require( "awful.util" ) - -local checkbox = {} - ---- The outer (unchecked area) border width. --- @beautiful beautiful.checkbox_border_width - ---- The outer (unchecked area) background color, pattern or gradient. --- @beautiful beautiful.checkbox_bg - ---- The outer (unchecked area) border color. --- @beautiful beautiful.checkbox_border_color - ---- The checked part border color. --- @beautiful beautiful.checkbox_check_border_color - ---- The checked part border width. --- @beautiful beautiful.checkbox_check_border_width - ---- The checked part filling color. --- @beautiful beautiful.checkbox_check_color - ---- The outer (unchecked area) shape. --- @beautiful beautiful.checkbox_shape --- @see gears.shape - ---- The checked part shape. --- If none is set, then the `shape` property will be used. --- @beautiful beautiful.checkbox_check_shape --- @see gears.shape - ---- The padding between the outline and the progressbar. --- @beautiful beautiful.checkbox_paddings --- @tparam[opt=0] table|number paddings A number or a table --- @tparam[opt=0] number paddings.top --- @tparam[opt=0] number paddings.bottom --- @tparam[opt=0] number paddings.left --- @tparam[opt=0] number paddings.right - ---- The checkbox color. --- This will be used for the unchecked part border color and the checked part --- filling color. Note that `check_color` and `border_color` have priority --- over this property. --- @beautiful beautiful.checkbox_color - ---- The outer (unchecked area) border width. --- @property border_width - ---- The outer (unchecked area) background color, pattern or gradient. --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_checkbox_bg.svg) --- --- @usage ---wibox.widget { --- checked = true, --- color = beautiful.bg_normal, --- bg = '#ff00ff', --- border_width = 3, --- paddings = 4, --- border_color = '#0000ff', --- check_color = '#ff0000', --- check_border_color = '#ffff00', --- check_border_width = 1, --- widget = wibox.widget.checkbox ---} --- @property bg - ---- The outer (unchecked area) border color. --- @property border_color - ---- The checked part border color. --- @property check_border_color - ---- The checked part border width. --- @property check_border_width - ---- The checked part filling color. --- @property check_color - ---- The outer (unchecked area) shape. --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_checkbox_shape.svg) --- --- @usage ---for _, s in ipairs {'rectangle', 'circle', 'losange', 'octogon'} do --- wibox.widget { --- checked = true, --- color = beautiful.bg_normal, --- paddings = 2, --- shape = gears.shape[s], --- widget = wibox.widget.checkbox --- } ---end --- @property shape --- @see gears.shape - ---- The checked part shape. --- If none is set, then the `shape` property will be used. --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_checkbox_check_shape.svg) --- --- @usage ---for _, s in ipairs {'rectangle', 'circle', 'losange', 'octogon'} do --- wibox.widget { --- checked = true, --- color = beautiful.bg_normal, --- paddings = 2, --- check_shape = gears.shape[s], --- widget = wibox.widget.checkbox --- } ---end --- @property check_shape --- @see gears.shape - ---- The padding between the outline and the progressbar. --- @property paddings --- @tparam[opt=0] table|number paddings A number or a table --- @tparam[opt=0] number paddings.top --- @tparam[opt=0] number paddings.bottom --- @tparam[opt=0] number paddings.left --- @tparam[opt=0] number paddings.right - ---- The checkbox color. --- This will be used for the unchecked part border color and the checked part --- filling color. Note that `check_color` and `border_color` have priority --- over this property. --- @property color - -local function outline_workarea(self, width, height) - local offset = (self._private.border_width or - beautiful.checkbox_border_width or 1)/2 - - return { - x = offset, - y = offset, - width = width-2*offset, - height = height-2*offset - } -end - --- The child widget area -local function content_workarea(self, width, height) - local padding = self._private.paddings or {} - local offset = self:get_check_border_width() or 0 - local wa = outline_workarea(self, width, height) - - wa.x = offset + wa.x + (padding.left or 1) - wa.y = offset + wa.y + (padding.top or 1) - wa.width = wa.width - (padding.left or 1) - (padding.right or 1) - 2*offset - wa.height = wa.height - (padding.top or 1) - (padding.bottom or 1) - 2*offset - - return wa -end - -local function draw(self, _, cr, width, height) - local size = math.min(width, height) - - local background_shape = self:get_shape() or shape.rectangle - local border_width = self:get_border_width() or 1 - - local main_color = self:get_color() - local bg = self:get_bg() - local border_color = self:get_border_color() - - -- If no color is set, it will fallback to the default one - if border_color or main_color then - cr:set_source(color(border_color or main_color)) - end - - local wa = outline_workarea(self, size, size) - cr:translate(wa.x, wa.y) - background_shape(cr, wa.width, wa.height) - cr:set_line_width(border_width) - - if bg then - cr:save() - cr:set_source(color(bg)) - cr:fill_preserve() - cr:restore() - end - - cr:stroke() - - cr:translate(-wa.x, -wa.y) - - -- Draw the checked part - if self._private.checked then - local col = self:get_check_color() or main_color - border_color = self:get_check_border_color() - border_width = self:get_check_border_width() or 0 - local check_shape = self:get_check_shape() or background_shape - - wa = content_workarea(self, size, size) - cr:translate(wa.x, wa.y) - - check_shape(cr, wa.width, wa.height) - - if col then - cr:set_source(color(col)) - end - - if border_width > 0 then - cr:fill_preserve() - cr:set_line_width(border_width) - cr:set_source(color(border_color)) - cr:stroke() - else - cr:fill() - end - end -end - -local function fit(_, _, w, h) - local size = math.min(w, h) - return size, size -end - ---- If the checkbox is checked. --- @property checked --- @param boolean - -for _, prop in ipairs {"border_width", "bg", "border_color", "check_border_color", - "check_border_width", "check_color", "shape", "check_shape", "paddings", - "checked", "color" } do - checkbox["set_"..prop] = function(self, value) - self._private[prop] = value - self:emit_signal("property::"..prop) - self:emit_signal("widget::redraw_needed") - end - checkbox["get_"..prop] = function(self) - return self._private[prop] or beautiful["checkbox_"..prop] - end -end - ---- The checkbox color. --- @property color - -function checkbox:set_paddings(val) - self._private.paddings = type(val) == "number" and { - left = val, - right = val, - top = val, - bottom = val, - } or val or {} - self:emit_signal("property::paddings") - self:emit_signal("widget::redraw_needed") -end - -local function new(checked, args) - checked, args = checked or false, args or {} - - local ret = base.make_widget(nil, nil, { - enable_properties = true, - }) - - util.table.crush(ret, checkbox) - - ret._private.checked = checked - ret._private.color = args.color and color(args.color) or nil - - rawset(ret, "fit" , fit ) - rawset(ret, "draw", draw) - - return ret -end - ---Imported documentation - - ---- Get a widex index. --- @param widget The widget to look for --- @param[opt] recursive Also check sub-widgets --- @param[opt] ... Aditional widgets to add at the end of the \"path\" --- @return The index --- @return The parent layout --- @return The path between \"self\" and \"widget\" --- @function index - ---- Get all direct and indirect children widgets. --- This will scan all containers recursively to find widgets --- Warning: This method it prone to stack overflow id the widget, or any of its --- children, contain (directly or indirectly) itself. --- @treturn table The children --- @function get_all_children - ---- Set a declarative widget hierarchy description. --- See [The declarative layout system](../documentation/03-declarative-layout.md.html) --- @param args An array containing the widgets disposition --- @function setup - ---- Force a widget height. --- @property forced_height --- @tparam number|nil height The height (`nil` for automatic) - ---- Force a widget width. --- @property forced_width --- @tparam number|nil width The width (`nil` for automatic) - ---- The widget opacity (transparency). --- @property opacity --- @tparam[opt=1] number opacity The opacity (between 0 and 1) - ---- The widget visibility. --- @property visible --- @param boolean - ---- Set/get a widget's buttons. --- @param _buttons The table of buttons that should bind to the widget. --- @function buttons - ---- Emit a signal and ensure all parent widgets in the hierarchies also --- forward the signal. This is useful to track signals when there is a dynamic --- set of containers and layouts wrapping the widget. --- @tparam string signal_name --- @param ... Other arguments --- @function emit_signal_recursive - ---- When the layout (size) change. --- This signal is emitted when the previous results of `:layout()` and `:fit()` --- are no longer valid. Unless this signal is emitted, `:layout()` and `:fit()` --- must return the same result when called with the same arguments. --- @signal widget::layout_changed --- @see widget::redraw_needed - ---- When the widget content changed. --- This signal is emitted when the content of the widget changes. The widget will --- be redrawn, it is not re-layouted. Put differently, it is assumed that --- `:layout()` and `:fit()` would still return the same results as before. --- @signal widget::redraw_needed --- @see widget::layout_changed - ---- When a mouse button is pressed over the widget. --- @signal button::press --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When a mouse button is released over the widget. --- @signal button::release --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse enter a widget. --- @signal mouse::enter --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse leave a widget. --- @signal mouse::leave --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - - ---Imported documentation - - ---- Disconnect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback that should be disconnected --- @function disconnect_signal - ---- Emit a signal. --- --- @tparam string name The name of the signal --- @param ... Extra arguments for the callback functions. Each connected --- function receives the object as first argument and then any extra arguments --- that are given to emit_signal() --- @function emit_signal - ---- Connect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function connect_signal - ---- Connect to a signal weakly. This allows the callback function to be garbage --- collected and automatically disconnects the signal when that happens. --- --- **Warning:** --- Only use this function if you really, really, really know what you --- are doing. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function weak_connect_signal - - -return setmetatable({}, { __call = function(_, ...) return new(...) end}) - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/graph.lua b/awesome/lib/wibox/widget/graph.lua deleted file mode 100644 index c03c726..0000000 --- a/awesome/lib/wibox/widget/graph.lua +++ /dev/null @@ -1,575 +0,0 @@ ---------------------------------------------------------------------------- ---- 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. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_defaults_graph.svg) --- --- @usage ---wibox.widget { --- max_value = 29, --- widget = wibox.widget.graph ---} --- @author Julien Danjou <julien@danjou.info> --- @copyright 2009 Julien Danjou --- @classmod wibox.widget.graph ---------------------------------------------------------------------------- - -local setmetatable = setmetatable -local ipairs = ipairs -local math = math -local table = table -local type = type -local color = require("gears.color") -local base = require("wibox.widget.base") -local beautiful = require("beautiful") - -local graph = { mt = {} } - ---- Set the graph border color. --- If the value is nil, no border will be drawn. --- --- @property border_color --- @tparam gears.color border_color The border color to set. --- @see gears.color - ---- Set the graph foreground color. --- --- @property color --- @tparam color color The graph color. --- @see gears.color - ---- Set the graph background color. --- --- @property background_color --- @tparam gears.color background_color The graph background color. --- @see gears.color - ---- Set the maximum value the graph should handle. --- If "scale" is also set, the graph never scales up below this value, but it --- automatically scales down to make all data fit. --- --- @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. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_graph_step.svg) --- --- @usage ---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 ---} --- --- @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 --- @param boolean - ---- Set the graph stacking colors. Order matters. --- --- @property stack_colors --- @param stack_colors A table with stacking colors. - ---- The graph background color. --- @beautiful beautiful.graph_bg - ---- The graph foreground color. --- @beautiful beautiful.graph_fg - ---- The graph border color. --- @beautiful beautiful.graph_border_color - -local properties = { "width", "height", "border_color", "stack", - "stack_colors", "color", "background_color", - "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 - cr:set_source(color(_graph._private.background_color or beautiful.graph_bg or "#000000aa")) - cr:paint() - - -- Account for the border width - cr:save() - if _graph._private.border_color then - cr:translate(1, 1) - width, height = width - 2, height - 2 - end - - -- Draw a stacked graph - if _graph._private.stack then - - if _graph._private.scale then - for _, v in ipairs(values) do - for _, sv in ipairs(v) do - if sv > max_value then - max_value = sv - end - if min_value > sv then - min_value = sv - end - end - end - end - - for i = 0, width do - local rel_i = 0 - local rel_x = i + 0.5 - - if _graph._private.stack_colors then - for idx, col in ipairs(_graph._private.stack_colors) do - local stack_values = values[idx] - if stack_values and i < #stack_values then - local value = stack_values[#stack_values - i] + rel_i - cr:move_to(rel_x, height * (1 - (rel_i / max_value))) - cr:line_to(rel_x, height * (1 - (value / max_value))) - cr:set_source(color(col or beautiful.graph_fg or "#ff0000")) - cr:stroke() - rel_i = value - end - end - end - end - else - if _graph._private.scale then - for _, v in ipairs(values) do - if v > max_value then - max_value = v - end - if min_value > v then - min_value = v - end - end - end - - -- Draw the background on no value - if #values ~= 0 then - -- Draw reverse - 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(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")) - - if step_shape or step_width > 1 then - cr:fill() - else - cr:stroke() - end - end - - end - - -- Undo the cr:translate() for the border and step shapes - cr:restore() - - -- Draw the border last so that it overlaps already drawn values - if _graph._private.border_color then - -- We decremented these by two above - width, height = width + 2, height + 2 - - -- Draw the border - cr:rectangle(0.5, 0.5, width - 1, height - 1) - cr:set_source(color(_graph._private.border_color or beautiful.graph_border_color or "#ffffff")) - cr:stroke() - end -end - -function graph.fit(_graph) - return _graph._private.width, _graph._private.height -end - ---- Add a value to the graph --- --- @param value The value to be added to the graph --- @param group The stack color group index. -function graph:add_value(value, group) - value = value or 0 - local values = self._private.values - local max_value = self._private.max_value - value = math.max(0, value) - if not self._private.scale then - value = math.min(max_value, value) - end - - if self._private.stack and group then - if not self._private.values[group] - or type(self._private.values[group]) ~= "table" - then - self._private.values[group] = {} - end - values = self._private.values[group] - end - table.insert(values, value) - - local border_width = 0 - if self._private.border_color then border_width = 2 end - - -- Ensure we never have more data than we can draw - while #values > self._private.width - border_width do - table.remove(values, 1) - end - - self:emit_signal("widget::redraw_needed") - return self -end - ---- Clear the graph. -function graph:clear() - self._private.values = {} - self:emit_signal("widget::redraw_needed") - return self -end - ---- Set the graph height. --- @param height The height to set. -function graph:set_height(height) - if height >= 5 then - self._private.height = height - self:emit_signal("widget::layout_changed") - end - return self -end - ---- Set the graph width. --- @param width The width to set. -function graph:set_width(width) - if width >= 5 then - self._private.width = width - self:emit_signal("widget::layout_changed") - end - return self -end - --- Build properties function -for _, prop in ipairs(properties) do - if not graph["set_" .. prop] then - graph["set_" .. prop] = function(_graph, value) - if _graph._private[prop] ~= value then - _graph._private[prop] = value - _graph:emit_signal("widget::redraw_needed") - end - return _graph - end - end - if not graph["get_" .. prop] then - graph["get_" .. prop] = function(_graph) - return _graph._private[prop] - end - end -end - ---- Create a graph widget. --- @param args Standard widget() arguments. You should add width and height --- key to set graph geometry. --- @return A new graph widget. --- @function wibox.widget.graph -function graph.new(args) - args = args or {} - - local width = args.width or 100 - local height = args.height or 20 - - if width < 5 or height < 5 then return end - - local _graph = base.make_widget(nil, nil, {enable_properties = true}) - - _graph._private.width = width - _graph._private.height = height - _graph._private.values = {} - _graph._private.max_value = 1 - - -- Set methods - _graph.add_value = graph["add_value"] - _graph.clear = graph["clear"] - _graph.draw = graph.draw - _graph.fit = graph.fit - - for _, prop in ipairs(properties) do - _graph["set_" .. prop] = graph["set_" .. prop] - _graph["get_" .. prop] = graph["get_" .. prop] - end - - return _graph -end - -function graph.mt:__call(...) - return graph.new(...) -end - ---Imported documentation - - ---- Get a widex index. --- @param widget The widget to look for --- @param[opt] recursive Also check sub-widgets --- @param[opt] ... Aditional widgets to add at the end of the \"path\" --- @return The index --- @return The parent layout --- @return The path between \"self\" and \"widget\" --- @function index - ---- Get all direct and indirect children widgets. --- This will scan all containers recursively to find widgets --- Warning: This method it prone to stack overflow id the widget, or any of its --- children, contain (directly or indirectly) itself. --- @treturn table The children --- @function get_all_children - ---- Set a declarative widget hierarchy description. --- See [The declarative layout system](../documentation/03-declarative-layout.md.html) --- @param args An array containing the widgets disposition --- @function setup - ---- Force a widget height. --- @property forced_height --- @tparam number|nil height The height (`nil` for automatic) - ---- Force a widget width. --- @property forced_width --- @tparam number|nil width The width (`nil` for automatic) - ---- The widget opacity (transparency). --- @property opacity --- @tparam[opt=1] number opacity The opacity (between 0 and 1) - ---- The widget visibility. --- @property visible --- @param boolean - ---- Set/get a widget's buttons. --- @param _buttons The table of buttons that should bind to the widget. --- @function buttons - ---- Emit a signal and ensure all parent widgets in the hierarchies also --- forward the signal. This is useful to track signals when there is a dynamic --- set of containers and layouts wrapping the widget. --- @tparam string signal_name --- @param ... Other arguments --- @function emit_signal_recursive - ---- When the layout (size) change. --- This signal is emitted when the previous results of `:layout()` and `:fit()` --- are no longer valid. Unless this signal is emitted, `:layout()` and `:fit()` --- must return the same result when called with the same arguments. --- @signal widget::layout_changed --- @see widget::redraw_needed - ---- When the widget content changed. --- This signal is emitted when the content of the widget changes. The widget will --- be redrawn, it is not re-layouted. Put differently, it is assumed that --- `:layout()` and `:fit()` would still return the same results as before. --- @signal widget::redraw_needed --- @see widget::layout_changed - ---- When a mouse button is pressed over the widget. --- @signal button::press --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When a mouse button is released over the widget. --- @signal button::release --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse enter a widget. --- @signal mouse::enter --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse leave a widget. --- @signal mouse::leave --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - - ---Imported documentation - - ---- Disconnect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback that should be disconnected --- @function disconnect_signal - ---- Emit a signal. --- --- @tparam string name The name of the signal --- @param ... Extra arguments for the callback functions. Each connected --- function receives the object as first argument and then any extra arguments --- that are given to emit_signal() --- @function emit_signal - ---- Connect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function connect_signal - ---- Connect to a signal weakly. This allows the callback function to be garbage --- collected and automatically disconnects the signal when that happens. --- --- **Warning:** --- Only use this function if you really, really, really know what you --- are doing. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function weak_connect_signal - - -return setmetatable(graph, graph.mt) - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/imagebox.lua b/awesome/lib/wibox/widget/imagebox.lua deleted file mode 100644 index bdfa499..0000000 --- a/awesome/lib/wibox/widget/imagebox.lua +++ /dev/null @@ -1,395 +0,0 @@ ---------------------------------------------------------------------------- --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_defaults_imagebox.svg) --- --- @usage ---wibox.widget { --- image = beautiful.awesome_icon, --- resize = false, --- widget = wibox.widget.imagebox ---} --- @author Uli Schlachter --- @copyright 2010 Uli Schlachter --- @classmod wibox.widget.imagebox ---------------------------------------------------------------------------- - -local base = require("wibox.widget.base") -local surface = require("gears.surface") -local util = require("awful.util") -local setmetatable = setmetatable -local type = type -local print = print -local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) - -local imagebox = { mt = {} } - --- Draw an imagebox with the given cairo context in the given geometry. -function imagebox:draw(_, cr, width, height) - if not self._private.image then return end - if width == 0 or height == 0 then return end - - if not self._private.resize_forbidden then - -- Let's scale the image so that it fits into (width, height) - local w = self._private.image:get_width() - local h = self._private.image:get_height() - local aspect = width / w - local aspect_h = height / h - if aspect > aspect_h then aspect = aspect_h end - - cr:scale(aspect, aspect) - end - - -- Set the clip - if self._private.clip_shape then - cr:clip(self._private.clip_shape(cr, width, height, unpack(self._private.clip_args))) - end - - cr:set_source_surface(self._private.image, 0, 0) - cr:paint() -end - --- Fit the imagebox into the given geometry -function imagebox:fit(_, width, height) - if not self._private.image then - return 0, 0 - end - - local w = self._private.image:get_width() - local h = self._private.image:get_height() - - if w > width then - h = h * width / w - w = width - end - if h > height then - w = w * height / h - h = height - end - - if h == 0 or w == 0 then - return 0, 0 - end - - if not self._private.resize_forbidden then - local aspect = width / w - local aspect_h = height / h - - -- Use the smaller one of the two aspect ratios. - if aspect > aspect_h then aspect = aspect_h end - - w, h = w * aspect, h * aspect - end - - return w, h -end - ---- Set an imagebox' image --- @property image --- @param image Either a string or a cairo image surface. A string is --- interpreted as the path to a png image file. --- @return true on success, false if the image cannot be used - -function imagebox:set_image(image) - if type(image) == "string" then - image = surface.load(image) - if not image then - print(debug.traceback()) - return false - end - end - - image = surface.load(image) - - if image then - local w = image.width - local h = image.height - if w <= 0 or h <= 0 then - return false - end - end - - if self._private.image == image then - -- The image could have been modified, so better redraw - self:emit_signal("widget::redraw_needed") - return - end - - self._private.image = image - - self:emit_signal("widget::redraw_needed") - self:emit_signal("widget::layout_changed") - return true -end - ---- Set a clip shape for this imagebox --- A clip shape define an area where the content is displayed and one where it --- is trimmed. --- --- @property clip_shape --- @param clip_shape A `gears_shape` compatible shape function --- @see gears.shape --- @see set_clip_shape - ---- Set a clip shape for this imagebox --- A clip shape define an area where the content is displayed and one where it --- is trimmed. --- --- Any other parameters will be passed to the clip shape function --- --- @param clip_shape A `gears_shape` compatible shape function --- @see gears.shape --- @see clip_shape -function imagebox:set_clip_shape(clip_shape, ...) - self._private.clip_shape = clip_shape - self._private.clip_args = {...} - self:emit_signal("widget::redraw_needed") -end - ---- Should the image be resized to fit into the available space? --- @property resize --- @param allowed If false, the image will be clipped, else it will be resized --- to fit into the available space. - -function imagebox:set_resize(allowed) - self._private.resize_forbidden = not allowed - self:emit_signal("widget::redraw_needed") - self:emit_signal("widget::layout_changed") -end - ---- Returns a new imagebox. --- Any other arguments will be passed to the clip shape function --- @param image the image to display, may be nil --- @param resize_allowed If false, the image will be clipped, else it will be resized --- to fit into the available space. --- @param clip_shape A `gears.shape` compatible function --- @treturn table A new `imagebox` --- @function wibox.widget.imagebox -local function new(image, resize_allowed, clip_shape) - local ret = base.make_widget(nil, nil, {enable_properties = true}) - - util.table.crush(ret, imagebox, true) - - if image then - ret:set_image(image) - end - if resize_allowed ~= nil then - ret:set_resize(resize_allowed) - end - - ret._private.clip_shape = clip_shape - ret._private.clip_args = {} - - return ret -end - -function imagebox.mt:__call(...) - return new(...) -end - ---Imported documentation - - ---- Get a widex index. --- @param widget The widget to look for --- @param[opt] recursive Also check sub-widgets --- @param[opt] ... Aditional widgets to add at the end of the \"path\" --- @return The index --- @return The parent layout --- @return The path between \"self\" and \"widget\" --- @function index - ---- Get all direct and indirect children widgets. --- This will scan all containers recursively to find widgets --- Warning: This method it prone to stack overflow id the widget, or any of its --- children, contain (directly or indirectly) itself. --- @treturn table The children --- @function get_all_children - ---- Set a declarative widget hierarchy description. --- See [The declarative layout system](../documentation/03-declarative-layout.md.html) --- @param args An array containing the widgets disposition --- @function setup - ---- Force a widget height. --- @property forced_height --- @tparam number|nil height The height (`nil` for automatic) - ---- Force a widget width. --- @property forced_width --- @tparam number|nil width The width (`nil` for automatic) - ---- The widget opacity (transparency). --- @property opacity --- @tparam[opt=1] number opacity The opacity (between 0 and 1) - ---- The widget visibility. --- @property visible --- @param boolean - ---- Set/get a widget's buttons. --- @param _buttons The table of buttons that should bind to the widget. --- @function buttons - ---- Emit a signal and ensure all parent widgets in the hierarchies also --- forward the signal. This is useful to track signals when there is a dynamic --- set of containers and layouts wrapping the widget. --- @tparam string signal_name --- @param ... Other arguments --- @function emit_signal_recursive - ---- When the layout (size) change. --- This signal is emitted when the previous results of `:layout()` and `:fit()` --- are no longer valid. Unless this signal is emitted, `:layout()` and `:fit()` --- must return the same result when called with the same arguments. --- @signal widget::layout_changed --- @see widget::redraw_needed - ---- When the widget content changed. --- This signal is emitted when the content of the widget changes. The widget will --- be redrawn, it is not re-layouted. Put differently, it is assumed that --- `:layout()` and `:fit()` would still return the same results as before. --- @signal widget::redraw_needed --- @see widget::layout_changed - ---- When a mouse button is pressed over the widget. --- @signal button::press --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When a mouse button is released over the widget. --- @signal button::release --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse enter a widget. --- @signal mouse::enter --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse leave a widget. --- @signal mouse::leave --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - - ---Imported documentation - - ---- Disconnect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback that should be disconnected --- @function disconnect_signal - ---- Emit a signal. --- --- @tparam string name The name of the signal --- @param ... Extra arguments for the callback functions. Each connected --- function receives the object as first argument and then any extra arguments --- that are given to emit_signal() --- @function emit_signal - ---- Connect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function connect_signal - ---- Connect to a signal weakly. This allows the callback function to be garbage --- collected and automatically disconnects the signal when that happens. --- --- **Warning:** --- Only use this function if you really, really, really know what you --- are doing. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function weak_connect_signal - - -return setmetatable(imagebox, imagebox.mt) - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/init.lua b/awesome/lib/wibox/widget/init.lua deleted file mode 100644 index 43c6fc0..0000000 --- a/awesome/lib/wibox/widget/init.lua +++ /dev/null @@ -1,22 +0,0 @@ ---------------------------------------------------------------------------- --- @author Uli Schlachter --- @copyright 2010 Uli Schlachter --- @classmod wibox.widget ---------------------------------------------------------------------------- -local base = require("wibox.widget.base") - -return setmetatable({ - base = base; - textbox = require("wibox.widget.textbox"); - imagebox = require("wibox.widget.imagebox"); - background = require("wibox.widget.background"); - systray = require("wibox.widget.systray"); - textclock = require("wibox.widget.textclock"); - progressbar = require("wibox.widget.progressbar"); - graph = require("wibox.widget.graph"); - checkbox = require("wibox.widget.checkbox"); - piechart = require("wibox.widget.piechart"); - slider = require("wibox.widget.slider"); -}, {__call = function(_, args) return base.make_widget_declarative(args) end}) - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/piechart.lua b/awesome/lib/wibox/widget/piechart.lua deleted file mode 100644 index 5a1c185..0000000 --- a/awesome/lib/wibox/widget/piechart.lua +++ /dev/null @@ -1,467 +0,0 @@ ---------------------------------------------------------------------------- --- Display percentage in a circle. --- --- Note that this widget makes no attempts to prevent overlapping labels or --- labels drawn outside of the widget boundaries. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_defaults_piechart.svg) --- --- @usage ---wibox.widget { --- data_list = { --- { 'L1', 100 }, --- { 'L2', 200 }, --- { 'L3', 300 }, --- }, --- border_width = 1, --- colors = { --- beautiful.bg_normal, --- beautiful.bg_highlight, --- beautiful.border_color, --- }, --- widget = wibox.widget.piechart ---} --- @author Emmanuel Lepage Valle --- @copyright 2012 Emmanuel Lepage Vallee --- @classmod wibox.widget.piechart ---------------------------------------------------------------------------- - -local color = require( "gears.color" ) -local base = require( "wibox.widget.base" ) -local beautiful = require( "beautiful" ) -local util = require( "awful.util" ) -local pie = require( "gears.shape" ).pie -local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) - -local module = {} - -local piechart = {} - -local function draw_label(cr,angle,radius,center_x,center_y,text) - local edge_x = center_x+(radius/2)*math.cos(angle) - local edge_y = center_y+(radius/2)*math.sin(angle) - - cr:move_to(edge_x, edge_y) - - cr:rel_line_to(radius*math.cos(angle), radius*math.sin(angle)) - - local x,y = cr:get_current_point() - - cr:rel_line_to(x > center_x and radius/2 or -radius/2, 0) - - local ext = cr:text_extents(text) - - cr:rel_move_to( - (x>center_x and radius/2.5 or (-radius/2.5 - ext.width)), - ext.height/2 - ) - - cr:show_text(text) --TODO eventually port away from the toy API - cr:stroke() - - cr:arc(edge_x, edge_y,2,0,2*math.pi) - cr:arc(x+(x>center_x and radius/2 or -radius/2),y,2,0,2*math.pi) - - cr:fill() -end - -local function compute_sum(data) - local ret = 0 - for _, entry in ipairs(data) do - ret = ret + entry[2] - end - - return ret -end - -local function draw(self, _, cr, width, height) - if not self._private.data_list then return end - - local radius = (height > width and width or height) / 4 - local sum, start, count = compute_sum(self._private.data_list),0,0 - local has_label = self._private.display_labels ~= false - - -- Labels need to be drawn later so the original source is kept - -- use get_source() wont work are the reference cannot be set from Lua(?) - local labels = {} - - local border_width = self:get_border_width() or 1 - local border_color = self:get_border_color() - border_color = border_color and color(border_color) - - -- Draw the pies - cr:save() - cr:set_line_width(border_width) - - -- Alternate from a given sets or colors - local colors = self:get_colors() - local col_count = colors and #colors or 0 - - for _, entry in ipairs(self._private.data_list) do - local k, v = entry[1], entry[2] - local end_angle = start + 2*math.pi*(v/sum) - - local col = colors and color(colors[math.fmod(count,col_count)+1]) or nil - - pie(cr, width, height, start, end_angle, radius) - - if col then - cr:save() - cr:set_source(color(col)) - end - - if border_width > 0 then - if col then - cr:fill_preserve() - cr:restore() - end - - -- By default, it uses the fg color - if border_color then - cr:set_source(border_color) - end - cr:stroke() - elseif col then - cr:fill() - cr:restore() - end - - -- Store the label position for later - if has_label then - table.insert(labels, { - --[[angle ]] start+(end_angle-start)/2, - --[[radius ]] radius, - --[[center_x]] width/2, - --[[center_y]] height/2, - --[[text ]] k, - }) - end - start,count = end_angle,count+1 - end - cr:restore() - - -- Draw the labels - if has_label then - for _, v in ipairs(labels) do - draw_label(cr, unpack(v)) - end - end -end - -local function fit(_, _, width, height) - return width, height -end - ---- The pie chart data list. --- @property data_list --- @tparam table data_list Sorted table where each entry has a label as its --- first value and a number as its second value. - ---- The pie chart data. --- @property data --- @tparam table data Labels as keys and number as value. - ---- The border color. --- If none is set, it will use current foreground (text) color. --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_piechart_border_color.svg) --- --- @property border_color --- @param color --- @see gears.color - ---- The pie elements border width. --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_piechart_border_width.svg) --- --- @property border_width --- @tparam[opt=1] number border_width - ---- The pie chart colors. --- If no color is set, only the border will be drawn. If less colors than --- required are set, colors will be re-used in order. --- @property colors --- @tparam table colors A table of colors, one for each elements --- @see gears.color - ---- The border color. --- If none is set, it will use current foreground (text) color. --- @beautiful beautiful.piechart_border_color --- @param color --- @see gears.color - ---- If the pie chart has labels. --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_piechart_label.svg) --- --- @property display_labels --- @param[opt=true] boolean - ---- The pie elements border width. --- @beautiful beautiful.piechart_border_width --- @tparam[opt=1] number border_width - ---- The pie chart colors. --- If no color is set, only the border will be drawn. If less colors than --- required are set, colors will be re-used in order. --- @beautiful beautiful.piechart_colors --- @tparam table colors A table of colors, one for each elements --- @see gears.color - -for _, prop in ipairs {"data_list", "border_color", "border_width", "colors", - "display_labels" - } do - piechart["set_"..prop] = function(self, value) - self._private[prop] = value - self:emit_signal("property::"..prop) - if prop == "data_list" then - self:emit_signal("property::data") - end - self:emit_signal("widget::redraw_needed") - end - piechart["get_"..prop] = function(self) - return self._private[prop] or beautiful["piechart_"..prop] - end -end - -function piechart:set_data(value) - local list = {} - for k, v in pairs(value) do - table.insert(list, { k, v }) - end - self:set_data_list(list) -end - -function piechart:get_data() - local list = {} - for _, entry in ipairs(self:get_data_list()) do - list[entry[1]] = entry[2] - end - return list -end - -local function new(data_list) - - local ret = base.make_widget(nil, nil, { - enable_properties = true, - }) - - util.table.crush(ret, piechart) - - rawset(ret, "fit" , fit ) - rawset(ret, "draw", draw) - - ret:set_data_list(data_list) - - return ret -end - ---Imported documentation - - ---- Get a widex index. --- @param widget The widget to look for --- @param[opt] recursive Also check sub-widgets --- @param[opt] ... Aditional widgets to add at the end of the \"path\" --- @return The index --- @return The parent layout --- @return The path between \"self\" and \"widget\" --- @function index - ---- Get all direct and indirect children widgets. --- This will scan all containers recursively to find widgets --- Warning: This method it prone to stack overflow id the widget, or any of its --- children, contain (directly or indirectly) itself. --- @treturn table The children --- @function get_all_children - ---- Set a declarative widget hierarchy description. --- See [The declarative layout system](../documentation/03-declarative-layout.md.html) --- @param args An array containing the widgets disposition --- @function setup - ---- Force a widget height. --- @property forced_height --- @tparam number|nil height The height (`nil` for automatic) - ---- Force a widget width. --- @property forced_width --- @tparam number|nil width The width (`nil` for automatic) - ---- The widget opacity (transparency). --- @property opacity --- @tparam[opt=1] number opacity The opacity (between 0 and 1) - ---- The widget visibility. --- @property visible --- @param boolean - ---- Set/get a widget's buttons. --- @param _buttons The table of buttons that should bind to the widget. --- @function buttons - ---- Emit a signal and ensure all parent widgets in the hierarchies also --- forward the signal. This is useful to track signals when there is a dynamic --- set of containers and layouts wrapping the widget. --- @tparam string signal_name --- @param ... Other arguments --- @function emit_signal_recursive - ---- When the layout (size) change. --- This signal is emitted when the previous results of `:layout()` and `:fit()` --- are no longer valid. Unless this signal is emitted, `:layout()` and `:fit()` --- must return the same result when called with the same arguments. --- @signal widget::layout_changed --- @see widget::redraw_needed - ---- When the widget content changed. --- This signal is emitted when the content of the widget changes. The widget will --- be redrawn, it is not re-layouted. Put differently, it is assumed that --- `:layout()` and `:fit()` would still return the same results as before. --- @signal widget::redraw_needed --- @see widget::layout_changed - ---- When a mouse button is pressed over the widget. --- @signal button::press --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When a mouse button is released over the widget. --- @signal button::release --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse enter a widget. --- @signal mouse::enter --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse leave a widget. --- @signal mouse::leave --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - - ---Imported documentation - - ---- Disconnect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback that should be disconnected --- @function disconnect_signal - ---- Emit a signal. --- --- @tparam string name The name of the signal --- @param ... Extra arguments for the callback functions. Each connected --- function receives the object as first argument and then any extra arguments --- that are given to emit_signal() --- @function emit_signal - ---- Connect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function connect_signal - ---- Connect to a signal weakly. This allows the callback function to be garbage --- collected and automatically disconnects the signal when that happens. --- --- **Warning:** --- Only use this function if you really, really, really know what you --- are doing. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function weak_connect_signal - - -return setmetatable(module, { __call = function(_, ...) return new(...) end }) --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/progressbar.lua b/awesome/lib/wibox/widget/progressbar.lua deleted file mode 100644 index 943c49f..0000000 --- a/awesome/lib/wibox/widget/progressbar.lua +++ /dev/null @@ -1,754 +0,0 @@ ---------------------------------------------------------------------------- ---- A progressbar widget. --- --- To add text on top of the progressbar, a `wibox.layout.stack` can be used: --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_progressbar_text.svg) --- --- --- 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 --- } --- --- To display the progressbar vertically, use a `wibox.container.rotate` widget: --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_progressbar_vertical.svg) --- --- --- wibox.widget { --- { --- max_value = 1, --- value = 0.33, --- widget = wibox.widget.progressbar, --- }, --- forced_height = 100, --- forced_width = 20, --- direction = 'east', --- layout = wibox.container.rotate, --- } --- --- 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. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_defaults_progressbar.svg) --- --- @usage ---wibox.widget { --- 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, ---} --- --- @author Julien Danjou <julien@danjou.info> --- @copyright 2009 Julien Danjou --- @classmod wibox.widget.progressbar ---------------------------------------------------------------------------- - -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 = {} } - ---- The progressbar border color. --- If the value is nil, no border will be drawn. --- --- @property border_color --- @tparam gears.color color The border color to set. --- @see gears.color - ---- 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. --- @see gears.color - ---- The progressbar inner border width. --- @property bar_border_width - ---- The progressbar foreground color. --- --- @property color --- @tparam gears.color color The progressbar color. --- @see gears.color - ---- The progressbar background color. --- --- @property background_color --- @tparam gears.color color The progressbar background color. --- @see gears.color - ---- The progressbar inner shape. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_progressbar_bar_shape.svg) --- --- @usage ---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, --- paddings = 1, --- widget = wibox.widget.progressbar, --- }) ---end --- --- @property bar_shape --- @tparam[opt=gears.shape.rectangle] gears.shape shape --- @see gears.shape - ---- The progressbar shape. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_progressbar_shape.svg) --- --- @usage ---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, --- widget = wibox.widget.progressbar, --- }) ---end --- --- @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. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_progressbar_clip.svg) --- --- @usage ---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, ---} --- --- @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 - ---- 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 - ---- 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 = 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 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 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 - - 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 - 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 - - 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)) - - 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 - cr:fill() - end - - -- Undo the translation - 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 - - - -- 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(_, 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 - - 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. Use a `wibox.container.constraint` widget or --- `forced_height`. --- @param height The height to set. --- @deprecated set_height -function progressbar:set_height(height) - util.deprecate("Use a `wibox.container.constraint` widget or `forced_height`") - self:set_forced_height(height) -end - ---- Set the progressbar width. --- This method is deprecated. Use a `wibox.container.constraint` widget or --- `forced_width`. --- @param width The width to set. --- @deprecated set_width -function progressbar:set_width(width) - util.deprecate("Use a `wibox.container.constraint` widget or `forced_width`") - self:set_forced_width(width) -end - --- Build properties function -for _, prop in ipairs(properties) do - if not progressbar["set_" .. prop] then - progressbar["set_" .. prop] = function(pbar, 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. --- @return A progressbar widget. --- @function wibox.widget.progressbar -function progressbar.new(args) - args = args or {} - - local pbar = base.make_widget(nil, nil, { - enable_properties = true, - }) - - pbar._private.width = args.width or 100 - pbar._private.height = args.height or 20 - pbar._private.value = 0 - pbar._private.max_value = 1 - - util.table.crush(pbar, progressbar, true) - - return pbar -end - -function progressbar.mt:__call(...) - return progressbar.new(...) -end - ---Imported documentation - - ---- Get a widex index. --- @param widget The widget to look for --- @param[opt] recursive Also check sub-widgets --- @param[opt] ... Aditional widgets to add at the end of the \"path\" --- @return The index --- @return The parent layout --- @return The path between \"self\" and \"widget\" --- @function index - ---- Get all direct and indirect children widgets. --- This will scan all containers recursively to find widgets --- Warning: This method it prone to stack overflow id the widget, or any of its --- children, contain (directly or indirectly) itself. --- @treturn table The children --- @function get_all_children - ---- Set a declarative widget hierarchy description. --- See [The declarative layout system](../documentation/03-declarative-layout.md.html) --- @param args An array containing the widgets disposition --- @function setup - ---- Force a widget height. --- @property forced_height --- @tparam number|nil height The height (`nil` for automatic) - ---- Force a widget width. --- @property forced_width --- @tparam number|nil width The width (`nil` for automatic) - ---- The widget opacity (transparency). --- @property opacity --- @tparam[opt=1] number opacity The opacity (between 0 and 1) - ---- The widget visibility. --- @property visible --- @param boolean - ---- Set/get a widget's buttons. --- @param _buttons The table of buttons that should bind to the widget. --- @function buttons - ---- Emit a signal and ensure all parent widgets in the hierarchies also --- forward the signal. This is useful to track signals when there is a dynamic --- set of containers and layouts wrapping the widget. --- @tparam string signal_name --- @param ... Other arguments --- @function emit_signal_recursive - ---- When the layout (size) change. --- This signal is emitted when the previous results of `:layout()` and `:fit()` --- are no longer valid. Unless this signal is emitted, `:layout()` and `:fit()` --- must return the same result when called with the same arguments. --- @signal widget::layout_changed --- @see widget::redraw_needed - ---- When the widget content changed. --- This signal is emitted when the content of the widget changes. The widget will --- be redrawn, it is not re-layouted. Put differently, it is assumed that --- `:layout()` and `:fit()` would still return the same results as before. --- @signal widget::redraw_needed --- @see widget::layout_changed - ---- When a mouse button is pressed over the widget. --- @signal button::press --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When a mouse button is released over the widget. --- @signal button::release --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse enter a widget. --- @signal mouse::enter --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse leave a widget. --- @signal mouse::leave --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - - ---Imported documentation - - ---- Disconnect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback that should be disconnected --- @function disconnect_signal - ---- Emit a signal. --- --- @tparam string name The name of the signal --- @param ... Extra arguments for the callback functions. Each connected --- function receives the object as first argument and then any extra arguments --- that are given to emit_signal() --- @function emit_signal - ---- Connect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function connect_signal - ---- Connect to a signal weakly. This allows the callback function to be garbage --- collected and automatically disconnects the signal when that happens. --- --- **Warning:** --- Only use this function if you really, really, really know what you --- are doing. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function weak_connect_signal - - -return setmetatable(progressbar, progressbar.mt) - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/slider.lua b/awesome/lib/wibox/widget/slider.lua deleted file mode 100644 index fd590c6..0000000 --- a/awesome/lib/wibox/widget/slider.lua +++ /dev/null @@ -1,709 +0,0 @@ ---------------------------------------------------------------------------- --- An interactive mouse based slider widget. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_defaults_slider.svg) --- --- @usage ---wibox.widget { --- bar_shape = gears.shape.rounded_rect, --- bar_height = 3, --- bar_color = beautiful.border_color, --- handle_color = beautiful.bg_normal, --- handle_shape = gears.shape.circle, --- handle_border_color = beautiful.border_color, --- handle_border_width = 1, --- value = 25, --- widget = wibox.widget.slider, ---} --- --- @author Grigory Mishchenko <grishkokot@gmail.com> --- @author Emmanuel Lepage Vallee <elv1313@gmail.com> --- @copyright 2015 Grigory Mishchenko, 2016 Emmanuel Lepage Vallee --- @classmod wibox.widget.slider ---------------------------------------------------------------------------- - -local setmetatable = setmetatable -local type = type -local color = require("gears.color") -local util = require("awful.util") -local beautiful = require("beautiful") -local base = require("wibox.widget.base") -local shape = require("gears.shape") -local capi = { - mouse = mouse, - mousegrabber = mousegrabber, - root = root, -} - -local slider = {mt={}} - ---- The slider handle shape. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_handle_shape.svg) --- --- --- @property handle_shape --- @tparam[opt=gears shape rectangle] gears.shape shape --- @see gears.shape - ---- The slider handle color. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_handle_color.svg) --- --- --- @property handle_color --- @param color - ---- The slider handle margins. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_handle_margins.svg) --- --- --- @property handle_margins --- @tparam[opt={}] table margins --- @tparam[opt=0] number margins.left --- @tparam[opt=0] number margins.right --- @tparam[opt=0] number margins.top --- @tparam[opt=0] number margins.bottom - ---- The slider handle width. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_handle_width.svg) --- --- --- @property handle_width --- @param number - ---- The handle border_color. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_handle_border.svg) --- --- --- @property handle_border_color --- @param color - ---- The handle border width. --- @property handle_border_width --- @param[opt=0] number - ---- The bar (background) shape. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_bar_shape.svg) --- --- --- @property bar_shape --- @tparam[opt=gears shape rectangle] gears.shape shape --- @see gears.shape - ---- The bar (background) height. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_bar_height.svg) --- --- --- @property bar_height --- @param number - ---- The bar (background) color. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_bar_color.svg) --- --- --- @property bar_color --- @param color - ---- The bar (background) margins. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_bar_margins.svg) --- --- --- @property bar_margins --- @tparam[opt={}] table margins --- @tparam[opt=0] number margins.left --- @tparam[opt=0] number margins.right --- @tparam[opt=0] number margins.top --- @tparam[opt=0] number margins.bottom - ---- The bar (background) border width. --- @property bar_border_width --- @param[opt=0] numbergb - ---- The bar (background) border_color. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_bar_border.svg) --- --- --- @property bar_border_color --- @param color - ---- The slider value. --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_slider_value.svg) --- --- --- @property value --- @param[opt=0] number - ---- The slider minimum value. --- @property minimum --- @param[opt=0] number - ---- The slider maximum value. --- @property maximum --- @param[opt=100] number - ---- The bar (background) border width. --- @beautiful beautiful.slider_bar_border_width --- @param number - ---- The bar (background) border color. --- @beautiful beautiful.slider_bar_border_color --- @param color - ---- The handle border_color. --- @beautiful beautiful.slider_handle_border_color --- @param color - ---- The handle border width. --- @beautiful beautiful.slider_handle_border_width --- @param number - ---- The handle . --- @beautiful beautiful.slider_handle_width --- @param number - --- @beautiful beautiful.slider_handle_color --- @param color - ---- The handle shape. --- @beautiful beautiful.slider_handle_shape --- @tparam[opt=gears shape rectangle] gears.shape shape --- @see gears.shape - ---- The bar (background) shape. --- @beautiful beautiful.slider_bar_shape --- @tparam[opt=gears shape rectangle] gears.shape shape --- @see gears.shape - ---- The bar (background) height. --- @beautiful beautiful.slider_bar_height --- @param number - ---- The bar (background) margins. --- @beautiful beautiful.slider_bar_margins --- @tparam[opt={}] table margins --- @tparam[opt=0] number margins.left --- @tparam[opt=0] number margins.right --- @tparam[opt=0] number margins.top --- @tparam[opt=0] number margins.bottom - ---- The slider handle margins. --- @beautiful beautiful.slider_handle_margins --- @tparam[opt={}] table margins --- @tparam[opt=0] number margins.left --- @tparam[opt=0] number margins.right --- @tparam[opt=0] number margins.top --- @tparam[opt=0] number margins.bottom - ---- The bar (background) color. --- @beautiful beautiful.slider_bar_color --- @param color - -local properties = { - -- Handle - handle_shape = shape.rectangle, - handle_color = false, - handle_margins = {}, - handle_width = false, - handle_border_width = 0, - handle_border_color = false, - - -- Bar - bar_shape = shape.rectangle, - bar_height = false, - bar_color = false, - bar_margins = {}, - bar_border_width = 0, - bar_border_color = false, - - -- Content - value = 0, - minimum = 0, - maximum = 100, -} - --- Create the accessors -for prop in pairs(properties) do - slider["set_"..prop] = function(self, value) - local changed = self._private[prop] ~= value - self._private[prop] = value - - if changed then - self:emit_signal("property::"..prop) - self:emit_signal("widget::redraw_needed") - end - end - - slider["get_"..prop] = function(self) - -- Ignoring the false's is on purpose - return self._private[prop] == nil - and properties[prop] - or self._private[prop] - end -end - --- Add some validation to set_value -function slider:set_value(value) - value = math.min(value, self:get_maximum()) - value = math.max(value, self:get_minimum()) - local changed = self._private.value ~= value - - self._private.value = value - - if changed then - self:emit_signal( "property::value" ) - self:emit_signal( "widget::redraw_needed" ) - end -end - -local function get_extremums(self) - local min = self._private.minimum or properties.minimum - local max = self._private.maximum or properties.maximum - local interval = max - min - - return min, max, interval -end - -function slider:draw(_, cr, width, height) - local bar_height = self._private.bar_height - - -- If there is no background, then skip this - local bar_color = self._private.bar_color - or beautiful.slider_bar_color - - if bar_color then - cr:set_source(color(bar_color)) - end - - local margins = self._private.bar_margins - or beautiful.slider_bar_margins - - local x_offset, right_margin, y_offset = 0, 0 - - if margins then - if type(margins) == "number" then - bar_height = bar_height or (height - 2*margins) - x_offset, y_offset = margins, margins - right_margin = margins - else - bar_height = bar_height or ( - height - (margins.top or 0) - (margins.bottom or 0) - ) - x_offset, y_offset = margins.left or 0, margins.top or 0 - right_margin = margins.right or 0 - end - else - bar_height = bar_height or beautiful.slider_bar_height or height - y_offset = (height - bar_height)/2 - end - - - cr:translate(x_offset, y_offset) - - local bar_shape = self._private.bar_shape - or beautiful.slider_bar_shape - or properties.bar_shape - - local bar_border_width = self._private.bar_border_width - or beautiful.slider_bar_border_width - or properties.bar_border_width - - bar_shape(cr, width - x_offset - right_margin, bar_height or height) - - if bar_color then - if bar_border_width == 0 then - cr:fill() - else - cr:fill_preserve() - end - end - - -- Draw the bar border - if bar_border_width > 0 then - local bar_border_color = self._private.bar_border_color - or beautiful.slider_bar_border_color - or properties.bar_border_color - - cr:set_line_width(bar_border_width) - - if bar_border_color then - cr:save() - cr:set_source(color(bar_border_color)) - cr:stroke() - cr:restore() - else - cr:stroke() - end - end - - cr:translate(-x_offset, -y_offset) - - -- Paint the handle - local handle_color = self._private.handle_color - or beautiful.slider_handle_color - - -- It is ok if there is no color, it will be inherited - if handle_color then - cr:set_source(color(handle_color)) - end - - local handle_height, handle_width = height, self._private.handle_width - or beautiful.slider_handle_width - or height/2 - - local handle_shape = self._private.handle_shape - or beautiful.slider_handle_shape - or properties.handle_shape - - -- Lets get the margins for the handle - margins = self._private.handle_margins - or beautiful.slider_handle_margins - - x_offset, y_offset = 0, 0 - - if margins then - if type(margins) == "number" then - x_offset, y_offset = margins, margins - handle_width = handle_width - 2*margins - handle_height = handle_height - 2*margins - else - x_offset, y_offset = margins.left or 0, margins.top or 0 - handle_width = handle_width - - (margins.left or 0) - (margins.right or 0) - handle_height = handle_height - - (margins.top or 0) - (margins.bottom or 0) - end - end - - local value = self._private.value or self._private.min or 0 - - -- Get the widget size back to it's non-transfored value - local min, _, interval = get_extremums(self) - local rel_value = ((value-min)/interval) * (width-handle_width) - - cr:translate(x_offset + rel_value, y_offset) - - local handle_border_width = self._private.handle_border_width - or beautiful.slider_handle_border_width - or properties.handle_border_width or 0 - - handle_shape(cr, handle_width, handle_height) - - if handle_border_width > 0 then - cr:fill_preserve() - else - cr:fill() - end - - -- Draw the handle border - if handle_border_width > 0 then - local handle_border_color = self._private.handle_border_color - or beautiful.slider_handle_border_color - or properties.handle_border_color - - if handle_border_color then - cr:set_source(color(handle_border_color)) - end - - cr:set_line_width(handle_border_width) - cr:stroke() - end -end - -function slider:fit(_, width, height) - -- Use all the space, this should be used with a constraint widget - return width, height -end - --- Move the handle to the correct location -local function move_handle(self, width, x, _) - local _, _, interval = get_extremums(self) - self:set_value(math.floor((x*interval)/width)) -end - -local function mouse_press(self, x, y, button_id, _, geo) - if button_id ~= 1 then return end - - local matrix_from_device = geo.hierarchy:get_matrix_from_device() - - -- Sigh. geo.width/geo.height is in device space. We need it in our own - -- coordinate system - local width = geo.widget_width - - move_handle(self, width, x, y) - - -- Calculate a matrix transforming from screen coordinates into widget coordinates - local wgeo = geo.drawable.drawable:geometry() - local matrix = matrix_from_device:translate(-wgeo.x, -wgeo.y) - - capi.mousegrabber.run(function(mouse) - if not mouse.buttons[1] then - return false - end - - -- Calculate the point relative to the widget - move_handle(self, width, matrix:transform_point(mouse.x, mouse.y)) - - return true - end,"fleur") -end - ---- Create a slider widget. --- @tparam[opt={}] table args --- @function wibox.widget.slider -local function new(args) - local ret = base.make_widget(nil, nil, { - enable_properties = true, - }) - - util.table.crush(ret._private, args or {}) - - util.table.crush(ret, slider, true) - - ret:connect_signal("button::press", mouse_press) - - return ret -end - -function slider.mt:__call(_, ...) - return new(...) -end - ---Imported documentation - - ---- Get a widex index. --- @param widget The widget to look for --- @param[opt] recursive Also check sub-widgets --- @param[opt] ... Aditional widgets to add at the end of the \"path\" --- @return The index --- @return The parent layout --- @return The path between \"self\" and \"widget\" --- @function index - ---- Get all direct and indirect children widgets. --- This will scan all containers recursively to find widgets --- Warning: This method it prone to stack overflow id the widget, or any of its --- children, contain (directly or indirectly) itself. --- @treturn table The children --- @function get_all_children - ---- Set a declarative widget hierarchy description. --- See [The declarative layout system](../documentation/03-declarative-layout.md.html) --- @param args An array containing the widgets disposition --- @function setup - ---- Force a widget height. --- @property forced_height --- @tparam number|nil height The height (`nil` for automatic) - ---- Force a widget width. --- @property forced_width --- @tparam number|nil width The width (`nil` for automatic) - ---- The widget opacity (transparency). --- @property opacity --- @tparam[opt=1] number opacity The opacity (between 0 and 1) - ---- The widget visibility. --- @property visible --- @param boolean - ---- Set/get a widget's buttons. --- @param _buttons The table of buttons that should bind to the widget. --- @function buttons - ---- Emit a signal and ensure all parent widgets in the hierarchies also --- forward the signal. This is useful to track signals when there is a dynamic --- set of containers and layouts wrapping the widget. --- @tparam string signal_name --- @param ... Other arguments --- @function emit_signal_recursive - ---- When the layout (size) change. --- This signal is emitted when the previous results of `:layout()` and `:fit()` --- are no longer valid. Unless this signal is emitted, `:layout()` and `:fit()` --- must return the same result when called with the same arguments. --- @signal widget::layout_changed --- @see widget::redraw_needed - ---- When the widget content changed. --- This signal is emitted when the content of the widget changes. The widget will --- be redrawn, it is not re-layouted. Put differently, it is assumed that --- `:layout()` and `:fit()` would still return the same results as before. --- @signal widget::redraw_needed --- @see widget::layout_changed - ---- When a mouse button is pressed over the widget. --- @signal button::press --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When a mouse button is released over the widget. --- @signal button::release --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse enter a widget. --- @signal mouse::enter --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse leave a widget. --- @signal mouse::leave --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - - ---Imported documentation - - ---- Disconnect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback that should be disconnected --- @function disconnect_signal - ---- Emit a signal. --- --- @tparam string name The name of the signal --- @param ... Extra arguments for the callback functions. Each connected --- function receives the object as first argument and then any extra arguments --- that are given to emit_signal() --- @function emit_signal - ---- Connect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function connect_signal - ---- Connect to a signal weakly. This allows the callback function to be garbage --- collected and automatically disconnects the signal when that happens. --- --- **Warning:** --- Only use this function if you really, really, really know what you --- are doing. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function weak_connect_signal - - -return setmetatable(slider, slider.mt) - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/systray.lua b/awesome/lib/wibox/widget/systray.lua deleted file mode 100644 index e83347c..0000000 --- a/awesome/lib/wibox/widget/systray.lua +++ /dev/null @@ -1,186 +0,0 @@ ---------------------------------------------------------------------------- --- @author Uli Schlachter --- @copyright 2010 Uli Schlachter --- @classmod wibox.widget.systray ---------------------------------------------------------------------------- - -local wbase = require("wibox.widget.base") -local beautiful = require("beautiful") -local util = require("awful.util") -local capi = { - awesome = awesome, - screen = screen -} -local setmetatable = setmetatable -local error = error -local abs = math.abs - -local systray = { mt = {} } - -local instance = nil -local horizontal = true -local base_size = nil -local reverse = false -local display_on_screen = "primary" - ---- The systray background color. --- @beautiful beautiful.bg_systray --- @param string The color (string like "#ff0000" only) - ---- The systray icon spacing. --- @beautiful beautiful.systray_icon_spacing --- @tparam[opt=0] integer The icon spacing - -local function should_display_on(s) - if display_on_screen == "primary" then - return s == capi.screen.primary - end - return s == display_on_screen -end - -function systray:draw(context, cr, width, height) - if not should_display_on(context.screen) then - return - end - - local x, y, _, _ = wbase.rect_to_device_geometry(cr, 0, 0, width, height) - local num_entries = capi.awesome.systray() - local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000" - local spacing = beautiful.systray_icon_spacing or 0 - - if context and not context.wibox then - error("The systray widget can only be placed inside a wibox.") - end - - -- Figure out if the cairo context is rotated - local dir_x, dir_y = cr:user_to_device_distance(1, 0) - local is_rotated = abs(dir_x) < abs(dir_y) - - local in_dir, ortho, base - if horizontal then - in_dir, ortho = width, height - is_rotated = not is_rotated - else - ortho, in_dir = width, height - end - if ortho * num_entries <= in_dir then - base = ortho - else - base = in_dir / num_entries - end - capi.awesome.systray(context.wibox.drawin, math.ceil(x), math.ceil(y), - base, is_rotated, bg, reverse, spacing) -end - -function systray:fit(context, width, height) - if not should_display_on(context.screen) then - return 0, 0 - end - - local num_entries = capi.awesome.systray() - local base = base_size - local spacing = beautiful.systray_icon_spacing or 0 - if num_entries == 0 then - return 0, 0 - end - if base == nil then - if width < height then - base = width - else - base = height - end - end - base = base + spacing - if horizontal then - return base * num_entries - spacing, base - end - return base, base * num_entries - spacing -end - --- Check if the function was called like :foo() or .foo() and do the right thing -local function get_args(self, ...) - if self == instance then - return ... - end - return self, ... -end - ---- Set the size of a single icon. --- If this is set to nil, then the size is picked dynamically based on the --- available space. Otherwise, any single icon has a size of `size`x`size`. --- @tparam integer|nil size The base size -function systray:set_base_size(size) - base_size = get_args(self, size) - if instance then - instance:emit_signal("widget::layout_changed") - end -end - ---- Decide between horizontal or vertical display. --- @tparam boolean horiz Use horizontal mode? -function systray:set_horizontal(horiz) - horizontal = get_args(self, horiz) - if instance then - instance:emit_signal("widget::layout_changed") - end -end - ---- Should the systray icons be displayed in reverse order? --- @tparam boolean rev Display in reverse order -function systray:set_reverse(rev) - reverse = get_args(self, rev) - if instance then - instance:emit_signal("widget::redraw_needed") - end -end - ---- Set the screen that the systray should be displayed on. --- This can either be a screen, in which case the systray will be displayed on --- exactly that screen, or the string `"primary"`, in which case it will be --- visible on the primary screen. The default value is "primary". --- @tparam screen|"primary" s The screen to display on. -function systray:set_screen(s) - display_on_screen = get_args(self, s) - if instance then - instance:emit_signal("widget::layout_changed") - end -end - ---- Create the systray widget. --- Note that this widget can only exist once. --- @tparam boolean revers Show in the opposite direction --- @treturn table The new `systray` widget --- @function wibox.widget.systray - -local function new(revers) - local ret = wbase.make_widget() - - util.table.crush(ret, systray, true) - - if revers then - ret:set_reverse(true) - end - - capi.awesome.connect_signal("systray::update", function() - ret:emit_signal("widget::layout_changed") - ret:emit_signal("widget::redraw_needed") - end) - capi.screen.connect_signal("primary_changed", function() - if display_on_screen == "primary" then - ret:emit_signal("widget::layout_changed") - end - end) - - return ret -end - -function systray.mt:__call(...) - if not instance then - instance = new(...) - end - return instance -end - -return setmetatable(systray, systray.mt) - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/textbox.lua b/awesome/lib/wibox/widget/textbox.lua deleted file mode 100644 index add35e9..0000000 --- a/awesome/lib/wibox/widget/textbox.lua +++ /dev/null @@ -1,507 +0,0 @@ ---------------------------------------------------------------------------- --- --- --- ---![Usage example](../images/AUTOGEN_wibox_widget_defaults_textbox.svg) --- --- @usage ---wibox.widget{ --- markup = 'This <i>is</i> a <b>textbox</b>!!!', --- align = 'center', --- valign = 'center', --- widget = wibox.widget.textbox ---} --- @author Uli Schlachter --- @author dodo --- @copyright 2010, 2011 Uli Schlachter, dodo --- @classmod wibox.widget.textbox ---------------------------------------------------------------------------- - -local base = require("wibox.widget.base") -local gdebug = require("gears.debug") -local beautiful = require("beautiful") -local lgi = require("lgi") -local util = require("awful.util") -local Pango = lgi.Pango -local PangoCairo = lgi.PangoCairo -local setmetatable = setmetatable - -local textbox = { mt = {} } - ---- The textbox font. --- @beautiful beautiful.font - ---- Set the DPI of a Pango layout -local function setup_dpi(box, dpi) - if box._private.dpi ~= dpi then - box._private.dpi = dpi - box._private.ctx:set_resolution(dpi) - box._private.layout:context_changed() - end -end - ---- Setup a pango layout for the given textbox and dpi -local function setup_layout(box, width, height, dpi) - box._private.layout.width = Pango.units_from_double(width) - box._private.layout.height = Pango.units_from_double(height) - setup_dpi(box, dpi) -end - --- Draw the given textbox on the given cairo context in the given geometry -function textbox:draw(context, cr, width, height) - setup_layout(self, width, height, context.dpi) - cr:update_layout(self._private.layout) - local _, logical = self._private.layout:get_pixel_extents() - local offset = 0 - if self._private.valign == "center" then - offset = (height - logical.height) / 2 - elseif self._private.valign == "bottom" then - offset = height - logical.height - end - cr:move_to(0, offset) - cr:show_layout(self._private.layout) -end - -local function do_fit_return(self) - local _, logical = self._private.layout:get_pixel_extents() - if logical.width == 0 or logical.height == 0 then - return 0, 0 - end - return logical.width, logical.height -end - --- Fit the given textbox -function textbox:fit(context, width, height) - setup_layout(self, width, height, context.dpi) - return do_fit_return(self) -end - ---- Get the preferred size of a textbox. --- This returns the size that the textbox would use if infinite space were --- available. --- @tparam integer|screen s The screen on which the textbox will be displayed. --- @treturn number The preferred width. --- @treturn number The preferred height. -function textbox:get_preferred_size(s) - return self:get_preferred_size_at_dpi(beautiful.xresources.get_dpi(s)) -end - ---- Get the preferred height of a textbox at a given width. --- This returns the height that the textbox would use when it is limited to the --- given width. --- @tparam number width The available width. --- @tparam integer|screen s The screen on which the textbox will be displayed. --- @treturn number The needed height. -function textbox:get_height_for_width(width, s) - return self:get_height_for_width_at_dpi(width, beautiful.xresources.get_dpi(s)) -end - ---- Get the preferred size of a textbox. --- This returns the size that the textbox would use if infinite space were --- available. --- @tparam number dpi The DPI value to render at. --- @treturn number The preferred width. --- @treturn number The preferred height. -function textbox:get_preferred_size_at_dpi(dpi) - local max_lines = 2^20 - setup_dpi(self, dpi) - self._private.layout.width = -1 -- no width set - self._private.layout.height = -max_lines -- show this many lines per paragraph - return do_fit_return(self) -end - ---- Get the preferred height of a textbox at a given width. --- This returns the height that the textbox would use when it is limited to the --- given width. --- @tparam number width The available width. --- @tparam number dpi The DPI value to render at. --- @treturn number The needed height. -function textbox:get_height_for_width_at_dpi(width, dpi) - local max_lines = 2^20 - setup_dpi(self, dpi) - self._private.layout.width = Pango.units_from_double(width) - self._private.layout.height = -max_lines -- show this many lines per paragraph - local _, h = do_fit_return(self) - return h -end - ---- Set the text of the textbox (with --- [Pango markup](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html)). --- @tparam string text The text to set. This can contain pango markup (e.g. --- `<b>bold</b>`). You can use `awful.util.escape` to escape --- parts of it. --- @treturn[1] boolean true --- @treturn[2] boolean false --- @treturn[2] string Error message explaining why the markup was invalid. -function textbox:set_markup_silently(text) - if self._private.markup == text then - return true - end - - local attr, parsed = Pango.parse_markup(text, -1, 0) - -- In case of error, attr is false and parsed is a GLib.Error instance. - if not attr then - return false, parsed.message or tostring(parsed) - end - - self._private.markup = text - self._private.layout.text = parsed - self._private.layout.attributes = attr - self:emit_signal("widget::redraw_needed") - self:emit_signal("widget::layout_changed") - return true -end - ---- Set the text of the textbox (with --- [Pango markup](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html)). --- @property markup --- @tparam string text The text to set. This can contain pango markup (e.g. --- `<b>bold</b>`). You can use `awful.util.escape` to escape --- parts of it. --- @see text - -function textbox:set_markup(text) - local success, message = self:set_markup_silently(text) - if not success then - gdebug.print_error(message) - end -end - -function textbox:get_markup() - return self._private.markup -end - ---- Set a textbox' text. --- @property text --- @param text The text to display. Pango markup is ignored and shown as-is. --- @see markup - -function textbox:set_text(text) - if self._private.layout.text == text and self._private.layout.attributes == nil then - return - end - self._private.markup = nil - self._private.layout.text = text - self._private.layout.attributes = nil - self:emit_signal("widget::redraw_needed") - self:emit_signal("widget::layout_changed") -end - -function textbox:get_text() - return self._private.layout.text -end - ---- Set a textbox' ellipsize mode. --- @property ellipsize --- @param mode Where should long lines be shortened? "start", "middle" or "end" - -function textbox:set_ellipsize(mode) - local allowed = { none = "NONE", start = "START", middle = "MIDDLE", ["end"] = "END" } - if allowed[mode] then - if self._private.layout:get_ellipsize() == allowed[mode] then - return - end - self._private.layout:set_ellipsize(allowed[mode]) - self:emit_signal("widget::redraw_needed") - self:emit_signal("widget::layout_changed") - end -end - ---- Set a textbox' wrap mode. --- @property wrap --- @param mode Where to wrap? After "word", "char" or "word_char" - -function textbox:set_wrap(mode) - local allowed = { word = "WORD", char = "CHAR", word_char = "WORD_CHAR" } - if allowed[mode] then - if self._private.layout:get_wrap() == allowed[mode] then - return - end - self._private.layout:set_wrap(allowed[mode]) - self:emit_signal("widget::redraw_needed") - self:emit_signal("widget::layout_changed") - end -end - ---- The textbox' vertical alignment --- @property valign --- @param mode Where should the textbox be drawn? "top", "center" or "bottom" - -function textbox:set_valign(mode) - local allowed = { top = true, center = true, bottom = true } - if allowed[mode] then - if self._private.valign == mode then - return - end - self._private.valign = mode - self:emit_signal("widget::redraw_needed") - self:emit_signal("widget::layout_changed") - end -end - ---- Set a textbox' horizontal alignment. --- @property align --- @param mode Where should the textbox be drawn? "left", "center" or "right" - -function textbox:set_align(mode) - local allowed = { left = "LEFT", center = "CENTER", right = "RIGHT" } - if allowed[mode] then - if self._private.layout:get_alignment() == allowed[mode] then - return - end - self._private.layout:set_alignment(allowed[mode]) - self:emit_signal("widget::redraw_needed") - self:emit_signal("widget::layout_changed") - end -end - ---- Set a textbox' font --- @property font --- @param font The font description as string - -function textbox:set_font(font) - self._private.layout:set_font_description(beautiful.get_font(font)) - self:emit_signal("widget::redraw_needed") - self:emit_signal("widget::layout_changed") -end - ---- Create a new textbox. --- @tparam[opt=""] string text The textbox content --- @tparam[opt=false] boolean ignore_markup Ignore the pango/HTML markup --- @treturn table A new textbox widget --- @function wibox.widget.textbox -local function new(text, ignore_markup) - local ret = base.make_widget(nil, nil, {enable_properties = true}) - - util.table.crush(ret, textbox, true) - - ret._private.dpi = -1 - ret._private.ctx = PangoCairo.font_map_get_default():create_context() - ret._private.layout = Pango.Layout.new(ret._private.ctx) - - ret:set_ellipsize("end") - ret:set_wrap("word_char") - ret:set_valign("center") - ret:set_align("left") - ret:set_font(beautiful and beautiful.font) - - if text then - if ignore_markup then - ret:set_text(text) - else - ret:set_markup(text) - end - end - - return ret -end - -function textbox.mt.__call(_, ...) - return new(...) -end - ---Imported documentation - - ---- Get a widex index. --- @param widget The widget to look for --- @param[opt] recursive Also check sub-widgets --- @param[opt] ... Aditional widgets to add at the end of the \"path\" --- @return The index --- @return The parent layout --- @return The path between \"self\" and \"widget\" --- @function index - ---- Get all direct and indirect children widgets. --- This will scan all containers recursively to find widgets --- Warning: This method it prone to stack overflow id the widget, or any of its --- children, contain (directly or indirectly) itself. --- @treturn table The children --- @function get_all_children - ---- Set a declarative widget hierarchy description. --- See [The declarative layout system](../documentation/03-declarative-layout.md.html) --- @param args An array containing the widgets disposition --- @function setup - ---- Force a widget height. --- @property forced_height --- @tparam number|nil height The height (`nil` for automatic) - ---- Force a widget width. --- @property forced_width --- @tparam number|nil width The width (`nil` for automatic) - ---- The widget opacity (transparency). --- @property opacity --- @tparam[opt=1] number opacity The opacity (between 0 and 1) - ---- The widget visibility. --- @property visible --- @param boolean - ---- Set/get a widget's buttons. --- @param _buttons The table of buttons that should bind to the widget. --- @function buttons - ---- Emit a signal and ensure all parent widgets in the hierarchies also --- forward the signal. This is useful to track signals when there is a dynamic --- set of containers and layouts wrapping the widget. --- @tparam string signal_name --- @param ... Other arguments --- @function emit_signal_recursive - ---- When the layout (size) change. --- This signal is emitted when the previous results of `:layout()` and `:fit()` --- are no longer valid. Unless this signal is emitted, `:layout()` and `:fit()` --- must return the same result when called with the same arguments. --- @signal widget::layout_changed --- @see widget::redraw_needed - ---- When the widget content changed. --- This signal is emitted when the content of the widget changes. The widget will --- be redrawn, it is not re-layouted. Put differently, it is assumed that --- `:layout()` and `:fit()` would still return the same results as before. --- @signal widget::redraw_needed --- @see widget::layout_changed - ---- When a mouse button is pressed over the widget. --- @signal button::press --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When a mouse button is released over the widget. --- @signal button::release --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse enter a widget. --- @signal mouse::enter --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse leave a widget. --- @signal mouse::leave --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - - ---Imported documentation - - ---- Disconnect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback that should be disconnected --- @function disconnect_signal - ---- Emit a signal. --- --- @tparam string name The name of the signal --- @param ... Extra arguments for the callback functions. Each connected --- function receives the object as first argument and then any extra arguments --- that are given to emit_signal() --- @function emit_signal - ---- Connect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function connect_signal - ---- Connect to a signal weakly. This allows the callback function to be garbage --- collected and automatically disconnects the signal when that happens. --- --- **Warning:** --- Only use this function if you really, really, really know what you --- are doing. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function weak_connect_signal - - -return setmetatable(textbox, textbox.mt) - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/awesome/lib/wibox/widget/textclock.lua b/awesome/lib/wibox/widget/textclock.lua deleted file mode 100644 index c688028..0000000 --- a/awesome/lib/wibox/widget/textclock.lua +++ /dev/null @@ -1,254 +0,0 @@ ---------------------------------------------------------------------------- ---- Text clock widget. --- --- @author Julien Danjou <julien@danjou.info> --- @copyright 2009 Julien Danjou --- @classmod wibox.widget.textclock ---------------------------------------------------------------------------- - -local setmetatable = setmetatable -local os = os -local textbox = require("wibox.widget.textbox") -local timer = require("gears.timer") -local DateTime = require("lgi").GLib.DateTime - -local textclock = { mt = {} } - ---- This lowers the timeout so that it occurs "correctly". For example, a timeout --- of 60 is rounded so that it occurs the next time the clock reads ":00 seconds". -local function calc_timeout(real_timeout) - return real_timeout - os.time() % real_timeout -end - ---- Create a textclock widget. It draws the time it is in a textbox. --- --- @tparam[opt=" %a %b %d, %H:%M "] string format The time format. --- @tparam[opt=60] number timeout How often update the time (in seconds). --- @treturn table A textbox widget. --- @function wibox.widget.textclock -function textclock.new(format, timeout) - format = format or " %a %b %d, %H:%M " - timeout = timeout or 60 - - local w = textbox() - local t - function w._private.textclock_update_cb() - w:set_markup(DateTime.new_now_local():format(format)) - t.timeout = calc_timeout(timeout) - t:again() - return true -- Continue the timer - end - t = timer.weak_start_new(timeout, w._private.textclock_update_cb) - t:emit_signal("timeout") - return w -end - -function textclock.mt:__call(...) - return textclock.new(...) -end - ---Imported documentation - - ---- Get a widex index. --- @param widget The widget to look for --- @param[opt] recursive Also check sub-widgets --- @param[opt] ... Aditional widgets to add at the end of the \"path\" --- @return The index --- @return The parent layout --- @return The path between \"self\" and \"widget\" --- @function index - ---- Get all direct and indirect children widgets. --- This will scan all containers recursively to find widgets --- Warning: This method it prone to stack overflow id the widget, or any of its --- children, contain (directly or indirectly) itself. --- @treturn table The children --- @function get_all_children - ---- Set a declarative widget hierarchy description. --- See [The declarative layout system](../documentation/03-declarative-layout.md.html) --- @param args An array containing the widgets disposition --- @function setup - ---- Force a widget height. --- @property forced_height --- @tparam number|nil height The height (`nil` for automatic) - ---- Force a widget width. --- @property forced_width --- @tparam number|nil width The width (`nil` for automatic) - ---- The widget opacity (transparency). --- @property opacity --- @tparam[opt=1] number opacity The opacity (between 0 and 1) - ---- The widget visibility. --- @property visible --- @param boolean - ---- Set/get a widget's buttons. --- @param _buttons The table of buttons that should bind to the widget. --- @function buttons - ---- Emit a signal and ensure all parent widgets in the hierarchies also --- forward the signal. This is useful to track signals when there is a dynamic --- set of containers and layouts wrapping the widget. --- @tparam string signal_name --- @param ... Other arguments --- @function emit_signal_recursive - ---- When the layout (size) change. --- This signal is emitted when the previous results of `:layout()` and `:fit()` --- are no longer valid. Unless this signal is emitted, `:layout()` and `:fit()` --- must return the same result when called with the same arguments. --- @signal widget::layout_changed --- @see widget::redraw_needed - ---- When the widget content changed. --- This signal is emitted when the content of the widget changes. The widget will --- be redrawn, it is not re-layouted. Put differently, it is assumed that --- `:layout()` and `:fit()` would still return the same results as before. --- @signal widget::redraw_needed --- @see widget::layout_changed - ---- When a mouse button is pressed over the widget. --- @signal button::press --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When a mouse button is released over the widget. --- @signal button::release --- @tparam number lx The horizontal position relative to the (0,0) position in --- the widget. --- @tparam number ly The vertical position relative to the (0,0) position in the --- widget. --- @tparam number button The button number. --- @tparam table mods The modifiers (mod4, mod1 (alt), Control, Shift) --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse enter a widget. --- @signal mouse::enter --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - ---- When the mouse leave a widget. --- @signal mouse::leave --- @tparam table find_widgets_result The entry from the result of --- @{wibox.drawable:find_widgets} for the position that the mouse hit. --- @tparam wibox.drawable find_widgets_result.drawable The drawable containing --- the widget. --- @tparam widget find_widgets_result.widget The widget being displayed. --- @tparam wibox.hierarchy find_widgets_result.hierarchy The hierarchy --- managing the widget's geometry. --- @tparam number find_widgets_result.x An approximation of the X position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.y An approximation of the Y position that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.width An approximation of the width that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.height An approximation of the height that --- the widget is visible at on the surface. --- @tparam number find_widgets_result.widget_width The exact width of the widget --- in its local coordinate system. --- @tparam number find_widgets_result.widget_height The exact height of the widget --- in its local coordinate system. --- @see mouse - - ---Imported documentation - - ---- Disconnect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback that should be disconnected --- @function disconnect_signal - ---- Emit a signal. --- --- @tparam string name The name of the signal --- @param ... Extra arguments for the callback functions. Each connected --- function receives the object as first argument and then any extra arguments --- that are given to emit_signal() --- @function emit_signal - ---- Connect to a signal. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function connect_signal - ---- Connect to a signal weakly. This allows the callback function to be garbage --- collected and automatically disconnects the signal when that happens. --- --- **Warning:** --- Only use this function if you really, really, really know what you --- are doing. --- @tparam string name The name of the signal --- @tparam function func The callback to call when the signal is emitted --- @function weak_connect_signal - - -return setmetatable(textclock, textclock.mt) - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 |