You are not logged in.

#1 2024-12-05 11:41:44

macromal
Member
Registered: 2024-08-03
Posts: 26

Night light

I create this simple script to set nocturne light in my window manager using xrandr.

#!/bin/sh

set_gamma() {
        for monitor in $(xrandr --listmonitors | awk 'NR>1 {print $NF}'); do
                xrandr --output "$monitor" --gamma "$1"
        done
}


if xrandr --verbose | grep -q "Gamma: *1.0:1.0:1.0"; then
        gamma="1:1:0.5"
else
        gamma="1:1:1"
fi

set_gamma "$gamma"

Do you know a better solution or program to use?

Offline

#2 2024-12-06 10:12:16

macromal
Member
Registered: 2024-08-03
Posts: 26

Re: Night light

Finally, I improved the script to incorporate the red light, which scientists recommend.

#!/bin/sh

NIGHT="1.0:1.0:0.5"
NORMAL="1.0:1.0:1.0"
RED="1.0:0.5:0.5"

usage() {
	printf '%s\n' "usage: nocturne [-r|--red]"
}

set_gamma() {
	for monitor in $(xrandr --listmonitors | awk 'NR>1 {print $NF}'); do
		xrandr --output "$monitor" --gamma "$gamma"
	done
}


while :; do
	case "$1" in
		-h | --h | --he | --hel | --help)
			usage
			exit 0
		;;

		-r | --red)
			gamma="$RED"
		;;

		-*)	 
			print_error "Unknown option: $1"
			usage
			exit 1
		;;

		*)
			break
		;;

	esac
	shift
done


actual="$(xrandr --verbose | awk '/Gamma/ {print $2}')"

if [ "$actual" = "$NORMAL" ]; then
	[ -z "$gamma" ] && gamma="$NIGHT"
else
	gamma="$NORMAL"
fi


if [ "$gamma" != "$actual" ]; then
	set_gamma "$gamma"
fi

Offline

#3 2024-12-06 14:58:43

seth
Member
Registered: 2012-09-03
Posts: 60,776

Offline

#4 2024-12-07 20:09:50

macromal
Member
Registered: 2024-08-03
Posts: 26

Re: Night light

I had seen it, but all those localization options scared me. I preferred the simple alternative using xrandr. I've been using the red light for a few days and I can hold out a bit longer now in front of the computer.

By the way, I had forgotten to define the print_error function.

print_error() {
	printf '\e[1;38;5;1m%s\e[m\n' "$1" >&2
}

Offline

#5 2024-12-07 21:43:11

seth
Member
Registered: 2012-09-03
Posts: 60,776

Re: Night light

I had seen it, but all those localization options scared me.

?
You tell it your geolocation so it can calculate the daylight timeframe, https://wiki.archlinux.org/title/Redshi … n_manually doesn't require any online queries.
But you don't acutally have to, you can just define dusk and dawn time (though that's cumbersome): https://man.archlinux.org/man/extra/red … #dawn_time

If you're super-worried about typing your geolocation anywhere, flipping the lattitude won't change anything about the sunrise/set  and you can also invert the temperatures and brightness and rotate your longitude by 180° smile

Edit: that's obviously wrong and dumb and I need more sleep.

Last edited by seth (2024-12-07 21:54:45)

Offline

#6 2024-12-17 09:23:16

macromal
Member
Registered: 2024-08-03
Posts: 26

Re: Night light

It doesn't work for multiple monitors. The solution is to return the first occurrence with awk.

actual="$(xrandr --verbose | awk '/Gamma/ {print $2; exit}')"

Offline

Board footer

Powered by FluxBB