1{ config, lib, pkgs, ... }:
2
3let
4 inherit (lib) mkOption types;
5
6 xcfg = config.services.xserver;
7 cfg = xcfg.desktopManager;
8
9 # If desktop manager `d' isn't capable of setting a background and
10 # the xserver is enabled, `feh' or `xsetroot' are used as a fallback.
11 needBGCond = d: ! (d ? bgSupport && d.bgSupport) && xcfg.enable;
12
13in
14
15{
16 # Note: the order in which desktop manager modules are imported here
17 # determines the default: later modules (if enabled) are preferred.
18 # E.g., if Plasma 5 is enabled, it supersedes xterm.
19 imports = [
20 ./none.nix ./xterm.nix ./phosh.nix ./xfce.nix ./plasma5.nix ../../desktop-managers/plasma6.nix ./lumina.nix
21 ./lxqt.nix ./enlightenment.nix ./gnome.nix ./retroarch.nix ./kodi.nix
22 ./mate.nix ./pantheon.nix ./surf-display.nix ./cde.nix
23 ./cinnamon.nix ./budgie.nix ./deepin.nix ../../desktop-managers/lomiri.nix
24 ];
25
26 options = {
27
28 services.xserver.desktopManager = {
29
30 wallpaper = {
31 mode = mkOption {
32 type = types.enum [ "center" "fill" "max" "scale" "tile" ];
33 default = "scale";
34 example = "fill";
35 description = ''
36 The file {file}`~/.background-image` is used as a background image.
37 This option specifies the placement of this image onto your desktop.
38
39 Possible values:
40 `center`: Center the image on the background. If it is too small, it will be surrounded by a black border.
41 `fill`: Like `scale`, but preserves aspect ratio by zooming the image until it fits. Either a horizontal or a vertical part of the image will be cut off.
42 `max`: Like `fill`, but scale the image to the maximum size that fits the screen with black borders on one side.
43 `scale`: Fit the file into the background without repeating it, cutting off stuff or using borders. But the aspect ratio is not preserved either.
44 `tile`: Tile (repeat) the image in case it is too small for the screen.
45 '';
46 };
47
48 combineScreens = mkOption {
49 type = types.bool;
50 default = false;
51 description = ''
52 When set to `true` the wallpaper will stretch across all screens.
53 When set to `false` the wallpaper is duplicated to all screens.
54 '';
55 };
56 };
57
58 session = mkOption {
59 internal = true;
60 default = [];
61 example = lib.singleton
62 { name = "kde";
63 bgSupport = true;
64 start = "...";
65 };
66 description = ''
67 Internal option used to add some common line to desktop manager
68 scripts before forwarding the value to the
69 `displayManager`.
70 '';
71 apply = map (d: d // {
72 manage = "desktop";
73 start = d.start
74 # literal newline to ensure d.start's last line is not appended to
75 + lib.optionalString (needBGCond d) ''
76
77 if [ -e $HOME/.background-image ]; then
78 ${pkgs.feh}/bin/feh --bg-${cfg.wallpaper.mode} ${lib.optionalString cfg.wallpaper.combineScreens "--no-xinerama"} $HOME/.background-image
79 fi
80 '';
81 });
82 };
83
84 };
85
86 };
87
88 config.services.xserver.displayManager.session = cfg.session;
89}