1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-11 07:10:39 +02:00

feat: make conditional top bar in wired

This commit is contained in:
oddlama 2023-10-12 15:50:56 +02:00
parent 056fe1e7fe
commit d8138efbec
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
2 changed files with 174 additions and 122 deletions

View file

@ -86,8 +86,8 @@
entriesStr = entriesStr =
if value ? _ronType if value ? _ronType
then specialType indent value then specialType indent value
else if builtins.isList value else if !builtins.isAttrs value
then list newIndent value then toRon indent value
else let else let
entries = mapAttrsToList toEntry value; entries = mapAttrsToList toEntry value;
entriesStrSpace = concatStringsSep ", " entries; entriesStrSpace = concatStringsSep ", " entries;

View file

@ -25,6 +25,9 @@
Hook = struct "Hook"; Hook = struct "Hook";
Vec2 = x: y: struct "Vec2" {inherit x y;}; Vec2 = x: y: struct "Vec2" {inherit x y;};
ShortcutsConfig = struct "ShortcutsConfig"; ShortcutsConfig = struct "ShortcutsConfig";
And = struct "And";
Or = struct "Or";
Not = struct "Not";
mkVec2 = x: y: Vec2 (globalScale * x) (globalScale * y); mkVec2 = x: y: Vec2 (globalScale * x) (globalScale * y);
@ -74,9 +77,10 @@
}); });
}; };
mkTopBar = name: [ mkTopBar = name: extra:
map (x: extra // x) [
{ {
name = "${name}_app_icon"; name = "${name}_app_image";
parent = "${name}_root"; parent = "${name}_root";
hook = mkHook "TL" "TL"; hook = mkHook "TL" "TL";
offset = mkVec2 0 0; offset = mkVec2 0 0;
@ -93,7 +97,7 @@
} }
{ {
name = "${name}_app_name"; name = "${name}_app_name";
parent = "${name}_app_icon"; parent = "${name}_app_image";
hook = mkHook "TR" "TL"; hook = mkHook "TR" "TL";
offset = mkVec2 0 0; offset = mkVec2 0 0;
params = struct "TextBlock" (unnamedStruct { params = struct "TextBlock" (unnamedStruct {
@ -105,25 +109,12 @@
text = "%n"; text = "%n";
}); });
} }
{
name = "${name}_time";
parent = "${name}_root";
hook = mkHook "TR" "TR";
offset = mkVec2 0 0;
params = struct "TextBlock" (unnamedStruct {
color = colors.base05;
dimensions = mkDimensionsWH 0 (-1) 28 28;
ellipsize = mkLiteral "End";
font = "${fonts.monospace.name} Bold ${toString (globalScale * 14)}";
padding = mkPaddingLrBt 0 16 4 12;
text = "%t(%a %H:%M)";
});
}
]; ];
mkBody = name: yOffset: [ mkBody = name: ident: yOffset: summaryRightPadding: extra:
map (x: extra // x) [
{ {
name = "${name}_hint"; name = "${name}_${ident}_hint";
parent = "${name}_root"; parent = "${name}_root";
hook = mkHook "TL" "TL"; hook = mkHook "TL" "TL";
offset = mkVec2 0 yOffset; offset = mkVec2 0 yOffset;
@ -137,8 +128,8 @@
}); });
} }
{ {
name = "${name}_summary"; name = "${name}_${ident}_summary";
parent = "${name}_hint"; parent = "${name}_${ident}_hint";
hook = mkHook "TR" "TL"; hook = mkHook "TR" "TL";
offset = mkVec2 0 0; offset = mkVec2 0 0;
params = struct "TextBlock" (unnamedStruct { params = struct "TextBlock" (unnamedStruct {
@ -146,18 +137,23 @@
font = "${fonts.sansSerif.name} Bold ${toString (globalScale * 16)}"; font = "${fonts.sansSerif.name} Bold ${toString (globalScale * 16)}";
ellipsize = mkLiteral "End"; ellipsize = mkLiteral "End";
color = colors.base06; color = colors.base06;
padding = mkPaddingLrBt 16 16 0 8; padding = mkPaddingLrBt 16 (summaryRightPadding + 16) 0 8;
dimensions = mkDimensionsWH 580 580 0 30; dimensions = mkDimensionsWH (580 - summaryRightPadding) (580 - summaryRightPadding) 0 30;
dimensions_image_hint = mkDimensionsWH 440 440 0 30; dimensions_image_hint = mkDimensionsWH 440 440 0 30;
dimensions_image_both = mkDimensionsWH 440 440 0 30; dimensions_image_both = mkDimensionsWH 440 440 0 30;
}); });
} }
{ {
name = "${name}_body"; name = "${name}_${ident}_body";
parent = "${name}_summary"; parent = "${name}_${ident}_summary";
hook = mkHook "BL" "TL"; hook = mkHook "BL" "TL";
offset = mkVec2 0 12; offset = mkVec2 0 12;
render_criteria = [(mkLiteral "Body")]; render_criteria = [
(And [
(Or extra.render_criteria)
(mkLiteral "Body")
])
];
params = struct "TextBlock" (unnamedStruct { params = struct "TextBlock" (unnamedStruct {
text = "%b"; text = "%b";
font = "${fonts.sansSerif.name} ${toString (globalScale * 16)}"; font = "${fonts.sansSerif.name} ${toString (globalScale * 16)}";
@ -171,12 +167,12 @@
} }
]; ];
mkProgress = name: yOffset: extra: mkProgress = name: parent: yOffset: extra:
map (x: x // extra) [ map (x: extra // x) [
{ {
name = "${name}_progress_${toString yOffset}_text"; name = "${name}_progress_${parent}_text";
parent = "${name}_root"; parent = "${name}_${parent}";
hook = mkHook "TL" "TL"; hook = mkHook "BL" "TL";
offset = mkVec2 0 0; offset = mkVec2 0 0;
params = struct "TextBlock" (unnamedStruct { params = struct "TextBlock" (unnamedStruct {
text = "%p%"; text = "%p%";
@ -189,9 +185,9 @@
}); });
} }
{ {
name = "${name}_progress_${toString yOffset}"; name = "${name}_progress_${parent}_bar";
parent = "${name}_root"; parent = "${name}_${parent}";
hook = mkHook "TL" "TL"; hook = mkHook "BL" "TL";
offset = mkVec2 0 0; offset = mkVec2 0 0;
params = struct "ProgressBlock" (unnamedStruct { params = struct "ProgressBlock" (unnamedStruct {
width = globalScale * 520; width = globalScale * 520;
@ -226,29 +222,85 @@
}; };
layout_blocks = let layout_blocks = let
# Progress for body or hint-image notifications criterionHasTopBar = And [
# must be much closer to the bottom (mkLiteral "AppImage")
bottomProgressCriteria = struct "Or" [ (Not (Or [
(mkLiteral "Body") (struct "AppName" "")
(mkLiteral "HintImage") (struct "AppName" "notify-send")
]))
]; ];
in in
map unnamedStruct (lib.flatten [ map unnamedStruct (lib.flatten [
(mkRootBlock "general") (mkRootBlock "general")
(mkTopBar "general") # Time is always shown in the top right corner.
(mkBody "general" 36) {
(mkProgress "general" 180 { name = "general_time";
parent = "general_root";
hook = mkHook "TR" "TR";
offset = mkVec2 0 0;
params = struct "TextBlock" (unnamedStruct {
color = colors.base05;
dimensions = mkDimensionsWH 0 (-1) 28 28;
ellipsize = mkLiteral "End";
font = "${fonts.monospace.name} Bold ${toString (globalScale * 14)}";
padding = mkPaddingLrBt 0 16 4 12;
text = "%t(%a %H:%M)";
});
}
# Top bar for app image, name and time, but only
# if there is an app name or image.
(mkTopBar "general" {
render_criteria = [criterionHasTopBar];
})
# if no top bar present: A body with no offset and a summary padding to the right (to not overlay the time)
(mkBody "general" "notop" 0 24 {
render_criteria = [(Not criterionHasTopBar)];
})
# if top bar present: A body with matching y offset and no summary padding to the right
(mkBody "general" "withtop" 36 0 {
render_criteria = [criterionHasTopBar];
})
# We unfortunately need to duplicate each layout that has the body, summary or hint as
# a parent, since each name must be unique and we cannot select the correct parent dynamically.
(lib.flip map ["notop" "withtop"] (parent: let
parentCriterion =
if parent == "withtop"
then criterionHasTopBar
else (Not criterionHasTopBar);
in [
(mkProgress "general" "${parent}_hint" 0 {
render_criteria = [ render_criteria = [
(struct "And" [ (And [
parentCriterion
(mkLiteral "Progress") (mkLiteral "Progress")
bottomProgressCriteria (mkLiteral "HintImage")
]) ])
]; ];
}) })
(mkProgress "general" 80 { (mkProgress "general" "${parent}_body" 0 {
render_criteria = [(mkLiteral "Progress")]; render_criteria = [
render_anti_criteria = [bottomProgressCriteria]; (And [
parentCriterion
(mkLiteral "Progress")
(mkLiteral "Body")
(Not (mkLiteral "HintImage"))
])
];
}) })
(mkProgress "general" "${parent}_summary" 9 {
render_criteria = [
(And [
parentCriterion
(mkLiteral "Progress")
(mkLiteral "Summary")
(Not (Or [
(mkLiteral "Body")
(mkLiteral "HintImage")
]))
])
];
})
]))
]); ]);
}); });
}; };