Tint the screen at night.

This commit is contained in:
Tom Alexander 2024-07-21 21:48:48 -04:00
parent 3a63d4d307
commit 621625d831
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
12 changed files with 132 additions and 20 deletions

View File

@ -1,5 +1,5 @@
options iwlwifi power_save=1 #options iwlwifi power_save=1
options iwlwifi uapsd_disable=0 #options iwlwifi uapsd_disable=0
options iwlmvm power_scheme=3 #options iwlmvm power_scheme=3

View File

@ -49,7 +49,7 @@ function copy {
PASSWORD="$2" PASSWORD="$2"
set -x set -x
exec ffmpeg \ </dev/null exec ffmpeg \
-re \ -re \
-stream_loop -1 \ -stream_loop -1 \
-i "$file_to_cast" \ -i "$file_to_cast" \
@ -71,7 +71,7 @@ function h264 {
set -x set -x
# -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames. # -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames.
exec ffmpeg \ </dev/null exec ffmpeg \
-re \ -re \
-stream_loop -1 \ -stream_loop -1 \
-init_hw_device vaapi=foo:/dev/dri/renderD128 \ -init_hw_device vaapi=foo:/dev/dri/renderD128 \
@ -100,7 +100,7 @@ function preprocess_hardware_h264 {
set -x set -x
# -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames. # -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames.
exec ffmpeg \ </dev/null exec ffmpeg \
-init_hw_device vaapi=foo:/dev/dri/renderD128 \ -init_hw_device vaapi=foo:/dev/dri/renderD128 \
-hwaccel vaapi \ -hwaccel vaapi \
-hwaccel_output_format vaapi \ -hwaccel_output_format vaapi \
@ -109,9 +109,12 @@ function preprocess_hardware_h264 {
-filter_hw_device foo \ -filter_hw_device foo \
-vf 'format=nv12|vaapi,hwupload' \ -vf 'format=nv12|vaapi,hwupload' \
-c:v h264_vaapi \ -c:v h264_vaapi \
-b:v 2M \
-profile:v high \
-bf 0 \ -bf 0 \
-strict -2 \ -strict -2 \
-c:a opus \ -c:a opus \
-ac 2 \
-b:a 320k \ -b:a 320k \
-ar 48000 \ -ar 48000 \
"$file_to_save" "$file_to_save"
@ -128,7 +131,7 @@ function software_h264 {
set -x set -x
# -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames. # -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames.
exec ffmpeg \ </dev/null exec ffmpeg \
-re \ -re \
-stream_loop -1 \ -stream_loop -1 \
-i "$file_to_cast" \ -i "$file_to_cast" \
@ -150,7 +153,7 @@ function preprocess_h264 {
set -x set -x
# -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames. # -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames.
exec ffmpeg \ </dev/null exec ffmpeg \
-i "$file_to_cast" \ -i "$file_to_cast" \
-c:v h264 \ -c:v h264 \
-bf 0 \ -bf 0 \
@ -171,7 +174,7 @@ function vp9 {
set -x set -x
# -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames. # -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames.
exec ffmpeg \ </dev/null exec ffmpeg \
-re \ -re \
-stream_loop -1 \ -stream_loop -1 \
-init_hw_device vaapi=foo:/dev/dri/renderD128 \ -init_hw_device vaapi=foo:/dev/dri/renderD128 \
@ -200,7 +203,7 @@ function preprocess_hardware_vp9 {
set -x set -x
# -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames. # -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames.
exec ffmpeg \ </dev/null exec ffmpeg \
-init_hw_device vaapi=foo:/dev/dri/renderD128 \ -init_hw_device vaapi=foo:/dev/dri/renderD128 \
-hwaccel vaapi \ -hwaccel vaapi \
-hwaccel_output_format vaapi \ -hwaccel_output_format vaapi \
@ -229,14 +232,14 @@ function software_vp8 {
# -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames. # -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames.
# -strict -2 :: Enable support for experimental codecs like opus. # -strict -2 :: Enable support for experimental codecs like opus.
# -b:v 1M :: Target 1 megabit/s # -b:v 2M :: Target 2 megabit/s
# -crf 10 :: Target a quality level and adjust bitrate accordingly. This should be preferred, but ideally both should be used. # -crf 10 :: Target a quality level and adjust bitrate accordingly. This should be preferred, but ideally both should be used.
exec ffmpeg \ </dev/null exec ffmpeg \
-re \ -re \
-stream_loop -1 \ -stream_loop -1 \
-i "$file_to_cast" \ -i "$file_to_cast" \
-c:v vp8 \ -c:v vp8 \
-b:v 1M \ -b:v 2M \
-crf 10 \ -crf 10 \
-bf 0 \ -bf 0 \
-c:a opus \ -c:a opus \
@ -257,12 +260,12 @@ function preprocess_vp8 {
# -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames. # -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames.
# -strict -2 :: Enable support for experimental codecs like opus. # -strict -2 :: Enable support for experimental codecs like opus.
# -b:v 1M :: Target 1 megabit/s # -b:v 2M :: Target 2 megabit/s
# -crf 10 :: Target a quality level and adjust bitrate accordingly. This should be preferred, but ideally both should be used. # -crf 10 :: Target a quality level and adjust bitrate accordingly. This should be preferred, but ideally both should be used.
exec ffmpeg \ </dev/null exec ffmpeg \
-i "$file_to_cast" \ -i "$file_to_cast" \
-c:v vp8 \ -c:v vp8 \
-b:v 1M \ -b:v 2M \
-crf 10 \ -crf 10 \
-bf 0 \ -bf 0 \
-c:a opus \ -c:a opus \
@ -281,7 +284,7 @@ function webcam {
set -x set -x
exec ffmpeg \ </dev/null exec ffmpeg \
-re \ -re \
-input_format h264 \ -input_format h264 \
-video_size 1920x1080 \ -video_size 1920x1080 \
@ -302,7 +305,7 @@ function encode_webcam {
set -x set -x
exec ffmpeg \ </dev/null exec ffmpeg \
-re \ -re \
-vaapi_device /dev/dri/renderD128 \ -vaapi_device /dev/dri/renderD128 \
-i /dev/video0 \ -i /dev/video0 \

View File

@ -4,4 +4,5 @@
# Have to use yt-dlp instead of youtube_dl because of mpv # Have to use yt-dlp instead of youtube_dl because of mpv
# - youtube_dl # - youtube_dl
- yt-dlp - yt-dlp
- mkvtoolnix # for mkvmerge
state: present state: present

View File

@ -19,4 +19,5 @@
name: name:
- yt-dlp - yt-dlp
- go-chromecast-git - go-chromecast-git
- mkvtoolnix-cli # for mkvmerge
state: present state: present

View File

@ -1,3 +1,4 @@
accessibility/wlsunset
archivers/unrar archivers/unrar
archivers/unzip archivers/unzip
archivers/zip archivers/zip
@ -43,6 +44,7 @@ multimedia/libva-intel-driver
multimedia/libva-intel-media-driver multimedia/libva-intel-media-driver
multimedia/libva-utils multimedia/libva-utils
multimedia/libvdpau-va-gl multimedia/libvdpau-va-gl
multimedia/mkvtoolnix
multimedia/mpv multimedia/mpv
multimedia/pwcview multimedia/pwcview
multimedia/v4l-utils multimedia/v4l-utils

View File

@ -11,3 +11,4 @@ default_sway_conf_files:
- lockscreen - lockscreen
- logout - logout
- force_focus - force_focus
- night_mode

View File

@ -0,0 +1 @@
# exec wlsunset -l 40.7 -L -74.0

View File

@ -21,6 +21,7 @@
- vulkan-validation-layers # For vulkan support in sway - vulkan-validation-layers # For vulkan support in sway
# - adwaita-qt5 # For dark theme # - adwaita-qt5 # For dark theme
# - adwaita-qt6 # For dark theme # - adwaita-qt6 # For dark theme
- wlsunset
state: present state: present
- name: Install scripts - name: Install scripts

View File

@ -63,6 +63,7 @@ tooltip {
#custom-available_memory, #custom-available_memory,
#custom-battery, #custom-battery,
#custom-clock, #custom-clock,
#custom-night_mode,
#custom-sound, #custom-sound,
#custom-temperature, #custom-temperature,
#idle_inhibitor, #idle_inhibitor,

View File

@ -1,7 +1,7 @@
{ {
// "height": 10, // Waybar height (to be removed for auto height) // "height": 10, // Waybar height (to be removed for auto height)
"modules-left": ["sway/workspaces", "sway/mode"], "modules-left": ["sway/workspaces", "sway/mode"],
"modules-right": ["custom/temperature", "custom/sound", "custom/available_memory", "custom/battery", "idle_inhibitor", "custom/clock", "tray"], "modules-right": ["custom/night_mode", "custom/temperature", "custom/sound", "custom/available_memory", "custom/battery", "idle_inhibitor", "custom/clock", "tray"],
"sway/workspaces": { "sway/workspaces": {
"disable-scroll": true "disable-scroll": true
}, },
@ -12,7 +12,7 @@
"format": "{icon}", "format": "{icon}",
"format-icons": { "format-icons": {
"activated": "☕",// "activated": "☕",//
"deactivated": ""// "deactivated": "💤"//💤
} }
}, },
"tray": { "tray": {
@ -43,5 +43,11 @@
"exec": "waybar_custom_temperature", "exec": "waybar_custom_temperature",
"return-type": "json", "return-type": "json",
"restart-interval": 30 "restart-interval": 30
},
"custom/night_mode": {
"exec": "waybar_night_mode",
"return-type": "json",
"restart-interval": 30,
"on-click": "pkill --signal USR1 -f waybar_night_mode"
} }
} }

View File

@ -0,0 +1,93 @@
#!/usr/bin/env bash
#
# Power an icon for tinting the screen at night.
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SLEEP_INTERVAL=${SLEEP_INTERVAL:-30}
# ◓◒●◌◎
# 🟠🟡🟢🟣🟤
# 🟥🟦🟧🟨🟩🟪🟫
# ☀☯⭐🌝🌞⏾
# 🌑🌓🌗🌕
# 👓
############## Setup #########################
function cleanup {
log "Killing child process $wlsunset_pid"
kill "$wlsunset_pid"
true
}
for sig in EXIT INT QUIT HUP TERM; do
trap "set +e; cleanup" "$sig"
done
function die {
local status_code="$1"
shift
(>&2 echo "${@}")
exit "$status_code"
}
function log {
(>&2 echo "${@}")
}
############## Program #########################
function main {
local night_mode_icon night_mode_text night_mode_class
night_mode_mode="auto"
night_mode_class=""
wlsunset -l 40.7 -L -74.0 &
wlsunset_pid=$!
while true; do
if [ "$night_mode_mode" == "auto" ]; then
night_mode_icon="🌗"
night_mode_text="auto"
elif [ "$night_mode_mode" == "on" ]; then
night_mode_icon="🌑"
night_mode_text="night"
elif [ "$night_mode_mode" == "off" ]; then
night_mode_icon="🌕"
night_mode_text="day"
fi
render
sleep "$SLEEP_INTERVAL" &
wait $! || true
done
}
function render {
jq --unbuffered --compact-output <<EOF
{
"text":"${night_mode_icon}",
"tooltip":"${night_mode_text}",
"percentage":100,
"class":"${night_mode_class}"
}
EOF
}
function handle_click {
if [ "$night_mode_mode" == "auto" ]; then
log "Setting night mode to force-day."
night_mode_mode="off"
elif [ "$night_mode_mode" == "on" ]; then
log "Setting night mode to auto."
night_mode_mode="auto"
elif [ "$night_mode_mode" == "off" ]; then
log "Setting night mode to force-night."
night_mode_mode="on"
fi
kill -USR1 "$wlsunset_pid"
}
trap "handle_click" SIGUSR1
main "${@}"

View File

@ -8,6 +8,8 @@
loop: loop:
- src: waybar_custom_clock.py - src: waybar_custom_clock.py
dest: /usr/local/bin/waybar_custom_clock dest: /usr/local/bin/waybar_custom_clock
- src: waybar_night_mode.bash
dest: /usr/local/bin/waybar_night_mode
- import_tasks: tasks/freebsd.yaml - import_tasks: tasks/freebsd.yaml
when: 'os_flavor == "freebsd"' when: 'os_flavor == "freebsd"'