From d9829a979c5d1ac87054efe9d11ceaeb4cf39587 Mon Sep 17 00:00:00 2001 From: Morwdan <5207513+Morwdan@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:16:09 +0000 Subject: [PATCH] Add new desktop folder settings for workspace module (#292) --- modules/workspace.nix | 174 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 156 insertions(+), 18 deletions(-) diff --git a/modules/workspace.nix b/modules/workspace.nix index 6575b71e..6f6ac693 100644 --- a/modules/workspace.nix +++ b/modules/workspace.nix @@ -4,6 +4,7 @@ let cfg = config.programs.plasma; inherit (import ../lib/wallpapers.nix { inherit lib; }) wallpaperPictureOfTheDayType wallpaperSlideShowType; + inherit (import ./widgets/lib.nix { inherit lib; }) stringIfNotNull; cursorType = with lib.types; submodule { options = { @@ -22,12 +23,27 @@ let }; }; + desktopIconSortingModeId = { + manual = -1; + name = 0; + size = 1; + date = 2; + type = 6; + }; + anyThemeSet = (cfg.workspace.theme != null || cfg.workspace.colorScheme != null || (cfg.workspace.cursor != null && cfg.workspace.cursor.theme != null) || cfg.workspace.lookAndFeel != null || cfg.workspace.iconTheme != null); + # Becomes true if any option under "cfg.workspace.desktop.icons" is set to something other than null. + anyDesktopFolderSettingsSet = + let + recurse = l: lib.any (v: if builtins.isAttrs v then recurse v else v != null) (builtins.attrValues l); + in + recurse cfg.workspace.desktop.icons; + splashScreenEngineDetect = theme: (if (theme == "None") then "none" else "KSplashQML"); in { @@ -54,7 +70,7 @@ in }; theme = lib.mkOption { - type = lib.types.nullOr lib.types.str; + type = with lib.types; nullOr str; default = null; example = "breeze-dark"; description = '' @@ -63,7 +79,7 @@ in }; colorScheme = lib.mkOption { - type = lib.types.nullOr lib.types.str; + type = with lib.types; nullOr str; default = null; example = "BreezeDark"; description = '' @@ -81,7 +97,7 @@ in }; lookAndFeel = lib.mkOption { - type = lib.types.nullOr lib.types.str; + type = with lib.types; nullOr str; default = null; example = "org.kde.breezedark.desktop"; description = '' @@ -90,7 +106,7 @@ in }; iconTheme = lib.mkOption { - type = lib.types.nullOr lib.types.str; + type = with lib.types; nullOr str; default = null; example = "Papirus"; description = '' @@ -126,7 +142,7 @@ in }; wallpaperPlainColor = lib.mkOption { - type = lib.types.nullOr lib.types.str; + type = with lib.types; nullOr str; default = null; example = "0,64,174,256"; description = '' @@ -190,6 +206,106 @@ in ''; }; }; + + desktop = { + icons = { + arrangement = lib.mkOption { + type = with lib.types; nullOr (enum [ "leftToRight" "topToBottom" ]); + default = null; + example = "topToBottom"; + description = '' + The direction, in which desktop icons are to be arranged. + ''; + }; + + alignment = lib.mkOption { + type = with lib.types; nullOr (enum [ "left" "right" ]); + default = null; + example = "right"; + description = '' + Whether to align the icons on the left (the default) or right + side of the screen. + ''; + }; + + lockInPlace = lib.mkOption { + type = with lib.types; nullOr bool; + default = null; + example = true; + description = '' + Locks the position of all desktop icons to the order and placement + defined by `arrangement`, `alignment` and the `sorting` options + so they can’t be manually moved. + ''; + }; + + sorting = { + mode = lib.mkOption { + type = with lib.types; nullOr (enum (builtins.attrNames desktopIconSortingModeId)); + default = null; + example = "type"; + description = '' + Specifies the sort mode for the desktop icons. By default they are + sorted by name. + ''; + apply = sortMode: if (sortMode == null) then null else desktopIconSortingModeId.${sortMode}; + }; + + descending = lib.mkOption { + type = with lib.types; nullOr bool; + default = null; + example = true; + description = '' + Reverses the sorting order if enabled. Sorting is ascending by default. + ''; + }; + + foldersFirst = lib.mkOption { + type = with lib.types; nullOr bool; + default = null; + example = false; + description = '' + Folders are sorted separately from files by default. This means + folders appear first, sorted for example ascending by name, + followed by files, also sorted ascending by name. + If this option is disabled, all items are sorted irrespective + of their type. + ''; + }; + }; + + size = lib.mkOption { + type = with lib.types; nullOr (ints.between 0 6); + default = null; + example = 2; + description = '' + The desktop icon size, which is normally configured via a slider + with seven possible values ranging from small (0) to large (6). + The fourth position (3) is the default. + ''; + }; + + folderPreviewPopups = lib.mkOption { + type = with lib.types; nullOr bool; + default = null; + example = false; + description = '' + Enables the arrow button when hovering over a folder on the desktop + which shows a preview popup of the folder’s contents. + Is enabled by default. + ''; + }; + + previewPlugins = lib.mkOption { + type = with lib.types; nullOr (listOf str); + default = null; + example = [ "audiothumbnail" "fontthumbnail" ]; + description = '' + Configures the preview plugins used to preview desktop files and folders. + ''; + }; + }; + }; }; config = (lib.mkIf cfg.enable { @@ -279,19 +395,41 @@ in # kde tools. We then run this using an autostart script, where this is # run only on the first login (unless overrideConfig is enabled), # granted all the commands succeed (until we change the settings again). - programs.plasma.startup.startupScript."apply_themes" = (lib.mkIf anyThemeSet { - text = '' - ${if cfg.workspace.lookAndFeel != null then "plasma-apply-lookandfeel -a ${cfg.workspace.lookAndFeel}" else ""} - ${if cfg.workspace.theme != null then "plasma-apply-desktoptheme ${cfg.workspace.theme}" else ""} - ${if (cfg.workspace.cursor != null && cfg.workspace.cursor.theme != null) then - "plasma-apply-cursortheme ${cfg.workspace.cursor.theme}" + - (if cfg.workspace.cursor.size != null then " --size ${builtins.toString cfg.workspace.cursor.size}" else "") - else ""} - ${if cfg.workspace.colorScheme != null then "plasma-apply-colorscheme ${cfg.workspace.colorScheme}" else ""} - ${if cfg.workspace.iconTheme != null then "${pkgs.kdePackages.plasma-workspace}/libexec/plasma-changeicons ${cfg.workspace.iconTheme}" else ""} - ''; - priority = 1; - }); + programs.plasma.startup = { + startupScript."apply_themes" = (lib.mkIf anyThemeSet { + text = '' + ${if cfg.workspace.lookAndFeel != null then "plasma-apply-lookandfeel -a ${cfg.workspace.lookAndFeel}" else ""} + ${if cfg.workspace.theme != null then "plasma-apply-desktoptheme ${cfg.workspace.theme}" else ""} + ${if (cfg.workspace.cursor != null && cfg.workspace.cursor.theme != null) then + "plasma-apply-cursortheme ${cfg.workspace.cursor.theme}" + + (if cfg.workspace.cursor.size != null then " --size ${builtins.toString cfg.workspace.cursor.size}" else "") + else ""} + ${if cfg.workspace.colorScheme != null then "plasma-apply-colorscheme ${cfg.workspace.colorScheme}" else ""} + ${if cfg.workspace.iconTheme != null then "${pkgs.kdePackages.plasma-workspace}/libexec/plasma-changeicons ${cfg.workspace.iconTheme}" else ""} + ''; + priority = 1; + }); + + desktopScript."set_desktop_folder_settings" = (lib.mkIf anyDesktopFolderSettingsSet { + text = '' + // Desktop folder settings + let allDesktops = desktops(); + for (const desktop of allDesktops) { + desktop.currentConfigGroup = ["General"]; + ${lib.optionalString (cfg.workspace.desktop.icons.arrangement == "topToBottom") ''desktop.writeConfig("arrangement", 1);''} + ${lib.optionalString (cfg.workspace.desktop.icons.alignment == "right") ''desktop.writeConfig("alignment", 1);''} + ${lib.optionalString (cfg.workspace.desktop.icons.lockInPlace == true) ''desktop.writeConfig("locked", true);''} + ${stringIfNotNull cfg.workspace.desktop.icons.size ''desktop.writeConfig("iconSize", ${builtins.toString cfg.workspace.desktop.icons.size});''} + ${lib.optionalString (cfg.workspace.desktop.icons.folderPreviewPopups == false) ''desktop.writeConfig("popups", false);''} + ${stringIfNotNull cfg.workspace.desktop.icons.previewPlugins ''desktop.writeConfig("previewPlugins", "${lib.strings.concatStringsSep "," cfg.workspace.desktop.icons.previewPlugins}");''} + ${stringIfNotNull cfg.workspace.desktop.icons.sorting.mode ''desktop.writeConfig("sortMode", ${builtins.toString cfg.workspace.desktop.icons.sorting.mode});''} + ${lib.optionalString (cfg.workspace.desktop.icons.sorting.descending == true) ''desktop.writeConfig("sortDesc", true);''} + ${lib.optionalString (cfg.workspace.desktop.icons.sorting.foldersFirst == false) ''desktop.writeConfig("sortDirsFirst", false);''} + } + ''; + priority = 3; + }); + }; # The wallpaper configuration can be found in panels.nix due to wallpaper # configuration and panel configuration being stored in the same file, and