wlogout returns, cosmic config probably finalised

This commit is contained in:
atagen 2024-05-16 11:29:36 +10:00
parent 05d0f6a949
commit 4ae5e113fe
8 changed files with 136 additions and 64 deletions

View file

@ -47,7 +47,7 @@
# Maximize,
# Spawn(String),
let
inherit (lib) concatStrings concatStringsSep mapAttrsToList concatLists foldlAttrs concatMapAttrs mapAttrs' nameValuePair boolToString;
inherit (lib) filterAttrs concatStrings concatStringsSep mapAttrsToList concatLists foldlAttrs concatMapAttrs mapAttrs' nameValuePair boolToString;
inherit (builtins) typeOf toString stringLength;
# build up serialisation machinery from here for various types
@ -60,16 +60,21 @@ let
${concatStringsSep ",\n" (concatLists (map _assoc a))}
}'';
# attrset -> struct
__struct = k: v: (concatStringsSep "=" [k (serialise.${typeOf v} v)]);
_struct = s:
_struct_kv = k: v:
if v == null
then ""
else (concatStringsSep ":" [k (serialise.${typeOf v} v)]);
_struct_concat = s:
foldlAttrs (
acc: k: v:
if stringLength acc > 0
then concatStringsSep ", " [acc (__struct k v)]
else __struct k v
then concatStringsSep ", " [acc (_struct_kv k v)]
else _struct_kv k v
) ""
s;
struct = s: "(${_struct s})";
_struct_filt = s:
_struct_concat (filterAttrs (k: v: v != null) s);
struct = s: "(${_struct_filt s})";
toQuotedString = s: ''"${toString s}"'';
# make an attrset for struct serialisation
@ -88,7 +93,10 @@ let
defineBinding = binding:
struct {
inherit (binding) modifiers;
key = toQuotedString binding.key;
key =
if isNull binding.key
then null
else toQuotedString binding.key;
};
# map keybinding from list of attrset to hashmap of (mod,key): action
@ -112,7 +120,7 @@ let
maybeToString = s:
if typeOf s == "set"
then concatStrings [s.type "(" s.data ")"]
then concatStrings [s.type "(" (toString s.data) ")"]
else s;
# set up boilerplate for keybinding config file
@ -133,7 +141,8 @@ in {
default = [];
};
key = mkOption {
type = str;
type = nullOr str;
default = null;
};
action = mkOption {
type = either str (submodule {
@ -171,12 +180,12 @@ in {
config.environment.etc =
{
"cosmic-comp/config-test.ron".text = cosmic-bindings config.services.desktopManager.cosmic.keybindings;
"cosmic-comp/config.ron".text = cosmic-bindings config.services.desktopManager.cosmic.keybindings;
}
// concatMapAttrs (
application: options:
mapAttrs' (k: v:
nameValuePair "xdg/cosmic-test/${application}/v${options.version}/${k}" {
nameValuePair "xdg/cosmic/${application}/v${options.version}/${k}" {
enable = true;
text = serialise.${typeOf v} v;
})