Skip to content

Commit 33b6f1f

Browse files
mbssrcbrianmcgillion
authored andcommitted
feat(powerctrl): add suspend flag
Add suspend flag to graphics profile to disallow suspend on certain targets. Signed-off-by: Manuel Bluhm <manuel@ssrc.tii.ae>
1 parent 079f678 commit 33b6f1f

File tree

6 files changed

+54
-18
lines changed

6 files changed

+54
-18
lines changed

modules/desktop/graphics/ewwbar.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ let
1010

1111
cfg = config.ghaf.graphics.labwc;
1212
useGivc = config.ghaf.givc.enable;
13-
ghaf-powercontrol = pkgs.ghaf-powercontrol.override { ghafConfig = config.ghaf; };
13+
ghaf-powercontrol = pkgs.ghaf-powercontrol.override {
14+
ghafConfig = config.ghaf;
15+
inherit (pkgs) ghaf-artwork;
16+
};
1417
inherit (config.ghaf.services.audio) pulseaudioTcpControlPort;
1518

1619
# Called by eww.yuck for updates and reloads

modules/microvm/modules.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ let
7575
# Graphics profiles module
7676
graphics = {
7777
config.ghaf.profiles.graphics = {
78-
inherit (configHost.ghaf.profiles.graphics) compositor renderer;
78+
inherit (configHost.ghaf.profiles.graphics) compositor renderer allowSuspend;
7979
idleManagement = {
8080
inherit (configHost.ghaf.profiles.graphics.idleManagement) enable;
8181
};

modules/microvm/sysvms/guivm.nix

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ let
134134
acpid = lib.mkIf config.ghaf.givc.enable {
135135
enable = true;
136136
lidEventCommands = ''
137+
wl_running=1
137138
case "$1" in
138139
"button/lid LID close")
139140
# Lock sessions
@@ -147,16 +148,24 @@ let
147148
wl_running=0
148149
fi
149150
150-
# Initiate Suspension
151-
${pkgs.givc-cli}/bin/givc-cli ${config.ghaf.givc.cliArgs} suspend
151+
${lib.optionalString config.ghaf.profiles.graphics.allowSuspend ''
152+
# Initiate Suspension
153+
${pkgs.givc-cli}/bin/givc-cli ${config.ghaf.givc.cliArgs} suspend
152154
153-
# Enable display
154-
if [ "$wl_running" -eq 1 ]; then
155-
WAYLAND_DISPLAY=/run/user/${builtins.toString config.ghaf.users.loginUser.uid}/wayland-0 ${pkgs.wlopm}/bin/wlopm --on '*'
156-
fi
155+
# Enable display
156+
if [ "$wl_running" -eq 1 ]; then
157+
WAYLAND_DISPLAY=/run/user/${builtins.toString config.ghaf.users.loginUser.uid}/wayland-0 ${pkgs.wlopm}/bin/wlopm --on '*'
158+
fi
159+
''}
157160
;;
158161
"button/lid LID open")
159162
# Command to run when the lid is opened
163+
${lib.optionalString (!config.ghaf.profiles.graphics.allowSuspend) ''
164+
# Enable display
165+
if [ "$wl_running" -eq 1 ]; then
166+
WAYLAND_DISPLAY=/run/user/${builtins.toString config.ghaf.users.loginUser.uid}/wayland-0 ${pkgs.wlopm}/bin/wlopm --on '*'
167+
fi
168+
''}
160169
;;
161170
esac
162171
'';

modules/profiles/graphics.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ in
5555
'';
5656
};
5757
};
58+
allowSuspend = mkOption {
59+
type = types.bool;
60+
default = true;
61+
description = ''
62+
Allow the system to suspend. When enabled, the system will suspend via either the suspend icon,
63+
lid close, or button press.
64+
'';
65+
};
5866
};
5967

6068
config = mkIf cfg.enable {

packages/ghaf-powercontrol/package.nix

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
lib,
66
systemd,
77
wlopm,
8+
libnotify,
89
wayland-logout,
910
givc-cli ? null,
1011
ghafConfig ? { },
12+
ghaf-artwork ? null,
1113
}:
1214
let
1315
useGivc = ghafConfig.givc.enable;
@@ -24,6 +26,7 @@ writeShellApplication {
2426
systemd
2527
wlopm
2628
wayland-logout
29+
libnotify
2730
] ++ (lib.optional useGivc givc-cli);
2831

2932
text = ''
@@ -52,19 +55,31 @@ writeShellApplication {
5255
${if useGivc then "givc-cli ${ghafConfig.givc.cliArgs}" else "systemctl"} "$1"
5356
;;
5457
suspend)
55-
# Lock sessions
56-
loginctl lock-session
58+
${
59+
if ghafConfig.profiles.graphics.allowSuspend then
60+
''
61+
# Lock sessions
62+
loginctl lock-session
5763
58-
# Switch off display before suspension
59-
${waylandDisplayCmd "off"}
64+
# Switch off display before suspension
65+
${waylandDisplayCmd "off"}
6066
61-
# Send suspend command to host, ensure screen is on in case of failure
62-
${if useGivc then "givc-cli ${ghafConfig.givc.cliArgs}" else "systemctl"} suspend \
63-
|| ${waylandDisplayCmd "on"}
67+
# Send suspend command to host, ensure screen is on in case of failure
68+
${if useGivc then "givc-cli ${ghafConfig.givc.cliArgs}" else "systemctl"} suspend \
69+
|| ${waylandDisplayCmd "on"}
6470
65-
# Switch on display on wakeup
66-
${waylandDisplayCmd "on"}
67-
;;
71+
# Switch on display on wakeup
72+
${waylandDisplayCmd "on"}
73+
''
74+
else
75+
''
76+
MSG="Suspend functionality is currently not enabled on this system."
77+
echo "$MSG"
78+
notify-send -i ${ghaf-artwork}/icons/suspend.svg 'Ghaf Power Control' "$MSG"
79+
exit 1
80+
''
81+
}
82+
;;
6883
logout)
6984
wayland-logout
7085
loginctl kill-user "$USER" -s SIGKILL

targets/laptop/flake-module.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ let
113113
reference.profiles.mvp-user-trial.enable = true;
114114
partitioning.disko.enable = true;
115115
profiles.graphics.idleManagement.enable = false;
116+
profiles.graphics.allowSuspend = false;
116117
};
117118
}
118119
]))

0 commit comments

Comments
 (0)