This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Correct way to respond to activeScreen change?

Tags: None
(comma "," separated)
jrl
Registered Member
Posts
4
Karma
0
I have a three-monitor setup and the middle screen is an ultrawide. Sometimes that's just too many photons, so I want to have a mode where the side screens have their brightness dimmed after a few minutes of inactivity, but then return to full brightness when I move the mouse into them.

I'm not a KDE developer, but I was hoping I could do this with a Kwin script. I did figure out that workspace.activeScreen correctly tracks the screen (since my active screen follows mouse focus). And I am happy to modulate the brightness using xrandr. But problematically, I think there is no "activeDesktopChanged" signal to latch onto.

What's the recommended way of monitoring the activeScreen?

Thanks for any help!
-James
jrl
Registered Member
Posts
4
Karma
0
As far as I can tell, since workspace.activeScreen is a property, there should be an associated signal workspace.activeScreenChanged. That's supposed to be the philosophy according to the latest API I could find. Of course, the philosophy seems to change every five seconds with vast inconsistencies from minor version to minor version. Kudos.
jrl
Registered Member
Posts
4
Karma
0
For the sake of anyone reading this at some point in the future, here is the hack I used to solve my problem with a bash script:

Code: Select all
#!/bin/bash

WAIT=0.1
DELAY=1
LCOUNTER=1
RCOUNTER=1
highbright="0.9"
lowbright="0.4"
defaultbright="1.0"

SHORT=h:l:
LONG=high:,low:

trap "xrandr --output DP-2 --brightness $defaultbright; xrandr --output DP-0 --brightness $defaultbright; exit" SIGHUP SIGINT SIGTERM

PARSED=$(getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@")

if [[ $? -ne 0 ]]; then
   # getopt was ****
   exit 2
fi

eval set -- "$PARSED"

#echo "$PARSED"

while true; do

   case "$1" in

      -h|--high)
         highbright="$2"
         shift 2
         ;;

      -l|--low)
         lowbright="$2"
         shift 2
         ;;

      --)
         shift
         break
         ;;

      *)
         echo "Invalid argument."
         exit 3
         ;;

   esac

done

while true; do

   sleep $WAIT
   eval $(xdotool getmouselocation --shell)

   if (( X < 2560 )); then

      if (( LCOUNTER > 0 )); then
#         echo "ON LEFT, first time: $highbright"
         xrandr --output DP-0 --brightness "$highbright"
      fi

      let LCOUNTER=-1
#      echo "ON LEFT"

   elif (( X > 6000 )); then

      if (( RCOUNTER > 0)); then
#         echo "ON RIGHT, first time: $highbright"
         xrandr --output DP-2 --brightness "$highbright"
      fi

      let RCOUNTER=-1
#      echo "ON RIGHT"

   fi

   let LCOUNTER=LCOUNTER+1
   let RCOUNTER=RCOUNTER+1         

   if (( LCOUNTER == DELAY )); then
#      echo "LEFT GOING OFF: $lowbright"
      xrandr --output DP-0 --brightness "$lowbright"
   fi

   if (( RCOUNTER == DELAY )); then
#      echo "RIGHT GOING OFF: $lowbright"
      xrandr --output DP-2 --brightness "$lowbright"
   fi

done


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]