You are not logged in.

#1 2011-08-23 13:57:21

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

[Solved] Brightness notifications?

Hello,

For aesthetic reasons I would like to have a notification when I change my brightness, like you also have volume notifications. I know the power managers (gnome and xfce) supply this feature, but I don't want to use either of them, so is there any stand-alone application (for example, you have xfce-volumed for volume notifications) for brightness? I already searched the AUR but came up with nothing that looked promising.

Last edited by Unia (2011-08-27 11:07:57)


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#2 2011-08-23 22:52:52

MoonSwan
Member
From: Great White North
Registered: 2008-01-23
Posts: 881

Re: [Solved] Brightness notifications?

I too would like an answer to this!  The only thing I've seen is what Asus did on the original Eeepc (701) which had a nifty little OSD for a lot of things.

Offline

#3 2011-08-24 17:23:47

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

Perhaps someone who can actually code could do something with that?


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#4 2011-08-24 18:07:48

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [Solved] Brightness notifications?

I have this:

#!/bin/bash

brightness="/sys/class/backlight/acpi_video0/brightness"
presbright=`cat /sys/class/backlight/acpi_video0/brightness`
perc=`expr $presbright "*" 100 "/" 24`

case "$1" in
	up)
	  echo $(( ${presbright}+1 )) > $brightness
	  sudo -u $user notify-send " " -i notification-display-brightness-low -h int:value:$perc -h string:x-canonical-private-synchronous:brightness &
	;;
	down)
	  echo $(( ${presbright}-1 )) > $brightness
	  sudo -u $user notify-send " " -i notification-display-brightness-low -h int:value:$perc -h string:x-canonical-private-synchronous:brightness &
	;;
	status)
	  echo $presbright
	;;
	*)
	  echo "Accepted arguments are: up, down, status."
	;;
esac

exit 0

My brightness keys didn't work out of the box, so I wrote a script for it. I just added the notification stuff (used notify-osd) today. Replace $user with your username, or prefix cat with sudo - whatever suits your scenario best. My brightness keys generate ACPI events and the script is called by the ACPI daemon, so everything is run as root, but notify-send won't work because root isn't authenticated with D-Bus etc. blabla. You also need to replace 24 with the maximum value your backlight supports.

Last edited by .:B:. (2011-08-24 18:09:38)


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#5 2011-08-24 19:52:31

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

So you wrote that for notify-osd? Do you happen to know any way I could adjust for xfce4-notifyd? Also, how would I find out the max brightness? And how would I make it called by the ACPI daemon?

sorry for the many questions, am totally new to this sort of stuff...

Last edited by Unia (2011-08-24 19:54:34)


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#6 2011-08-24 19:58:11

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

Re: [Solved] Brightness notifications?

Won't work with xfce4-notifyd, the synchronous hint is only understood by notify-osd. For all other notifiers you need to update them programmatically. Which means either C or python. Kinda shame, because the synchronous hint is perfect for such shell scripting.

Offline

#7 2011-08-24 20:02:00

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

Hmm.. I'm willing to give notify-osd a shot.

Say I installed that, I would only have to look up my max brightness and change the $user value, no?


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#8 2011-08-24 20:05:25

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [Solved] Brightness notifications?

Yes. Also, if you take a careful look at the variables in my script, it's pretty easy to find out where your brightness values are stored.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#9 2011-08-24 20:07:29

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

Ok, thank you! I will have a go at this tomorrow!


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#10 2011-08-25 15:46:02

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

Where would I put my max brightness? I assume somewhere in this line, but I would like to be sure before I might harm my hardware:

perc=`expr $presbright "*" 100 "/" 24`

Also, you said you had the ACPI daemon call the script, how would I do that?


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#11 2011-08-25 22:03:56

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [Solved] Brightness notifications?

Unia wrote:

Where would I put my max brightness? I assume somewhere in this line, but I would like to be sure before I might harm my hardware:

perc=`expr $presbright "*" 100 "/" 24`

Like I said:

.:B:. wrote:

You also need to replace 24 with the maximum value your backlight supports.

Unia wrote:

Also, you said you had the ACPI daemon call the script, how would I do that?

Adapt /etc/acpi/handler.sh. But as I said: that only works if it generates ACPI events.

Last edited by .:B:. (2011-08-25 22:04:19)


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#12 2011-08-25 22:47:07

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,793

Re: [Solved] Brightness notifications?

Moved to Newbie Corner.  Have you checked the Wiki for some of these questions?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#13 2011-08-26 17:40:53

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

ewaller wrote:

Have you checked the Wiki for some of these questions?

Not for the max brightness, I guess I misread .:B:.'s post or not good enough. For the ACPI, I did search but didn't know the article I need was "ACPI Hotkeys". I did not scan those pages because of limited time.

I will have a go at all this now - I do have time now since it's weekend big_smile


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#14 2011-08-26 19:02:34

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

Well.. I got it all working now - but when I'm using the notifications, it seems like switching brightness levels is a bit choppier (and more flashing) than without the notifications.
Also, my max brightness is 9:

┌─[jente@lappy ~][20:57:26] 
└─■ cat /sys/class/backlight/acpi_video0/max_brightness
9

But with notifications enabled it only goes up to 8. Lastly, whilst decreasing brightness, it goes down to 0 in just four steps.

Is something wrong?

EDIT: When I edit the script to not modify /sys/class/backlight/acpi_video0/brightness, the switching is as it should be. I am now working on editing the script to only get the current brightness level and calculate a percentage from there. As my bash skills (sadly) aren't that good, I'm puzzling now, but I will post the results once I'm done!

Last edited by Unia (2011-08-26 20:00:14)


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#15 2011-08-27 09:57:59

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

Done! Somehow it firstly didn't want to accept the expr command, so I tried all sorts of stuff, but this morning it suddenly accepted expr so in the end, the script didn't change that much. Anyway, here's my version:

#!/bin/bash

curbright=`cat /sys/class/backlight/acpi_video0/brightness`
perc=`expr $curbright "*" 100 "/" 9`

case "$1" in
	up)
	  sudo -u jente notify-send " " -i notification-display-brightness-low -h int:value:$perc -h string:x-canonical-private-synchronous:brightness &
	;;
	down)
	  	  sudo -u jente notify-send " " -i notification-display-brightness-low -h int:value:$perc -h string:x-canonical-private-synchronous:brightness &
	;;
	status)
	  echo $curbright
	;;
	*)
	  echo "Accepted arguments are: up, down, status."
	;;
esac

exit 0

If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#16 2011-08-27 18:33:17

MoonSwan
Member
From: Great White North
Registered: 2008-01-23
Posts: 881

Re: [Solved] Brightness notifications?

Thanks to .:B:. and Unia's for their efforts.  I'm sorry I couldn't contribute anything meaningful (I can't code for beans).  I will try both scripts now and see which fits my netbook's configuration.

Offline

#17 2011-08-29 05:41:59

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [Solved] Brightness notifications?

As for volume notifications, the xfce4-volumed will monitor the Master level and display a popup accordingly, you don't need any scripting for that. Apparently that notification stuff also picks up on downloads in Firefox and lets you know when they're done... Kinda creepy, really.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#18 2011-08-29 12:00:52

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

Re: [Solved] Brightness notifications?

Nothing creepy about it, it's Firefox that sends notifications. That's the point of having a notification daemon, it's there so that apps can display notifications in a consistent way. If you compile Firefox yourself, you can turn that off, so that Firefox will use an internal notification mechanism.

Offline

#19 2011-08-29 16:23:40

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

.:B:. wrote:

As for volume notifications, the xfce4-volumed will monitor the Master level and display a popup accordingly, you don't need any scripting for that.

I asked you for that because a script like your brightness script would be lighter. And it could make me drop all xfce dependencies I have (which basically are just those for xfce4-volumed).


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#20 2011-08-29 16:32:10

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [Solved] Brightness notifications?

Sorry man, don't have a script for it. I use xfce4-volumed myself, I have some XFCE libs installed anyway (Thunar etc.) so it didn't add any overhead.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#21 2011-08-29 16:47:34

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

That's cool. It's not that heavy anyway and it does a good job. Thanks again for your brightness script, it's working like a charm!


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#22 2011-09-02 18:27:37

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [Solved] Brightness notifications?

For anyone interested, I found a volume script after all on our boards. Here's the topic link:
https://bbs.archlinux.org/viewtopic.php?id=69589

And here is the script itself:

#!/bin/sh

usage="usage: $0 -c {up|down|mute} [-i increment] [-m mixer]"
command=
increment=5%
mixer=Master

while getopts i:m:h o
do case "$o" in
    i) increment=$OPTARG;;
    m) mixer=$OPTARG;;
    h) echo "$usage"; exit 0;;
    ?) echo "$usage"; exit 0;;
esac
done

shift $(($OPTIND - 1))
command=$1

if [ "$command" = "" ]; then
    echo "usage: $0 {up|down|mute} [increment]"
    exit 0;
fi

display_volume=0

if [ "$command" = "up" ]; then
    display_volume=$(amixer set $mixer $increment+ unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
fi

if [ "$command" = "down" ]; then
    display_volume=$(amixer set $mixer $increment- unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
fi

icon_name=""

if [ "$command" = "mute" ]; then
    if amixer get Master | grep "\[on\]"; then
        display_volume=0
        icon_name="notification-audio-volume-muted"
        amixer set $mixer mute
    else
        display_volume=$(amixer set $mixer unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
    fi
fi

if [ "$icon_name" = "" ]; then
    if [ "$display_volume" = "0" ]; then
        icon_name="notification-audio-volume-off"
    else
        if [ "$display_volume" -lt "33" ]; then
            icon_name="notification-audio-volume-low"
        else
            if [ "$display_volume" -lt "67" ]; then
                icon_name="notification-audio-volume-medium"
            else
                icon_name="notification-audio-volume-high"
            fi
        fi
    fi
fi
notify-send " " -i $icon_name -h int:value:$display_volume -h string:synchronous:volume

If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#23 2011-12-25 00:41:56

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [Solved] Brightness notifications?

As a follow-up, if you happen to use the notify-osd-icons (in the AUR), I have a more fine-grained script that uses the different brightness statuses (it provides five different stages - off, low, medium, high, full).

brightness="/sys/class/backlight/acpi_video0/brightness"
presbright=$(cat /sys/class/backlight/acpi_video0/brightness)
perc=$(expr $presbright "*" 100 "/" 8)


	video/brightnessdown)
		case "$2" in
		  BRTDN)
		    echo $(( ${presbright}-1 )) > $brightness
                    if [ $presbright = 1
		    if [ $presbright = 0 ]
		    then
		      sudo -u $user notify-send " " -i notification-display-brightness-off -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
		    elif [ $presbright = 1 ]
		    then
		      sudo -u $user notify-send " " -i notification-display-brightness-low -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
		    elif [ $presbright = 2 ]
                    then
		      sudo -u $user notify-send " " -i notification-display-brightness-low -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
		    elif [ $presbright = 3 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-medium -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
		    elif [ $presbright = 4 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-medium -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
		    elif [ $presbright = 5 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-medium -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
		    elif [ $presbright = 6 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-high -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
		    elif [ $presbright = 7 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-high -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
		    fi
		    ;;
		esac
		;;

	video/brightnessup)
		case "$2" in
		  BRTUP)
		    echo $(( ${presbright}+1 )) > $brightness
                    if [ $presbright = 1 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-low -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
                    elif [ $presbright = 2 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-low -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
                    elif [ $presbright = 3 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-medium -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
                    elif [ $presbright = 4 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-medium -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
                    elif [ $presbright = 5 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-medium -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
                    elif [ $presbright = 6 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-high -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
                    elif [ $presbright = 7 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-high -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
                    elif [ $presbright = 8 ]
                    then
                      sudo -u $user notify-send " " -i notification-display-brightness-full -h int:value:$perc -h string:x-canonical-private-synchronous:brightness
                    fi
		    ;;
		esac
		;;

This is part of my ACPI handler.sh script.

Last edited by .:B:. (2011-12-25 00:42:21)


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

Board footer

Powered by FluxBB