Xfce Forum

Sub domains
 

You are not logged in.

#1 2019-05-13 19:16:49

japers
Member
Registered: 2013-01-26
Posts: 3

Controlling LED Backlight from Keyboard

Recently installed Debian testing (pre-release Buster) on an Intel NUC with Intel IRIS graphics. I've been using Xfce for a long time and decided to try LXQt, just for grins. It's a nice DE. I still prefer Xfce.

I'm using a Cherry desktop keyboard with no dedicated brightness keyss. I was able, under LXQt, to assign key combinations for increasing and decreasing brightness. That turned out to be very helpful for me in a room where brightness varies from vampire killer to bat friendly. I miss the ability LXQt had to adjust backlight brightness from the keyboard.  Under Xfce I'm having to fiddle with the inconsistent Dell monitor membrane pushbutton controls to control screen brightness.

I've searched for information on how to roll my own. I'm surprised to find no clear and definitive information. (Just realized I should have looked at the Arch wiki. They almost always have useful info on things like this.) I can see that changes to the features of the power manager and other desktop environment changes have caused old solutions to not work any more.

Suggestions for an old guy with rheumy eyes? A step-by-step would be very nice. Xfce is so highly customizable and nice-looking I'm a little surprised that we went from having a brightness plugin for the panel to having to twiddle with monitor buttons.

Thanks,
japers

Offline

#2 2019-05-14 18:30:11

Misko_2083
Member
Registered: 2015-10-13
Posts: 191
Website

Re: Controlling LED Backlight from Keyboard

Well you could use some bits from next script:

#!/bin/bash
# Script to set the monitor brightness

ERR(){ echo "ERROR: $1" 1>&2; }

declare -i DEPCOUNT=0
for DEP in /usr/bin/{xdotool,yad,xrandr};do
    [ -x "$DEP" ] || {
        ERR "$LINENO Dependency '$DEP' not met."
        DEPCOUNT+=1
        }
done

[ $DEPCOUNT -eq 0 ] || exit 1

VERSION=`yad --version | awk '{ print $1 }'`
verlte() {
    [  "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}

verlt() {
    [ "$1" = "$2" ] && return 1 || verlte $1 $2
}

if verlt $VERSION 0.38.2; then
   yad --text=" The version of yad installed is too old for to run this program, \n Please upgrade yad to a version higher than 0.38.2   " \
       --button="gtk-close"
   exit
fi 


# Set the icon here
ICON="sunny"

# fifo
export YAD_NOTIF=$(mktemp -u --tmpdir YAD_NOTIF.XXXXXX)
mkfifo "$YAD_NOTIF" 

# trap that removes fifo
trap "rm -f $YAD_NOTIF" EXIT 

# window class for the list dialog
export CLASS="brightness_001" 

yad_scale() {
# Ensures only one instance of this window
# if there is another yad window close any dialog with the mathing class
if [[ $(pgrep -c $(basename $0)) -ne 1 ]]; then
   pids="$(xdotool search --class "$CLASS")"
   wpid="$(xdotool getwindowfocus)"

   for pid in $pids; do
        # Compares window class pid with the pid of a window in focus
        if [[ "$pid" == "$wpid" ]]; then
           xdotool windowunmap $pid
           exit 1
        fi
   done
fi 


# detect monitor
MON=$(xrandr -q | grep " connected" | cut -f1 -d ' ')

# find current xrandr brightness value
XR=$(xrandr --verbose | grep -i brightness | cut -f2 -d ' ' | head -n1)
BrCur=`awk "BEGIN {print $XR*100}"` # calculate, so e.g. 0.5 gets 50
BrMax="100"
BrMin="5"

yad --scale  --mouse   --class="$CLASS" --skip-taskbar --min-value $BrMin --max-value $BrMax \
    --value $BrCur --print-partial --undecorated --width 300 \
    --on-top --escape-ok --no-buttons --hide-value --close-on-unfocus \
| while read BrNew; do
    # division using awk, so xrandr value gets e.g. 0.5 rather than 50
    xrandr --output $MON --brightness $(awk "BEGIN {print $BrNew/100}")
done
}
export -f yad_scale

# fuction to set the notification icon
function set_notification_icon() {
  echo "icon:$ICON"
  echo "tooltip:brighness control"
  echo "menu:About!bash -c 'yad --about'!gtk-about||Quit!quit!gtk-quit"
}

exec 3<> $YAD_NOTIF

yad --notification --command="bash -c yad_scale" --listen <&3 & notifpid=$!

# waits until the notification icon is ready
until xdotool getwindowname $(xdotool search --pid "$notifpid" | tail -1) &>/dev/null; do
        # sleep until the window opens
        sleep 0.5       
done

set_notification_icon >&3 

The script sets the notification icon.
Once you click on the icon it displays a scale that you can move and set the brighness.

Dependancies: yad (v0.38 or better), xrandr,  xdotool


Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

#3 2019-05-15 04:15:24

japers
Member
Registered: 2013-01-26
Posts: 3

Re: Controlling LED Backlight from Keyboard

Misko_2083, thank you!

I tested this solution, and it works perfectly. I really appreciate your post. You gave me a quick and efficient solution.

I'm parsing it to see if I can follow the logic all the way through. I'm old, my eyes are troublesome, and I live with many distractions.

I found an article on "Backlight" at the Arch wiki and am delving into it, and other information on controlling external monitors. There are so many approaches to controlling display panel brightness on laptops alone. It will keep me occupied for a while.

Many thanks, again!

Offline

Board footer

Powered by FluxBB