From d5458a9fcf1f42265ceabf1db33b994a514b4784 Mon Sep 17 00:00:00 2001
From: gytic <149968794+gytic@users.noreply.github.com>
Date: Mon, 28 Jul 2025 15:24:12 +0200
Subject: [PATCH] feat(keybinds): add options to specify keybinds
this adds two new options:
nixos95.keybinds.commands -> specify normal shortcuts
nixos95.keybinds.xfwm4 -> specify xfwm4 related shortcuts
---
nixos95/dotfiles/xfce4-keyboard-shortcuts.xml | 197 ------------------
nixos95/keybinds.nix | 109 +++++++++-
nixos95/taskbar.nix | 5 +-
nixos95/util/lib.nix | 6 +
4 files changed, 110 insertions(+), 207 deletions(-)
delete mode 100644 nixos95/dotfiles/xfce4-keyboard-shortcuts.xml
create mode 100644 nixos95/util/lib.nix
diff --git a/nixos95/dotfiles/xfce4-keyboard-shortcuts.xml b/nixos95/dotfiles/xfce4-keyboard-shortcuts.xml
deleted file mode 100644
index f5582e2..0000000
--- a/nixos95/dotfiles/xfce4-keyboard-shortcuts.xml
+++ /dev/null
@@ -1,197 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/nixos95/keybinds.nix b/nixos95/keybinds.nix
index 06b92ed..0ae9207 100644
--- a/nixos95/keybinds.nix
+++ b/nixos95/keybinds.nix
@@ -2,17 +2,110 @@
* For now this just hard copies the config file.
* This can be improved by allowing users to define there own keybinds
*/
-{ config, lib, ... }: let
- cfg = config.nixos95;
-in lib.mkIf cfg.enable {
+{ config, lib, pkgs, ... }: let
+ cfg = config.nixos95.keybinds;
+ t = lib.types;
+ slib = pkgs.callPackage ./util/lib.nix { };
+in {
- home-manager.users.${cfg.user} = {
+ options.nixos95.keybinds = {
+ commands = lib.mkOption {
+ description = ''
+ Keyboard shortcuts that should be made available.
- xdg.configFile = {
- "xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml" = {
- force = true;
- source = ./dotfiles/xfce4-keyboard-shortcuts.xml;
+ Each keyboard shortcut is defined as a set with the follwoing schema:
+ {
+ enable = bool; [optional; default = true]
+ key = string; [key sequence to triggger the command]
+ # to specify which command to execute use on of the following:
+ pkg = package; [use mainProgramm of a nix package; e.g. pkgs.firefox]
+ exe = string; [provide a program name directly; e.g. firefox]
+ }
+
+ > Modifier keys must be surrounded by angle brackets
+ '';
+ type = t.listOf t.attrs;
+ default = [
+ {
+ key = "r";
+ exe = "xfce4-appfinder --collapsed";
+ }
+ {
+ key = "XF86WWW";
+ exe = "exo-open --launch WebBrowser";
+ }
+ {
+ key = "XF86Mail";
+ exe = "exo-open --launch MailReder";
+ }
+ {
+ key = "Print";
+ exe = "xfce4-screenshooter";
+ }
+ ];
+ };
+ xfwm4 = lib.mkOption {
+ description = ''
+ Keyboard shortcuts to control xfwm4
+
+ Each keyboard shortcut is defined as a set with the follwoing schema:
+ {
+ enable = bool; [optional; default = true]
+ key = string; [key sequence to triggger the command]
+ # to specify which command to execute use on of the following:
+ pkg = package; [use mainProgramm of a nix package; e.g. pkgs.firefox]
+ exe = string; [provide a program name directly; e.g. firefox]
+ }
+
+ > Modifier keys must be surrounded by angle brackets
+ '';
+ type = t.listOf t.attrs;
+ default = [ ];
+ };
+ };
+
+ config = lib.mkIf config.nixos95.enable {
+
+ home-manager.users.${config.nixos95.user} = {
+
+ xdg.configFile = let
+ to_xml = list : list
+ |> lib.filter slib.isEnable
+ |> lib.map ( elm : let
+ key = lib.escapeXML elm.key;
+ exe = lib.escapeXML (slib.getExe elm);
+ in '' '')
+ |> lib.concatStringsSep "\n";
+ commands_xml = to_xml cfg.commands;
+ xfwm4_xml = to_xml cfg.xfwm4;
+ in {
+ "xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml" = {
+ force = true;
+ text = ''
+
+
+
+
+
+
+ ${commands_xml}
+
+
+
+
+
+ ${xfwm4_xml}
+
+
+
+
+
+
+
+ '';
+ };
};
+
};
};
diff --git a/nixos95/taskbar.nix b/nixos95/taskbar.nix
index e3e81db..7fad763 100644
--- a/nixos95/taskbar.nix
+++ b/nixos95/taskbar.nix
@@ -6,6 +6,7 @@
cfg = config.nixos95.taskbar;
user = config.nixos95.user;
t = lib.types;
+ slib = pkgs.callPackage ./util/lib.nix { };
in {
options.nixos95.taskbar = {
@@ -108,14 +109,14 @@ in {
battery_xml = ifBattery '' '';
applications_cfg = cfg.applications
- |> lib.filter ( elm : !( lib.hasAttr "enable" elm) || elm.enable )
+ |> lib.filter slib.isEnable
|> lib.imap0 ( ptr : elm : rec {
# we start IDs in the 20 range to not get confilics with other plugins
plugin_id = "2" + builtins.toString ptr;
plugin_desktop = let
desc = if elm ? description then elm.description else "";
term = if elm ? term && elm.term then "true" else "false";
- exec = if elm ? pkg then lib.getExe elm.pkg else elm.exe;
+ exec = slib.getExe elm;
in pkgs.writeTextFile {
name = "${elm.name}.desktop";
text = ''
diff --git a/nixos95/util/lib.nix b/nixos95/util/lib.nix
new file mode 100644
index 0000000..b84463e
--- /dev/null
+++ b/nixos95/util/lib.nix
@@ -0,0 +1,6 @@
+{ lib, ... }: {
+ # return true if elm.enable is not set or elm.enable is true
+ isEnable = elm : !( lib.hasAttr "enable" elm ) || elm.enable;
+ # return executable path from elm.pkg if defined or elm.exe
+ getExe = elm : if elm ? pkg then lib.getExe elm.pkg else elm.exe;
+}