mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-25 14:02:53 -05:00
* <quickshell/Modules/Settings/DisplayConfig>: Added mirroring option to the displayconfiguration * removed niri option for mirroring * Fix trailing whitespace * removed emty rows --------- Co-authored-by: Postboote1 <stoessel.matthias>
179 lines
6.5 KiB
QML
179 lines
6.5 KiB
QML
pragma Singleton
|
|
pragma ComponentBehavior: Bound
|
|
|
|
import QtCore
|
|
import QtQuick
|
|
import Quickshell
|
|
import qs.Common
|
|
|
|
Singleton {
|
|
id: root
|
|
|
|
readonly property string configDir: Paths.strip(StandardPaths.writableLocation(StandardPaths.ConfigLocation))
|
|
readonly property string hyprDmsDir: configDir + "/hypr/dms"
|
|
readonly property string outputsPath: hyprDmsDir + "/outputs.conf"
|
|
|
|
function getOutputIdentifier(output, outputName) {
|
|
if (SettingsData.displayNameMode === "model" && output.make && output.model)
|
|
return "desc:" + output.make + " " + output.model;
|
|
return outputName;
|
|
}
|
|
|
|
function generateOutputsConfig(outputsData, hyprlandSettings) {
|
|
if (!outputsData || Object.keys(outputsData).length === 0)
|
|
return;
|
|
|
|
const settings = hyprlandSettings || SettingsData.hyprlandOutputSettings;
|
|
let lines = ["# Auto-generated by DMS - do not edit manually", ""];
|
|
let monitorv2Blocks = [];
|
|
|
|
for (const outputName in outputsData) {
|
|
const output = outputsData[outputName];
|
|
if (!output)
|
|
continue;
|
|
|
|
const identifier = getOutputIdentifier(output, outputName);
|
|
const outputSettings = settings[identifier] || {};
|
|
|
|
let resolution = "preferred";
|
|
if (output.modes && output.current_mode !== undefined) {
|
|
const mode = output.modes[output.current_mode];
|
|
if (mode)
|
|
resolution = mode.width + "x" + mode.height + "@" + (mode.refresh_rate / 1000).toFixed(3);
|
|
}
|
|
|
|
const x = output.logical?.x ?? 0;
|
|
const y = output.logical?.y ?? 0;
|
|
const position = x + "x" + y;
|
|
const scale = output.logical?.scale ?? 1.0;
|
|
|
|
let monitorLine = "monitor = " + identifier + ", " + resolution + ", " + position + ", " + scale;
|
|
|
|
const transform = transformToHyprland(output.logical?.transform ?? "Normal");
|
|
if (transform !== 0)
|
|
monitorLine += ", transform, " + transform;
|
|
|
|
if (output.vrr_supported && output.vrr_enabled)
|
|
monitorLine += ", vrr, 1";
|
|
|
|
if (output.mirror && output.mirror.length > 0)
|
|
monitorLine += ", mirror, " + output.mirror;
|
|
|
|
if (outputSettings.bitdepth && outputSettings.bitdepth !== 8)
|
|
monitorLine += ", bitdepth, " + outputSettings.bitdepth;
|
|
|
|
if (outputSettings.colorManagement && outputSettings.colorManagement !== "auto")
|
|
monitorLine += ", cm, " + outputSettings.colorManagement;
|
|
|
|
if (outputSettings.sdrBrightness !== undefined && outputSettings.sdrBrightness !== 1.0)
|
|
monitorLine += ", sdrbrightness, " + outputSettings.sdrBrightness;
|
|
|
|
if (outputSettings.sdrSaturation !== undefined && outputSettings.sdrSaturation !== 1.0)
|
|
monitorLine += ", sdrsaturation, " + outputSettings.sdrSaturation;
|
|
|
|
lines.push(monitorLine);
|
|
|
|
const needsMonitorv2 = outputSettings.supportsHdr || outputSettings.supportsWideColor ||
|
|
outputSettings.sdrMinLuminance !== undefined || outputSettings.sdrMaxLuminance !== undefined ||
|
|
outputSettings.minLuminance !== undefined || outputSettings.maxLuminance !== undefined ||
|
|
outputSettings.maxAvgLuminance !== undefined;
|
|
|
|
if (needsMonitorv2) {
|
|
let block = "monitorv2 {\n";
|
|
block += " output = " + identifier + "\n";
|
|
|
|
if (outputSettings.supportsWideColor)
|
|
block += " supports_wide_color = true\n";
|
|
if (outputSettings.supportsHdr)
|
|
block += " supports_hdr = true\n";
|
|
if (outputSettings.sdrMinLuminance !== undefined)
|
|
block += " sdr_min_luminance = " + outputSettings.sdrMinLuminance + "\n";
|
|
if (outputSettings.sdrMaxLuminance !== undefined)
|
|
block += " sdr_max_luminance = " + outputSettings.sdrMaxLuminance + "\n";
|
|
if (outputSettings.minLuminance !== undefined)
|
|
block += " min_luminance = " + outputSettings.minLuminance + "\n";
|
|
if (outputSettings.maxLuminance !== undefined)
|
|
block += " max_luminance = " + outputSettings.maxLuminance + "\n";
|
|
if (outputSettings.maxAvgLuminance !== undefined)
|
|
block += " max_avg_luminance = " + outputSettings.maxAvgLuminance + "\n";
|
|
|
|
block += "}";
|
|
monitorv2Blocks.push(block);
|
|
}
|
|
}
|
|
|
|
if (monitorv2Blocks.length > 0) {
|
|
lines.push("");
|
|
for (const block of monitorv2Blocks)
|
|
lines.push(block);
|
|
}
|
|
|
|
lines.push("");
|
|
|
|
const content = lines.join("\n");
|
|
|
|
Proc.runCommand("hypr-write-outputs", ["sh", "-c", `mkdir -p "${hyprDmsDir}" && cat > "${outputsPath}" << 'EOF'\n${content}EOF`], (output, exitCode) => {
|
|
if (exitCode !== 0) {
|
|
console.warn("HyprlandService: Failed to write outputs config:", output);
|
|
return;
|
|
}
|
|
console.info("HyprlandService: Generated outputs config at", outputsPath);
|
|
if (CompositorService.isHyprland)
|
|
reloadConfig();
|
|
});
|
|
}
|
|
|
|
function reloadConfig() {
|
|
Proc.runCommand("hyprctl-reload", ["hyprctl", "reload"], (output, exitCode) => {
|
|
if (exitCode !== 0)
|
|
console.warn("HyprlandService: hyprctl reload failed:", output);
|
|
});
|
|
}
|
|
|
|
function transformToHyprland(transform) {
|
|
switch (transform) {
|
|
case "Normal":
|
|
return 0;
|
|
case "90":
|
|
return 1;
|
|
case "180":
|
|
return 2;
|
|
case "270":
|
|
return 3;
|
|
case "Flipped":
|
|
return 4;
|
|
case "Flipped90":
|
|
return 5;
|
|
case "Flipped180":
|
|
return 6;
|
|
case "Flipped270":
|
|
return 7;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
function hyprlandToTransform(value) {
|
|
switch (value) {
|
|
case 0:
|
|
return "Normal";
|
|
case 1:
|
|
return "90";
|
|
case 2:
|
|
return "180";
|
|
case 3:
|
|
return "270";
|
|
case 4:
|
|
return "Flipped";
|
|
case 5:
|
|
return "Flipped90";
|
|
case 6:
|
|
return "Flipped180";
|
|
case 7:
|
|
return "Flipped270";
|
|
default:
|
|
return "Normal";
|
|
}
|
|
}
|
|
}
|