Hyprland: prefer bluetooth keyboard

This commit is contained in:
Filippo Berto 2024-04-14 18:01:52 +02:00
parent 69b77af215
commit ec6ef6b771
No known key found for this signature in database
GPG key ID: FE98AE5EC52B1056
2 changed files with 64 additions and 0 deletions

View file

@ -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
'';
};
};
}

View file

@ -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