nwg-panel: add a button to toggle the flashlight on moby

This commit is contained in:
2024-07-05 23:11:55 +00:00
parent 5048bd8d70
commit 5e5ecfe81e
4 changed files with 50 additions and 1 deletions

View File

@@ -7,6 +7,7 @@
# - use sane-sysload
{
controlsSettingsComponents,
controlsSettingsCustomItems,
height,
locker,
modulesRight,
@@ -82,7 +83,7 @@
# commands.battery = ""; #< optional action to perform when battery icon is clicked in the drop-down menu
components = controlsSettingsComponents;
click-closes = false;
custom-items = [];
custom-items = controlsSettingsCustomItems;
css-name = "controls-window";
hover-opens = false;
icon-size = 16;

View File

@@ -13,6 +13,19 @@ let
};
in
{
sane.programs.torch-toggle = {
packageUnwrapped = pkgs.static-nix-shell.mkBash {
pname = "torch-toggle";
pkgs = [ "brightnessctl" ];
srcRoot = ./.;
};
suggestedPrograms = [
"brightnessctl"
];
sandbox.enable = false; # trivial, and all deps are sandboxed
};
sane.programs.nwg-panel = {
configOption = with lib; mkOption {
default = {};
@@ -44,6 +57,15 @@ in
s6 service to start which can lock the screen
'';
};
torch = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
device name for the torch (flashlight), if any.
find with `brightnessctl -l`
'';
example = "white:flash";
};
battery = mkEnableOption' true "display battery status";
brightness = mkEnableOption' true "display backlight level and slider";
mediaTitle = mkEnableOption' true "display title of current song/media";
@@ -117,7 +139,10 @@ in
});
suggestedPrograms = [
"brightnessctl"
"pactl" # pactl required by `per-app-volume` component.
] ++ lib.optionals (cfg.config.torch != null) [
"torch-toggle"
];
fs.".config/nwg-panel/style.css".symlink.target = pkgs.substituteAll {
@@ -139,6 +164,15 @@ in
"battery"
]
;
controlsSettingsCustomItems = lib.optionals (cfg.config.torch != null) [
{
name = "Torch";
# icons: find them in /etc/profiles/per-user/colin/share/icons
# display-brightness-symbolic, keyboard-brightness-symbolic, night-light-symbolic
icon = "display-brightness-symbolic";
cmd = "torch-toggle ${cfg.config.torch}";
}
];
modulesRight = [
"playerctl"
] ++ lib.optionals cfg.config.sysload [
@@ -157,6 +191,7 @@ in
];
sandbox.extraPaths = [
"/sys/class/backlight"
"/sys/class/leds" #< for torch/flashlight on moby
"/sys/class/power_supply" #< for the battery indicator
"/sys/devices"
];

View File

@@ -0,0 +1,12 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash -p brightnessctl
dev="$1"
if [ -z "$dev" ]; then
dev="white:flash"
fi
if [ "$(brightnessctl -d "$dev" get)" -gt 0 ]; then
brightnessctl -q -d "$dev" set "0%"
else
brightnessctl -q -d "$dev" set "100%"
fi

View File

@@ -283,6 +283,7 @@ in
# dd if=${pkgs.tow-boot-pinephone}/Tow-Boot.noenv.bin of=$out bs=1024 seek=8 conv=notrunc
# '';
sane.programs.nwg-panel.config.torch = "white:flash";
sane.programs.gps-share.config = {
device = "/dev/ttyUSB1";
};