[英]Change icon color by means of awesome wm
在超贊的wm 3.5中,您可以使用cairo創建自定義窗口小部件以繪制其外觀。 我想要一個顯示單色PNG圖標的小部件(例如wibox.widget.imagebox可以這樣做),並允許快速更改其顏色。 我試圖在wibox.widget.imagebox的繪制功能中修改幾行
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
但這是行不通的。 我嘗試設置其他一些cairo的合成運算符,但大多數運算符均未達到預期。 錯誤的重疊區域和黑色區域,而不是Wibox背景顏色。 SOURCE和OVER都是正確的。 我在哪里弄錯了?
錯誤是您對開羅的繪畫方法的理解。 黑色/透明是IN在其未觸摸的地方留下的東西。 換句話說,您首先要在背景上繪制其他內容,因此背景會丟失。
嘗試以下方法:
local pat = require("lgi").cairo.Pattern
cr:set_source_rgba(0, 0, 1, 0.5)
cr:mask(pat.create_for_surface(self._image), 0, 0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.