diff --git a/modules/hm/hyprland-bluetooth-keyboard.nix b/modules/hm/hyprland-bluetooth-keyboard.nix new file mode 100644 index 0000000..1609073 --- /dev/null +++ b/modules/hm/hyprland-bluetooth-keyboard.nix @@ -0,0 +1,57 @@ +{ pkgs, lib, nixosConfig, ... }: { + systemd.user.services."bluetooth-keyboard" = { + Unit = { + Description = "Disable the laptop keyboard when the bluetooth keyboard is connected"; + After = [ "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + Install.WantedBy = [ "graphical-session.target" ]; + Service = { + Type = "simple"; + ExecStart = pkgs.writeShellScript "bluetooth-keyboard.sh" '' + PATH=$PATH:${lib.makeBinPath [pkgs.coreutils pkgs.gnugrep pkgs.libnotify nixosConfig.programs.hyprland.package]} + BLUETOOTH_DEVICE="keychron-k1-max-keyboard" + LAPTOP_DEVICE="at-translated-set-2-keyboard" + + if [ -z "$XDG_RUNTIME_DIR" ]; then + export XDG_RUNTIME_DIR=/run/user/$(id -u) + fi + + export STATUS_FILE="$XDG_RUNTIME_DIR/bluetooth_keyboard.status" + + enable_laptop_keyboard() { + if [[ `cat $STATUS_FILE` == "false" ]]; then + printf "true" > "$STATUS_FILE" + echo "Enabling laptop keyboard" + notify-send -u normal "Enabling laptop keyboard" + hyprctl keyword '$LAPTOP_KEYBOARD_ENABLED' true + hyprctl keyword device:a "" + fi + } + + disable_laptop_keyboard() { + if [[ `cat $STATUS_FILE` == "true" ]]; then + printf "false" > "$STATUS_FILE" + echo "Disabling laptop keyboard" + notify-send -u normal "Disabling laptop keyboard" + hyprctl keyword '$LAPTOP_KEYBOARD_ENABLED' false + hyprctl keyword device:a "" + fi + } + + printf "true" > "$STATUS_FILE" + + while true; do + if hyprctl devices | grep --quiet $BLUETOOTH_DEVICE ; then + disable_laptop_keyboard + else + enable_laptop_keyboard + fi + + sleep 5; + done + ''; + }; + }; +} + diff --git a/modules/hm/hyprland.nix b/modules/hm/hyprland.nix index 58dc96b..bd729f3 100644 --- a/modules/hm/hyprland.nix +++ b/modules/hm/hyprland.nix @@ -9,6 +9,7 @@ ./swayidle.nix ./swaynotificationcenter.nix ./wl_update_background.nix + ./hyprland-bluetooth-keyboard.nix ]; home.packages = builtins.attrValues { inherit (pkgs) blueman brillo gamescope grimblast networkmanagerapplet wireplumber playerctl swaylock swww way-lockscreen waybar wl-clipboard wl-clipedit wlogout wofi wofi-emoji wtype xdg-desktop-portal-gtk; }; @@ -81,6 +82,12 @@ sensitivity = 0 # -1.0 - 1.0, 0 means no modification. } + $LAPTOP_KEYBOARD_ENABLED = true + device { + name = at-translated-set-2-keyboard + enabled = $LAPTOP_KEYBOARD_ENABLED + } + device { name=keychron-k1-max-keyboard kb_layout=us