I want to change the brightness of my screen with awful.widget.launcher. The 
launcher should contain an icon, indicating the actual brightness. Clicking on 
the launcher should open a menu to choose the brightness value in percent.

Problem: When clicking on the launcher, the icon is changing immediately to the 
icon, which was first loaded after starting awesome, ignoring the actual 
brightness. Choosing a value from the list of the menu will update the icon 
properly. But if cancelling the menu, the wrong icon will remain.

For example, the brightness was 30% when starting awesome. I change the 
brightness with the launcher to 100%. No problem. But now I click on the 
launcher again: the launcher will show the 30% icon, despite the fact that I 
have not chosen a value from the menu. Pressing Escape will cancel the menu, 
but the wrong icon still remains: The brightness is 100% but the icon shows 30%.

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()


--
To unsubscribe, send mail to [email protected].

Reply via email to