mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
General code cleanups
This commit is contained in:
@@ -7,79 +7,22 @@ import Quickshell
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
// Durations match M3 token tiers: short4/medium4/long4
|
||||
readonly property int durShort: 200
|
||||
readonly property int durMed: 450
|
||||
readonly property int durLong: 600
|
||||
|
||||
readonly property int slidePx: 80
|
||||
|
||||
// Material Design 3 motion curves (for QML BezierSpline)
|
||||
// Use groups of: [cx1, cy1, cx2, cy2, endX, endY, ...]
|
||||
// Single-segment cubics end with 1,1.
|
||||
|
||||
// Emphasized (multi-segment) – for on-screen-to-on-screen moves
|
||||
readonly property var emphasized: [
|
||||
0.05, 0.00, 0.133333, 0.06, 0.166667, 0.40,
|
||||
0.208333, 0.82, 0.25, 1.00, 1.00, 1.00
|
||||
]
|
||||
|
||||
// Emphasized decelerate – entering
|
||||
readonly property var emphasizedDecel: [ 0.05, 0.70, 0.10, 1.00, 1.00, 1.00 ]
|
||||
|
||||
// Emphasized accelerate – exiting
|
||||
readonly property var emphasizedAccel: [ 0.30, 0.00, 0.80, 0.15, 1.00, 1.00 ]
|
||||
|
||||
// Standard set – for small/subtle transitions
|
||||
readonly property var standard: [ 0.20, 0.00, 0.00, 1.00, 1.00, 1.00 ]
|
||||
readonly property var standardDecel: [ 0.00, 0.00, 0.00, 1.00, 1.00, 1.00 ]
|
||||
readonly property var standardAccel: [ 0.30, 0.00, 1.00, 1.00, 1.00, 1.00 ]
|
||||
|
||||
// readonly property QtObject direction: QtObject {
|
||||
// readonly property int fromLeft: 0
|
||||
// readonly property int fromRight: 1
|
||||
// readonly property int fadeOnly: 2
|
||||
// }
|
||||
|
||||
// // Slide transitions (surface/large moves)
|
||||
// // Enter = emphasizedDecel, Exit = emphasizedAccel
|
||||
// readonly property Component slideInLeft: Transition {
|
||||
// NumberAnimation {
|
||||
// properties: "x"; from: -root.slidePx; to: 0; duration: root.durMed
|
||||
// easing.type: Easing.BezierSpline; easing.bezierCurve: root.emphasizedDecel
|
||||
// }
|
||||
// }
|
||||
// readonly property Component slideOutLeft: Transition {
|
||||
// NumberAnimation {
|
||||
// properties: "x"; to: -root.slidePx; duration: root.durShort
|
||||
// easing.type: Easing.BezierSpline; easing.bezierCurve: root.emphasizedAccel
|
||||
// }
|
||||
// }
|
||||
// readonly property Component slideInRight: Transition {
|
||||
// NumberAnimation {
|
||||
// properties: "x"; from: root.slidePx; to: 0; duration: root.durMed
|
||||
// easing.type: Easing.BezierSpline; easing.bezierCurve: root.emphasizedDecel
|
||||
// }
|
||||
// }
|
||||
// readonly property Component slideOutRight: Transition {
|
||||
// NumberAnimation {
|
||||
// properties: "x"; to: root.slidePx; duration: root.durShort
|
||||
// easing.type: Easing.BezierSpline; easing.bezierCurve: root.emphasizedAccel
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Fade transitions (small/subtle moves)
|
||||
// // Enter = standardDecel, Exit = standardAccel
|
||||
// readonly property Component fadeIn: Transition {
|
||||
// NumberAnimation {
|
||||
// properties: "opacity"; from: 0.0; to: 1.0; duration: root.durMed
|
||||
// easing.type: Easing.BezierSpline; easing.bezierCurve: root.standardDecel
|
||||
// }
|
||||
// }
|
||||
// readonly property Component fadeOut: Transition {
|
||||
// NumberAnimation {
|
||||
// properties: "opacity"; to: 0.0; duration: root.durShort
|
||||
// easing.type: Easing.BezierSpline; easing.bezierCurve: root.standardAccel
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -52,20 +52,16 @@ Singleton {
|
||||
|
||||
function onLightModeChanged() {
|
||||
if (matugenColors && Object.keys(matugenColors).length > 0) {
|
||||
console.log("Light mode changed - updating dynamic colors");
|
||||
colorUpdateTrigger++;
|
||||
colorsUpdated();
|
||||
|
||||
// If dynamic theme is active, regenerate system themes with new light/dark mode
|
||||
if (typeof Theme !== "undefined" && Theme.isDynamicTheme) {
|
||||
console.log("Regenerating system themes for new light/dark mode");
|
||||
generateSystemThemes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function extractColors() {
|
||||
console.log("Colors.extractColors() called, matugenAvailable:", matugenAvailable);
|
||||
extractionRequested = true;
|
||||
if (matugenAvailable)
|
||||
fileChecker.running = true;
|
||||
@@ -91,7 +87,6 @@ Singleton {
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
console.log("Colors.qml → home =", homeDir);
|
||||
matugenCheck.running = true;
|
||||
checkGtkThemingAvailability();
|
||||
checkQtThemingAvailability();
|
||||
@@ -105,15 +100,12 @@ Singleton {
|
||||
command: ["which", "matugen"]
|
||||
onExited: (code) => {
|
||||
matugenAvailable = (code === 0);
|
||||
console.log("Matugen in PATH:", matugenAvailable);
|
||||
if (!matugenAvailable) {
|
||||
console.warn("Matugen missing → dynamic theme disabled");
|
||||
ToastService.wallpaperErrorStatus = "matugen_missing";
|
||||
ToastService.showWarning("matugen not found - dynamic theming disabled");
|
||||
return ;
|
||||
}
|
||||
if (extractionRequested) {
|
||||
console.log("Continuing with color extraction");
|
||||
fileChecker.running = true;
|
||||
}
|
||||
}
|
||||
@@ -127,8 +119,6 @@ Singleton {
|
||||
if (code === 0) {
|
||||
matugenProcess.running = true;
|
||||
} else {
|
||||
console.error("code", code);
|
||||
console.error("Wallpaper not found:", wallpaperPath);
|
||||
ToastService.wallpaperErrorStatus = "error";
|
||||
ToastService.showError("Wallpaper processing failed");
|
||||
}
|
||||
@@ -146,7 +136,6 @@ Singleton {
|
||||
onStreamFinished: {
|
||||
const out = matugenCollector.text;
|
||||
if (!out.length) {
|
||||
console.error("matugen produced zero bytes\nstderr:", matugenProcess.stderr);
|
||||
ToastService.wallpaperErrorStatus = "error";
|
||||
ToastService.showError("Wallpaper Processing Failed");
|
||||
return ;
|
||||
@@ -158,7 +147,6 @@ Singleton {
|
||||
generateAppConfigs();
|
||||
ToastService.clearWallpaperError();
|
||||
} catch (e) {
|
||||
console.error("JSON parse failed:", e);
|
||||
ToastService.wallpaperErrorStatus = "error";
|
||||
ToastService.showError("Wallpaper Processing Failed");
|
||||
}
|
||||
@@ -173,7 +161,6 @@ Singleton {
|
||||
|
||||
function generateAppConfigs() {
|
||||
if (!matugenColors || !matugenColors.colors) {
|
||||
console.warn("No matugen colors available for app config generation");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -197,8 +184,7 @@ Singleton {
|
||||
var secondary = dark.secondary || "#8ab4f8";
|
||||
var inverse = dark.inverse_primary || "#6200ea";
|
||||
|
||||
var content = `// AUTO-GENERATED on ${new Date().toISOString()}
|
||||
layout {
|
||||
var content = `layout {
|
||||
border {
|
||||
active-color "${primary}"
|
||||
inactive-color "${secondary}"
|
||||
@@ -209,8 +195,7 @@ layout {
|
||||
background-color "${bg}"
|
||||
}`;
|
||||
|
||||
niriConfigWriter.command = ["bash", "-c", `echo '${content}' > niri-colors.generated.kdl`];
|
||||
niriConfigWriter.running = true;
|
||||
Quickshell.execDetached(["bash", "-c", `echo '${content}' > niri-colors.generated.kdl`]);
|
||||
}
|
||||
|
||||
function generateGhosttyConfig() {
|
||||
@@ -236,8 +221,7 @@ layout {
|
||||
var error_b = light.error || "#b00020";
|
||||
var inverse_b = light.inverse_primary || "#bb86fc";
|
||||
|
||||
var content = `# AUTO-GENERATED on ${new Date().toISOString()}
|
||||
background = ${bg}
|
||||
var content = `background = ${bg}
|
||||
foreground = ${fg}
|
||||
cursor-color = ${inverse}
|
||||
selection-background = ${secondary}
|
||||
@@ -259,8 +243,10 @@ palette = 13=${tertiary_ctr_b}
|
||||
palette = 14=${inverse_b}
|
||||
palette = 15=${fg_b}`;
|
||||
|
||||
ghosttyConfigWriter.command = ["bash", "-c", `echo '${content}' > ghostty-colors.generated.conf`];
|
||||
ghosttyConfigWriter.running = true;
|
||||
var ghosttyConfigDir = configDir + "/ghostty";
|
||||
var ghosttyConfigPath = ghosttyConfigDir + "/config-colors";
|
||||
|
||||
Quickshell.execDetached(["bash", "-c", `mkdir -p '${ghosttyConfigDir}' && echo '${content}' > '${ghosttyConfigPath}'`]);
|
||||
}
|
||||
|
||||
function checkGtkThemingAvailability() {
|
||||
@@ -273,97 +259,49 @@ palette = 15=${fg_b}`;
|
||||
|
||||
function generateSystemThemes() {
|
||||
if (systemThemeGenerationInProgress) {
|
||||
console.log("System theme generation already in progress, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!matugenAvailable) {
|
||||
console.warn("Matugen not available, cannot generate system themes");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wallpaperPath || wallpaperPath === "") {
|
||||
console.warn("No wallpaper path set, cannot generate system themes");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Generating system themes using matugen templates");
|
||||
console.log("Wallpaper:", wallpaperPath);
|
||||
console.log("Shell directory:", shellDir);
|
||||
|
||||
// Get current theme preferences
|
||||
const isLight = (typeof Theme !== "undefined" && Theme.isLightMode) ? "true" : "false";
|
||||
const iconTheme = (typeof Prefs !== "undefined" && Prefs.iconTheme) ? Prefs.iconTheme : "System Default";
|
||||
const gtkTheming = (typeof Prefs !== "undefined" && Prefs.gtkThemingEnabled) ? "true" : "false";
|
||||
const qtTheming = (typeof Prefs !== "undefined" && Prefs.qtThemingEnabled) ? "true" : "false";
|
||||
|
||||
console.log("Theme mode:", isLight === "true" ? "light" : "dark");
|
||||
console.log("Icon theme:", iconTheme);
|
||||
console.log("GTK theming enabled:", gtkTheming);
|
||||
console.log("Qt theming enabled:", qtTheming);
|
||||
|
||||
systemThemeGenerationInProgress = true;
|
||||
systemThemeGenerator.command = [shellDir + "/generate-themes.sh", wallpaperPath, shellDir, configDir, "generate", isLight, iconTheme, gtkTheming, qtTheming];
|
||||
systemThemeGenerator.running = true;
|
||||
}
|
||||
|
||||
function generateGtkThemes() {
|
||||
console.log("Generating GTK themes using matugen templates");
|
||||
generateSystemThemes();
|
||||
}
|
||||
|
||||
function generateQtThemes() {
|
||||
console.log("Generating Qt themes using matugen templates");
|
||||
generateSystemThemes();
|
||||
}
|
||||
|
||||
function restoreSystemThemes() {
|
||||
console.log("Restoring original system themes");
|
||||
|
||||
const shellDir = root.shellDir;
|
||||
if (!shellDir) {
|
||||
console.warn("Shell directory not available, cannot restore system themes");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get current theme preferences
|
||||
const isLight = (typeof Theme !== "undefined" && Theme.isLightMode) ? "true" : "false";
|
||||
const iconTheme = (typeof Prefs !== "undefined" && Prefs.iconTheme) ? Prefs.iconTheme : "System Default";
|
||||
const gtkTheming = (typeof Prefs !== "undefined" && Prefs.gtkThemingEnabled) ? "true" : "false";
|
||||
const qtTheming = (typeof Prefs !== "undefined" && Prefs.qtThemingEnabled) ? "true" : "false";
|
||||
|
||||
console.log("Restoring to theme mode:", isLight === "true" ? "light" : "dark");
|
||||
console.log("Icon theme:", iconTheme);
|
||||
console.log("GTK theming enabled:", gtkTheming);
|
||||
console.log("Qt theming enabled:", qtTheming);
|
||||
|
||||
systemThemeRestoreProcess.command = [shellDir + "/generate-themes.sh", "", shellDir, configDir, "restore", isLight, iconTheme, gtkTheming, qtTheming];
|
||||
systemThemeRestoreProcess.running = true;
|
||||
}
|
||||
|
||||
Process {
|
||||
id: niriConfigWriter
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode === 0) {
|
||||
console.log("Generated niri-colors.generated.kdl");
|
||||
} else {
|
||||
console.warn("Failed to generate niri config, exit code:", exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: ghosttyConfigWriter
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode === 0) {
|
||||
console.log("Generated ghostty-colors.generated.conf");
|
||||
} else {
|
||||
console.warn("Failed to generate ghostty config, exit code:", exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: gtkAvailabilityChecker
|
||||
@@ -371,7 +309,6 @@ palette = 15=${fg_b}`;
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
gtkThemingEnabled = (exitCode === 0);
|
||||
console.log("GTK theming available:", gtkThemingEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,7 +318,6 @@ palette = 15=${fg_b}`;
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
qtThemingEnabled = (exitCode === 0);
|
||||
console.log("Qt theming available:", qtThemingEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,21 +333,10 @@ palette = 15=${fg_b}`;
|
||||
id: systemThemeStderr
|
||||
}
|
||||
|
||||
onStarted: {
|
||||
console.log("System theme generation process started with command:", command);
|
||||
}
|
||||
|
||||
onExited: (exitCode) => {
|
||||
systemThemeGenerationInProgress = false;
|
||||
console.log("System theme generation process exited with code:", exitCode);
|
||||
|
||||
if (exitCode === 0) {
|
||||
console.log("System themes generated successfully");
|
||||
console.log("stdout:", systemThemeStdout.text);
|
||||
} else {
|
||||
console.error("System theme generation failed, exit code:", exitCode);
|
||||
console.error("stdout:", systemThemeStdout.text);
|
||||
console.error("stderr:", systemThemeStderr.text);
|
||||
if (exitCode !== 0) {
|
||||
ToastService.showError("Failed to generate system themes: " + systemThemeStderr.text);
|
||||
}
|
||||
}
|
||||
@@ -429,21 +354,10 @@ palette = 15=${fg_b}`;
|
||||
id: restoreThemeStderr
|
||||
}
|
||||
|
||||
onStarted: {
|
||||
console.log("System theme restoration process started with command:", command);
|
||||
}
|
||||
|
||||
onExited: (exitCode) => {
|
||||
console.log("System theme restoration process exited with code:", exitCode);
|
||||
|
||||
if (exitCode === 0) {
|
||||
console.log("System themes restored successfully");
|
||||
console.log("stdout:", restoreThemeStdout.text);
|
||||
ToastService.showInfo("System themes restored to default");
|
||||
} else {
|
||||
console.error("System theme restoration failed, exit code:", exitCode);
|
||||
console.error("stdout:", restoreThemeStdout.text);
|
||||
console.error("stderr:", restoreThemeStderr.text);
|
||||
ToastService.showWarning("Failed to restore system themes: " + restoreThemeStderr.text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,12 +42,10 @@ Singleton {
|
||||
property var topBarCenterWidgets: ["clock", "music", "weather"]
|
||||
property var topBarRightWidgets: ["systemTray", "clipboard", "systemResources", "notificationButton", "battery", "controlCenterButton"]
|
||||
|
||||
// Reactive ListModel properties for TopBar
|
||||
property alias topBarLeftWidgetsModel: leftWidgetsModel
|
||||
property alias topBarCenterWidgetsModel: centerWidgetsModel
|
||||
property alias topBarRightWidgetsModel: rightWidgetsModel
|
||||
|
||||
// Signal to force immediate TopBar layout refresh
|
||||
signal forceTopBarLayoutRefresh()
|
||||
|
||||
ListModel {
|
||||
@@ -108,7 +106,6 @@ Singleton {
|
||||
|
||||
if (missingFonts.length > 0) {
|
||||
var message = "Missing fonts: " + missingFonts.join(", ") + ". Using system defaults."
|
||||
console.warn("Prefs: " + message)
|
||||
ToastService.showWarning(message)
|
||||
}
|
||||
}
|
||||
@@ -162,7 +159,6 @@ Singleton {
|
||||
showWorkspaceIndex = settings.showWorkspaceIndex !== undefined ? settings.showWorkspaceIndex : false;
|
||||
showWorkspacePadding = settings.showWorkspacePadding !== undefined ? settings.showWorkspacePadding : false;
|
||||
if (settings.topBarWidgetOrder) {
|
||||
// Migrate from old single list to new three-list system
|
||||
topBarLeftWidgets = settings.topBarWidgetOrder.filter(w => ["launcherButton", "workspaceSwitcher", "focusedWindow"].includes(w));
|
||||
topBarCenterWidgets = settings.topBarWidgetOrder.filter(w => ["clock", "music", "weather"].includes(w));
|
||||
topBarRightWidgets = settings.topBarWidgetOrder.filter(w => ["systemTray", "clipboard", "systemResources", "notificationButton", "battery", "controlCenterButton"].includes(w));
|
||||
@@ -497,7 +493,6 @@ Singleton {
|
||||
function updateListModel(listModel, order) {
|
||||
listModel.clear();
|
||||
for (var i = 0; i < order.length; i++) {
|
||||
// Handle both old string format and new object format
|
||||
var widgetId = typeof order[i] === "string" ? order[i] : order[i].id;
|
||||
var enabled = typeof order[i] === "string" ? true : order[i].enabled;
|
||||
var size = typeof order[i] === "string" ? undefined : order[i].size;
|
||||
@@ -577,21 +572,16 @@ Singleton {
|
||||
updateQtIconTheme(themeName);
|
||||
saveSettings();
|
||||
|
||||
// If dynamic theme is active, regenerate system themes with new icon theme
|
||||
if (typeof Theme !== "undefined" && Theme.isDynamicTheme && typeof Colors !== "undefined") {
|
||||
console.log("Icon theme changed during dynamic theming - regenerating system themes");
|
||||
Colors.generateSystemThemes();
|
||||
}
|
||||
}
|
||||
|
||||
function updateGtkIconTheme(themeName) {
|
||||
console.log("Updating GTK icon theme to:", themeName);
|
||||
var gtkThemeName = (themeName === "System Default") ? systemDefaultIconTheme : themeName;
|
||||
|
||||
// Update icon theme via dconf/gsettings AND settings.ini files
|
||||
if (gtkThemeName !== "System Default" && gtkThemeName !== "") {
|
||||
var script =
|
||||
"# Update dconf/gsettings with multiple fallbacks for Fedora\n" +
|
||||
var script =
|
||||
"if command -v gsettings >/dev/null 2>&1 && gsettings list-schemas | grep -q org.gnome.desktop.interface; then\n" +
|
||||
" gsettings set org.gnome.desktop.interface icon-theme '" + gtkThemeName + "'\n" +
|
||||
" echo 'Updated via gsettings'\n" +
|
||||
@@ -635,7 +625,6 @@ Singleton {
|
||||
}
|
||||
|
||||
function updateQtIconTheme(themeName) {
|
||||
console.log("Updating Qt icon theme to:", themeName);
|
||||
var qtThemeName = (themeName === "System Default") ? "" : themeName;
|
||||
|
||||
var home = _shq(root._homeUrl.replace("file://", ""));
|
||||
@@ -743,7 +732,6 @@ Singleton {
|
||||
wallpaperPath = path;
|
||||
saveSettings();
|
||||
|
||||
// Trigger dynamic theming if enabled
|
||||
if (wallpaperDynamicTheming && path && typeof Theme !== "undefined") {
|
||||
Theme.switchTheme(themeIndex, true, true);
|
||||
}
|
||||
@@ -753,7 +741,6 @@ Singleton {
|
||||
wallpaperDynamicTheming = enabled;
|
||||
saveSettings();
|
||||
|
||||
// If enabled and we have a wallpaper, trigger dynamic theming
|
||||
if (enabled && wallpaperPath && typeof Theme !== "undefined") {
|
||||
Theme.switchTheme(themeIndex, true, true);
|
||||
}
|
||||
@@ -763,7 +750,6 @@ Singleton {
|
||||
wallpaperPath = imagePath;
|
||||
saveSettings();
|
||||
|
||||
// Trigger color extraction if dynamic theming is enabled
|
||||
if (wallpaperDynamicTheming && typeof Colors !== "undefined") {
|
||||
Colors.extractColors();
|
||||
}
|
||||
@@ -799,7 +785,6 @@ Singleton {
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
// Helper to safely single-quote shell strings
|
||||
function _shq(s) {
|
||||
return "'" + String(s).replace(/'/g, "'\\''") + "'";
|
||||
}
|
||||
@@ -819,64 +804,7 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: gtk3Process
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode === 0) {
|
||||
} else {
|
||||
console.warn("Failed to update GTK 3 settings, exit code:", exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: gtk4Process
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode === 0) {
|
||||
} else {
|
||||
console.warn("Failed to update GTK 4 settings, exit code:", exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: reloadThemeProcess
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode === 0) {
|
||||
} else {
|
||||
console.log("GTK theme reload failed (this is normal if gsettings is not available), exit code:", exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: qtThemeProcess
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
// Qt theme reload signal sent
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: envCheckProcess
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode !== 0) {
|
||||
console.warn("Environment check failed, exit code:", exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Process {
|
||||
id: envSetProcess
|
||||
running: false
|
||||
onExited: (exitCode) => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Process {
|
||||
id: systemDefaultDetectionProcess
|
||||
|
||||
@@ -9,7 +9,6 @@ import Quickshell.Services.UPower
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
// Theme definitions with complete Material 3 expressive color palettes
|
||||
property var themes: [{
|
||||
"name": "Blue",
|
||||
"primary": "#42a5f5",
|
||||
@@ -171,7 +170,6 @@ Singleton {
|
||||
"surfaceContainer": "#201a19",
|
||||
"surfaceContainerHigh": "#2b2221"
|
||||
}]
|
||||
// Light theme variants
|
||||
property var lightThemes: [{
|
||||
"name": "Blue Light",
|
||||
"primary": "#1976d2",
|
||||
@@ -333,11 +331,9 @@ Singleton {
|
||||
"surfaceContainer": "#f3f3f3",
|
||||
"surfaceContainerHigh": "#ececec"
|
||||
}]
|
||||
// Current theme index (10 = Auto/Dynamic)
|
||||
property int currentThemeIndex: 0
|
||||
property bool isDynamicTheme: false
|
||||
property bool isLightMode: false
|
||||
// Dynamic color properties that change based on current theme
|
||||
property color primary: isDynamicTheme ? Colors.accentHi : getCurrentTheme().primary
|
||||
property color primaryText: isDynamicTheme ? Colors.primaryText : getCurrentTheme().primaryText
|
||||
property color primaryContainer: isDynamicTheme ? Colors.primaryContainer : getCurrentTheme().primaryContainer
|
||||
@@ -352,25 +348,20 @@ Singleton {
|
||||
property color outline: isDynamicTheme ? Colors.outline : getCurrentTheme().outline
|
||||
property color surfaceContainer: isDynamicTheme ? Colors.surfaceContainer : getCurrentTheme().surfaceContainer
|
||||
property color surfaceContainerHigh: isDynamicTheme ? Colors.surfaceContainerHigh : getCurrentTheme().surfaceContainerHigh
|
||||
// Static colors that don't change with themes
|
||||
property color archBlue: "#1793D1"
|
||||
property color success: "#4CAF50"
|
||||
property color warning: "#FF9800"
|
||||
property color info: "#2196F3"
|
||||
property color error: "#F2B8B5"
|
||||
|
||||
// Common alpha color variants for consistency
|
||||
// Primary colors with alpha
|
||||
property color primaryHover: Qt.rgba(primary.r, primary.g, primary.b, 0.12)
|
||||
property color primaryHoverLight: Qt.rgba(primary.r, primary.g, primary.b, 0.08)
|
||||
property color primaryPressed: Qt.rgba(primary.r, primary.g, primary.b, 0.16)
|
||||
property color primarySelected: Qt.rgba(primary.r, primary.g, primary.b, 0.3)
|
||||
property color primaryBackground: Qt.rgba(primary.r, primary.g, primary.b, 0.04)
|
||||
|
||||
// Secondary colors with alpha
|
||||
property color secondaryHover: Qt.rgba(secondary.r, secondary.g, secondary.b, 0.08)
|
||||
|
||||
// Surface colors with alpha
|
||||
property color surfaceHover: Qt.rgba(surfaceVariant.r, surfaceVariant.g, surfaceVariant.b, 0.08)
|
||||
property color surfacePressed: Qt.rgba(surfaceVariant.r, surfaceVariant.g, surfaceVariant.b, 0.12)
|
||||
property color surfaceSelected: Qt.rgba(surfaceVariant.r, surfaceVariant.g, surfaceVariant.b, 0.15)
|
||||
@@ -382,7 +373,6 @@ Singleton {
|
||||
property color surfaceTextLight: Qt.rgba(surfaceText.r, surfaceText.g, surfaceText.b, 0.06)
|
||||
property color surfaceTextMedium: Qt.rgba(surfaceText.r, surfaceText.g, surfaceText.b, 0.7)
|
||||
|
||||
// Outline colors with alpha
|
||||
property color outlineLight: Qt.rgba(outline.r, outline.g, outline.b, 0.05)
|
||||
property color outlineMedium: Qt.rgba(outline.r, outline.g, outline.b, 0.08)
|
||||
property color outlineStrong: Qt.rgba(outline.r, outline.g, outline.b, 0.12)
|
||||
@@ -390,14 +380,11 @@ Singleton {
|
||||
property color outlineHeavy: Qt.rgba(outline.r, outline.g, outline.b, 0.3)
|
||||
property color outlineButton: Qt.rgba(outline.r, outline.g, outline.b, 0.5)
|
||||
|
||||
// Error colors with alpha
|
||||
property color errorHover: Qt.rgba(error.r, error.g, error.b, 0.12)
|
||||
property color errorPressed: Qt.rgba(error.r, error.g, error.b, 0.9)
|
||||
|
||||
// Warning colors with alpha
|
||||
property color warningHover: Qt.rgba(warning.r, warning.g, warning.b, 0.12)
|
||||
|
||||
// Shadow colors
|
||||
property color shadowLight: Qt.rgba(0, 0, 0, 0.05)
|
||||
property color shadowMedium: Qt.rgba(0, 0, 0, 0.08)
|
||||
property color shadowDark: Qt.rgba(0, 0, 0, 0.1)
|
||||
@@ -429,80 +416,51 @@ Singleton {
|
||||
property real opacityMedium: 0.6
|
||||
property real opacityHigh: 0.87
|
||||
property real opacityFull: 1
|
||||
// Transparency system - can be overridden by Prefs
|
||||
property real panelTransparency: 0.85
|
||||
property real widgetTransparency: 0.85
|
||||
property real popupTransparency: 0.92
|
||||
|
||||
// Handle successful color extraction
|
||||
function onColorsUpdated() {
|
||||
console.log("Colors updated successfully - switching to dynamic theme");
|
||||
// Only switch to dynamic theme if we're already in dynamic mode
|
||||
if (isDynamicTheme) {
|
||||
currentThemeIndex = 10;
|
||||
isDynamicTheme = true;
|
||||
console.log("Dynamic theme activated. Theme.primary should now be:", primary);
|
||||
// Save preference after successful switch
|
||||
if (typeof Prefs !== "undefined")
|
||||
Prefs.setTheme(currentThemeIndex, isDynamicTheme);
|
||||
|
||||
} else {
|
||||
console.log("Color extraction completed, but staying with static theme");
|
||||
}
|
||||
}
|
||||
|
||||
// Function to switch themes
|
||||
function switchTheme(themeIndex, isDynamic = false, savePrefs = true) {
|
||||
console.log("Theme.switchTheme called:", themeIndex, isDynamic, "savePrefs:", savePrefs);
|
||||
if (isDynamic && themeIndex === 10) {
|
||||
console.log("Attempting to switch to dynamic theme - checking colors first");
|
||||
// Set dynamic theme flag immediately so onColorsUpdated works
|
||||
isDynamicTheme = true;
|
||||
// Don't change theme index yet - wait for color extraction to succeed
|
||||
if (typeof Colors !== "undefined") {
|
||||
console.log("Calling Colors.extractColors()");
|
||||
Colors.extractColors();
|
||||
} else {
|
||||
console.error("Colors singleton not available");
|
||||
}
|
||||
} else if (themeIndex >= 0 && themeIndex < themes.length) {
|
||||
// If switching away from dynamic theme, restore system themes
|
||||
if (isDynamicTheme && typeof Colors !== "undefined") {
|
||||
console.log("Switching away from dynamic theme, restoring system themes");
|
||||
Colors.restoreSystemThemes();
|
||||
}
|
||||
currentThemeIndex = themeIndex;
|
||||
isDynamicTheme = false;
|
||||
}
|
||||
// Save preference (unless this is a startup restoration)
|
||||
if (savePrefs && typeof Prefs !== "undefined")
|
||||
Prefs.setTheme(currentThemeIndex, isDynamicTheme);
|
||||
|
||||
}
|
||||
|
||||
// Function to toggle light/dark mode
|
||||
function toggleLightMode(savePrefs = true) {
|
||||
console.log("Theme.toggleLightMode called, current isLightMode:", isLightMode);
|
||||
isLightMode = !isLightMode;
|
||||
console.log("Light mode toggled to:", isLightMode);
|
||||
// Save preference
|
||||
if (savePrefs && typeof Prefs !== "undefined")
|
||||
Prefs.setLightMode(isLightMode);
|
||||
|
||||
}
|
||||
|
||||
// Helper function to get current theme array
|
||||
function getCurrentThemeArray() {
|
||||
return isLightMode ? lightThemes : themes;
|
||||
}
|
||||
|
||||
// Helper function to get current theme
|
||||
function getCurrentTheme() {
|
||||
var themeArray = getCurrentThemeArray();
|
||||
return currentThemeIndex < themeArray.length ? themeArray[currentThemeIndex] : themeArray[0];
|
||||
}
|
||||
|
||||
// Smart transparency functions for content-aware backgrounds
|
||||
function getPopupBackgroundAlpha() {
|
||||
return popupTransparency;
|
||||
}
|
||||
@@ -511,7 +469,6 @@ Singleton {
|
||||
return popupTransparency;
|
||||
}
|
||||
|
||||
// Convenience functions for themed backgrounds with transparency
|
||||
function popupBackground() {
|
||||
return Qt.rgba(surfaceContainer.r, surfaceContainer.g, surfaceContainer.b, popupTransparency);
|
||||
}
|
||||
@@ -606,7 +563,6 @@ Singleton {
|
||||
}
|
||||
|
||||
function getPowerProfileLabel(profile) {
|
||||
console.log("Theme.getPowerProfileLabel called with profile:", profile);
|
||||
switch (profile) {
|
||||
case PowerProfile.PowerSaver:
|
||||
return "Power Saver";
|
||||
@@ -632,14 +588,10 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize theme system
|
||||
Component.onCompleted: {
|
||||
console.log("Theme Component.onCompleted");
|
||||
// Connect to Colors signal
|
||||
if (typeof Colors !== "undefined")
|
||||
Colors.colorsUpdated.connect(root.onColorsUpdated);
|
||||
|
||||
// Initialize transparency values from Prefs
|
||||
if (typeof Prefs !== "undefined") {
|
||||
if (Prefs.popupTransparency !== undefined)
|
||||
root.popupTransparency = Prefs.popupTransparency;
|
||||
@@ -647,23 +599,18 @@ Singleton {
|
||||
if (Prefs.topBarWidgetTransparency !== undefined)
|
||||
root.widgetTransparency = Prefs.topBarWidgetTransparency;
|
||||
|
||||
// Connect to transparency changes
|
||||
if (Prefs.popupTransparencyChanged)
|
||||
Prefs.popupTransparencyChanged.connect(function() {
|
||||
if (typeof Prefs !== "undefined" && Prefs.popupTransparency !== undefined)
|
||||
root.popupTransparency = Prefs.popupTransparency;
|
||||
|
||||
});
|
||||
|
||||
if (Prefs.topBarWidgetTransparencyChanged)
|
||||
Prefs.topBarWidgetTransparencyChanged.connect(function() {
|
||||
if (typeof Prefs !== "undefined" && Prefs.topBarWidgetTransparency !== undefined)
|
||||
root.widgetTransparency = Prefs.topBarWidgetTransparency;
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
console.log("Theme initialized, waiting for Prefs to load settings and apply theme");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user