{
  config,
  inputs,
  lib,
  ...
}:
let
  cosmicLib = import "${inputs.cosmic-manager}/lib" { inherit lib; };
  mkRON = cosmicLib.mkRON;
  accent = mkRON "optional" {
    red = mkRON "raw" "0.3882353";
    green = mkRON "raw" "0.8156863";
    blue = mkRON "raw" "0.8745098";
  };
  active_hint = 1;
  corner_radii = {
    radius_0 = mkRON "tuple" [
      0.0
      0.0
      0.0
      0.0
    ];
    radius_xs = mkRON "tuple" [
      2.0
      2.0
      2.0
      2.0
    ];
    radius_s = mkRON "tuple" [
      8.0
      8.0
      8.0
      8.0
    ];
    radius_m = mkRON "tuple" [
      8.0
      8.0
      8.0
      8.0
    ];
    radius_l = mkRON "tuple" [
      8.0
      8.0
      8.0
      8.0
    ];
    radius_xl = mkRON "tuple" [
      8.0
      8.0
      8.0
      8.0
    ];
  };
  gaps = mkRON "tuple" [
    0
    1
  ];
in
{
  config = lib.mkIf (config.khscodes.desktop.enable && config.khscodes.khs.enable) {
    wayland.desktopManager.cosmic = {
      enable = true;
      applets = {
        # This is the "dock"
        app-list = {
          settings = {
            enable_drag_source = false;
            favorites = [
              "com.system76.CosmicFiles"
              "thunderbird"
              "Google-chrome"
              "Code"
              "Alacritty"
              "com.system76.CosmicSettings"
              "Spotify"
              "steam"
            ];
            filter_top_levels = mkRON "optional" null;
          };
        };
      };
      appearance = {
        toolkit = {
          interface_density = mkRON "enum" "Standard";
          monospace_font = {
            family = config.stylix.fonts.monospace.name;
            stretch = mkRON "enum" "Normal";
            style = mkRON "enum" "Normal";
            weight = mkRON "enum" "Normal";
          };
        };
        theme = {
          light = {
            inherit
              accent
              active_hint
              corner_radii
              gaps
              ;
          };
          dark = {
            inherit
              accent
              active_hint
              corner_radii
              gaps
              ;
          };
        };
      };
      compositor = {
        active_hint = true;
        autotile = true;
        autotile_behavior = mkRON "enum" "PerWorkspace";
        cursor_follows_focus = false;
        focus_follows_cursor = false;
      };
    };
  };
}
