From 3e85ddb11d33e5dd92c1ca091aa990711942155e Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 9 Jul 2016 10:28:42 +0200 Subject: [PATCH 1/3] Add a test for drawable:set_bgimage() Signed-off-by: Uli Schlachter --- tests/test-drawable-bgimage.lua | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/test-drawable-bgimage.lua diff --git a/tests/test-drawable-bgimage.lua b/tests/test-drawable-bgimage.lua new file mode 100644 index 00000000..b3fb7a74 --- /dev/null +++ b/tests/test-drawable-bgimage.lua @@ -0,0 +1,56 @@ +local runner = require("_runner") +local wibox = require("wibox") +local beautiful = require("beautiful") +local cairo = require("lgi").cairo + +local w = wibox { + x = 10, + y = 10, + width = 20, + height = 20, + visible = true, + bg = "#ff0000", +} + +local callback_called +local function callback(context, cr, width, height, arg) + assert(type(context) == "table", type(context)) + assert(type(context.dpi) == "number", context.dpi) + assert(cairo.Context:is_type_of(cr), cr) + assert(width == 20, width) + assert(height == 20, height) + assert(arg == "argument: 42", arg) + + callback_called = true +end + +runner.run_steps({ + -- Set some bg image + function() + local img = assert(beautiful.titlebar_close_button_normal) + w:set_bgimage(img) + return true + end, + + -- Do nothing for a while iteration to give the repaint some time to happen + function(arg) + if arg == 3 then + return true + end + end, + + -- Set some bg image function + function() + w:set_bgimage(callback, "argument: 42") + return true + end, + + -- Wait for the function to be done + function() + if callback_called then + return true + end + end, +}) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 From d4454aba1523ce3ee6af5b3f7f0ebe500c952c12 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 9 Jul 2016 10:29:05 +0200 Subject: [PATCH 2/3] Fix drawable:set_bgimage() When called with the file name of an image, this function failed to turn that file name into a cairo surface. Fixes: https://github.com/awesomeWM/awesome/issues/954 Signed-off-by: Uli Schlachter --- lib/wibox/drawable.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index 75cce527..38d554e7 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -237,6 +237,9 @@ end -- as arguments. Any other arguments passed to this method will be appended. -- @param image A background image or a function function drawable:set_bgimage(image, ...) + if type(image) ~= "function" then + image = surface(image) + end self.background_image = image self.background_image_args = {...} From 7f74c7c859234452aaf31ab48be0af351c47663d Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 9 Jul 2016 10:30:36 +0200 Subject: [PATCH 3/3] drawable: Draw bgimage with operator OVER The actual bg is drawn either with fake transparency over the wallpaper (this uses operator OVER) or for true transparency with operator SOURCE. The bgimage should be drawn ontop of this without erasing the background and thus needs operator OVER. However, before this commit the bgimage was drawn in the same way as the bg and thus inherited its SOURCE operator if a compositor is running. Fix this by restoring the default operator (OVER) and also e.g. the default source before drawing the bgimage. Fixes: https://github.com/awesomeWM/awesome/issues/954 Signed-off-by: Uli Schlachter --- lib/wibox/drawable.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index 38d554e7..10cd8cfd 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -123,8 +123,11 @@ local function do_redraw(self) cr:set_source(self.background_color) cr:paint() + cr:restore() + -- Paint the background image if self.background_image then + cr:save() if type(self.background_image) == "function" then self.background_image(context, cr, width, height, unpack(self.background_image_args)) else @@ -132,10 +135,9 @@ local function do_redraw(self) cr:set_source(pattern) cr:paint() end + cr:restore() end - cr:restore() - -- Draw the widget if self._widget_hierarchy then cr:set_source(self.foreground_color)