2022-05-03 13:04:01 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2021-11-01 20:33:21 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.ptw.services.gamemode;
|
|
|
|
in {
|
|
|
|
options.ptw.services.gamemode = {
|
|
|
|
enable = lib.mkEnableOption "Enable and configure gamemode";
|
|
|
|
};
|
|
|
|
|
2023-04-30 13:22:52 +00:00
|
|
|
config = let
|
|
|
|
keyboardBrightnessScript = pkgs.writeShellScript "keyboard-brightness.sh" ''
|
|
|
|
${pkgs.rgb_keyboard}/bin/rgb_keyboard -l ripple -b "$1"
|
|
|
|
'';
|
|
|
|
in lib.mkIf cfg.enable {
|
|
|
|
security.sudo.extraConfig = ''
|
|
|
|
${config.ptw.system.singleUser} ALL = (ALL) NOPASSWD: ${keyboardBrightnessScript}
|
|
|
|
'';
|
|
|
|
|
2021-11-01 20:33:21 +00:00
|
|
|
programs.gamemode = {
|
|
|
|
enable = true;
|
|
|
|
enableRenice = true;
|
|
|
|
settings = {
|
|
|
|
general = {
|
|
|
|
reaper_freq = 5;
|
|
|
|
desiredgov = "performance";
|
|
|
|
igpu_desiredgov = "powersave";
|
|
|
|
igpu_power_threshold = 0.3;
|
|
|
|
|
|
|
|
softrealtime = "on";
|
|
|
|
renice = 0;
|
|
|
|
ioprio = 0;
|
|
|
|
inhibit_screensaver = 1;
|
|
|
|
};
|
2022-05-03 13:04:01 +00:00
|
|
|
|
|
|
|
gpu = {
|
|
|
|
amd_performance_level = "high";
|
|
|
|
};
|
|
|
|
|
|
|
|
custom = let
|
2023-04-30 13:22:52 +00:00
|
|
|
switchScript = groupName: "${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.fcitx.Fcitx5 /controller org.fcitx.Fcitx.Controller1.SwitchInputMethodGroup string:'${groupName}'";
|
2023-02-22 12:35:28 +00:00
|
|
|
pauseFcitx = switchScript "Group 2";
|
|
|
|
resumeFcitx = switchScript "Group 1";
|
2023-04-30 13:22:52 +00:00
|
|
|
|
|
|
|
# The scripts
|
|
|
|
start = pkgs.writeShellScript "gamemode-start.sh" ''
|
|
|
|
# Disable Fcitx's IME
|
|
|
|
${pauseFcitx}
|
|
|
|
|
|
|
|
# Turn on the keyboard lights
|
|
|
|
${config.security.wrapperDir}/sudo ${keyboardBrightnessScript} 1
|
|
|
|
'';
|
|
|
|
end = pkgs.writeShellScript "gamemode-end.sh" ''
|
|
|
|
# Resume Fcitx's IME
|
|
|
|
${resumeFcitx}
|
|
|
|
|
|
|
|
# Turn off the keyboard lights
|
|
|
|
${config.security.wrapperDir}/sudo ${keyboardBrightnessScript} 0
|
|
|
|
'';
|
2022-05-03 13:04:01 +00:00
|
|
|
in {
|
2023-04-30 13:22:52 +00:00
|
|
|
start = "${start}";
|
|
|
|
end = "${end}";
|
2022-05-03 13:04:01 +00:00
|
|
|
};
|
2021-11-01 20:33:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|