From 5f0316688642266c408d2e2d8e0aa4cedb7995bf Mon Sep 17 00:00:00 2001 From: ooks-io Date: Sun, 9 Jun 2024 17:14:01 +1200 Subject: [PATCH] refactor(home:binds): make mkBind function to simplify expression --- home/modules/desktop/tools/default.nix | 1 + .../compositor/hyprland/settings/binds.nix | 40 ++++------ home/modules/options/desktop/binds.nix | 73 +++++++------------ 3 files changed, 43 insertions(+), 71 deletions(-) diff --git a/home/modules/desktop/tools/default.nix b/home/modules/desktop/tools/default.nix index ce37abe..a56f5ae 100644 --- a/home/modules/desktop/tools/default.nix +++ b/home/modules/desktop/tools/default.nix @@ -3,6 +3,7 @@ ./kdeconnect.nix ./ookvolume.nix ./ookbrightness.nix + ./ookpower.nix ./zellijMenu.nix ]; } diff --git a/home/modules/desktop/wayland/compositor/hyprland/settings/binds.nix b/home/modules/desktop/wayland/compositor/hyprland/settings/binds.nix index 701506c..a82ef0e 100644 --- a/home/modules/desktop/wayland/compositor/hyprland/settings/binds.nix +++ b/home/modules/desktop/wayland/compositor/hyprland/settings/binds.nix @@ -1,39 +1,27 @@ -{ lib, config, pkgs, ... }: +{ lib, config, ... }: let inherit (lib) mkIf; wayland = config.ooknet.wayland; + binds = config.ooknet.binds; in { config = mkIf (wayland.compositor == "hyprland") { wayland.windowManager.hyprland.settings = { - bind = let - terminal = config.home.sessionVariables.TERMINAL; - browser = config.home.sessionVariables.BROWSER; - editor = config.home.sessionVariables.EDITOR; - locker = config.home.sessionVariables.LOCKER; - - spotifyctl = "${pkgs.spotify-player}/bin/spotify_player"; - discord = "${pkgs.vesktop}/bin/vesktop"; - - explorer = "${pkgs.cinnamon.nemo-with-extensions}/bin/nemo"; - - password = "${pkgs._1password-gui}/bin/1password"; - in [ - + bind = [ # Program Launch - "SUPER, b, exec, ${browser}" - "SUPER, return, exec, ${terminal}" - "SUPER, e, exec, ${terminal} ${editor}" - "SUPERSHIFT, P, exec, ${password}" - "SUPER, d, exec, ${discord}" - "SUPERSHIFT, e, exec, ${explorer}" - "SUPERSHIFT, S, exec, steam" - "SUPER, escape, exec, ${terminal} --title=BTOP btop" - "SUPER CTRL, return, exec, zellijmenu -n" + "SUPER, b, exec, ${binds.browser}" + "SUPER, return, exec, ${binds.terminal}" + "SUPER, e, exec, ${binds.terminalLaunch} $EDITOR" + "SUPERSHIFT, P, exec, ${binds.password}" + "SUPER, d, exec, ${binds.discord}" + "SUPERSHIFT, e, exec, ${binds.fileManager}" + "SUPERSHIFT, S, exec, ${binds.steam}" + "SUPER, escape, exec, ${binds.terminalLaunch} --title=BTOP btop" + "SUPER CTRL, return, exec, ${binds.zellijMenu}" - "SUPER, delete, exec, powermenu -c dmenu" + "SUPER, delete, exec, ${binds.powermenu} -c dmenu" @@ -116,7 +104,7 @@ in "SUPERSHIFT, 0, movetoworkspace,10" # Lock Screen - "SUPER, Backspace, exec, ${locker}" + "SUPER, Backspace, exec, ${binds.lock}" ]; # Mouse bindm = [ diff --git a/home/modules/options/desktop/binds.nix b/home/modules/options/desktop/binds.nix index 8dd2f61..e208547 100644 --- a/home/modules/options/desktop/binds.nix +++ b/home/modules/options/desktop/binds.nix @@ -1,56 +1,39 @@ -{ lib, ... }: +{ lib, pkgs, ... }: let - inherit (lib) mkOption types; - inherit (types) str; - mkWarn = message: "notify-send --urgency=normal 'warning' '${message}'"; + mkBind = message: lib.mkOption { + type = lib.types.str; + default = "${pkgs.libnotify}/bin/notify-send --urgency=normal 'Warning' '${message}'"; + }; in { options.ooknet.binds = { - browser = mkOption { - type = str; - default = mkWarn "No browser is enabled"; + browser = mkBind "No browser is enabled"; + terminal = mkBind "No terminal is enabled"; + terminalLaunch = mkBind "Failed to launch tui"; + fileManager = mkBind "No file manager is enabled."; + notes = mkBind "No Notes app is enabled"; + discord = mkBind "No Discord app is enabled"; + steam = mkBind "Steam is not enabled"; + powerMenu = mkBind "No power menu is enabled"; + lock = mkBind "No screen locker enabled"; + password = mkBind "No password manager enabled"; + zellijMenu = mkBind "Zellij Menu is not enabled"; + volume = { + up = mkBind "Volume binding not found..."; + down = mkBind "Volume binding not found..."; + mute = mkBind "Volume binding not found..."; }; - - terminal = mkOption { - type = str; - default = mkWarn "No terminal is enabled"; + brightness = { + up = mkBind "Brightness binding not found..."; + down = mkBind "Brightness binding not found..."; }; - - terminalLaunch = mkOption { - type = str; - default = mkWarn "Failed to launch tui"; - }; - - fileManager = mkOption { - type = str; - default = mkWarn "No file manager is enabled."; - }; - - notes = mkOption { - type = str; - default = mkWarn "No notes app is enabled"; - }; - - discord = mkOption { - type = str; - default = mkWarn "No discord app is enabled"; - }; - - steam = mkOption { - type = str; - default = mkWarn "Steam is not enabled"; - }; - - powerMenu = mkOption { - type = str; - default = mkWarn "No power menu is enabled"; - }; - - locker = mkOption { - type = str; - default = mkWarn "No screen locker enabled"; + spotify = { + launch = mkBind "Spotify is not enabled"; + next = mkBind "Spotify is not enabled"; + previous = mkBind "Spotify is not enabled"; + play = mkBind "Spotify is not enabled"; }; }; }