1

Further refactor hyprland keybindings + integrate with rofi

This commit is contained in:
2023-05-25 20:25:26 +02:00
parent f479f9a925
commit 7f21b51143
6 changed files with 52 additions and 90 deletions

View File

@ -92,16 +92,11 @@ rec {
keybindings = {
main-mod = "SUPER";
mod-bindings = {
"Q" = ["killactive"];
"V" = ["togglefloating"];
};
bindings = {
"CTRL ALT, R" = [
"moveworkspacetomonitor, 1 HDMI-A-1"
"moveworkspacetomonitor, 2 HDMI-A-1"
];
"$mainMod, E" = ["exec, kitty fish -c \"nnncd -a -P p\""];
"$mainMod, P" = ["exec, hyprpicker -a"];
"$mainMod, S" = ["exec, grim -g \"$(slurp)\""];
"$mainMod CTRL, S" = ["exec, grim -g \"$(slurp)\" - | wl-copy"];
};
};

View File

@ -95,26 +95,27 @@ in {
# Keybindings
home.file.".config/hypr/keybindings.conf".text = let
always-bind = {
# Hyprland control
"$mainMod, Q" = ["killactive"];
"$mainMod, V" = ["togglefloating"];
"$mainMod, F" = ["fullscreen"];
"$mainMod, C" = ["exec, clipman pick --tool=rofi"];
"$mainMod, G" = ["togglegroup"];
"$mainMod, T" = ["exec, kitty"];
"ALT, tab" = ["changegroupactive"];
};
mkBind = key: action: "bind = ${key}, ${action}";
mkBinds = key: actions: builtins.map (mkBind key) actions;
binds = lib.pipe cfg.keybindings.bindings [
binds = lib.pipe (lib.mergeAttrs cfg.keybindings.bindings always-bind) [
(builtins.mapAttrs mkBinds)
builtins.attrValues
builtins.concatLists
(builtins.concatStringsSep "\n")
];
mkModBind = key: action: "bind = $mainMod, ${key}, ${action}";
mkModBinds = key: actions: builtins.map (mkModBind key) actions;
mod-binds = lib.pipe cfg.keybindings.mod-bindings [
(builtins.mapAttrs mkModBinds)
builtins.attrValues
builtins.concatLists
(builtins.concatStringsSep "\n")
];
in ''
$mainMod = ${cfg.keybindings.main-mod}
${mod-binds}
${binds}
'';
@ -170,6 +171,19 @@ in {
(builtins.concatStringsSep "\n")
];
# Set wallpaper for each configured monitor
home.file.".config/hypr/hyprpaper.conf".text = let
mkWallpaper = monitor: "wallpaper = ${monitor}, ${config.home.homeDirectory}/NixFlake/wallpapers/${cfg.theme}.png";
wallpapers = lib.pipe cfg.monitors [
builtins.attrNames
(builtins.map mkWallpaper)
(builtins.concatStringsSep "\n")
];
in ''
preload = ~/NixFlake/wallpapers/${cfg.theme}.png
${wallpapers}
'';
# Keyboard layout
home.file.".config/hypr/input.conf".text = ''
input {
@ -189,19 +203,6 @@ in {
}
'';
# Set wallpaper for each configured monitor
home.file.".config/hypr/hyprpaper.conf".text = let
mkWallpaper = monitor: "wallpaper = ${monitor}, ${config.home.homeDirectory}/NixFlake/wallpapers/${cfg.theme}.png";
wallpapers = lib.pipe cfg.monitors [
builtins.attrNames
(builtins.map mkWallpaper)
(builtins.concatStringsSep "\n")
];
in ''
preload = ~/NixFlake/wallpapers/${cfg.theme}.png
${wallpapers}
'';
home.activation = {
# NOTE: Keep the hyprland config symlinked, to allow easy changes with hotreload
# TODO: Don't symlink at all, why not just tell Hyprland where the config is? Much easier

View File

@ -110,22 +110,13 @@ with mylib.modules; {
example = ''
"SUPER"
'';
};
mod-bindings = mkOption {
type = types.attrs;
description = "Hyprland keyboard shortcuts using the modifier key";
example = ''
{
"Q" = ["killactive"];
"V" = ["togglefloating"];
}
'';
default = "SUPER";
};
bindings = mkOption {
type = types.attrs;
description = "Hyprland keyboard shortcuts";
default = {};
example = ''
{
"CTRL ALT, R" = [

View File

@ -7,36 +7,41 @@
mylib,
pkgs,
...
}:
with lib;
with mylib.modules; let
}: let
cfg = config.modules.rofi;
in {
options.modules.rofi = import ./options.nix {inherit lib mylib;};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
home.packages = with pkgs; [
rofi-wayland
];
# Power Menu
(mylib.rofi.mkSimpleMenu
modules.hyprland.keybindings = let
power-menu =
mylib.rofi.mkSimpleMenu
"power"
{
"Poweroff" = "poweroff";
"Reboot" = "reboot";
"Reload Hyprland" = "hyprctl reload";
"Exit Hyprland" = "hyprctl dispatch exit";
})
];
};
in {
bindings = {
"$mainMod, A" = ["exec, rofi -show drun"];
"$mainMod, escape" = ["exec, \"${power-menu}\""];
};
};
home.activation = {
# NOTE: Keep the rofi config symlinked, to allow easy changes with hotreload
linkRofiConfig =
hm.dag.entryAfter ["writeBoundary"]
(mkLink "~/NixFlake/config/rofi/rofi.rasi" "~/.config/rofi/config.rasi");
lib.hm.dag.entryAfter ["writeBoundary"]
(mylib.modules.mkLink "~/NixFlake/config/rofi/rofi.rasi" "~/.config/rofi/config.rasi");
linkRofiColors =
hm.dag.entryAfter ["writeBoundary"]
(mkLink "~/NixFlake/config/rofi/colors/${cfg.theme}.rasi" "~/.config/rofi/colors.rasi");
lib.hm.dag.entryAfter ["writeBoundary"]
(mylib.modules.mkLink "~/NixFlake/config/rofi/colors/${cfg.theme}.rasi" "~/.config/rofi/colors.rasi");
};
};
}