diff --git a/lib/modules.nix b/lib/modules.nix index 597a7c9..05ae82c 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -1,4 +1,11 @@ {lib}: let + inherit + (builtins) + # keep-sorted start + isString + fromJSON + # keep-sorted end + ; inherit (lib) # keep-sorted start @@ -35,7 +42,12 @@ in rec { mkHylixDispatcher = toLua: bind: if bind.exec != null - then "hl.dsp.exec_cmd(${toLua bind.exec})" + then + if bind.execRules != null + then "hl.dsp.exec_cmd(${toLua bind.exec}, ${toLua bind.execRules})" + else "hl.dsp.exec_cmd(${toLua bind.exec})" + else if bind.execRaw != null + then "hl.dsp.exec_raw(${toLua bind.execRaw})" else if bind.lua != null then bind.lua else if bind.action != null @@ -98,11 +110,15 @@ in rec { bindGroups; mkHylixMonitorLine = toLua: monitor: let + scaleVal = + if monitor.scale != null && isString monitor.scale + then fromJSON monitor.scale + else monitor.scale; base = {inherit (monitor) output;} // optionalAttrs (monitor.mode != null) {inherit (monitor) mode;} // optionalAttrs (monitor.position != null) {inherit (monitor) position;} - // optionalAttrs (monitor.scale != null) {inherit (monitor) scale;}; + // optionalAttrs (scaleVal != null) {scale = scaleVal;}; in "hl.monitor(${toLua (base // monitor.extra)})"; mkHylixRuleLine = toLua: func: rule: "${func}(${toLua rule})"; diff --git a/lib/ordering.nix b/lib/ordering.nix index f1e1f92..ba5c6b5 100644 --- a/lib/ordering.nix +++ b/lib/ordering.nix @@ -6,10 +6,12 @@ curves = 500; devices = 400; env = 200; + events = 1100; extraLua = 1500; gestures = 850; layerRules = 700; monitors = 300; + notifications = 1050; permissions = 800; settings = 100; windowRules = 600; diff --git a/modules/hylix/autostart.nix b/modules/hylix/autostart.nix index 4c2ef57..d8d79a7 100644 --- a/modules/hylix/autostart.nix +++ b/modules/hylix/autostart.nix @@ -15,12 +15,21 @@ _: { mkOrder # keep-sorted end ; - inherit (lib.self) ordering; + inherit + (lib.self) + # keep-sorted start + ordering + toLua + # keep-sorted end + ; inherit (lib.types) # keep-sorted start + anything listOf + nullOr str + submodule # keep-sorted end ; @@ -28,12 +37,35 @@ _: { lines = concatStringsSep "\n" - (map (cmd: "hl.exec_cmd(\"${cmd}\")") cfg.autostart); + (map ( + entry: + if entry.rules != null + then "hl.exec_cmd(${toLua entry.cmd}, ${toLua entry.rules})" + else "hl.exec_cmd(${toLua entry.cmd})" + ) + cfg.autostart); in { options.programs.hylix.autostart = mkOption { description = "commands to run at startup via hl.exec_cmd()"; - type = listOf str; + type = listOf (submodule { + options = { + # keep-sorted start block=yes newline_separated=yes + cmd = mkOption { + description = "the command to run"; + + type = str; + }; + + rules = mkOption { + description = "optional Hyprland rules table"; + + type = nullOr anything; + default = null; + }; + # keep-sorted end + }; + }); default = []; }; diff --git a/modules/hylix/binds.nix b/modules/hylix/binds.nix index 2a3099c..2922818 100644 --- a/modules/hylix/binds.nix +++ b/modules/hylix/binds.nix @@ -80,6 +80,20 @@ default = null; }; + execRaw = mkOption { + description = "command to execute via hl.dsp.exec_raw"; + + type = nullOr str; + default = null; + }; + + execRules = mkOption { + description = "hyprland dispatcher rules for the exec command (e.g. {float = true; move = {0, 0;}})"; + + type = nullOr anything; + default = null; + }; + keys = mkOption { description = "key combination (e.g. [\"SUPER\" \"q\"])"; diff --git a/modules/hylix/events.nix b/modules/hylix/events.nix new file mode 100644 index 0000000..3f519a1 --- /dev/null +++ b/modules/hylix/events.nix @@ -0,0 +1,82 @@ +_: { + flake.modules.generic.hylix = { + # keep-sorted start + config, + lib, + # keep-sorted end + ... + }: let + inherit + (lib) + # keep-sorted start + concatStringsSep + mkIf + mkOption + mkOrder + # keep-sorted end + ; + inherit + (lib.self) + # keep-sorted start + ordering + toLua + # keep-sorted end + ; + inherit + (lib.types) + # keep-sorted start + listOf + nullOr + str + submodule + # keep-sorted end + ; + + cfg = config.programs.hylix; + + lines = + concatStringsSep "\n" + (map ( + entry: + if entry.lua != null + then "hl.on(${toLua entry.event}, ${entry.lua})" + else if entry.exec != null + then "hl.on(${toLua entry.event}, function() hl.dsp.exec_cmd(${toLua entry.exec}) end)" + else "" + ) + cfg.events); + in { + options.programs.hylix.events = mkOption { + description = "Hyprland event hooks via hl.on()"; + + type = listOf (submodule { + options = { + event = mkOption { + description = "hyprland event name (e.g. \"hyprland.start\", \"window.active\", \"workspace.active\")"; + + type = str; + }; + + exec = mkOption { + description = "command to execute when the event fires"; + + type = nullOr str; + default = null; + }; + + lua = mkOption { + description = "raw Lua function body for the event callback (e.g. ''function(w, ws) ... end'')"; + + type = nullOr str; + default = null; + }; + }; + }); + default = []; + }; + + config = mkIf (cfg.events != []) { + programs.hylix._generatedConfig = mkOrder ordering.events lines; + }; + }; +} diff --git a/modules/hylix/monitors.nix b/modules/hylix/monitors.nix index d03f19c..e872cd6 100644 --- a/modules/hylix/monitors.nix +++ b/modules/hylix/monitors.nix @@ -27,6 +27,9 @@ _: { (lib.types) # keep-sorted start anything + either + float + int listOf nullOr str @@ -69,9 +72,9 @@ _: { }; scale = mkOption { - description = "scale factor (string, e.g. \"1\" or \"1.5\")"; + description = "scale factor (number or string, e.g. 1 or \"1.5\")"; - type = nullOr str; + type = nullOr (either str (either int float)); default = null; }; # keep-sorted end diff --git a/modules/hylix/notifications.nix b/modules/hylix/notifications.nix new file mode 100644 index 0000000..d92f8df --- /dev/null +++ b/modules/hylix/notifications.nix @@ -0,0 +1,82 @@ +_: { + flake.modules.generic.hylix = { + # keep-sorted start + config, + lib, + # keep-sorted end + ... + }: let + inherit + (lib) + # keep-sorted start + concatStringsSep + mkIf + mkOption + mkOrder + # keep-sorted end + ; + inherit + (lib.self) + # keep-sorted start + ordering + toLua + # keep-sorted end + ; + inherit + (lib.types) + # keep-sorted start + int + listOf + nullOr + str + submodule + # keep-sorted end + ; + + cfg = config.programs.hylix; + + lines = + concatStringsSep "\n" + (map (n: "hl.notification.create(${toLua n})") cfg.notifications); + in { + options.programs.hylix.notifications = mkOption { + description = "notifications sent on startup via hl.notification.create()"; + + type = listOf (submodule { + options = { + group = mkOption { + description = "notification group for grouping/dedup"; + + type = nullOr str; + default = null; + }; + + icon = mkOption { + description = "icon (e.g. \"info\", \"warning\", \"error\")"; + + type = nullOr str; + default = null; + }; + + text = mkOption { + description = "notification text"; + + type = str; + }; + + time = mkOption { + description = "display duration in milliseconds"; + + type = int; + default = 5000; + }; + }; + }); + default = []; + }; + + config = mkIf (cfg.notifications != []) { + programs.hylix._generatedConfig = mkOrder ordering.notifications lines; + }; + }; +}