phases: Allow loosen brightness setting again

Didn't manage to do what I wanted to do for some reason, but hey,
at least ddcutils is there.
This commit is contained in:
Geoffrey Frogeye 2024-06-10 03:00:52 +02:00
parent d5917b1264
commit 865bffa641
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
5 changed files with 42 additions and 32 deletions

View file

@ -44,11 +44,23 @@ in
];
maxVideoHeight = 1440;
numlock = true;
phasesBrightness = {
enable = true;
jour = "40000";
crepuscule = "10000";
nuit = "1";
phasesCommands = {
jour = ''
${pkgs.brightnessctl}/bin/brightnessctl set 40000 &
${pkgs.ddcutil}/bin/ddcutil setvcp 10 20 -d 1 &
${pkgs.ddcutil}/bin/ddcutil setvcp 10 20 -d 2 &
'';
crepuscule = ''
${pkgs.brightnessctl}/bin/brightnessctl set 10000 &
${pkgs.ddcutil}/bin/ddcutil setvcp 10 10 -d 1 &
${pkgs.ddcutil}/bin/ddcutil setvcp 10 10 -d 2 &
'';
nuit = ''
${pkgs.brightnessctl}/bin/brightnessctl set 1 &
${pkgs.ddcutil}/bin/ddcutil setvcp 10 0 -d 1 &
${pkgs.ddcutil}/bin/ddcutil setvcp 10 0 -d 2 &
'';
# TODO Display 2 doesn't work anymore?
};
};
nixpkgs.overlays = [

View file

@ -6,27 +6,19 @@ let
{ command = "crepuscule"; specialisation = "dark"; }
{ command = "nuit"; specialisation = "dark"; }
];
phasesBrightness = config.frogeye.desktop.phasesBrightness;
in
{
config = {
home.packages = map
(phase: (pkgs.writeShellApplication {
name = "${phase.command}";
runtimeInputs = [ pkgs.brightnessctl ];
text = (lib.optionalString phasesBrightness.enable ''
brightnessctl set ${builtins.getAttr phase.command phasesBrightness}
'') + ''
(phase: (pkgs.writeShellScriptBin phase.command ''
switch="/nix/var/nix/profiles/system${lib.strings.optionalString (phase.specialisation != null) "/specialisation/${phase.specialisation}"}/bin/switch-to-configuration"
if [ -x "$switch" ]
then
# In two steps to get the visual changes slightly earlier
sudo "$switch" test
sudo "$switch" boot
sudo "$switch" test &
sudo "$switch" boot &
fi
'';
})
)
${builtins.getAttr phase.command config.frogeye.desktop.phasesCommands}
''))
phases;
xsession.windowManager.i3.config.keybindings = {
"XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set +5%";

View file

@ -22,11 +22,10 @@
description = "Maximum video height in pixel the machine can reasonably watch";
default = 1080;
};
phasesBrightness = {
enable = lib.mkEnableOption "Set a specific brightness for the screen when running phases commands";
jour = lib.mkOption { type = lib.types.str; default = "100%"; description = "brightnessctl value for phase: jour"; };
crepuscule = lib.mkOption { type = lib.types.str; default = "50%"; description = "brightnessctl value for phase: crepuscule"; };
nuit = lib.mkOption { type = lib.types.str; default = "1%"; description = "brightnessctl value for phase: nuit"; };
phasesCommands = {
jour = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: jour"; };
crepuscule = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: crepuscule"; };
nuit = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: nuit"; };
};
};
dev = {

View file

@ -1,9 +1,11 @@
{ pkgs, lib, config, ... }:
{
config = lib.mkIf config.frogeye.desktop.xorg {
boot.kernelModules = [ "i2c-dev" ]; # Allows using ddcutil
services = {
blueman.enable = true;
displayManager.defaultSession = "none+i3";
udev.packages = with pkgs; [ ddcutil ]; # TODO Doesn't seem to help
xserver = {
enable = true;
windowManager.i3.enable = true;

View file

@ -16,11 +16,16 @@
frogeye.desktop = {
x11_screens = [ "DP-1" "eDP-1" ];
maxVideoHeight = 1080;
phasesBrightness = {
enable = true;
jour = "3500";
crepuscule = "3000";
nuit = "700";
phasesCommands = {
jour = ''
${pkgs.brightnessctl}/bin/brightnessctl set 3500
'';
crepuscule = ''
${pkgs.brightnessctl}/bin/brightnessctl set 3000
'';
nuit = ''
${pkgs.brightnessctl}/bin/brightnessctl set 700
'';
};
};