1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

more matugen b16 improvements

This commit is contained in:
bbedward
2025-08-25 17:51:48 -04:00
parent 1c290fa9d7
commit a185679cd1
3 changed files with 168 additions and 50 deletions

View File

@@ -32,6 +32,7 @@ Singleton {
property bool gtkThemingEnabled: typeof SettingsData !== "undefined" ? SettingsData.gtkAvailable : false
property bool qtThemingEnabled: typeof SettingsData !== "undefined" ? (SettingsData.qt5ctAvailable || SettingsData.qt6ctAvailable) : false
property bool systemThemeGenerationInProgress: false
property var pendingThemeRequest: null
property var matugenColors: ({})
property bool extractionRequested: false
property int colorUpdateTrigger: 0
@@ -155,6 +156,10 @@ Singleton {
property real popupTransparency: typeof SettingsData !== "undefined" && SettingsData.popupTransparency !== undefined ? SettingsData.popupTransparency : 0.92
function switchTheme(themeName, savePrefs = true) {
// Clear cached colors when switching themes
matugenColors = {}
colorUpdateTrigger++
if (themeName === dynamic) {
currentTheme = dynamic
extractColors()
@@ -364,18 +369,17 @@ Singleton {
}
function generateSystemThemesFromCurrentTheme() {
if (systemThemeGenerationInProgress || !matugenAvailable)
if (!matugenAvailable)
return
const isLight = (typeof SessionData !== "undefined" && SessionData.isLightMode) ? "true" : "false"
const iconTheme = (typeof SettingsData !== "undefined" && SettingsData.iconTheme) ? SettingsData.iconTheme : "System Default"
let cmd
if (currentTheme === dynamic) {
if (!wallpaperPath)
return
systemThemeGenerationInProgress = true
systemThemeGenerator.command = [shellDir + "/scripts/matugen.sh", wallpaperPath, shellDir, configDir, "generate", isLight, iconTheme]
systemThemeGenerator.running = true
cmd = [shellDir + "/scripts/matugen.sh", wallpaperPath, shellDir, configDir, "generate", isLight, iconTheme]
} else {
let primaryColor
if (currentTheme === "custom") {
@@ -388,11 +392,42 @@ Singleton {
primaryColor = currentThemeData.primary
}
if (!primaryColor)
if (!primaryColor) {
console.warn("No primary color available for theme:", currentTheme)
return
systemThemeGenerationInProgress = true
systemThemeGenerator.command = [shellDir + "/scripts/matugen.sh", primaryColor, shellDir, configDir, "generate-color", isLight, iconTheme]
systemThemeGenerator.running = true
}
cmd = [shellDir + "/scripts/matugen.sh", primaryColor, shellDir, configDir, "generate-color", isLight, iconTheme]
}
// Clear any pending request and queue this new one
pendingThemeRequest = {
command: cmd,
isDynamic: currentTheme === dynamic,
timestamp: Date.now()
}
// Clear cached colors to force refresh
matugenColors = {}
colorUpdateTrigger++
// Process the queue
processThemeQueue()
}
function processThemeQueue() {
if (systemThemeGenerationInProgress || !pendingThemeRequest)
return
const request = pendingThemeRequest
pendingThemeRequest = null
systemThemeGenerationInProgress = true
systemThemeGenerator.command = request.command
systemThemeGenerator.running = true
if (request.isDynamic) {
// Re-extract colors after system theme generation
Qt.callLater(extractColors)
}
}
@@ -572,7 +607,14 @@ Singleton {
if (typeof ToastService !== "undefined") {
ToastService.showError("Failed to generate system themes: " + systemThemeStderr.text)
}
console.warn("System theme generation failed with exit code:", exitCode)
console.warn("STDOUT:", systemThemeStdout.text)
console.warn("STDERR:", systemThemeStderr.text)
} else {
}
// Process next request in queue if any
Qt.callLater(processThemeQueue)
}
}

View File

@@ -7,13 +7,12 @@ def hex_to_rgb(hex_color):
return tuple(int(hex_color[i:i+2], 16)/255.0 for i in (0, 2, 4))
def rgb_to_hex(r, g, b):
# Clamp RGB values to valid range [0, 1]
r = max(0, min(1, r))
g = max(0, min(1, g))
b = max(0, min(1, b))
return f"#{int(r*255):02x}{int(g*255):02x}{int(b*255):02x}"
def generate_palette(base_color, is_light=False):
def generate_palette(base_color, is_light=False, honor_primary=None):
r, g, b = hex_to_rgb(base_color)
h, s, v = colorsys.rgb_to_hsv(r, g, b)
@@ -24,22 +23,42 @@ def generate_palette(base_color, is_light=False):
else:
palette.append("#1a1a1a")
red_h = h * 0.15
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(red_h, 0.5, 0.88)))
red_h = 0.0 # Force true red hue (0 degrees)
if is_light:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(red_h, 0.75, 0.85)))
else:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(red_h, 0.65, 1.0)))
green_h = h + 0.25 if h < 0.75 else h - 0.75
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(green_h, s * 0.6, v * 1.1)))
green_h = 0.33 # Force true green hue (120 degrees / 360 = 0.33)
if is_light:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(green_h, max(s * 0.8, 0.65), v * 0.9)))
else:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(green_h, max(s * 0.7, 0.6), v * 1.1)))
yellow_h = h + 0.15 if h < 0.85 else h - 0.85
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(yellow_h, s * 0.5, v * 1.3)))
yellow_h = 0.16 # Force true yellow hue (60 degrees / 360 = 0.16)
if is_light:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(yellow_h, max(s * 0.7, 0.55), v * 1.2)))
else:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(yellow_h, max(s * 0.5, 0.45), v * 1.4)))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(h, s * 0.8, v * 1.2)))
if is_light:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(h, max(s * 0.9, 0.7), v * 1.1)))
else:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(h, max(s * 0.7, 0.6), min(v * 1.3, 0.9))))
mag_h = h - 0.08 if h > 0.08 else h + 0.08
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(mag_h, s * 0.9, v * 1.1)))
mag_h = h + 0.15 if h + 0.15 <= 1.0 else h + 0.15 - 1.0 # Derive from primary hue for harmony
if is_light:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(mag_h, max(s * 0.8, 0.65), v * 0.95)))
else:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(mag_h, max(s * 0.65, 0.55), min(v * 1.15, 0.8))))
cyan_h = h + 0.08
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(cyan_h, s * 0.7, v * 1.15)))
if honor_primary and not is_light:
palette.append(honor_primary)
elif is_light:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(cyan_h, max(s * 0.8, 0.65), v * 1.05)))
else:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(cyan_h, max(s * 0.6, 0.5), min(v * 1.25, 0.85))))
if is_light:
palette.append("#2e2e2e")
@@ -48,12 +67,25 @@ def generate_palette(base_color, is_light=False):
palette.append("#abb2bf")
palette.append("#5c6370")
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(red_h, 0.4, 0.94)))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(green_h, s * 0.5, v * 1.3)))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(yellow_h, s * 0.4, v * 1.4)))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(h, s * 0.7, min(v * 1.4, 1.0))))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(mag_h, s * 0.8, min(v * 1.3, 1.0))))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(cyan_h, s * 0.6, min(v * 1.3, 1.0))))
if is_light:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(red_h, 0.6, 0.9)))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(green_h, max(s * 0.7, 0.6), v * 1.25)))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(yellow_h, max(s * 0.6, 0.5), v * 1.35)))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(h, max(s * 0.8, 0.7), min(v * 1.3, 1.0))))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(mag_h, max(s * 0.9, 0.75), min(v * 1.25, 1.0))))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(cyan_h, max(s * 0.75, 0.65), min(v * 1.25, 1.0))))
else:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(red_h, 0.45, min(1.0, 0.9))))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(green_h, max(s * 0.5, 0.4), min(v * 1.5, 0.9))))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(yellow_h, max(s * 0.4, 0.35), min(v * 1.6, 0.95))))
if honor_primary:
hr, hg, hb = hex_to_rgb(honor_primary)
hh, hs, hv = colorsys.rgb_to_hsv(hr, hg, hb)
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(hh, min(hs * 1.2, 1.0), min(hv * 1.1, 1.0))))
else:
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(h, max(s * 0.6, 0.5), min(v * 1.5, 0.9))))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(mag_h, max(s * 0.65, 0.55), min(v * 1.4, 0.85))))
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(cyan_h, max(s * 0.55, 0.45), min(v * 1.4, 0.85))))
if is_light:
palette.append("#1a1a1a")
@@ -63,8 +95,8 @@ def generate_palette(base_color, is_light=False):
return palette
if __name__ == "__main__":
if len(sys.argv) < 2 or len(sys.argv) > 4:
print("Usage: b16.py <hex_color> [--light] [--kitty]", file=sys.stderr)
if len(sys.argv) < 2:
print("Usage: b16.py <hex_color> [--light] [--kitty] [--honor-primary HEX]", file=sys.stderr)
sys.exit(1)
base = sys.argv[1]
@@ -73,32 +105,44 @@ if __name__ == "__main__":
is_light = "--light" in sys.argv
is_kitty = "--kitty" in sys.argv
colors = generate_palette(base, is_light)
honor_primary = None
if "--honor-primary" in sys.argv:
try:
honor_idx = sys.argv.index("--honor-primary")
if honor_idx + 1 < len(sys.argv):
honor_primary = sys.argv[honor_idx + 1]
if not honor_primary.startswith('#'):
honor_primary = '#' + honor_primary
except (ValueError, IndexError):
print("Error: --honor-primary requires a hex color", file=sys.stderr)
sys.exit(1)
colors = generate_palette(base, is_light, honor_primary)
if is_kitty:
# Kitty color format mapping
kitty_colors = [
("color0", colors[0]), # black
("color1", colors[1]), # red
("color2", colors[2]), # green
("color3", colors[3]), # yellow
("color4", colors[4]), # blue
("color5", colors[5]), # magenta
("color6", colors[6]), # cyan
("color7", colors[7]), # white
("color8", colors[8]), # bright black
("color9", colors[9]), # bright red
("color10", colors[10]), # bright green
("color11", colors[11]), # bright yellow
("color12", colors[12]), # bright blue
("color13", colors[13]), # bright magenta
("color14", colors[14]), # bright cyan
("color15", colors[15]) # bright white
("color0", colors[0]),
("color1", colors[1]),
("color2", colors[2]),
("color3", colors[3]),
("color4", colors[4]),
("color5", colors[5]),
("color6", colors[6]),
("color7", colors[7]),
("color8", colors[8]),
("color9", colors[9]),
("color10", colors[10]),
("color11", colors[11]),
("color12", colors[12]),
("color13", colors[13]),
("color14", colors[14]),
("color15", colors[15])
]
for name, color in kitty_colors:
print(f"{name} {color}")
else:
# Ghostty format (original)
for i, color in enumerate(colors):
print(f"palette = {i}={color}")

View File

@@ -198,25 +198,51 @@ if [ -s "$TEMP_CONTENT_CONFIG" ] && grep -q '\[templates\.' "$TEMP_CONTENT_CONFI
matugen -c "$TEMP_CONTENT_CONFIG" -t scheme-content color hex "$INPUT_SOURCE" $MATUGEN_MODE
fi
# Small delay to ensure content generation completes
sleep 0.1
# Get JSON with error handling
if [ "$MODE" = "generate" ]; then
DEFAULT_JSON=$(matugen --json hex image "$INPUT_SOURCE" $MATUGEN_MODE 2>/dev/null)
if ! DEFAULT_JSON=$(matugen --json hex image "$INPUT_SOURCE" $MATUGEN_MODE 2>&1); then
echo "Warning: Failed to get JSON from matugen for image mode"
DEFAULT_JSON=""
fi
elif [ "$MODE" = "generate-color" ]; then
DEFAULT_JSON=$(matugen --json hex color hex "$INPUT_SOURCE" $MATUGEN_MODE 2>/dev/null)
if ! DEFAULT_JSON=$(matugen --json hex color hex "$INPUT_SOURCE" $MATUGEN_MODE 2>&1); then
echo "Warning: Failed to get JSON from matugen for color mode"
DEFAULT_JSON=""
fi
fi
if [ "$IS_LIGHT" = "true" ]; then
# Extract primary_container for b16 base color and primary for honoring
if [ -n "$DEFAULT_JSON" ] && echo "$DEFAULT_JSON" | grep -q '"primary_container"'; then
EXTRACTED_PRIMARY=$(echo "$DEFAULT_JSON" | grep -oE '"primary_container":"#[0-9a-fA-F]{6}"' | sed -n '1p' | cut -d'"' -f4)
echo "Successfully extracted primary_container: $EXTRACTED_PRIMARY"
# Also extract the actual primary color to honor in palette
if [ "$IS_LIGHT" = "true" ]; then
# Light mode: get primary from light theme (second occurrence)
HONOR_PRIMARY=$(echo "$DEFAULT_JSON" | grep -oE '"primary":"#[0-9a-fA-F]{6}"' | sed -n '2p' | cut -d'"' -f4)
else
# Dark mode: get primary from dark theme (first occurrence)
HONOR_PRIMARY=$(echo "$DEFAULT_JSON" | grep -oE '"primary":"#[0-9a-fA-F]{6}"' | sed -n '1p' | cut -d'"' -f4)
fi
echo "Successfully extracted primary for honoring: $HONOR_PRIMARY"
else
EXTRACTED_PRIMARY=$(echo "$DEFAULT_JSON" | grep -oE '"primary":"#[0-9a-fA-F]{6}"' | sed -n '2p' | cut -d'"' -f4)
echo "Warning: No primary_container found in JSON output"
EXTRACTED_PRIMARY=""
HONOR_PRIMARY=""
fi
# Fallback if extraction failed
if [ -z "$EXTRACTED_PRIMARY" ]; then
if [ "$MODE" = "generate-color" ]; then
EXTRACTED_PRIMARY="$INPUT_SOURCE"
HONOR_PRIMARY="$INPUT_SOURCE"
echo "Using input color as primary: $EXTRACTED_PRIMARY"
else
EXTRACTED_PRIMARY="#6b5f8e"
HONOR_PRIMARY="#ccbeff" # Default Material Design primary for fallback
echo "Warning: Could not extract primary color, using fallback: $EXTRACTED_PRIMARY"
fi
else
@@ -241,6 +267,9 @@ if [ -s "$TEMP_CONTENT_CONFIG" ] && grep -q '\[templates\.' "$TEMP_CONTENT_CONFI
if [ "$IS_LIGHT" = "true" ]; then
B16_ARGS="$B16_ARGS --light"
fi
if [ -n "$HONOR_PRIMARY" ]; then
B16_ARGS="$B16_ARGS --honor-primary $HONOR_PRIMARY"
fi
B16_OUTPUT=$("$SHELL_DIR/matugen/b16.py" $B16_ARGS)
@@ -280,6 +309,9 @@ if [ -s "$TEMP_CONTENT_CONFIG" ] && grep -q '\[templates\.' "$TEMP_CONTENT_CONFI
if [ "$IS_LIGHT" = "true" ]; then
B16_ARGS="$B16_ARGS --light"
fi
if [ -n "$HONOR_PRIMARY" ]; then
B16_ARGS="$B16_ARGS --honor-primary $HONOR_PRIMARY"
fi
B16_OUTPUT=$("$SHELL_DIR/matugen/b16.py" $B16_ARGS --kitty)