Allow bools, ints and floats for widget configs and major refactoring (#248)

This commit is contained in:
magnouvean 2024-07-12 18:47:31 +02:00 committed by GitHub
parent 8c84e04023
commit 0557cecf3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 510 additions and 352 deletions

View File

@ -1,40 +1,60 @@
{ lib, widgets, ... }:
{ lib, ... }:
let
inherit (lib) mkOption types;
inherit (widgets.lib) mkBoolOption mkEnumOption;
convertHorizontalAlignment = horizontalAlignment: let
mkBoolOption = description: lib.mkOption {
type = with lib.types; nullOr bool;
default = null;
inherit description;
};
convertHorizontalAlignment = horizontalAlignment:
let
mappings = {
"left" = "1";
"right" = "2";
"center" = "4";
"justify" = "8";
left = 1;
right = 2;
center = 4;
justify = 8;
};
in
mappings.${horizontalAlignment} or (throw "Invalid enum value: ${horizontalAlignment}");
convertVerticalAlignment = verticalAlignment: let
convertVerticalAlignment = verticalAlignment:
let
mappings = {
"top" = "1";
"center" = "128";
"bottom" = "64";
"baseline" = "256";
top = 1;
center = 128;
bottom = 64;
baseline = 256;
};
in
mappings.${verticalAlignment} or (throw "Invalid enum value: ${verticalAlignment}");
getIndexFromEnum = enum: value:
if value == null
then null
else
lib.lists.findFirstIndex
(x: x == value)
(throw "getIndexFromEnum (application-title-bar widget): Value ${value} isn't present in the enum. This is a bug")
enum;
fontType = types.submodule {
options = {
bold = mkBoolOption "Enable bold text.";
fit = mkEnumOption [ "fixedSize" "horizontalFit" "verticalFit" "fit" ] // {
fit =
let enumVals = [ "fixedSize" "horizontalFit" "verticalFit" "fit" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "fixedSize";
description = "The mode of the size of the font.";
apply = getIndexFromEnum enumVals;
};
size = mkOption {
type = types.ints.positive;
default = 10;
description = "The size of the font.";
apply = builtins.toString;
};
};
};
@ -45,25 +65,21 @@ let
type = types.ints.unsigned;
default = 10;
description = "The left margin.";
apply = builtins.toString;
};
right = mkOption {
type = types.ints.unsigned;
default = 10;
description = "The right margin.";
apply = builtins.toString;
};
top = mkOption {
type = types.ints.unsigned;
default = 0;
description = "The top margin.";
apply = builtins.toString;
};
bottom = mkOption {
type = types.ints.unsigned;
default = 0;
description = "The bottom margin.";
apply = builtins.toString;
};
};
};
@ -78,13 +94,11 @@ in
type = types.nullOr types.ints.unsigned;
default = null;
description = "The margins around the widget.";
apply = builtins.toString;
};
spacingBetweenElements = mkOption {
type = types.nullOr types.ints.unsigned;
default = null;
description = "The spacing between elements.";
apply = builtins.toString;
};
horizontalAlignment = mkOption {
type = types.enum [ "left" "right" "center" "justify" ];
@ -98,9 +112,14 @@ in
description = "The vertical alignment of the widget.";
apply = convertVerticalAlignment;
};
showDisabledElements = mkEnumOption [ "deactivated" "hideKeepSpace" "hide" ] // {
showDisabledElements =
let enumVals = [ "deactivated" "hideKeepSpace" "hide" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "deactivated";
description = "How to show the elements when the widget is disabled.";
apply = getIndexFromEnum enumVals;
};
fillFreeSpace = mkBoolOption "Whether the widget should fill the free space on the panel.";
elements = mkOption {
@ -123,7 +142,11 @@ in
};
};
windowControlButtons = {
iconSource = mkEnumOption [ "plasma" "breeze" "aurorae" "oxygen" ] // {
iconSource =
let enumVals = [ "plasma" "breeze" "aurorae" "oxygen" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "plasma";
description = ''
The icon source for the control buttons.
@ -133,6 +156,7 @@ in
- Aurorae: Window decorations theme
- Oxygen: Implicit Oxygen icons
'';
apply = getIndexFromEnum enumVals;
};
auroraeTheme = mkOption {
type = types.nullOr types.str;
@ -143,19 +167,16 @@ in
type = types.nullOr types.ints.unsigned;
default = null;
description = "The margin around the buttons.";
apply = builtins.toString;
};
buttonsAspectRatio = mkOption {
type = types.nullOr types.ints.unsigned;
default = null;
description = "The ratio of button width in percent to 100% of its height. If you need wider buttons, the value should be >100, otherwise less.";
apply = builtins.toString;
};
buttonsAnimationSpeed = mkOption {
type = types.nullOr types.ints.unsigned;
default = null;
description = "The speed of the buttons animation in milliseconds.";
apply = builtins.toString;
};
};
windowTitle = {
@ -163,13 +184,11 @@ in
type = types.nullOr types.ints.unsigned;
default = null;
description = "The minimum width of the window title.";
apply = builtins.toString;
};
maximumWidth = mkOption {
type = types.nullOr types.ints.unsigned;
default = null;
description = "The maximum width of the window title.";
apply = builtins.toString;
};
font = mkOption {
type = types.nullOr fontType;
@ -192,7 +211,11 @@ in
default = null;
description = "The text to show when the window title is undefined.";
};
source = mkEnumOption [ "appName" "decoration" "genericAppName" "alwaysUndefined" ] // {
source =
let enumVals = [ "appName" "decoration" "genericAppName" "alwaysUndefined" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "appName";
description = ''
The source of the window title.
@ -202,6 +225,7 @@ in
- genericAppName: The generic name of the application
- alwaysUndefined: Always show the undefined title
'';
apply = getIndexFromEnum enumVals;
};
margins = mkOption {
type = types.nullOr marginType;
@ -241,7 +265,13 @@ in
The elements to show in the widget for maximized windows.
'';
};
source = mkEnumOption [ "appName" "decoration" "genericAppName" "alwaysUndefined" ] // {
source =
let
enumVals = [ "appName" "decoration" "genericAppName" "alwaysUndefined" ];
in
mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "appName";
description = ''
The source of the window title for maximized windows.
@ -251,10 +281,15 @@ in
- genericAppName: The generic name of the application
- alwaysUndefined: Always show the undefined title
'';
apply = getIndexFromEnum enumVals;
};
};
behavior = {
activeTaskSource = mkEnumOption [ "activeTask" "lastActiveTask" "lastActiveMaximized" ] // {
activeTaskSource =
let enumVals = [ "activeTask" "lastActiveTask" "lastActiveMaximized" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "activeTask";
description = ''
The source of the active task.
@ -263,6 +298,7 @@ in
- lastActiveTask: The last active task
- lastActiveMaximized: The last active maximized task
'';
apply = getIndexFromEnum enumVals;
};
filterByActivity = mkBoolOption "Whether to filter the tasks by activity.";
filterByScreen = mkBoolOption "Whether to filter the tasks by screen.";
@ -277,7 +313,6 @@ in
type = types.nullOr types.ints.unsigned;
default = null;
description = "The threshold for dragging the widget.";
apply = builtins.toString;
};
leftDragAction = mkOption {
type = types.nullOr types.str;
@ -329,13 +364,11 @@ in
type = types.nullOr types.ints.unsigned;
default = null;
description = "The distance of the first event.";
apply = builtins.toString;
};
nextEventDistance = mkOption {
type = types.nullOr types.ints.unsigned;
default = null;
description = "The distance of the next event.";
apply = builtins.toString;
};
wheelUp = mkOption {
type = types.nullOr types.str;

View File

@ -1,9 +1,14 @@
{ lib, widgets, ... }: {
{ lib, ... }: {
battery = {
description = "The battery indicator widget.";
# See https://invent.kde.org/plasma/plasma-workspace/-/blob/master/applets/batterymonitor/package/contents/config/main.xml for the accepted raw options
opts.showPercentage = widgets.lib.mkBoolOption "Enable to show the battery percentage as a small label over the battery icon.";
opts.showPercentage = lib.mkOption {
type = with lib.types; nullOr bool;
default = null;
example = true;
description = "Enable to show the battery percentage as a small label over the battery icon.";
};
convert = { showPercentage }: {
name = "org.kde.plasma.battery";

View File

@ -34,7 +34,7 @@ let
description = "The name of the widget to add.";
};
config = lib.mkOption {
type = with lib.types; nullOr (attrsOf (attrsOf (either str (listOf str))));
type = (import ./lib.nix (args // { widgets = self; })).configValueType;
default = null;
example = {
General.icon = "nix-snowflake-white";

View File

@ -1,7 +1,21 @@
{ lib, widgets, ... }:
{ lib, ... }:
let
inherit (lib) mkOption types;
inherit (widgets.lib) mkBoolOption mkEnumOption boolToString';
mkBoolOption = description: mkOption {
type = with types; nullOr bool;
default = null;
inherit description;
};
getIndexFromEnum = enum: value:
if value == null
then null
else
lib.lists.findFirstIndex
(x: x == value)
(throw "getIndexFromEnum (digital-clock widget): Value ${value} isn't present in the enum. This is a bug")
enum;
fontType = types.submodule {
options = {
@ -16,7 +30,6 @@ let
type = types.ints.between 1 1000;
default = 50;
description = "The weight of the font.";
apply = builtins.toString;
};
style = mkOption {
type = types.nullOr types.str;
@ -27,7 +40,6 @@ let
type = types.ints.positive;
default = 10;
description = "The size of the font.";
apply = builtins.toString;
};
};
};
@ -44,12 +56,12 @@ in
format =
let
enum = [ "shortDate" "longDate" "isoDate" ];
enumVals = [ "shortDate" "longDate" "isoDate" ];
in
mkOption {
type = types.nullOr (types.either (types.enum enum) (types.submodule {
type = with types; nullOr (either (enum enumVals) (submodule {
options.custom = mkOption {
type = types.str;
type = str;
example = "ddd d";
description = "The custom date format to use.";
};
@ -75,38 +87,53 @@ in
};
position = mkEnumOption [ "adaptive" "besideTime" "belowTime" ] // {
position =
let enumVals = [ "adaptive" "besideTime" "belowTime" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "belowTime";
description = ''
The position where the date is displayed.
Could be adaptive, always beside the displayed time, or below the displayed time.
'';
apply = getIndexFromEnum enumVals;
};
};
time = {
showSeconds = mkEnumOption [ "never" "onlyInTooltip" "always" ] // {
showSeconds =
let enumVals = [ "never" "onlyInTooltip" "always" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "always";
description = ''
When and where the seconds should be shown on the clock.
Could be never, only in the tooltip on hover, or always.
'';
apply = getIndexFromEnum enumVals;
};
format = mkEnumOption [ "12h" "default" "24h" ] // {
format =
let enumVals = [ "12h" "default" "24h" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "24h";
description = ''
The time format used for this clock.
Could be 12-hour, the default for your locale, or 24-hour.
'';
apply = getIndexFromEnum enumVals;
};
};
timeZone = {
selected = mkOption {
type = types.nullOr (types.listOf types.str);
type = with types; nullOr (listOf str);
default = null;
example = [ "Europe/Berlin" "Asia/Shanghai" ];
description = ''
@ -116,7 +143,7 @@ in
'';
};
lastSelected = mkOption {
type = types.nullOr types.str;
type = with types; nullOr str;
default = null;
description = ''
The timezone to show upon widget restore.
@ -125,7 +152,11 @@ in
'';
};
changeOnScroll = mkBoolOption "Allow changing the displayed timezone by scrolling on the widget with the mouse wheel.";
format = mkEnumOption [ "code" "city" "offset" ] // {
format =
let enumVals = [ "code" "city" "offset" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "code";
description = ''
The format of the timezone displayed, whether as a
@ -135,18 +166,24 @@ in
For example, for the timezone Asia/Shanghai, the three formats
listed above would display "CST", "Shanghai" and "+8" respectively.
'';
apply = getIndexFromEnum enumVals;
};
alwaysShow = mkBoolOption "Always show the selected timezone, when it's the same with the system timezone";
};
calendar = {
firstDayOfWeek = mkEnumOption [ "sunday" "monday" "tuesday" "wednesday" "thursday" "friday" "saturday" ] // {
firstDayOfWeek =
let enumVals = [ "sunday" "monday" "tuesday" "wednesday" "thursday" "friday" "saturday" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "monday";
description = ''
The first day of the week that the calendar uses.
If null, then the default for the user locale is used.
'';
apply = getIndexFromEnum enumVals;
};
plugins = mkOption {
type = types.nullOr (types.listOf types.str);
@ -171,7 +208,7 @@ in
'';
apply = font:
{
autoFontAndSize = boolToString' (font == null);
autoFontAndSize = (font == null);
}
// lib.optionalAttrs (font != null) {
fontFamily = font.family;

View File

@ -1,19 +1,38 @@
{ lib, widgets, ... }:
{ lib, ... }:
let
inherit (lib) mkOption types;
inherit (widgets.lib) mkBoolOption mkEnumOption;
convertSpacing = spacing: let
mappings = {
"small" = "0";
"medium" = "1";
"large" = "3";
mkBoolOption = description: mkOption {
type = with types; nullOr bool;
default = null;
inherit description;
};
in mappings.${spacing} or (throw "Invalid spacing: ${spacing}");
positionToReverse = position: let
mappings = { "left" = "true"; "right" = "false"; };
in mappings.${position} or (throw "Invalid position: ${position}");
convertSpacing = spacing:
let
mappings = {
small = 0;
medium = 1;
large = 3;
};
in
mappings.${spacing} or (throw "Invalid spacing: ${spacing}");
getIndexFromEnum = enum: value:
if value == null
then null
else
lib.lists.findFirstIndex
(x: x == value)
(throw "getIndexFromEnum (icon-tasks widget): Value ${value} isn't present in the enum. This is a bug")
enum;
positionToReverse = position:
let
mappings = { left = true; right = false; };
in
mappings.${position} or (throw "Invalid position: ${position}");
in
{
iconTasks = {
@ -37,14 +56,13 @@ in
default = "never";
example = "lowSpace";
description = "When to use multi-row view.";
apply = multirowView: if multirowView == "never" then "false" else (if multirowView == "always" then "true" else null);
apply = multirowView: if multirowView == "never" then false else (if multirowView == "always" then true else null);
};
maximum = mkOption {
type = types.nullOr types.ints.positive;
default = null;
example = 5;
description = "The maximum number of rows (in a horizontal-orientation containment, i.e. panel) or columns (in a vertical-orientation containment) to layout task buttons in.";
apply = builtins.toString;
};
};
iconSpacing = mkOption {
@ -57,23 +75,43 @@ in
};
behavior = {
grouping = {
method = mkEnumOption [ "none" "byProgramName" ] // {
method =
let enumVals = [ "none" "byProgramName" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "none";
description = "How tasks are grouped";
apply = getIndexFromEnum enumVals;
};
clickAction = mkEnumOption [ "cycle" "showTooltips" "showPresentWindowsEffect" "showTextualList" ] // {
clickAction =
let enumVals = [ "cycle" "showTooltips" "showPresentWindowsEffect" "showTextualList" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "cycle";
description = "What happens when clicking on a grouped task";
apply = getIndexFromEnum enumVals;
};
};
sortingMethod = mkEnumOption [ "none" "manually" "alphabetically" "byDesktop" "byActivity" ] // {
sortingMethod =
let enumVals = [ "none" "manually" "alphabetically" "byDesktop" "byActivity" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "manually";
description = "How to sort tasks";
apply = getIndexFromEnum enumVals;
};
minimizeActiveTaskOnClick = mkBoolOption "Whether to minimize the currently-active task when clicked. If false, clicking on the currently-active task will do nothing.";
middleClickAction = mkEnumOption [ "none" "close" "newInstance" "toggleMinimized" "toggleGrouping" "bringToCurrentDesktop" ] // {
middleClickAction =
let enumVals = [ "none" "close" "newInstance" "toggleMinimized" "toggleGrouping" "bringToCurrentDesktop" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "bringToCurrentDesktop";
description = "What to do on middle-mouse click on a task button.";
apply = getIndexFromEnum enumVals;
};
wheel = {
switchBetweenTasks = mkBoolOption "Whether using the mouse wheel with the mouse pointer above the widget should switch between tasks.";
@ -98,7 +136,8 @@ in
convert =
{ appearance
, behavior
, launchers }: {
, launchers
}: {
name = "org.kde.plasma.icontasks";
config.General = lib.filterAttrs (_: v: v != null) (
{

View File

@ -1,11 +1,27 @@
{ lib, widgets, ...}:
{ lib, ... }:
let
inherit (lib) mkOption types;
inherit (widgets.lib) mkBoolOption mkEnumOption;
convertSidebarPosition = sidebarPosition: let
mappings = { "left" = "false"; "right" = "true"; };
in mappings.${sidebarPosition} or (throw "Invalid sidebar position: ${sidebarPosition}");
mkBoolOption = description: mkOption {
type = with types; nullOr bool;
default = null;
inherit description;
};
getIndexFromEnum = enum: value:
if value == null
then null
else
lib.lists.findFirstIndex
(x: x == value)
(throw "getIndexFromEnum (kickoff widget): Value ${value} isn't present in the enum. This is a bug")
enum;
convertSidebarPosition = sidebarPosition:
let
mappings = { left = false; right = true; };
in
mappings.${sidebarPosition} or (throw "Invalid sidebar position: ${sidebarPosition}");
in
{
kickoff = {
@ -33,17 +49,32 @@ in
description = "The position of the sidebar.";
apply = convertSidebarPosition;
};
favoritesDisplayMode = mkEnumOption [ "grid" "list" ] // {
favoritesDisplayMode =
let enumVals = [ "grid" "list" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "list";
description = "How to display favorites.";
apply = getIndexFromEnum enumVals;
};
applicationsDisplayMode = mkEnumOption [ "grid" "list" ] // {
applicationsDisplayMode =
let enumVals = [ "grid" "list" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "grid";
description = "How to display applications.";
apply = getIndexFromEnum enumVals;
};
showButtonsFor = mkEnumOption [ "power" "session" "custom" "powerAndSession" ] // {
showButtonsFor =
let enumVals = [ "power" "session" "custom" "powerAndSession" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "powerAndSession";
description = "Which actions should be displayed in the footer.";
apply = getIndexFromEnum enumVals;
};
showActionButtonCaptions = mkBoolOption "Whether to display captions ('shut down', 'log out', etc.) for the footer action buttons";
pin = mkBoolOption "Whether the popup should remain open when another window is activated.";

View File

@ -1,39 +1,35 @@
{ lib, widgets, ... }:
{ lib, ... }:
let
inherit (lib)
optionalString
concatMapStringsSep
concatStringsSep
mapAttrsToList
splitString
mkOption
types
;
splitString;
configValueTypes = with lib.types; oneOf [ bool float int str ];
configValueType = with lib.types; nullOr (attrsOf (attrsOf (either configValueTypes (listOf configValueTypes))));
# any value or null -> string -> string
# If value is null, returns the empty string, otherwise returns the provided string
stringIfNotNull = v: optionalString (v != null);
# string -> string
# Wrap a string in double quotes.
wrapInQuotes = s: ''"${s}"'';
# Converts each datatype into an expression which can be parsed in JavaScript
valToJS = v: if (builtins.isString v) then ''"${v}"'' else if (builtins.isBool v) then (lib.boolToString v) else (builtins.toString v);
# list of strings -> string
# Converts a list of strings to a single string, that can be parsed as a string list in JavaScript
toJSStringList = values: ''[${concatMapStringsSep ", " wrapInQuotes values}]'';
# Converts a list of to a single string, that can be parsed as a string list in JavaScript
toJSList = values: ''[${concatMapStringsSep ", " valToJS values}]'';
setWidgetSettings = var: settings:
let
perConfig = group: key: value: ''${var}.writeConfig("${key}", ${
if builtins.isString value
then wrapInQuotes value
else if builtins.isList value
then toJSStringList value
else throw "widget config ${group}.${key} can only be string or string list, found ${builtins.typeOf value}"
if builtins.isList value
then toJSList value
else valToJS value
});'';
perGroup = group: configs: ''
${var}.currentConfigGroup = ${toJSStringList (splitString "/" group)};
${var}.currentConfigGroup = ${toJSList (splitString "/" group)};
${concatStringsSep "\n" (mapAttrsToList (perConfig group) configs)}
'';
in
@ -58,43 +54,11 @@ let
const ${var} = {};
${lib.concatMapStringsSep "\n" addStmt ws}
'';
boolToString' = b: if b == null then null else lib.boolToString b;
getEnum = es: e:
if e == null
then null
else
toString (
lib.lists.findFirstIndex
(x: x == e)
(throw "getEnum: nonexistent key ${e}! This is a bug!")
es
);
mkBoolOption = description: mkOption {
inherit description;
type = types.nullOr types.bool;
default = null;
example = true;
apply = widgets.lib.boolToString';
};
mkEnumOption = enum: mkOption {
type = types.nullOr (types.enum enum);
default = null;
apply = widgets.lib.getEnum enum;
};
in
{
inherit
stringIfNotNull
setWidgetSettings
addWidgetStmts
boolToString'
getEnum
mkBoolOption
mkEnumOption
;
configValueType;
}

View File

@ -1,7 +1,21 @@
{lib, widgets, ...}:
{ lib, ... }:
let
inherit (lib) mkOption types;
inherit (widgets.lib) mkBoolOption mkEnumOption;
mkBoolOption = description: lib.mkOption {
type = with lib.types; nullOr bool;
default = null;
inherit description;
};
getIndexFromEnum = enum: value:
if value == null
then null
else
lib.lists.findFirstIndex
(x: x == value)
(throw "getIndexFromEnum (plasmusic-toolbar widget): Value ${value} isn't present in the enum. This is a bug")
enum;
in
{
plasmusicToolbar = {
@ -22,13 +36,17 @@ in
default = null;
example = 8;
description = "Radius of the album cover icon.";
apply = builtins.toString;
};
};
};
preferredSource = mkEnumOption [ "any" "spotify" "vlc" ] // {
preferredSource =
let enumVals = [ "any" "spotify" "vlc" ];
in mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "any";
description = "Preferred source for song information.";
apply = getIndexFromEnum enumVals;
};
songText = {
maximumWidth = mkOption {
@ -36,19 +54,24 @@ in
default = null;
example = 200;
description = "Maximum width of the song text.";
apply = builtins.toString;
};
scrolling = {
behavior = mkEnumOption [ "alwaysScroll" "scrollOnHover" "alwaysScrollExceptOnHover" ] // {
behavior =
let
enumVals = [ "alwaysScroll" "scrollOnHover" "alwaysScrollExceptOnHover" ];
in
mkOption {
type = with types; nullOr (enum enumVals);
default = null;
example = "alwaysScroll";
description = "Scrolling behavior of the song text.";
apply = getIndexFromEnum enumVals;
};
speed = mkOption {
type = types.nullOr (types.ints.between 1 10);
default = null;
example = 3;
description = "Speed of the scrolling text.";
apply = builtins.toString;
};
};
displayInSeparateLines = mkBoolOption "Whether to display song information (title and artist) in separate lines or not.";

View File

@ -1,7 +1,6 @@
{ lib, widgets, ... }:
{ lib, ... }:
let
inherit (lib) mkOption types;
inherit (widgets.lib) mkBoolOption;
# KDE expects a key/value pair like this:
# ```ini
@ -60,7 +59,11 @@ in
default = null;
description = "The title of this system monitor.";
};
showTitle = mkBoolOption "Show or hide the title.";
showTitle = mkOption {
type = with types; nullOr bool;
default = null;
description = "Show or hide the title.";
};
displayStyle = mkOption {
type = with types; nullOr str;
default = null;
@ -116,6 +119,18 @@ in
The list of text-only sensors, displayed in the pop-up upon clicking the widget.
'';
};
range = {
from = mkOption {
type = with lib.types; nullOr (ints.between 0 100);
default = null;
description = "The lower range the sensors can take.";
};
to = mkOption {
type = with lib.types; nullOr (ints.between 0 100);
default = null;
description = "The upper range the sensors can take.";
};
};
};
convert =
@ -125,10 +140,12 @@ in
, totalSensors
, sensors
, textOnlySensors
, range
}: {
name = "org.kde.plasma.systemmonitor";
config = lib.filterAttrsRecursive (_: v: v != null) (lib.recursiveUpdate
{
config = lib.filterAttrsRecursive (_: v: v != null)
(lib.recursiveUpdate
({
Appearance = {
inherit title;
inherit showTitle;
@ -138,7 +155,12 @@ in
lowPrioritySensorIds = textOnlySensors;
totalSensors = totalSensors;
};
}
"org.kde.ksysguard.piechart/General" = {
rangeAuto = (range.from == null && range.to == null);
rangeFrom = range.from;
rangeTo = range.to;
};
})
sensors);
};
};

View File

@ -1,7 +1,12 @@
{ lib, widgets, ... }:
let
inherit (lib) mkOption types;
inherit (widgets.lib) mkBoolOption;
mkBoolOption = description: mkOption {
type = with types; nullOr bool;
default = null;
inherit description;
};
in
{
systemTray = {
@ -29,9 +34,9 @@ in
(if (spacing == null) then null
else
(if builtins.isInt spacing then
toString spacing
spacing
else
builtins.elemAt [ "1" "2" "6" ] (
builtins.elemAt [ 1 2 6 ] (
lib.lists.findFirstIndex
(x: x == spacing)
(throw "systemTray: nonexistent spacing ${spacing}! This is a bug!")

View File

@ -1,10 +1,9 @@
{ lib
, pkgs
, config
, ...
}:
with lib.types; let
inherit (builtins) length listToAttrs foldl' toString attrNames getAttr hasAttr concatStringsSep add isAttrs;
inherit (builtins) length listToAttrs foldl' toString attrNames getAttr concatStringsSep add isAttrs;
inherit (lib) mkOption mkIf;
inherit (lib.trivial) mergeAttrs;
inherit (lib.lists) imap0;