From e23940cc6a1c685530ec64030e03642c7b6a193f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 5 Jan 2022 11:40:28 -0800 Subject: [PATCH] imagebox: Expose the "optimal size" properties. The `textbox` already has the equivalent. This will soon be used by the new `wibox.container.border` widget. --- lib/wibox/widget/imagebox.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/wibox/widget/imagebox.lua b/lib/wibox/widget/imagebox.lua index 76ca28604..bed1887fd 100644 --- a/lib/wibox/widget/imagebox.lua +++ b/lib/wibox/widget/imagebox.lua @@ -362,6 +362,28 @@ end -- @tparam[opt=nil] image|nil image -- @propemits false false +--- Return the source image width. +-- +-- For SVG images, this may be affected by the DPI and might not +-- reflect the size the images will be rendered at. For PNG or +-- JPG images, this will return the file resolution. +-- +-- @property source_width +-- @tparam number source_width +-- @see image +-- @see source_height + +--- Return the source image height. +-- +-- For SVG images, this may be affected by the DPI and might not +-- reflect the size the images will be rendered at. For PNG or +-- JPG images, this will return the file resolution. +-- +-- @property source_height +-- @tparam number source_height +-- @see image +-- @see source_width + --- Set the `imagebox` image. -- -- The image can be a file, a cairo image surface, or an rsvg handle object @@ -417,6 +439,14 @@ function imagebox:set_image(image) return true end +for _, dim in ipairs { "width", "height" } do + imagebox["get_source_"..dim] = function(self) + if not self._private.default then return nil end + + return self._private.default[dim] + end +end + --- Set a clip shape for this imagebox. -- -- A clip shape defines an area and dimension to which the content should be