From f634d5f6ee9be365b2ca08b2d00e0e3b0c240b9e Mon Sep 17 00:00:00 2001 From: Heitor Augusto Date: Thu, 31 Oct 2024 06:26:28 -0300 Subject: [PATCH] feat(plasmusic-toolbar): update playback source option (#378) --- examples/home.nix | 2 +- modules/widgets/plasmusic-toolbar.nix | 193 +++++++++++++------------- 2 files changed, 99 insertions(+), 96 deletions(-) diff --git a/examples/home.nix b/examples/home.nix index 510ad865..8c61614b 100644 --- a/examples/home.nix +++ b/examples/home.nix @@ -189,7 +189,7 @@ }; icon = "view-media-track"; }; - preferredSource = "spotify"; + playbackSource = "auto"; musicControls.showPlaybackControls = true; songText = { displayInSeparateLines = true; diff --git a/modules/widgets/plasmusic-toolbar.nix b/modules/widgets/plasmusic-toolbar.nix index b76afd8a..1d2c0203 100644 --- a/modules/widgets/plasmusic-toolbar.nix +++ b/modules/widgets/plasmusic-toolbar.nix @@ -1,6 +1,5 @@ { lib, ... }: let - inherit (lib) mkOption types; inherit (import ./lib.nix { inherit lib; }) configValueType; inherit (import ./default.nix { inherit lib; }) positionType sizeType; @@ -23,9 +22,9 @@ let (throw "getIndexFromEnum (plasmusic-toolbar widget): Value ${value} isn't present in the enum. This is a bug") enum; - styleStrategyType = types.submodule { + styleStrategyType = lib.types.submodule { options = with qfont.styleStrategy; { - prefer = mkOption { + prefer = lib.mkOption { type = prefer; default = "default"; description = '' @@ -36,7 +35,7 @@ let respectively. ''; }; - matchingPrefer = mkOption { + matchingPrefer = lib.mkOption { type = matchingPrefer; default = "default"; description = '' @@ -46,7 +45,7 @@ let correspond to `PreferMatch` and `PreferQuality` enum flags respectively. ''; }; - antialiasing = mkOption { + antialiasing = lib.mkOption { type = antialiasing; default = "default"; description = '' @@ -56,8 +55,8 @@ let correspond to `PreferAntialias` and `NoAntialias` enum flags respectively. ''; }; - noSubpixelAntialias = mkOption { - type = types.bool; + noSubpixelAntialias = lib.mkOption { + type = lib.types.bool; default = false; description = '' If set to true, this font will try to avoid subpixel antialiasing. @@ -66,7 +65,7 @@ let ''; }; noFontMerging = mkOption { - type = types.bool; + type = lib.types.bool; default = false; description = '' If set to true, this font will not try to find a substitute font when encountering missing glyphs. @@ -75,7 +74,7 @@ let ''; }; preferNoShaping = mkOption { - type = types.bool; + type = lib.types.bool; default = false; description = '' If set to true, this font will not try to apply shaping rules that may be required for some scripts @@ -87,15 +86,15 @@ let }; }; - fontType = types.submodule { + fontType = lib.types.submodule { options = { - family = mkOption { - type = types.str; + family = lib.mkOption { + type = lib.types.str; description = "The font family of this font."; example = "Noto Sans"; }; - pointSize = mkOption { - type = types.nullOr types.numbers.positive; + pointSize = lib.mkOption { + type = with lib.types; nullOr numbers.positive; default = null; description = '' The point size of this font. @@ -103,8 +102,8 @@ let Could be a decimal, but usually an integer. Mutually exclusive with pixel size. ''; }; - pixelSize = mkOption { - type = types.nullOr types.ints.u16; + pixelSize = lib.mkOption { + type = with lib.types; nullOr types.ints.u16; default = null; description = '' The pixel size of this font. @@ -112,7 +111,7 @@ let Mutually exclusive with point size. ''; }; - styleHint = mkOption { + styleHint = lib.mkOption { type = qfont.styleHint; default = "anyStyle"; description = '' @@ -121,8 +120,8 @@ let See https://doc.qt.io/qt-6/qfont.html#StyleHint-enum for more. ''; }; - weight = mkOption { - type = types.either (types.ints.between 1 1000) qfont.weight; + weight = lib.mkOption { + type = with lib.types; either (ints.between 1 1000) qfont.weight; default = "normal"; description = '' The weight of the font, either as a number between 1 to 1000 or as a pre-defined weight string. @@ -130,27 +129,27 @@ let See https://doc.qt.io/qt-6/qfont.html#Weight-enum for more. ''; }; - style = mkOption { + style = lib.mkOption { type = qfont.style; default = "normal"; description = "The style of the font."; }; - underline = mkOption { - type = types.bool; + underline = lib.mkOption { + type = lib.types.bool; default = false; description = "Whether the font is underlined."; }; - strikeOut = mkOption { - type = types.bool; + strikeOut = lib.mkOption { + type = lib.types.bool; default = false; description = "Whether the font is struck out."; }; - fixedPitch = mkOption { - type = types.bool; + fixedPitch = lib.mkOption { + type = lib.types.bool; default = false; description = "Whether the font has a fixed pitch."; }; - capitalization = mkOption { + capitalization = lib.mkOption { type = qfont.capitalization; default = "mixedCase"; description = '' @@ -159,7 +158,7 @@ let See https://doc.qt.io/qt-6/qfont.html#Capitalization-enum for more. ''; }; - letterSpacingType = mkOption { + letterSpacingType = lib.mkOption { type = qfont.spacingType; default = "percentage"; description = '' @@ -168,8 +167,8 @@ let See https://doc.qt.io/qt-6/qfont.html#SpacingType-enum for more. ''; }; - letterSpacing = mkOption { - type = types.number; + letterSpacing = lib.mkOption { + type = lib.types.number; default = 0; description = '' The amount of letter spacing for this font. @@ -178,8 +177,8 @@ let based on the selected `letterSpacingType`. ''; }; - wordSpacing = mkOption { - type = types.number; + wordSpacing = lib.mkOption { + type = lib.types.number; default = 0; description = '' The amount of word spacing for this font, in pixels. @@ -187,15 +186,15 @@ let Positive values increase spacing while negative ones decrease spacing. ''; }; - stretch = mkOption { - type = types.either (types.ints.between 1 4000) qfont.stretch; + stretch = lib.mkOption { + type = with lib.types; either (ints.between 1 4000) qfont.stretch; default = "anyStretch"; description = '' The stretch factor for this font, as an integral percentage (i.e. 150 means a 150% stretch), or as a pre-defined stretch factor string. ''; }; - styleStrategy = mkOption { + styleStrategy = lib.mkOption { type = styleStrategyType; default = { }; description = '' @@ -204,8 +203,8 @@ let See https://doc.qt.io/qt-6/qfont.html#StyleStrategy-enum for more. ''; }; - styleName = mkOption { - type = types.nullOr types.str; + styleName = lib.mkOption { + type = with lib.types; nullOr str; default = null; description = '' The style name of this font, overriding the `style` and `weight` parameters when set. @@ -220,7 +219,7 @@ in description = "KDE Plasma widget that shows currently playing song information and provide playback controls."; opts = { - position = mkOption { + position = lib.mkOption { type = positionType; example = { horizontal = 250; @@ -228,7 +227,7 @@ in }; description = "The position of the widget. (Only for desktop widget)"; }; - size = mkOption { + size = lib.mkOption { type = sizeType; example = { width = 500; @@ -237,8 +236,8 @@ in description = "The size of the widget. (Only for desktop widget)"; }; panelIcon = { - icon = mkOption { - type = types.nullOr types.str; + icon = lib.mkOption { + type = with lib.types; nullOr str; default = null; example = "view-media-track"; description = "Icon to show in the panel."; @@ -246,32 +245,37 @@ in albumCover = { fallbackToIcon = mkBoolOption "Whether to fallback to icon if cover is not available."; useAsIcon = mkBoolOption "Whether to use album cover as icon or not."; - radius = mkOption { - type = types.nullOr (types.ints.between 0 25); + radius = lib.mkOption { + type = with lib.types; nullOr (ints.between 0 25); default = null; example = 8; description = "Radius of the album cover icon."; }; }; }; - 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; - }; + playbackSource = lib.mkOption { + type = with lib.types; nullOr (either (enum [ "auto" ]) str); + default = null; + example = "auto"; + description = "Preferred source to use for playback."; + apply = + source: + if source == null then + { } + else if source == "auto" then + { + choosePlayerAutomatically = true; + preferredPlayerIdentity = null; + } + else + { + choosePlayerAutomatically = false; + preferredPlayerIdentity = source; + }; + }; songText = { - maximumWidth = mkOption { - type = types.nullOr types.ints.unsigned; + maximumWidth = lib.mkOption { + type = with lib.types; nullOr ints.unsigned; default = null; example = 200; description = "Maximum width of the song text."; @@ -286,15 +290,15 @@ in "alwaysScrollExceptOnHover" ]; in - mkOption { - type = with types; nullOr (enum enumVals); + lib.mkOption { + type = with lib.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); + speed = lib.mkOption { + type = with lib.types; nullOr (ints.between 1 10); default = null; example = 3; description = "Speed of the scrolling text."; @@ -305,15 +309,15 @@ in }; musicControls = { showPlaybackControls = mkBoolOption "Whether to show playback controls or not."; - volumeStep = mkOption { - type = types.nullOr (types.ints.between 1 100); + volumeStep = lib.mkOption { + type = with lib.types; nullOr (ints.between 1 100); default = null; example = 5; description = "Step size for volume control."; }; }; - font = mkOption { - type = types.nullOr fontType; + font = lib.mkOption { + type = lib.types.nullOr fontType; default = null; example = { family = "Noto Sans"; @@ -330,8 +334,8 @@ in "transparentShadow" ]; in - mkOption { - type = with types; nullOr (enum enumVals); + lib.mkOption { + type = with lib.types; nullOr (enum enumVals); default = null; example = "transparent"; description = "Widget background type (only for desktop widget)"; @@ -353,14 +357,14 @@ in ); }; albumCover = { - albumPlaceholder = mkOption { - type = types.nullOr types.str; + albumPlaceholder = lib.mkOption { + type = with lib.types; nullOr str; default = null; example = "file:///home/user/placeholder.png"; description = "Path to the album placeholder image."; }; }; - settings = mkOption { + settings = lib.mkOption { type = configValueType; default = null; example = { @@ -379,45 +383,44 @@ in convert = { panelIcon, - preferredSource, songText, musicControls, font, background, albumCover, + playbackSource, settings, ... }: { name = "plasmusic-toolbar"; - config = lib.recursiveUpdate { - General = lib.filterAttrs (_: v: v != null) { - panelIcon = panelIcon.icon; - useAlbumCoverAsPanelIcon = panelIcon.albumCover.useAsIcon; - albumCoverRadius = panelIcon.albumCover.radius; - fallbackToIconWhenArtNotAvailable = panelIcon.albumCover.fallbackToIcon; - - sourceIndex = preferredSource; + General = + lib.filterAttrs (_: v: v != null) { + panelIcon = panelIcon.icon; + useAlbumCoverAsPanelIcon = panelIcon.albumCover.useAsIcon; + albumCoverRadius = panelIcon.albumCover.radius; + fallbackToIconWhenArtNotAvailable = panelIcon.albumCover.fallbackToIcon; - maxSongWidthInPanel = songText.maximumWidth; - separateText = songText.displayInSeparateLines; + maxSongWidthInPanel = songText.maximumWidth; + separateText = songText.displayInSeparateLines; - textScrollingEnabled = songText.scrolling.enable; - textScrollingBehaviour = songText.scrolling.behavior; - textScrollingSpeed = songText.scrolling.speed; - textScrollingResetOnPause = songText.scrolling.resetOnPause; + textScrollingEnabled = songText.scrolling.enable; + textScrollingBehaviour = songText.scrolling.behavior; + textScrollingSpeed = songText.scrolling.speed; + textScrollingResetOnPause = songText.scrolling.resetOnPause; - commandsInPanel = musicControls.showPlaybackControls; - volumeStep = musicControls.volumeStep; + commandsInPanel = musicControls.showPlaybackControls; + volumeStep = musicControls.volumeStep; - useCustomFont = (font != null); - customFont = font; + useCustomFont = font != null; + customFont = font; - desktopWidgetBg = background; + desktopWidgetBg = background; - albumPlaceholder = albumCover.albumPlaceholder; - }; + albumPlaceholder = albumCover.albumPlaceholder; + } + // playbackSource; } settings; }; };