mirror of
https://github.com/pjones/plasma-manager.git
synced 2024-09-11 15:56:02 +03:00
Add powerdevil module (#274)
This commit is contained in:
parent
325869ebe0
commit
b967e04289
@ -212,6 +212,18 @@
|
||||
}
|
||||
];
|
||||
|
||||
powerdevil = {
|
||||
powerButtonAction = "lockScreen";
|
||||
autoSuspend = {
|
||||
action = "shutDown";
|
||||
idleTimeout = 1000;
|
||||
};
|
||||
turnOffDisplay = {
|
||||
idleTimeout = 1000;
|
||||
idleTimeoutWhenLocked = "immediately";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#
|
||||
# Some mid-level settings:
|
||||
|
@ -9,10 +9,10 @@
|
||||
./kscreenlocker.nix
|
||||
./kwin.nix
|
||||
./panels.nix
|
||||
./powerdevil.nix
|
||||
./shortcuts.nix
|
||||
./spectacle.nix
|
||||
./startup.nix
|
||||
./windows.nix
|
||||
./window-rules.nix
|
||||
./workspace.nix
|
||||
];
|
||||
|
@ -57,6 +57,7 @@ let
|
||||
"plasmanotifyrc"
|
||||
"plasmarc"
|
||||
"plasmashellrc"
|
||||
"powerdevilrc"
|
||||
"systemsettingsrc"
|
||||
] else lib.optional (builtins.length plasmaCfg.window-rules > 0) "kwinrulesrc");
|
||||
in
|
||||
|
108
modules/powerdevil.nix
Normal file
108
modules/powerdevil.nix
Normal file
@ -0,0 +1,108 @@
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
cfg = config.programs.plasma;
|
||||
|
||||
powerButtonActions = {
|
||||
nothing = 0;
|
||||
sleep = 1;
|
||||
shutDown = 8;
|
||||
lockScreen = 32;
|
||||
showLogoutScreen = null;
|
||||
turnOffScreen = 64;
|
||||
};
|
||||
|
||||
autoSuspendActions = {
|
||||
nothing = 0;
|
||||
sleep = null;
|
||||
shutDown = 8;
|
||||
};
|
||||
in
|
||||
{
|
||||
config.assertions = [
|
||||
{
|
||||
assertion = (cfg.powerdevil.autoSuspend.action != autoSuspendActions.nothing || cfg.powerdevil.autoSuspend.idleTimeout == null);
|
||||
message = "Setting programs.plasma.powerdevil.autoSuspend.idleTimeout for autosuspend-action \"nothing\" is not supported.";
|
||||
}
|
||||
{
|
||||
assertion = (cfg.powerdevil.turnOffDisplay.idleTimeout != -1 || cfg.powerdevil.turnOffDisplay.idleTimeoutWhenLocked == null);
|
||||
message = "Setting programs.plasma.powerdevil.turnOffDisplay.idleTimeoutWhenLocked for when idleTimeout is \"never\" is not supported.";
|
||||
}
|
||||
];
|
||||
|
||||
options = {
|
||||
programs.plasma.powerdevil = {
|
||||
powerButtonAction = lib.mkOption {
|
||||
type = with lib.types; nullOr (enum (builtins.attrNames powerButtonActions));
|
||||
default = null;
|
||||
example = "nothing";
|
||||
description = ''
|
||||
The action to perform when the power button is pressed.
|
||||
'';
|
||||
apply = action: if (action == null) then null else powerButtonActions."${action}";
|
||||
};
|
||||
autoSuspend = {
|
||||
action = lib.mkOption {
|
||||
type = with lib.types; nullOr (enum (builtins.attrNames autoSuspendActions));
|
||||
default = null;
|
||||
example = "nothing";
|
||||
description = ''
|
||||
The action to perform after a certain period of inactivity.
|
||||
'';
|
||||
apply = action: if (action == null) then null else autoSuspendActions."${action}";
|
||||
};
|
||||
idleTimeout = lib.mkOption {
|
||||
type = with lib.types; nullOr (ints.between 60 600000);
|
||||
default = null;
|
||||
example = 600;
|
||||
description = ''
|
||||
The duration (in seconds) the computer must be idle until the
|
||||
auto-suspend action is executed.
|
||||
'';
|
||||
};
|
||||
};
|
||||
turnOffDisplay = {
|
||||
idleTimeout = lib.mkOption {
|
||||
type = with lib.types; nullOr (either (enum [ "never" ]) (ints.between 30 600000));
|
||||
default = null;
|
||||
example = 300;
|
||||
description = ''
|
||||
The duration (in seconds) the computer must be idle (when unlocked)
|
||||
until the display turns off.
|
||||
'';
|
||||
apply = timeout:
|
||||
if (timeout == null) then null else
|
||||
if (timeout == "never") then -1
|
||||
else timeout;
|
||||
};
|
||||
idleTimeoutWhenLocked = lib.mkOption {
|
||||
type = with lib.types; nullOr (either (enum [ "whenLockedAndUnlocked" "immediately" ]) (ints.between 20 600000));
|
||||
default = null;
|
||||
example = 60;
|
||||
description = ''
|
||||
The duration (in seconds) the computer must be idle (when locked)
|
||||
until the display turns off.
|
||||
'';
|
||||
apply = timeout:
|
||||
if (timeout == null) then null else
|
||||
if (timeout == "whenLockedAndUnlocked") then -2 else
|
||||
if (timeout == "immediately") then 0
|
||||
else timeout;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config.programs.plasma.configFile = lib.mkIf cfg.enable {
|
||||
powerdevilrc = lib.filterAttrs (k: v: v != null) {
|
||||
"AC/SuspendAndShutdown" = {
|
||||
PowerButtonAction = cfg.powerdevil.powerButtonAction;
|
||||
AutoSuspendAction = cfg.powerdevil.autoSuspend.action;
|
||||
AutoSuspendIdleTimeoutSec = cfg.powerdevil.autoSuspend.idleTimeout;
|
||||
};
|
||||
"AC/Display" = {
|
||||
TurnOffDisplayIdleTimeoutSec = cfg.powerdevil.turnOffDisplay.idleTimeout;
|
||||
TurnOffDisplayIdleTimeoutWhenLockedSec = cfg.powerdevil.turnOffDisplay.idleTimeoutWhenLocked;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user