aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/quarrel/ui/init.lua
diff options
context:
space:
mode:
authordelta <darkussdelta@gmail.com>2026-04-17 08:10:30 +0200
committerdelta <darkussdelta@gmail.com>2026-04-17 08:10:30 +0200
commita7c79cb5a04562be10347856642a80f0c4be89fc (patch)
tree98fac95855d84f5037a1c6f44061cbe94b550600 /.config/awesome/quarrel/ui/init.lua
parent225eeafcea67d63a608f9c666faf2a2ef014be4a (diff)
Diffstat (limited to '.config/awesome/quarrel/ui/init.lua')
-rw-r--r--.config/awesome/quarrel/ui/init.lua87
1 files changed, 87 insertions, 0 deletions
diff --git a/.config/awesome/quarrel/ui/init.lua b/.config/awesome/quarrel/ui/init.lua
index 5e68b1d..7ba6a58 100644
--- a/.config/awesome/quarrel/ui/init.lua
+++ b/.config/awesome/quarrel/ui/init.lua
@@ -4,7 +4,9 @@ local gshape = require "gears.shape"
local gtable = require "gears.table"
local qbind = require "quarrel.bind"
local qcolor = require "quarrel.color"
+local qdelegate = require "quarrel.delegate"
local wibox = require "wibox"
+local cairo = require("lgi").cairo
--- Clip Cairo context
---@param cr cairo_surface Cairo surface
@@ -199,4 +201,89 @@ function M.hoverable(widget, cursor)
return widget
end
+---@param wibox wibox
+function M.animateable_shape(wibox)
+ local old_apply_shape = wibox._apply_shape
+
+ wibox:disconnect_signal("property::geometry", old_apply_shape)
+ wibox:disconnect_signal("property::border_width", old_apply_shape)
+
+ function wibox:set_shape_width(value)
+ self._shape_width = value
+ self:emit_signal("property::shape_width")
+ end
+
+ function wibox:get_shape_width(value)
+ return self._shape_width
+ end
+
+ function wibox:set_shape_height(value)
+ self._shape_height = value
+ self:emit_signal("property::shape_height")
+ end
+
+ function wibox:get_shape_height(value)
+ return self._shape_height
+ end
+
+ -- override to allow us to override shape
+ wibox._apply_shape = qdelegate(function(env, self)
+ local shape = self._shape
+
+ if not shape then
+ self.shape_bounding = nil
+ self.shape_clip = nil
+ return
+ end
+
+ local geo = self:geometry()
+ local bw = self.border_width
+
+ if self.shape_width then
+ geo.width = self.shape_width
+ end
+
+ if self.shape_height then
+ geo.height = self.shape_height
+ end
+
+ -- First handle the bounding shape (things including the border)
+ local img = cairo.ImageSurface(cairo.Format.A1, geo.width + 2*bw, geo.height + 2*bw)
+ local cr = cairo.Context(img)
+
+ -- We just draw the shape in its full size
+ shape(cr, geo.width + 2*bw, geo.height + 2*bw)
+ cr:set_operator(cairo.Operator.SOURCE)
+ cr:fill()
+ self.shape_bounding = img._native
+ img:finish()
+
+ -- Now handle the clip shape (things excluding the border)
+ img = cairo.ImageSurface(cairo.Format.A1, geo.width, geo.height)
+ cr = cairo.Context(img)
+
+ -- We give the shape the same arguments as for the bounding shape and draw
+ -- it in its full size (the translate is to compensate for the smaller
+ -- surface)
+ cr:translate(-bw, -bw)
+ shape(cr, geo.width + 2*bw, geo.height + 2*bw)
+ cr:set_operator(cairo.Operator.SOURCE)
+ cr:fill_preserve()
+ -- Now we remove an area of width 'bw' again around the shape (We use 2*bw
+ -- since half of that is on the outside and only half on the inside)
+ cr:set_source_rgba(0, 0, 0, 0)
+ cr:set_line_width(2*bw)
+ cr:stroke()
+ self.shape_clip = img._native
+ img:finish()
+ end, old_apply_shape)
+
+ wibox:connect_signal("property::geometry", wibox._apply_shape)
+ wibox:connect_signal("property::border_width", wibox._apply_shape)
+ wibox:connect_signal("property::shape_width", wibox._apply_shape)
+ wibox:connect_signal("property::shape_height", wibox._apply_shape)
+
+ return wibox
+end
+
return M