diff --git a/lib/fontType.nix b/lib/fontType.nix new file mode 100644 index 00000000..8946ccda --- /dev/null +++ b/lib/fontType.nix @@ -0,0 +1,197 @@ +{ + lib, + ... +}: let + inherit (lib) mkOption types; + qfont = import ./qfont.nix { inherit lib; }; + + styleStrategyType = types.submodule { + options = with qfont.styleStrategy; { + prefer = mkOption { + type = prefer; + default = "default"; + description = '' + Which type of font is preferred by the font when finding an appropriate default family. + + `default`, `bitmap`, `device`, `outline`, `forceOutline` correspond to the + `PreferDefault`, `PreferBitmap`, `PreferDevice`, `PreferOutline`, `ForceOutline` enum flags + respectively. + ''; + }; + matchingPrefer = mkOption { + type = matchingPrefer; + default = "default"; + description = '' + Whether the font matching process prefers exact matches, or best quality matches. + + `default` corresponds to not setting any enum flag, and `exact` and `quality` + correspond to `PreferMatch` and `PreferQuality` enum flags respectively. + ''; + }; + antialiasing = mkOption { + type = antialiasing; + default = "default"; + description = '' + Whether antialiasing is preferred for this font. + + `default` corresponds to not setting any enum flag, and `prefer` and `disable` + correspond to `PreferAntialias` and `NoAntialias` enum flags respectively. + ''; + }; + noSubpixelAntialias = mkOption { + type = types.bool; + default = false; + description = '' + If set to `true`, this font will try to avoid subpixel antialiasing. + + Corresponds to the `NoSubpixelAntialias` enum flag. + ''; + }; + noFontMerging = mkOption { + type = types.bool; + default = false; + description = '' + If set to `true`, this font will not try to find a substitute font when encountering missing glyphs. + + Corresponds to the `NoFontMerging` enum flag. + ''; + }; + preferNoShaping = mkOption { + type = 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 + (e.g. Indic scripts), increasing performance if these rules are not required. + + Corresponds to the `PreferNoShaping` enum flag. + ''; + }; + }; + }; +in types.submodule { + options = { + family = mkOption { + type = types.str; + description = "The font family of this font."; + example = "Noto Sans"; + }; + pointSize = mkOption { + type = types.nullOr types.numbers.positive; + default = null; + description = '' + The point size of this font. + + Could be a decimal, but usually an integer. Mutually exclusive with pixel size. + ''; + }; + pixelSize = mkOption { + type = types.nullOr types.ints.u16; + default = null; + description = '' + The pixel size of this font. + + Mutually exclusive with point size. + ''; + }; + styleHint = mkOption { + type = qfont.styleHint; + default = "anyStyle"; + description = '' + The style hint of this font. + + 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; + default = "normal"; + description = '' + The weight of the font, either as a number between 1 to 1000 or as a pre-defined weight string. + + See https://doc.qt.io/qt-6/qfont.html#Weight-enum for more. + ''; + }; + style = mkOption { + type = qfont.style; + default = "normal"; + description = "The style of the font."; + }; + underline = mkOption { + type = types.bool; + default = false; + description = "Whether the font is underlined."; + }; + strikeOut = mkOption { + type = types.bool; + default = false; + description = "Whether the font is struck out."; + }; + fixedPitch = mkOption { + type = types.bool; + default = false; + description = "Whether the font has a fixed pitch."; + }; + capitalization = mkOption { + type = qfont.capitalization; + default = "mixedCase"; + description = '' + The capitalization settings for this font. + + See https://doc.qt.io/qt-6/qfont.html#Capitalization-enum for more. + ''; + }; + letterSpacingType = mkOption { + type = qfont.spacingType; + default = "percentage"; + description = '' + Whether to use percentage or absolute spacing for this font. + + See https://doc.qt.io/qt-6/qfont.html#SpacingType-enum for more. + ''; + }; + letterSpacing = mkOption { + type = types.number; + default = 0; + description = '' + The amount of letter spacing for this font. + + Could be a percentage or an absolute spacing change (positive increases spacing, negative decreases spacing), + based on the selected `letterSpacingType`. + ''; + }; + wordSpacing = mkOption { + type = types.number; + default = 0; + description = '' + The amount of word spacing for this font, in pixels. + + Positive values increase spacing while negative ones decrease spacing. + ''; + }; + stretch = mkOption { + type = types.either (types.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 { + type = styleStrategyType; + default = { }; + description = '' + The strategy for matching similar fonts to this font. + + See https://doc.qt.io/qt-6/qfont.html#StyleStrategy-enum for more. + ''; + }; + styleName = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + The style name of this font, overriding the `style` and `weight` parameters when set. + Used for special fonts that have styles beyond traditional settings. + ''; + }; + }; +} diff --git a/modules/apps/kate/default.nix b/modules/apps/kate/default.nix index 2756c226..28af2898 100644 --- a/modules/apps/kate/default.nix +++ b/modules/apps/kate/default.nix @@ -41,198 +41,7 @@ let ) (throw "getIndexFromEnum (kate): Value ${value} isn't present in the enum. This is a bug.") enum; qfont = import ../../../lib/qfont.nix { inherit lib; }; - - styleStrategyType = lib.types.submodule { - options = with qfont.styleStrategy; { - prefer = lib.mkOption { - type = prefer; - default = "default"; - description = '' - Which type of font is preferred by the font when finding an appropriate default family. - - `default`, `bitmap`, `device`, `outline`, `forceOutline` correspond to the - `PreferDefault`, `PreferBitmap`, `PreferDevice`, `PreferOutline`, `ForceOutline` enum flags - respectively. - ''; - }; - matchingPrefer = lib.mkOption { - type = matchingPrefer; - default = "default"; - description = '' - Whether the font matching process prefers exact matches, or best quality matches. - - `default` corresponds to not setting any enum flag, and `exact` and `quality` - correspond to `PreferMatch` and `PreferQuality` enum flags respectively. - ''; - }; - antialiasing = lib.mkOption { - type = antialiasing; - default = "default"; - description = '' - Whether antialiasing is preferred for this font. - - `default` corresponds to not setting any enum flag, and `prefer` and `disable` - correspond to `PreferAntialias` and `NoAntialias` enum flags respectively. - ''; - }; - noSubpixelAntialias = lib.mkOption { - type = lib.types.bool; - default = false; - description = '' - If set to `true`, this font will try to avoid subpixel antialiasing. - - Corresponds to the `NoSubpixelAntialias` enum flag. - ''; - }; - noFontMerging = lib.mkOption { - 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. - - Corresponds to the `NoFontMerging` enum flag. - ''; - }; - preferNoShaping = lib.mkOption { - 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 - (e.g. Indic scripts), increasing performance if these rules are not required. - - Corresponds to the `PreferNoShaping` enum flag. - ''; - }; - }; - }; - - fontType = lib.types.submodule { - options = { - family = lib.mkOption { - type = lib.types.str; - description = "The font family of this font."; - example = "Noto Sans"; - }; - pointSize = lib.mkOption { - type = lib.types.nullOr lib.types.numbers.positive; - default = null; - description = '' - The point size of this font. - - Could be a decimal, but usually an integer. Mutually exclusive with pixel size. - ''; - }; - pixelSize = lib.mkOption { - type = lib.types.nullOr lib.types.ints.u16; - default = null; - description = '' - The pixel size of this font. - - Mutually exclusive with point size. - ''; - }; - styleHint = lib.mkOption { - type = qfont.styleHint; - default = "anyStyle"; - description = '' - The style hint of this font. - - See https://doc.qt.io/qt-6/qfont.html#StyleHint-enum for more. - ''; - }; - weight = lib.mkOption { - type = lib.types.either (lib.types.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. - - See https://doc.qt.io/qt-6/qfont.html#Weight-enum for more. - ''; - }; - style = lib.mkOption { - type = qfont.style; - default = "normal"; - description = "The style of the font."; - }; - underline = lib.mkOption { - type = lib.types.bool; - default = false; - description = "Whether the font is underlined."; - }; - strikeOut = lib.mkOption { - type = lib.types.bool; - default = false; - description = "Whether the font is struck out."; - }; - fixedPitch = lib.mkOption { - type = lib.types.bool; - default = false; - description = "Whether the font has a fixed pitch."; - }; - capitalization = lib.mkOption { - type = qfont.capitalization; - default = "mixedCase"; - description = '' - The capitalization settings for this font. - - See https://doc.qt.io/qt-6/qfont.html#Capitalization-enum for more. - ''; - }; - letterSpacingType = lib.mkOption { - type = qfont.spacingType; - default = "percentage"; - description = '' - Whether to use percentage or absolute spacing for this font. - - See https://doc.qt.io/qt-6/qfont.html#SpacingType-enum for more. - ''; - }; - letterSpacing = lib.mkOption { - type = lib.types.number; - default = 0; - description = '' - The amount of letter spacing for this font. - - Could be a percentage or an absolute spacing change (positive increases spacing, negative decreases spacing), - based on the selected `letterSpacingType`. - ''; - }; - wordSpacing = lib.mkOption { - type = lib.types.number; - default = 0; - description = '' - The amount of word spacing for this font, in pixels. - - Positive values increase spacing while negative ones decrease spacing. - ''; - }; - stretch = lib.mkOption { - type = lib.types.either (lib.types.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 = lib.mkOption { - type = styleStrategyType; - default = { }; - description = '' - The strategy for matching similar fonts to this font. - - See https://doc.qt.io/qt-6/qfont.html#StyleStrategy-enum for more. - ''; - }; - styleName = lib.mkOption { - type = lib.types.nullOr lib.types.str; - default = null; - description = '' - The style name of this font, overriding the `style` and `weight` parameters when set. - Used for special fonts that have styles beyond traditional settings. - ''; - }; - }; - }; + fontType = import ../../../lib/fontType.nix { inherit lib; }; in { options.programs.kate = { @@ -331,10 +140,12 @@ in font = lib.mkOption { type = fontType; - default = { - family = "Hack"; - pointSize = 10; - }; + default = let + generaldefaultFont = { + family = "Hack"; + pointSize = 10; + }; + in lib.defaultTo generaldefaultFont config.programs.plasma.fonts.fixedWidth; example = { family = "Fira Code"; pointSize = 11; diff --git a/modules/fonts.nix b/modules/fonts.nix index 0f00cef5..88897bae 100644 --- a/modules/fonts.nix +++ b/modules/fonts.nix @@ -2,198 +2,7 @@ let inherit (lib) mkIf mkOption types; qfont = import ../lib/qfont.nix { inherit lib; }; - - styleStrategyType = types.submodule { - options = with qfont.styleStrategy; { - prefer = mkOption { - type = prefer; - default = "default"; - description = '' - Which type of font is preferred by the font when finding an appropriate default family. - - `default`, `bitmap`, `device`, `outline`, `forceOutline` correspond to the - `PreferDefault`, `PreferBitmap`, `PreferDevice`, `PreferOutline`, `ForceOutline` enum flags - respectively. - ''; - }; - matchingPrefer = mkOption { - type = matchingPrefer; - default = "default"; - description = '' - Whether the font matching process prefers exact matches, or best quality matches. - - `default` corresponds to not setting any enum flag, and `exact` and `quality` - correspond to `PreferMatch` and `PreferQuality` enum flags respectively. - ''; - }; - antialiasing = mkOption { - type = antialiasing; - default = "default"; - description = '' - Whether antialiasing is preferred for this font. - - `default` corresponds to not setting any enum flag, and `prefer` and `disable` - correspond to `PreferAntialias` and `NoAntialias` enum flags respectively. - ''; - }; - noSubpixelAntialias = mkOption { - type = types.bool; - default = false; - description = '' - If set to `true`, this font will try to avoid subpixel antialiasing. - - Corresponds to the `NoSubpixelAntialias` enum flag. - ''; - }; - noFontMerging = mkOption { - type = types.bool; - default = false; - description = '' - If set to `true`, this font will not try to find a substitute font when encountering missing glyphs. - - Corresponds to the `NoFontMerging` enum flag. - ''; - }; - preferNoShaping = mkOption { - type = 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 - (e.g. Indic scripts), increasing performance if these rules are not required. - - Corresponds to the `PreferNoShaping` enum flag. - ''; - }; - }; - }; - - fontType = types.submodule { - options = { - family = mkOption { - type = types.str; - description = "The font family of this font."; - example = "Noto Sans"; - }; - pointSize = mkOption { - type = types.nullOr types.numbers.positive; - default = null; - description = '' - The point size of this font. - - Could be a decimal, but usually an integer. Mutually exclusive with pixel size. - ''; - }; - pixelSize = mkOption { - type = types.nullOr types.ints.u16; - default = null; - description = '' - The pixel size of this font. - - Mutually exclusive with point size. - ''; - }; - styleHint = mkOption { - type = qfont.styleHint; - default = "anyStyle"; - description = '' - The style hint of this font. - - 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; - default = "normal"; - description = '' - The weight of the font, either as a number between 1 to 1000 or as a pre-defined weight string. - - See https://doc.qt.io/qt-6/qfont.html#Weight-enum for more. - ''; - }; - style = mkOption { - type = qfont.style; - default = "normal"; - description = "The style of the font."; - }; - underline = mkOption { - type = types.bool; - default = false; - description = "Whether the font is underlined."; - }; - strikeOut = mkOption { - type = types.bool; - default = false; - description = "Whether the font is struck out."; - }; - fixedPitch = mkOption { - type = types.bool; - default = false; - description = "Whether the font has a fixed pitch."; - }; - capitalization = mkOption { - type = qfont.capitalization; - default = "mixedCase"; - description = '' - The capitalization settings for this font. - - See https://doc.qt.io/qt-6/qfont.html#Capitalization-enum for more. - ''; - }; - letterSpacingType = mkOption { - type = qfont.spacingType; - default = "percentage"; - description = '' - Whether to use percentage or absolute spacing for this font. - - See https://doc.qt.io/qt-6/qfont.html#SpacingType-enum for more. - ''; - }; - letterSpacing = mkOption { - type = types.number; - default = 0; - description = '' - The amount of letter spacing for this font. - - Could be a percentage or an absolute spacing change (positive increases spacing, negative decreases spacing), - based on the selected `letterSpacingType`. - ''; - }; - wordSpacing = mkOption { - type = types.number; - default = 0; - description = '' - The amount of word spacing for this font, in pixels. - - Positive values increase spacing while negative ones decrease spacing. - ''; - }; - stretch = mkOption { - type = types.either (types.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 { - type = styleStrategyType; - default = { }; - description = '' - The strategy for matching similar fonts to this font. - - See https://doc.qt.io/qt-6/qfont.html#StyleStrategy-enum for more. - ''; - }; - styleName = mkOption { - type = types.nullOr types.str; - default = null; - description = '' - The style name of this font, overriding the `style` and `weight` parameters when set. - Used for special fonts that have styles beyond traditional settings. - ''; - }; - }; - }; + fontType = import ../lib/fontType.nix { inherit lib; }; inherit (config.programs.plasma) enable; cfg = lib.filterAttrs (_: v: v != null) config.programs.plasma.fonts;