素晴らしい wm 3.5 では、cairo を使用してカスタム ウィジェットを作成し、ビジュアルを描画できます。モノクロのPNGアイコンを表示し(wibox.widget.imageboxのように)、その色をすばやく変更できるウィジェットが必要です。wibox.widget.imagebox の draw 関数で数行修正してみました
local cairo = require("lgi").cairo
--- Draw an imagebox with the given cairo context in the given geometry.
function imagebox:draw(wibox, cr, width, height)
if not self._image then return end
if width == 0 or height == 0 then return end
cr:save()
if not self.resize_forbidden then
-- Let's scale the image so that it fits into (width, height)
local w = self._image:get_width()
local h = self._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
-- Here is my modifications
cr:set_source_surface(self._image, 0, 0)
cr:paint()
cr:set_operator(cairo.Operator.IN)
cr:set_source_rgba(0, 0, 1, 0.5)
cr:paint()
-- End of my my modifications
-- This is original draw code how it was
--cr:set_source_surface(self._image, 0, 0)
--cr:paint()
cr:restore()
end
しかし、うまくいきません。他のいくつかのカイロの合成演算子を設定しようとしましたが、それらのほとんどは期待どおりに機能しません。wibox の背景色ではなく、間違ったオーバーラップ エリアと黒い領域。SOURCE と OVER は正常に動作するだけです。どこで間違えたのですか?