07-07-2020, 10:21 PM
(This post was last modified: 07-07-2020, 10:29 PM by antiX-Dave.)
Going off into my thoughts in the flashlight app thread I have been trying to see where the proximity /light sensor is being monitored to blank the screen if covered. I have not yet found where this is but suspect it is programmed within phosh/phoc. I was hoping to add a section to this where if the light level is above the threshold to blank the screen but below another threshold it would change the gtk theme to a dark variant.
After spending some time looking and not finding, I thought it might be done with an udev rule like:
Where set-dark-theme contains
Of course doing only this would need a manual reset; but it should be good enough for testing...
Unfortunately the event does not trigger when the light level changes, only when the sensor is added as far as udev is concerned. This works by restarting udev which is nice, but does not really help anything.
Next I thought to hook into the lock screen unlock where a script would run to check the value in /sys/bus/iio/devices/iio\:device1/in_illuminance_raw and set the theme accordingly. (If you had an incorrect theme pressing the power button and unlocking would switch it) Tried a few spots that I thought might hook into the lock screen but without success.
It is probably not the best idea to constantly probe. However as a proof of concept, a simple bash script. (Most visible difference with gnome-clocks and the flashlight app)
Any information/pointers to bring this past a looping bash script?
After spending some time looking and not finding, I thought it might be done with an udev rule like:
Code:
# Set the theme based on light level
ACTION=="add|change", SUBSYSTEM=="iio", KERNEL=="iio:device1", ATTR{in_illuminance_raw}=="[0-9]|[0-9][0-9]", RUN+="/bin/su mobian -c /usr/local/bin/set-dark-theme"
Where set-dark-theme contains
Code:
#!/bin/sh
gsettings set org.gnome.desktop.interface gtk-theme Adwaita-dark
Of course doing only this would need a manual reset; but it should be good enough for testing...
Unfortunately the event does not trigger when the light level changes, only when the sensor is added as far as udev is concerned. This works by restarting udev which is nice, but does not really help anything.
Next I thought to hook into the lock screen unlock where a script would run to check the value in /sys/bus/iio/devices/iio\:device1/in_illuminance_raw and set the theme accordingly. (If you had an incorrect theme pressing the power button and unlocking would switch it) Tried a few spots that I thought might hook into the lock screen but without success.
It is probably not the best idea to constantly probe. However as a proof of concept, a simple bash script. (Most visible difference with gnome-clocks and the flashlight app)
Code:
#!/bin/sh
while : ; do
reading=`cat /sys/bus/iio/devices/iio\:device1/in_illuminance_raw`
if [ "$reading" -lt "100" ]; then
gsettings set org.gnome.desktop.interface gtk-theme Adwaita-dark
while : ; do
reading=`cat /sys/bus/iio/devices/iio\:device1/in_illuminance_raw`
if [ "$reading" -gt "100" ]; then
gsettings set org.gnome.desktop.interface gtk-theme Adwaita
break;
fi
sleep 10;
done
sleep 10;
fi
done
Any information/pointers to bring this past a looping bash script?