Bug fixes for Komplex Engine

This commit is contained in:
Digital Artifex
2025-08-12 17:09:26 -04:00
parent a6f72ab34b
commit f09b36f920
3 changed files with 48 additions and 29 deletions

View File

@@ -56,13 +56,22 @@ Item
id: mainItem id: mainItem
Item
{
id: data
property var channels: []
}
Komplex.ShaderPackModel Komplex.ShaderPackModel
{ {
id: shaderPackModel id: shaderPackModel
onJsonChanged: onJsonChanged:
{ {
// clean up old channels
while(data.channels.length > 0)
data.channels.pop().destroy()
// Handle the JSON change if needed // Handle the JSON change if needed
console.log("Shader pack JSON changed:", shaderPackModel.json);
mainItem.parsePack(shaderPackModel.json); mainItem.parsePack(shaderPackModel.json);
} }
} }
@@ -161,21 +170,27 @@ Item
var source = getFilePath(channel.source) var source = getFilePath(channel.source)
var result = Qt.createQmlObject(`ShaderChannel // Qt.createQmlObject() method was not working the same inside plasma
{ // as it was inside a QMLEngine instance. This resulted in the Loader
z: 0 // object being undefined and thus breaking the Komplex wallpaper mode. (oops)
invert: ${channel.invert || true}
iTimeScale: ${channel.time_scale || 1.0} // Instead, use Qt.createComponent() then manually setup bindings
iResolutionScale: ${channel.resolution_scale || 1.0} var component = Qt.createComponent("./ShaderChannel.qml")
visible: false var result
anchors.fill: parent
source: "file://" + "${source || ''}" if (component.status === Component.Ready) {
type: ${channel.type || 0} result = component.createObject(mainItem, { x: 100, y: 100 });
iTime: mainItem.iTime * ${channel.time_scale || 1.0} }
iMouse: mainItem.iMouse result.type = channel.type
mouseBias: ${channel.mouse_scale || 1.0} result.anchors.fill = mainItem
iResolution: Qt.vector3d(${(channel.resolution_x || mainItem.width) * (channel.resolution_scale || 1.0)}, ${(channel.resolution_y || mainItem.width) * (channel.resolution_scale || 1.0)}, pixelRatio) result.visible = false
}`, mainItem); result.iMouse = Qt.binding(function () { return mainItem.iMouse; })
result.iTime = Qt.binding(function() { return mainItem.iTime; })
result.iResolution = Qt.vector3d(channel.resolution_x || mainItem.width, channel.resolution_y || mainItem.height, 1.0)
result.mouseBias = channel.mouse_scale ? channel.mouse_scale : 1.0
result.iTimeScale = channel.time_scale ? channel.time_scale : 1.0
result.invert = channel.invert ? channel.invert : false
result.source = source
if (channel.channel0) if (channel.channel0)
result.iChannel0 = parseChannel(channel.channel0); result.iChannel0 = parseChannel(channel.channel0);
@@ -186,26 +201,28 @@ Item
if (channel.channel3) if (channel.channel3)
result.iChannel3 = parseChannel(channel.channel3); result.iChannel3 = parseChannel(channel.channel3);
data.channels.push(result) // save for destroying
return result; return result;
} }
function getFilePath(source) function getFilePath(source)
{ {
if(source === "") if(source === undefined || source === "")
return ""; return "";
// Ensure the source path is correctly resolved for relative paths // Ensure the source path is correctly resolved for relative paths
if(source.startsWith("./")) if(source.startsWith("./"))
{ {
var temp = source.replace("./", "file://" + shaderPackModel.shaderPackPath + "/") var temp = source.replace("./", "file://" + shaderPackModel.shaderPackPath + "/")
return Qt.resolvedUrl(temp); return temp;
} }
else if(source.startsWith("$/")) else if(source.startsWith("$/"))
{ {
var temp = source.replace("$/", "file://" + StandardPaths.writableLocation(StandardPaths.HomeLocation) + "/.local/share/komplex/") var temp = source.replace("$/", "file://" + StandardPaths.writableLocation(StandardPaths.HomeLocation) + "/.local/share/komplex/")
return Qt.resolvedUrl(temp); return temp;
} }
else if(!source.startsWith("file://")) else if(!source.startsWith("file://"))
return Qt.resolvedUrl("file://" + source); return "file://" + source;
} }
} }

View File

@@ -45,12 +45,12 @@ WallpaperItem
id: pageLoader id: pageLoader
anchors.fill: parent anchors.fill: parent
active: true active: true
sourceComponent: shaderToysContent sourceComponent: wallpaper.configuration.komplex_mode === 0 ? shaderToysContent : packContent
states: [ states: [
State State
{ {
when: wallpaper.komplex_mode === 0 when: wallpaper.configuration.komplex_mode === 0
PropertyChanges PropertyChanges
{ {
pageLoader.sourceComponent: shaderToysContent pageLoader.sourceComponent: shaderToysContent
@@ -58,7 +58,7 @@ WallpaperItem
}, },
State State
{ {
when: wallpaper.komplex_mode === 1 when: wallpaper.configuration.komplex_mode === 1
PropertyChanges PropertyChanges
{ {
pageLoader.sourceComponent: packContent pageLoader.sourceComponent: packContent

View File

@@ -20,12 +20,13 @@ void ShaderPackModel::loadJson(const QString &filePath)
setState(Loading); // Set the state to Loading setState(Loading); // Set the state to Loading
// Open the file and read its contents // Open the file and read its contents
QFile file(filePath); QFile file(QUrl(filePath).toLocalFile());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
setState(Idle); // Reset state to Idle setState(Idle); // Reset state to Idle
qWarning("Could not open file %s for reading", qPrintable(filePath)); qWarning("Could not open file %s for reading", qPrintable(filePath));
qWarning(file.errorString().toStdString().c_str());
return; return;
} }
@@ -49,10 +50,11 @@ void ShaderPackModel::loadJson(const QString &filePath)
// Check if the JSON content has changed // Check if the JSON content has changed
if (json != m_json) if (json != m_json)
{ {
QFileInfo info(file);
setShaderPackPath(info.absolutePath()); // Update the shader pack path
m_json = json; m_json = json;
Q_EMIT jsonChanged(); Q_EMIT jsonChanged();
setShaderPackPath(filePath); // Update the shader pack path
} }
setState(Idle); // Reset state to Idle setState(Idle); // Reset state to Idle
@@ -73,14 +75,14 @@ void ShaderPackModel::refreshShaderPacks()
setState(Loading); setState(Loading);
// check for and create the directory if it doesn't exist // check for and create the directory if it doesn't exist
QDir dir(m_shaderPackPath); QDir dir(m_shaderPackInstallPath);
if (!dir.exists()) if (!dir.exists())
{ {
if (!dir.mkpath(m_shaderPackPath)) if (!dir.mkpath(m_shaderPackInstallPath))
{ {
setState(Idle); // Reset state to Idle setState(Idle); // Reset state to Idle
qWarning("Failed to create shader pack directory: %s", qPrintable(m_shaderPackPath)); qWarning("Failed to create shader pack directory: %s", qPrintable(m_shaderPackInstallPath));
return; return;
} }
} }