-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi,

Am 15.09.2014 um 12:39 schrieb Zum Testen:
[...]
> mybrightness.lua (the global mybrightness_launcher will be added to my
> wibox):
> 
> local awful = require("awful")
> 
> local mybrightness_menu = awful.menu({ items = {{"100%", function()
> awful.util.pread("xbacklight -time 0 -set 100"); brightness_update() end}, 
> {" 30%", function() awful.util.pread("xbacklight -time 0 -set  30");
> brightness_update() end}}}) mybrightness_launcher =
> awful.widget.launcher({image = "bright100.png", menu = mybrightness_menu})
> 
> function brightness_update() local max_brightness = awful.util.pread('cat
> /sys/class/backlight/intel_backlight/max_brightness') local
> actual_brightness = awful.util.pread('cat
> /sys/class/backlight/intel_backlight/actual_brightness') local
> brightness_percent = 0 if max_brightness ~= nil and actual_brightness ~=
> nil then brightness_percent = actual_brightness * 100 / max_brightness end
> 
> if brightness_percent > 50 then brightness_icon = "bright100.png" else 
> brightness_icon = "bright030.png" end 
> mybrightness_launcher:set_image(brightness_icon) end
> 
> brightness_update()

Apparently, :set_image() was never intended to be usable on launchers / be
accessible after the widget was created.

Fixed with this commit:

http://git.naquadah.org/?p=awesome.git;a=commitdiff;h=a113fe0f3c268f10e1a0264d0fbc2962d3c562a7;hp=305f148c4b747b7e28f679deaf6a6872ebbf6f8d

That commit is also attached to this mail.

If you are using 3.5, you should be able to apply these changes to your
/usr/share/awesome/lib/awful/widget/button.lua and your code starts working.

Cheers,
Uli
- -- 
"Are you preparing for another war, Plutarch?" I ask.
"Oh, not now. Now we're in that sweet period where everyone agrees that our
recent horrors should never be repeated," he says. "But collective thinking is
usually short-lived. We're fickle, stupid beings with poor memories and a great
gift for self-destruction.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBCAAGBQJUFtV5AAoJECLkKOvLj8sGyzkH/itUsPywOP2TGAEzS8PJJuNA
2IEojotI2U0PWBbSVHb6omozWOJ2rENL39pXokkB6lcw1RNPSUqVwDd0fjDm/LSA
EdtoLH663xcBmncLr741p5HNxPi7GS/Kb0r9rBXft9WMEgjyLl0zFq/TWZcjuppF
N9hQCX722WH6qeRdoeNRpxisFRyVb9fY9hlR4jo4sb9aBnn8emav1K5NnUmtmm+q
6hKngYIZdXE1ghpQOpSmQKDzIJqH9XzmJfEPkS1UX0e6OiyBi3cnIsFans3UmyNn
tmEtHx5xFmFXl10igaGhN4vgizkLyfoSXFyViQqMsstPj1m/B9akvztrFjj6tAg=
=BxXf
-----END PGP SIGNATURE-----
From a113fe0f3c268f10e1a0264d0fbc2962d3c562a7 Mon Sep 17 00:00:00 2001
From: Uli Schlachter <[email protected]>
Date: Mon, 15 Sep 2014 13:55:21 +0200
Subject: [PATCH] awful.widget.button: Override :set_image() to do the right
 thing

Reported-at: http://article.gmane.org/gmane.comp.window-managers.awesome/10778
Signed-off-by: Uli Schlachter <[email protected]>
---
 lib/awful/widget/button.lua.in | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/lib/awful/widget/button.lua.in b/lib/awful/widget/button.lua.in
index 0f0d758..204081e 100644
--- a/lib/awful/widget/button.lua.in
+++ b/lib/awful/widget/button.lua.in
@@ -24,15 +24,22 @@ function button.new(args)
     if not args or not args.image then
         return widget.empty_widget()
     end
-    local img_release = surface.load(args.image)
-    local img_press = cairo.ImageSurface(cairo.Format.ARGB32, img_release.width, img_release.height)
-    local cr = cairo.Context(img_press)
-    cr:set_source_surface(img_release, 2, 2)
-    cr:paint()
 
     local w = imagebox()
-    w:set_image(img_release)
-    w:buttons(abutton({}, 1, function () w:set_image(img_press) end, function () w:set_image(img_release) end))
+    local orig_set_image = w.set_image
+    local img_release
+    local img_press
+
+    w.set_image = function(w, image)
+        img_release = surface.load(image)
+        img_press = img_release:create_similar(cairo.Content.COLOR_ALPHA, img_release.width, img_release.height)
+        local cr = cairo.Context(img_press)
+        cr:set_source_surface(img_release, 2, 2)
+        cr:paint()
+        orig_set_image(w, img_release)
+    end
+    w:set_image(args.image)
+    w:buttons(abutton({}, 1, function () orig_set_image(w, img_press) end, function () orig_set_image(w, img_release) end))
     return w
 end
 
-- 
2.1.0

Attachment: 0001-awful.widget.button-Override-set_image-to-do-the-rig.patch.sig
Description: PGP signature

Reply via email to