Skip to content

Commit e27f1fa

Browse files
committed
feat: material specification version configuration
1 parent 1e2805a commit e27f1fa

6 files changed

Lines changed: 84 additions & 4 deletions

File tree

src/kde_material_you_colors/apply_themes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def apply(config: Configs, wallpaper: WallpaperReader, dark_light):
2424
config.read("chroma_multiplier"),
2525
config.read("tone_multiplier"),
2626
config.read("contrast_level"),
27+
config.read("spec_version"),
2728
)
2829

2930
if material_colors is None:

src/kde_material_you_colors/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def defaults(self):
182182
"qdbus_executable": [args.qdbus_executable, None, 3],
183183
"manual_fetch": [args.manual_fetch, False, 0],
184184
"fetch_colors": [None, False, 0],
185+
"spec_version": [args.spec_version, None, 3],
185186
}
186187

187188
def parse_conf(self):

src/kde_material_you_colors/data/sample_config.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,9 @@ contrast_level = 0
227227
# scheduled screenshot take in screenshot mode
228228
# Default is False
229229
manual_fetch = False
230+
231+
# Spec version
232+
# The version of the material color specification to use
233+
# One of 2021 2025
234+
# Default is 2025
235+
spec_version = 2025

src/kde_material_you_colors/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ def main():
378378
metavar="<float>",
379379
)
380380

381+
parser.add_argument(
382+
"--spec-version",
383+
type=str,
384+
help="The version of the material color specification to use (2021, 2025)",
385+
default=None,
386+
metavar="<version>",
387+
)
388+
381389
# Get commandline arguments
382390
args = parser.parse_args()
383391
# Check for one shot arguments

src/kde_material_you_colors/utils/m3_scheme_utils.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ def palette_to_hex(palette: TonalPalette):
5454
]
5555

5656

57-
def getScheme(scheme_variant, source, isDark, contrastLevel):
57+
def getScheme(scheme_variant, source, isDark, contrastLevel, spec):
5858
scheme_class = schemes[scheme_variant]
5959
return scheme_class(
6060
source_color_hct=source,
6161
is_dark=isDark,
6262
contrast_level=contrastLevel,
63+
spec_version=spec if spec is not None else "2025",
6364
)
6465

6566

@@ -85,11 +86,16 @@ def getColors(scheme, chroma_mult, tone_mult, is_dark):
8586

8687

8788
def themeFromSourceColor(
88-
seed_color, scheme_variant=5, chroma_mult=1, tone_mult=1, contrast_level=0
89+
seed_color,
90+
scheme_variant=5,
91+
chroma_mult=1,
92+
tone_mult=1,
93+
contrast_level=0,
94+
spec_version="2025",
8995
):
9096
source = Hct.from_int(seed_color)
91-
scheme = getScheme(scheme_variant, source, False, contrast_level)
92-
schemeDark = getScheme(scheme_variant, source, True, contrast_level)
97+
scheme = getScheme(scheme_variant, source, False, contrast_level, spec_version)
98+
schemeDark = getScheme(scheme_variant, source, True, contrast_level, spec_version)
9399
colorsLight = getColors(scheme, chroma_mult, tone_mult, False)
94100
colorsDark = getColors(schemeDark, chroma_mult, tone_mult, True)
95101
# Base text states taken from Breeze Color Scheme
@@ -136,6 +142,7 @@ def get_material_you_colors(
136142
chroma_mult,
137143
tone_mult,
138144
contrast_level,
145+
spec_version,
139146
):
140147
"""Get material you colors from wallpaper or hex color using material-color-utility
141148
@@ -179,6 +186,7 @@ def get_material_you_colors(
179186
chroma_mult,
180187
tone_mult,
181188
contrast_level,
189+
spec_version,
182190
)
183191

184192
materialYouColors = {
@@ -217,6 +225,7 @@ def get_color_schemes(
217225
chroma_mult=1.0,
218226
tone_mult=1.0,
219227
contrast_level=0.0,
228+
spec_version="2025",
220229
):
221230
"""Display best colors, allow to select alternative color,
222231
and make and apply color schemes for dark and light mode
@@ -247,6 +256,7 @@ def get_color_schemes(
247256
chroma_mult,
248257
tone_mult,
249258
contrast_level,
259+
spec_version,
250260
)
251261

252262
elif wallpaper_type == "color" and wallpaper_data:
@@ -259,6 +269,7 @@ def get_color_schemes(
259269
chroma_mult,
260270
tone_mult,
261271
contrast_level,
272+
spec_version,
262273
)
263274

264275
if materialYouColors is not None:

src/plasmoid/package/contents/ui/FullRepresentation.qml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ ColumnLayout {
552552
property real tone_multiplier: 1.0; \
553553
property real frame_contrast: 0.2; \
554554
property real contrast_level: 0.0; \
555+
property string spec_version: "2025"; \
555556
}';
556557

557558
settings = Qt.createQmlObject(settingsString, mainLayout, "settingsObject");
@@ -2193,6 +2194,58 @@ ColumnLayout {
21932194
opacity: dividerOpacity
21942195
}
21952196

2197+
PlasmaExtras.Heading {
2198+
level: 1
2199+
text: "Spec Version"
2200+
Layout.alignment: Qt.AlignHCenter
2201+
visible: fullRepresentation.showAdvanced
2202+
}
2203+
2204+
RowLayout {
2205+
PlasmaComponents3.Label {
2206+
text: "Version"
2207+
Layout.alignment: Qt.AlignLeft
2208+
}
2209+
2210+
PlasmaComponents3.ComboBox {
2211+
model: ["2021", "2025"]
2212+
Layout.fillWidth: true
2213+
currentValue: settings.spec_version
2214+
onActivated: (index) => {
2215+
settings.spec_version = currentText
2216+
}
2217+
2218+
// Prevent starting scrolling on collapsed combobox
2219+
MouseArea {
2220+
anchors.fill: parent
2221+
hoverEnabled: true
2222+
onWheel: {}
2223+
onClicked: parent.popup.open()
2224+
}
2225+
}
2226+
PlasmaComponents3.ToolButton {
2227+
icon.name: "help-contents"
2228+
2229+
hoverEnabled: true
2230+
onClicked: specPopup.open()
2231+
2232+
PlasmaComponents3.ToolTip {
2233+
id: specPopup
2234+
x: parent.width / 2
2235+
y: parent.height
2236+
text: "The version of the material color specification to use"
2237+
}
2238+
}
2239+
}
2240+
2241+
Rectangle {
2242+
Layout.topMargin: Kirigami.Units.mediumSpacing
2243+
Layout.preferredWidth: mainLayout.width
2244+
height: 1
2245+
color: dividerColor
2246+
opacity: dividerOpacity
2247+
}
2248+
21962249
PlasmaExtras.Heading {
21972250
level: 1
21982251
text: "Colors"

0 commit comments

Comments
 (0)