From b58d5eb12f66bc0f3e0394b10217576785c6939f Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sun, 30 Apr 2023 15:22:52 +0200 Subject: [PATCH] miku: Disable keypad lights with gamemode --- flake.nix | 2 +- hosts/miku.nix | 2 ++ modules/services/gamemode/default.nix | 34 +++++++++++++++---- .../desktop/rgb_keyboard/default.nix | 30 ++++++++++++++++ packages/default.nix | 2 ++ 5 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 packages/applications/desktop/rgb_keyboard/default.nix diff --git a/flake.nix b/flake.nix index 8c86ada..21b4ba4 100644 --- a/flake.nix +++ b/flake.nix @@ -56,7 +56,7 @@ ]; }; in { - inherit (pkgs) wayqt dfl-ipc dfl-applications dfl-utils qtgreet xwaylandvideobridge obs-cli; + inherit (pkgs) wayqt dfl-ipc dfl-applications dfl-utils qtgreet xwaylandvideobridge obs-cli rgb_keyboard; }; }); } diff --git a/hosts/miku.nix b/hosts/miku.nix index 25bf015..a31be70 100644 --- a/hosts/miku.nix +++ b/hosts/miku.nix @@ -166,6 +166,8 @@ kernel.sysctl = { # League of Legends under Linux "abi.vsyscall32" = 0; + # Fedora 39 + "vm.max_map_count" = 2147483642; }; extraModulePackages = [ kernel.vendor-reset ]; diff --git a/modules/services/gamemode/default.nix b/modules/services/gamemode/default.nix index e5bda01..724c21f 100644 --- a/modules/services/gamemode/default.nix +++ b/modules/services/gamemode/default.nix @@ -7,7 +7,15 @@ in { enable = lib.mkEnableOption "Enable and configure gamemode"; }; - config = lib.mkIf cfg.enable { + 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} + ''; + programs.gamemode = { enable = true; enableRenice = true; @@ -29,14 +37,28 @@ in { }; custom = let - switchScript = groupName: pkgs.writeShellScript "switch-input-group.sh" '' - ${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.fcitx.Fcitx5 /controller org.fcitx.Fcitx.Controller1.SwitchInputMethodGroup string:'${groupName}' - ''; + switchScript = groupName: "${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.fcitx.Fcitx5 /controller org.fcitx.Fcitx.Controller1.SwitchInputMethodGroup string:'${groupName}'"; pauseFcitx = switchScript "Group 2"; resumeFcitx = switchScript "Group 1"; + + # 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 + ''; in { - start = ''${pauseFcitx}''; - end = ''${resumeFcitx}''; + start = "${start}"; + end = "${end}"; }; }; }; diff --git a/packages/applications/desktop/rgb_keyboard/default.nix b/packages/applications/desktop/rgb_keyboard/default.nix new file mode 100644 index 0000000..b2015e2 --- /dev/null +++ b/packages/applications/desktop/rgb_keyboard/default.nix @@ -0,0 +1,30 @@ +{ + stdenv +, fetchFromGitHub +, gcc, gnumake +, libusb +}: + +stdenv.mkDerivation rec { + pname = "rgb_keyboard"; + version = "20230430"; + src = fetchFromGitHub { + owner = "PapaTutuWawa"; + repo = "rgb_keyboard"; + rev = "5bbdafea77ef3c3eb47081494f3b58abcd5c4e27"; + sha256 = "0m5hvlhqncy1qn5v6gpsz9qd2p4cvcjjnma08vb4b2ybq4kfv7qw"; + }; + + buildInputs = [ + libusb + ]; + + buildPhase = '' + ${gnumake}/bin/make build + ''; + + installPhase = '' + mkdir -p $out/bin/ + cp rgb_keyboard $out/bin/ + ''; +} diff --git a/packages/default.nix b/packages/default.nix index 1354795..6461dbb 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -123,4 +123,6 @@ in { gajim = prev.callPackage ./applications/networking/instant-messengers/gajim/default.nix { nbxmpp = prev.python3.pkgs.callPackage ./applications/networking/instant-messengers/gajim/nbxmpp.nix {}; }; + + rgb_keyboard = prev.callPackage ./applications/desktop/rgb_keyboard/default.nix {}; }