mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-08 12:13:31 -04:00
fix(display): unify compositor output profiles
This commit is contained in:
@@ -1248,15 +1248,36 @@ Singleton {
|
||||
|
||||
const commands = [];
|
||||
|
||||
if (config.disabled !== undefined) {
|
||||
commands.push(`niri msg output "${outputName}" ${config.disabled ? "off" : "on"}`);
|
||||
if (config.disabled) {
|
||||
const fullDisableCommand = "{ " + commands.join(" && ") + "; } 2>&1";
|
||||
Proc.runCommand("niri-output-config", ["sh", "-c", fullDisableCommand], (output, exitCode) => {
|
||||
if (exitCode !== 0) {
|
||||
log.warn("Failed to apply output config:", outputName, "exit:", exitCode, output);
|
||||
if (callback)
|
||||
callback(false, output);
|
||||
return;
|
||||
}
|
||||
fetchOutputs();
|
||||
if (callback)
|
||||
callback(true, "Success");
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (config.position !== undefined) {
|
||||
commands.push(`niri msg output "${outputName}" position ${config.position.x} ${config.position.y}`);
|
||||
commands.push(`niri msg output "${outputName}" position set ${config.position.x} ${config.position.y}`);
|
||||
}
|
||||
|
||||
if (config.mode !== undefined) {
|
||||
commands.push(`niri msg output "${outputName}" mode ${config.mode}`);
|
||||
}
|
||||
|
||||
if (config.vrr !== undefined) {
|
||||
if (config.vrrOnDemand !== undefined) {
|
||||
commands.push(`niri msg output "${outputName}" vrr --on-demand ${config.vrrOnDemand ? "on" : "off"}`);
|
||||
} else if (config.vrr !== undefined) {
|
||||
commands.push(`niri msg output "${outputName}" vrr ${config.vrr ? "on" : "off"}`);
|
||||
}
|
||||
|
||||
@@ -1274,10 +1295,10 @@ Singleton {
|
||||
return;
|
||||
}
|
||||
|
||||
const fullCommand = commands.join(" && ");
|
||||
const fullCommand = "{ " + commands.join(" && ") + "; } 2>&1";
|
||||
Proc.runCommand("niri-output-config", ["sh", "-c", fullCommand], (output, exitCode) => {
|
||||
if (exitCode !== 0) {
|
||||
log.warn("Failed to apply output config:", output);
|
||||
log.warn("Failed to apply output config:", outputName, "exit:", exitCode, output);
|
||||
if (callback)
|
||||
callback(false, output);
|
||||
return;
|
||||
@@ -1297,10 +1318,32 @@ Singleton {
|
||||
return outputName;
|
||||
}
|
||||
|
||||
function generateOutputsConfig(outputsData) {
|
||||
function outputSettingsFor(output, outputName, niriSettings) {
|
||||
const identifier = getOutputIdentifier(output, outputName);
|
||||
if (niriSettings)
|
||||
return niriSettings[identifier] || niriSettings[outputName] || {};
|
||||
return SettingsData.getNiriOutputSettings(identifier);
|
||||
}
|
||||
|
||||
function transformToNiri(transform) {
|
||||
const transformMap = {
|
||||
"Normal": "normal",
|
||||
"90": "90",
|
||||
"180": "180",
|
||||
"270": "270",
|
||||
"Flipped": "flipped",
|
||||
"Flipped90": "flipped-90",
|
||||
"Flipped180": "flipped-180",
|
||||
"Flipped270": "flipped-270"
|
||||
};
|
||||
return transformMap[transform] || "normal";
|
||||
}
|
||||
|
||||
function buildOutputsConfig(outputsData, niriSettings) {
|
||||
const data = outputsData || outputs;
|
||||
if (!data || Object.keys(data).length === 0)
|
||||
return;
|
||||
return "";
|
||||
|
||||
let kdlContent = `// Auto-generated by DMS - do not edit manually\n\n`;
|
||||
|
||||
const sortedNames = Object.keys(data).sort((a, b) => {
|
||||
@@ -1311,11 +1354,11 @@ Singleton {
|
||||
for (const outputName of sortedNames) {
|
||||
const output = data[outputName];
|
||||
const identifier = getOutputIdentifier(output, outputName);
|
||||
const niriSettings = SettingsData.getNiriOutputSettings(identifier);
|
||||
const outputSettings = outputSettingsFor(output, outputName, niriSettings);
|
||||
|
||||
kdlContent += `output "${identifier}" {\n`;
|
||||
|
||||
if (niriSettings.disabled) {
|
||||
if (outputSettings.disabled) {
|
||||
kdlContent += ` off\n`;
|
||||
kdlContent += `}\n\n`;
|
||||
continue;
|
||||
@@ -1330,17 +1373,7 @@ Singleton {
|
||||
kdlContent += ` scale ${output.logical.scale || 1.0}\n`;
|
||||
|
||||
if (output.logical.transform && output.logical.transform !== "Normal") {
|
||||
const transformMap = {
|
||||
"Normal": "normal",
|
||||
"90": "90",
|
||||
"180": "180",
|
||||
"270": "270",
|
||||
"Flipped": "flipped",
|
||||
"Flipped90": "flipped-90",
|
||||
"Flipped180": "flipped-180",
|
||||
"Flipped270": "flipped-270"
|
||||
};
|
||||
kdlContent += ` transform "${transformMap[output.logical.transform] || "normal"}"\n`;
|
||||
kdlContent += ` transform "${transformToNiri(output.logical.transform)}"\n`;
|
||||
}
|
||||
|
||||
if (output.logical.x !== undefined && output.logical.y !== undefined) {
|
||||
@@ -1348,25 +1381,38 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
if (output.vrr_enabled || niriSettings.vrrOnDemand) {
|
||||
const vrrOnDemand = niriSettings.vrrOnDemand ?? false;
|
||||
if (output.vrr_enabled || outputSettings.vrrOnDemand) {
|
||||
const vrrOnDemand = outputSettings.vrrOnDemand ?? false;
|
||||
kdlContent += vrrOnDemand ? ` variable-refresh-rate on-demand=true\n` : ` variable-refresh-rate\n`;
|
||||
}
|
||||
|
||||
if (niriSettings.focusAtStartup) {
|
||||
if (outputSettings.focusAtStartup) {
|
||||
kdlContent += ` focus-at-startup\n`;
|
||||
}
|
||||
|
||||
if (niriSettings.backdropColor) {
|
||||
kdlContent += ` backdrop-color "${niriSettings.backdropColor}"\n`;
|
||||
if (outputSettings.backdropColor) {
|
||||
kdlContent += ` backdrop-color "${outputSettings.backdropColor}"\n`;
|
||||
}
|
||||
|
||||
kdlContent += generateHotCornersBlock(niriSettings);
|
||||
kdlContent += generateLayoutBlock(niriSettings);
|
||||
kdlContent += generateHotCornersBlock(outputSettings);
|
||||
kdlContent += generateLayoutBlock(outputSettings);
|
||||
|
||||
kdlContent += `}\n\n`;
|
||||
}
|
||||
|
||||
return kdlContent;
|
||||
}
|
||||
|
||||
function generateOutputsConfig(outputsData, settingsOrCallback, maybeCallback) {
|
||||
const niriSettings = typeof settingsOrCallback === "function" ? null : settingsOrCallback;
|
||||
const callback = typeof settingsOrCallback === "function" ? settingsOrCallback : maybeCallback;
|
||||
const kdlContent = buildOutputsConfig(outputsData, niriSettings);
|
||||
if (!kdlContent) {
|
||||
if (callback)
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const configDir = Paths.strip(StandardPaths.writableLocation(StandardPaths.ConfigLocation));
|
||||
const niriDmsDir = configDir + "/niri/dms";
|
||||
const outputsPath = niriDmsDir + "/outputs.kdl";
|
||||
@@ -1374,9 +1420,13 @@ Singleton {
|
||||
Proc.runCommand("niri-write-outputs", ["sh", "-c", `mkdir -p "${niriDmsDir}" && cat > "${outputsPath}" << 'EOF'\n${kdlContent}EOF`], (output, exitCode) => {
|
||||
if (exitCode !== 0) {
|
||||
log.warn("Failed to write outputs config:", output);
|
||||
if (callback)
|
||||
callback(false, output);
|
||||
return;
|
||||
}
|
||||
log.info("Generated outputs config at", outputsPath);
|
||||
if (callback)
|
||||
callback(true, "");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user