mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-08 04:09:15 -04:00
feat(mango): first-class MangoWM support across DMS, dankinstaller & UI tools
- Bring up Mango to parity with niri/hyprland via a native JSON-IPC w/Native MangoServic., replaces the legacy dwl/`mmsg` path and recent breaking changes - Dankinstall: mango supported installer, config/binds templates, and packaging (Arch AUR, Fedora Terra auto-enable, Gentoo GURU) - Window rules: Go provider + CLI + Settings GUI editor - Keybinds + config reload on edit (mmsg dispatch reload_config) - Misc new supported options in DMS settings
This commit is contained in:
@@ -16,6 +16,7 @@ Singleton {
|
||||
property bool isHyprland: false
|
||||
property bool isNiri: false
|
||||
property bool isDwl: false
|
||||
property bool isMango: false
|
||||
property bool isSway: false
|
||||
property bool isScroll: false
|
||||
property bool isMiracle: false
|
||||
@@ -29,7 +30,9 @@ Singleton {
|
||||
readonly property string scrollSocket: Quickshell.env("SWAYSOCK")
|
||||
readonly property string miracleSocket: Quickshell.env("MIRACLESOCK")
|
||||
readonly property string labwcPid: Quickshell.env("LABWC_PID")
|
||||
readonly property string mangoSignature: Quickshell.env("MANGO_INSTANCE_SIGNATURE")
|
||||
property bool useNiriSorting: isNiri && NiriService
|
||||
property bool useMangoSorting: isMango && MangoService
|
||||
|
||||
property var randrScales: ({})
|
||||
property bool randrReady: false
|
||||
@@ -100,6 +103,12 @@ Singleton {
|
||||
return dwlScale;
|
||||
}
|
||||
|
||||
if (isMango && screen) {
|
||||
const mangoScale = MangoService.getOutputScale(screen.name);
|
||||
if (mangoScale !== undefined && mangoScale > 0)
|
||||
return mangoScale;
|
||||
}
|
||||
|
||||
return screen?.devicePixelRatio || 1;
|
||||
}
|
||||
|
||||
@@ -114,6 +123,8 @@ Singleton {
|
||||
screenName = focusedWs?.monitor?.name || "";
|
||||
} else if (isDwl && DwlService.activeOutput)
|
||||
screenName = DwlService.activeOutput;
|
||||
else if (isMango && MangoService.activeOutput)
|
||||
screenName = MangoService.activeOutput;
|
||||
|
||||
if (!screenName)
|
||||
return Quickshell.screens.length > 0 ? Quickshell.screens[0] : null;
|
||||
@@ -194,6 +205,18 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: MangoService
|
||||
function onStateChanged() {
|
||||
if (isMango)
|
||||
scheduleSort();
|
||||
}
|
||||
function onWindowsChanged() {
|
||||
if (isMango)
|
||||
scheduleSort();
|
||||
}
|
||||
}
|
||||
|
||||
function computeSortedToplevels() {
|
||||
if (!ToplevelManager.toplevels || !ToplevelManager.toplevels.values)
|
||||
return [];
|
||||
@@ -201,6 +224,9 @@ Singleton {
|
||||
if (useNiriSorting)
|
||||
return NiriService.sortToplevels(ToplevelManager.toplevels.values);
|
||||
|
||||
if (useMangoSorting)
|
||||
return MangoService.sortToplevels(ToplevelManager.toplevels.values);
|
||||
|
||||
if (isHyprland)
|
||||
return sortHyprlandToplevelsSafe();
|
||||
|
||||
@@ -697,6 +723,51 @@ Singleton {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Mango clients carry absolute geometry + tags; count those on the screen's
|
||||
// active tags (not minimized), made screen-relative via the monitor offset.
|
||||
function mangoDockOverlapForSmartAutoHide(screenName, dockPosition, dockThickness, screenWidth, screenHeight) {
|
||||
if (!isMango || !screenName || !MangoService.windows)
|
||||
return false;
|
||||
|
||||
const out = MangoService.outputs[screenName];
|
||||
const active = new Set((out?.activeTags) || []);
|
||||
const monX = out?.x ?? 0;
|
||||
const monY = out?.y ?? 0;
|
||||
|
||||
for (let i = 0; i < MangoService.windows.length; i++) {
|
||||
const win = MangoService.windows[i];
|
||||
if (!win || win.monitor !== screenName || win.is_minimized)
|
||||
continue;
|
||||
if (active.size > 0 && !(win.tags || []).some(t => active.has(t)))
|
||||
continue;
|
||||
|
||||
const winX = (win.x ?? 0) - monX;
|
||||
const winY = (win.y ?? 0) - monY;
|
||||
const winW = win.width ?? 0;
|
||||
const winH = win.height ?? 0;
|
||||
|
||||
switch (dockPosition) {
|
||||
case SettingsData.Position.Top:
|
||||
if (winY < dockThickness)
|
||||
return true;
|
||||
break;
|
||||
case SettingsData.Position.Bottom:
|
||||
if (winY + winH > screenHeight - dockThickness)
|
||||
return true;
|
||||
break;
|
||||
case SettingsData.Position.Left:
|
||||
if (winX < dockThickness)
|
||||
return true;
|
||||
break;
|
||||
case SettingsData.Position.Right:
|
||||
if (winX + winW > screenWidth - dockThickness)
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function filterHyprlandCurrentDisplaySafe(toplevels, screenName) {
|
||||
if (!toplevels || toplevels.length === 0 || !Hyprland.toplevels)
|
||||
return toplevels;
|
||||
@@ -790,15 +861,31 @@ Singleton {
|
||||
NiriService.generateNiriLayoutConfig();
|
||||
HyprlandService.generateLayoutConfig();
|
||||
DwlService.generateLayoutConfig();
|
||||
MangoService.generateLayoutConfig();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function detectCompositor() {
|
||||
if (mangoSignature && mangoSignature.length > 0) {
|
||||
isHyprland = false;
|
||||
isNiri = false;
|
||||
isDwl = false;
|
||||
isMango = true;
|
||||
isSway = false;
|
||||
isScroll = false;
|
||||
isMiracle = false;
|
||||
isLabwc = false;
|
||||
compositor = "mango";
|
||||
log.info("Detected MangoWM via MANGO_INSTANCE_SIGNATURE");
|
||||
return;
|
||||
}
|
||||
|
||||
if (hyprlandSignature && hyprlandSignature.length > 0 && !niriSocket && !swaySocket && !scrollSocket && !miracleSocket && !labwcPid) {
|
||||
isHyprland = true;
|
||||
isNiri = false;
|
||||
isDwl = false;
|
||||
isMango = false;
|
||||
isSway = false;
|
||||
isScroll = false;
|
||||
isMiracle = false;
|
||||
@@ -814,6 +901,7 @@ Singleton {
|
||||
isNiri = true;
|
||||
isHyprland = false;
|
||||
isDwl = false;
|
||||
isMango = false;
|
||||
isSway = false;
|
||||
isScroll = false;
|
||||
isMiracle = false;
|
||||
@@ -849,6 +937,7 @@ Singleton {
|
||||
isNiri = false;
|
||||
isHyprland = false;
|
||||
isDwl = false;
|
||||
isMango = false;
|
||||
isSway = false;
|
||||
isScroll = false;
|
||||
isMiracle = true;
|
||||
@@ -866,6 +955,7 @@ Singleton {
|
||||
isNiri = false;
|
||||
isHyprland = false;
|
||||
isDwl = false;
|
||||
isMango = false;
|
||||
isSway = false;
|
||||
isScroll = true;
|
||||
isMiracle = false;
|
||||
@@ -881,6 +971,7 @@ Singleton {
|
||||
isHyprland = false;
|
||||
isNiri = false;
|
||||
isDwl = false;
|
||||
isMango = false;
|
||||
isSway = false;
|
||||
isScroll = false;
|
||||
isMiracle = false;
|
||||
@@ -896,6 +987,7 @@ Singleton {
|
||||
isHyprland = false;
|
||||
isNiri = false;
|
||||
isDwl = false;
|
||||
isMango = false;
|
||||
isSway = false;
|
||||
isScroll = false;
|
||||
isMiracle = false;
|
||||
@@ -908,13 +1000,15 @@ Singleton {
|
||||
Connections {
|
||||
target: DMSService
|
||||
function onCapabilitiesReceived() {
|
||||
if (!isHyprland && !isNiri && !isDwl && !isLabwc) {
|
||||
if (!isHyprland && !isNiri && !isDwl && !isMango && !isLabwc) {
|
||||
checkForDwl();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkForDwl() {
|
||||
if (isMango)
|
||||
return;
|
||||
if (DMSService.apiVersion >= 12 && DMSService.capabilities.includes("dwl")) {
|
||||
isHyprland = false;
|
||||
isNiri = false;
|
||||
@@ -935,6 +1029,8 @@ Singleton {
|
||||
return HyprlandService.dpmsOff();
|
||||
if (isDwl)
|
||||
return _dwlPowerOffMonitors();
|
||||
if (isMango)
|
||||
return MangoService.powerOffMonitors();
|
||||
if (isSway || isScroll || isMiracle) {
|
||||
try {
|
||||
I3.dispatch("output * dpms off");
|
||||
@@ -954,6 +1050,8 @@ Singleton {
|
||||
return HyprlandService.dpmsOn();
|
||||
if (isDwl)
|
||||
return _dwlPowerOnMonitors();
|
||||
if (isMango)
|
||||
return MangoService.powerOnMonitors();
|
||||
if (isSway || isScroll || isMiracle) {
|
||||
try {
|
||||
I3.dispatch("output * dpms on");
|
||||
@@ -975,7 +1073,7 @@ Singleton {
|
||||
for (let i = 0; i < Quickshell.screens.length; i++) {
|
||||
const screen = Quickshell.screens[i];
|
||||
if (screen && screen.name) {
|
||||
Quickshell.execDetached(["mmsg", "-d", "disable_monitor," + screen.name]);
|
||||
Quickshell.execDetached(["mmsg", "dispatch", "disable_monitor," + screen.name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -989,7 +1087,7 @@ Singleton {
|
||||
for (let i = 0; i < Quickshell.screens.length; i++) {
|
||||
const screen = Quickshell.screens[i];
|
||||
if (screen && screen.name) {
|
||||
Quickshell.execDetached(["mmsg", "-d", "enable_monitor," + screen.name]);
|
||||
Quickshell.execDetached(["mmsg", "dispatch", "enable_monitor," + screen.name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ Singleton {
|
||||
property int _lastGapValue: -1
|
||||
|
||||
property bool dwlAvailable: false
|
||||
// Alias so consumers can treat DwlService/MangoService uniformly via `.available`.
|
||||
readonly property bool available: dwlAvailable
|
||||
property var outputs: ({})
|
||||
property var tagCount: 9
|
||||
property var layouts: []
|
||||
@@ -233,27 +235,23 @@ Singleton {
|
||||
}
|
||||
|
||||
function quit() {
|
||||
Quickshell.execDetached(["mmsg", "-d", "quit"]);
|
||||
Quickshell.execDetached(["mmsg", "dispatch", "quit"]);
|
||||
}
|
||||
|
||||
Process {
|
||||
id: scaleQueryProcess
|
||||
command: ["mmsg", "-A"]
|
||||
command: ["mmsg", "get", "all-monitors"]
|
||||
running: false
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
try {
|
||||
const newScales = {};
|
||||
const lines = text.trim().split('\n');
|
||||
for (const line of lines) {
|
||||
const parts = line.trim().split(/\s+/);
|
||||
if (parts.length >= 3 && parts[1] === "scale_factor") {
|
||||
const outputName = parts[0];
|
||||
const scale = parseFloat(parts[2]);
|
||||
if (!isNaN(scale)) {
|
||||
newScales[outputName] = scale;
|
||||
}
|
||||
const data = JSON.parse(text.trim());
|
||||
const monitors = data.monitors || [];
|
||||
for (const mon of monitors) {
|
||||
if (mon.name && typeof mon.scale === "number" && mon.scale > 0) {
|
||||
newScales[mon.name] = mon.scale;
|
||||
}
|
||||
}
|
||||
outputScales = newScales;
|
||||
@@ -327,7 +325,7 @@ Singleton {
|
||||
const transform = transformToMango(output.logical?.transform ?? "Normal");
|
||||
const vrr = output.vrr_enabled ? 1 : 0;
|
||||
|
||||
const rule = ["name:" + outputName, "width:" + width, "height:" + height, "refresh:" + refreshRate, "x:" + x, "y:" + y, "scale:" + scale, "rr:" + transform, "vrr:" + vrr].join(",");
|
||||
const rule = ["name:^" + outputName + "$", "width:" + width, "height:" + height, "refresh:" + refreshRate, "x:" + x, "y:" + y, "scale:" + scale, "rr:" + transform, "vrr:" + vrr].join(",");
|
||||
|
||||
lines.push("monitorrule=" + rule);
|
||||
}
|
||||
@@ -352,7 +350,7 @@ Singleton {
|
||||
}
|
||||
|
||||
function reloadConfig() {
|
||||
Proc.runCommand("mango-reload", ["mmsg", "-d", "reload_config"], (output, exitCode) => {
|
||||
Proc.runCommand("mango-reload", ["mmsg", "dispatch", "reload_config"], (output, exitCode) => {
|
||||
if (exitCode !== 0)
|
||||
log.warn("mmsg reload_config failed:", output);
|
||||
});
|
||||
|
||||
@@ -14,13 +14,13 @@ Singleton {
|
||||
id: root
|
||||
readonly property var log: Log.scoped("KeybindsService")
|
||||
|
||||
property bool available: CompositorService.isNiri || CompositorService.isHyprland || CompositorService.isDwl
|
||||
property bool available: CompositorService.isNiri || CompositorService.isHyprland || CompositorService.isDwl || CompositorService.isMango
|
||||
property string currentProvider: {
|
||||
if (CompositorService.isNiri)
|
||||
return "niri";
|
||||
if (CompositorService.isHyprland)
|
||||
return "hyprland";
|
||||
if (CompositorService.isDwl)
|
||||
if (CompositorService.isDwl || CompositorService.isMango)
|
||||
return "mangowc";
|
||||
return "";
|
||||
}
|
||||
@@ -30,7 +30,7 @@ Singleton {
|
||||
return "niri";
|
||||
if (CompositorService.isHyprland)
|
||||
return "hyprland";
|
||||
if (CompositorService.isDwl)
|
||||
if (CompositorService.isDwl || CompositorService.isMango)
|
||||
return "mangowc";
|
||||
return "";
|
||||
}
|
||||
@@ -118,7 +118,7 @@ Singleton {
|
||||
Connections {
|
||||
target: CompositorService
|
||||
function onCompositorChanged() {
|
||||
if (!CompositorService.isNiri)
|
||||
if (!CompositorService.isNiri && !CompositorService.isMango)
|
||||
return;
|
||||
Qt.callLater(root.loadBinds);
|
||||
}
|
||||
@@ -203,6 +203,8 @@ Singleton {
|
||||
}
|
||||
root.lastError = "";
|
||||
root.bindSaveCompleted(true);
|
||||
if (CompositorService.isMango)
|
||||
MangoService.reloadConfig();
|
||||
root.loadBinds(false);
|
||||
}
|
||||
}
|
||||
@@ -226,6 +228,8 @@ Singleton {
|
||||
return;
|
||||
}
|
||||
root.lastError = "";
|
||||
if (CompositorService.isMango)
|
||||
MangoService.reloadConfig();
|
||||
root.loadBinds(false);
|
||||
}
|
||||
}
|
||||
@@ -254,6 +258,8 @@ Singleton {
|
||||
root.dmsBindsFixed();
|
||||
const bindsRel = root.currentProvider === "niri" ? "dms/binds.kdl" : root.currentProvider === "hyprland" ? "dms/binds.lua" : "dms/binds.conf";
|
||||
ToastService.showInfo(I18n.tr("Binds include added"), I18n.tr("%1 is now included in config").arg(bindsRel), "", "keybinds");
|
||||
if (CompositorService.isMango)
|
||||
MangoService.reloadConfig();
|
||||
Qt.callLater(root.forceReload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,561 @@
|
||||
pragma Singleton
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtCore
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
|
||||
// Native MangoWM IPC client. mango advertises a JSON-over-Unix-socket protocol
|
||||
// via MANGO_INSTANCE_SIGNATURE; each connection issues one `watch <target>` verb
|
||||
// and gets a full JSON snapshot followed by newline-delimited updates. Replaces
|
||||
// the legacy dwl-ipc-v2 path (DwlService) for mango, exposing a
|
||||
// DwlService-compatible tag API plus a per-client window list.
|
||||
Singleton {
|
||||
id: root
|
||||
readonly property var log: Log.scoped("MangoService")
|
||||
|
||||
readonly property string socketPath: Quickshell.env("MANGO_INSTANCE_SIGNATURE")
|
||||
readonly property bool available: socketPath.length > 0
|
||||
|
||||
readonly property string configDir: Paths.strip(StandardPaths.writableLocation(StandardPaths.ConfigLocation))
|
||||
readonly property string mangoDmsDir: configDir + "/mango/dms"
|
||||
readonly property string outputsPath: mangoDmsDir + "/outputs.conf"
|
||||
readonly property string layoutPath: mangoDmsDir + "/layout.conf"
|
||||
readonly property string cursorPath: mangoDmsDir + "/cursor.conf"
|
||||
|
||||
property int _lastGapValue: -1
|
||||
|
||||
// name -> { name, active, x, y, width, height, scale, layoutIndex,
|
||||
// layoutSymbol, lastOpenSurface, kbLayout, keymode,
|
||||
// tags: [{ tag, state, clients, focused, urgent, layout }] }
|
||||
property var outputs: ({})
|
||||
property string activeOutput: ""
|
||||
property int tagCount: 9
|
||||
property var displayScales: ({})
|
||||
property string currentKeyboardLayout: ""
|
||||
// Rich client list from `watch all-clients` (mango "clients").
|
||||
property var windows: []
|
||||
|
||||
// windowsChanged is auto-generated by the `windows` property's change signal.
|
||||
signal stateChanged
|
||||
|
||||
// ── State sockets ──────────────────────────────────────────────────────
|
||||
// One connection per watch target; mango streams a fresh full snapshot on
|
||||
// every change, so each line is treated as the complete state.
|
||||
|
||||
DankSocket {
|
||||
id: monitorsSocket
|
||||
path: root.socketPath
|
||||
connected: root.available
|
||||
|
||||
onConnectionStateChanged: {
|
||||
if (connected)
|
||||
send("watch all-monitors");
|
||||
}
|
||||
|
||||
parser: SplitParser {
|
||||
onRead: line => root._handleMonitors(line)
|
||||
}
|
||||
}
|
||||
|
||||
DankSocket {
|
||||
id: clientsSocket
|
||||
path: root.socketPath
|
||||
connected: root.available
|
||||
|
||||
onConnectionStateChanged: {
|
||||
if (connected)
|
||||
send("watch all-clients");
|
||||
}
|
||||
|
||||
parser: SplitParser {
|
||||
onRead: line => root._handleClients(line)
|
||||
}
|
||||
}
|
||||
|
||||
function _handleMonitors(line) {
|
||||
if (!line || !line.trim())
|
||||
return;
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(line);
|
||||
} catch (e) {
|
||||
log.warn("Failed to parse all-monitors:", e);
|
||||
return;
|
||||
}
|
||||
const monitors = data.monitors;
|
||||
if (!Array.isArray(monitors))
|
||||
return;
|
||||
|
||||
const newOutputs = {};
|
||||
const newScales = {};
|
||||
let newActive = "";
|
||||
let newTagCount = root.tagCount;
|
||||
let newKbLayout = root.currentKeyboardLayout;
|
||||
|
||||
for (const m of monitors) {
|
||||
if (!m.name)
|
||||
continue;
|
||||
const tags = (m.tags || []).map(t => ({
|
||||
// 0-based to match the legacy dwl tag model used by consumers
|
||||
"tag": (t.index ?? 1) - 1,
|
||||
"state": t.is_urgent ? 2 : (t.is_active ? 1 : 0),
|
||||
"clients": t.client_count ?? 0,
|
||||
"focused": !!t.is_active,
|
||||
"urgent": !!t.is_urgent,
|
||||
"layout": t.layout ?? ""
|
||||
}));
|
||||
newOutputs[m.name] = {
|
||||
"name": m.name,
|
||||
"active": !!m.active,
|
||||
"x": m.x ?? 0,
|
||||
"y": m.y ?? 0,
|
||||
"width": m.width ?? 0,
|
||||
"height": m.height ?? 0,
|
||||
"scale": m.scale ?? 1.0,
|
||||
"layoutIndex": m.layout_index ?? 0,
|
||||
"layout": m.layout_index ?? 0,
|
||||
"activeTags": m.active_tags || [],
|
||||
"layoutSymbol": m.layout_symbol ?? "",
|
||||
"lastOpenSurface": m.last_open_surface ?? "",
|
||||
"keymode": m.keymode ?? "",
|
||||
"kbLayout": m.keyboardlayout ?? "",
|
||||
"tags": tags
|
||||
};
|
||||
if (typeof m.scale === "number" && m.scale > 0)
|
||||
newScales[m.name] = m.scale;
|
||||
if (m.active) {
|
||||
newActive = m.name;
|
||||
if (m.keyboardlayout)
|
||||
newKbLayout = m.keyboardlayout;
|
||||
}
|
||||
if (tags.length > 0)
|
||||
newTagCount = tags.length;
|
||||
}
|
||||
|
||||
root.outputs = newOutputs;
|
||||
root.displayScales = newScales;
|
||||
root.tagCount = newTagCount;
|
||||
if (newActive)
|
||||
root.activeOutput = newActive;
|
||||
root.currentKeyboardLayout = newKbLayout;
|
||||
root.stateChanged();
|
||||
}
|
||||
|
||||
function _handleClients(line) {
|
||||
if (!line || !line.trim())
|
||||
return;
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(line);
|
||||
} catch (e) {
|
||||
log.warn("Failed to parse all-clients:", e);
|
||||
return;
|
||||
}
|
||||
if (!Array.isArray(data.clients))
|
||||
return;
|
||||
root.windows = data.clients;
|
||||
}
|
||||
|
||||
// ── DwlService-compatible tag API ──────────────────────────────────────
|
||||
|
||||
function getOutputState(outputName) {
|
||||
return (outputs && outputs[outputName]) ? outputs[outputName] : null;
|
||||
}
|
||||
|
||||
function getActiveTags(outputName) {
|
||||
const output = getOutputState(outputName);
|
||||
if (!output || !output.tags)
|
||||
return [];
|
||||
return output.tags.filter(tag => tag.state === 1).map(tag => tag.tag);
|
||||
}
|
||||
|
||||
function getTagsWithClients(outputName) {
|
||||
const output = getOutputState(outputName);
|
||||
if (!output || !output.tags)
|
||||
return [];
|
||||
return output.tags.filter(tag => tag.clients > 0).map(tag => tag.tag);
|
||||
}
|
||||
|
||||
function getUrgentTags(outputName) {
|
||||
const output = getOutputState(outputName);
|
||||
if (!output || !output.tags)
|
||||
return [];
|
||||
return output.tags.filter(tag => tag.state === 2).map(tag => tag.tag);
|
||||
}
|
||||
|
||||
function getVisibleTags(outputName) {
|
||||
const output = getOutputState(outputName);
|
||||
if (!output || !output.tags)
|
||||
return [];
|
||||
const visibleTags = new Set();
|
||||
output.tags.forEach(tag => {
|
||||
if (tag.state === 1 || tag.clients > 0)
|
||||
visibleTags.add(tag.tag);
|
||||
});
|
||||
return Array.from(visibleTags).sort((a, b) => a - b);
|
||||
}
|
||||
|
||||
function getOutputScale(outputName) {
|
||||
return displayScales[outputName];
|
||||
}
|
||||
|
||||
// ── Window list ↔ wlr toplevel matching (per-tag sort/filter) ──────────
|
||||
// Match mango clients to wlr foreign-toplevels by appId+title to enrich them
|
||||
// with owning tags/monitor for per-tag filtering and stable ordering.
|
||||
|
||||
function _screenName(screenOrName) {
|
||||
return (typeof screenOrName === "string") ? screenOrName : (screenOrName?.name ?? "");
|
||||
}
|
||||
|
||||
function _orderedClients() {
|
||||
const list = (windows || []).slice();
|
||||
list.sort((a, b) => {
|
||||
const ma = outputs[a.monitor], mb = outputs[b.monitor];
|
||||
const ax = ma?.x ?? 1e9, ay = ma?.y ?? 1e9;
|
||||
const bx = mb?.x ?? 1e9, by = mb?.y ?? 1e9;
|
||||
if (ax !== bx)
|
||||
return ax - bx;
|
||||
if (ay !== by)
|
||||
return ay - by;
|
||||
if ((a.y ?? 0) !== (b.y ?? 0))
|
||||
return (a.y ?? 0) - (b.y ?? 0);
|
||||
if ((a.x ?? 0) !== (b.x ?? 0))
|
||||
return (a.x ?? 0) - (b.x ?? 0);
|
||||
return (a.id ?? 0) - (b.id ?? 0);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
function _matchAndEnrich(toplevels, clients) {
|
||||
const used = new Set();
|
||||
const result = [];
|
||||
for (const client of clients) {
|
||||
let bestMatch = null;
|
||||
let bestScore = -1;
|
||||
for (const toplevel of toplevels) {
|
||||
if (used.has(toplevel))
|
||||
continue;
|
||||
if (toplevel.appId !== client.appid)
|
||||
continue;
|
||||
let score = 1;
|
||||
if (client.title && toplevel.title) {
|
||||
if (toplevel.title === client.title)
|
||||
score = 3;
|
||||
else if (toplevel.title.includes(client.title) || client.title.includes(toplevel.title))
|
||||
score = 2;
|
||||
}
|
||||
if (score > bestScore) {
|
||||
bestScore = score;
|
||||
bestMatch = toplevel;
|
||||
if (score === 3)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!bestMatch)
|
||||
continue;
|
||||
used.add(bestMatch);
|
||||
|
||||
const enriched = {
|
||||
"appId": bestMatch.appId,
|
||||
"title": bestMatch.title,
|
||||
"activated": !!client.is_focused,
|
||||
"mangoWindowId": client.id,
|
||||
"mangoTags": client.tags || [],
|
||||
"mangoMonitor": client.monitor
|
||||
};
|
||||
for (let prop in bestMatch) {
|
||||
if (!(prop in enriched))
|
||||
enriched[prop] = bestMatch[prop];
|
||||
}
|
||||
result.push(enriched);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function sortToplevels(toplevels) {
|
||||
if (!toplevels || toplevels.length === 0 || windows.length === 0)
|
||||
return [...toplevels];
|
||||
const enriched = _matchAndEnrich(toplevels, _orderedClients());
|
||||
const used = new Set(enriched.map(e => e.mangoWindowId));
|
||||
// Append wlr toplevels that had no mango client match (rare).
|
||||
const matchedTitles = new Set(enriched.map(e => e.title + "\u0000" + e.appId));
|
||||
for (const t of toplevels) {
|
||||
if (!matchedTitles.has((t.title || "") + "\u0000" + (t.appId || "")))
|
||||
enriched.push(t);
|
||||
}
|
||||
return enriched;
|
||||
}
|
||||
|
||||
function _activeTagSet(screenName) {
|
||||
const out = outputs[screenName];
|
||||
return new Set((out?.activeTags) || []);
|
||||
}
|
||||
|
||||
function filterCurrentWorkspace(toplevels, screenOrName) {
|
||||
const screenName = _screenName(screenOrName);
|
||||
if (!screenName)
|
||||
return toplevels;
|
||||
const active = _activeTagSet(screenName);
|
||||
if (active.size === 0)
|
||||
return toplevels;
|
||||
|
||||
const onActive = tags => (tags || []).some(t => active.has(t));
|
||||
|
||||
if (toplevels.length > 0 && toplevels[0].mangoTags !== undefined)
|
||||
return toplevels.filter(t => t.mangoMonitor === screenName && onActive(t.mangoTags));
|
||||
|
||||
const clients = (windows || []).filter(c => c.monitor === screenName && onActive(c.tags));
|
||||
return _matchAndEnrich(toplevels, clients);
|
||||
}
|
||||
|
||||
function filterCurrentDisplay(toplevels, screenOrName) {
|
||||
const screenName = _screenName(screenOrName);
|
||||
if (!toplevels || toplevels.length === 0 || !screenName)
|
||||
return toplevels;
|
||||
|
||||
if (toplevels.length > 0 && toplevels[0].mangoMonitor !== undefined)
|
||||
return toplevels.filter(t => t.mangoMonitor === screenName);
|
||||
|
||||
const clients = (windows || []).filter(c => c.monitor === screenName);
|
||||
return _matchAndEnrich(toplevels, clients);
|
||||
}
|
||||
|
||||
// ── Commands (mango verb IPC: mmsg dispatch <func>,<args>) ─────────────
|
||||
|
||||
function reloadConfig() {
|
||||
Proc.runCommand("mango-reload", ["mmsg", "dispatch", "reload_config"], (output, exitCode) => {
|
||||
if (exitCode !== 0)
|
||||
log.warn("mmsg reload_config failed:", output);
|
||||
});
|
||||
}
|
||||
|
||||
function quit() {
|
||||
Quickshell.execDetached(["mmsg", "dispatch", "quit"]);
|
||||
}
|
||||
|
||||
// mango tag dispatches act on the focused monitor; tagIndex is 0-based
|
||||
// (dwl model), mango `view`/`toggleview` take a 1-based tag number.
|
||||
function switchToTag(outputName, tagIndex) {
|
||||
Quickshell.execDetached(["mmsg", "dispatch", "view," + (tagIndex + 1)]);
|
||||
}
|
||||
|
||||
function toggleTag(outputName, tagIndex) {
|
||||
Quickshell.execDetached(["mmsg", "dispatch", "toggleview," + (tagIndex + 1)]);
|
||||
}
|
||||
|
||||
// mango's tiling layouts are a fixed compiled-in set the IPC doesn't expose,
|
||||
// so mirror it here in mango's layouts[] order (layout_index aligns). The
|
||||
// parallel name list exists because `setlayout` dispatches by name, not index.
|
||||
readonly property var layouts: ["T", "S", "G", "M", "K", "CT", "RT", "VS", "VT", "VG", "VK", "DW", "F", "VF"]
|
||||
readonly property var _layoutNames: ["tile", "scroller", "grid", "monocle", "deck", "center_tile", "right_tile", "vertical_scroller", "vertical_tile", "vertical_grid", "vertical_deck", "dwindle", "fair", "vertical_fair"]
|
||||
|
||||
function setLayout(outputName, index) {
|
||||
const name = _layoutNames[index];
|
||||
if (name)
|
||||
Quickshell.execDetached(["mmsg", "dispatch", "setlayout," + name]);
|
||||
}
|
||||
|
||||
function cycleKeyboardLayout() {
|
||||
Quickshell.execDetached(["mmsg", "dispatch", "switch_keyboard_layout"]);
|
||||
}
|
||||
|
||||
function powerOffMonitors() {
|
||||
const screens = Quickshell.screens || [];
|
||||
for (let i = 0; i < screens.length; i++) {
|
||||
if (screens[i] && screens[i].name)
|
||||
Quickshell.execDetached(["mmsg", "dispatch", "disable_monitor," + screens[i].name]);
|
||||
}
|
||||
}
|
||||
|
||||
function powerOnMonitors() {
|
||||
const screens = Quickshell.screens || [];
|
||||
for (let i = 0; i < screens.length; i++) {
|
||||
if (screens[i] && screens[i].name)
|
||||
Quickshell.execDetached(["mmsg", "dispatch", "enable_monitor," + screens[i].name]);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Config generation (mango config fragments under ~/.config/mango/dms) ─
|
||||
|
||||
Connections {
|
||||
target: SettingsData
|
||||
function onBarConfigsChanged() {
|
||||
if (!CompositorService.isMango)
|
||||
return;
|
||||
const newGaps = Math.max(4, (SettingsData.barConfigs[0]?.spacing ?? 4));
|
||||
if (newGaps === root._lastGapValue)
|
||||
return;
|
||||
root._lastGapValue = newGaps;
|
||||
generateLayoutConfig();
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: CompositorService
|
||||
function onIsMangoChanged() {
|
||||
if (CompositorService.isMango)
|
||||
generateLayoutConfig();
|
||||
}
|
||||
}
|
||||
|
||||
function transformToMango(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 generateOutputsConfig(outputsData, callback) {
|
||||
if (!outputsData || Object.keys(outputsData).length === 0) {
|
||||
if (callback)
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
let lines = ["# Auto-generated by DMS - do not edit manually", ""];
|
||||
|
||||
for (const outputName in outputsData) {
|
||||
const output = outputsData[outputName];
|
||||
if (!output)
|
||||
continue;
|
||||
let width = 1920;
|
||||
let height = 1080;
|
||||
let refreshRate = 60;
|
||||
if (output.modes && output.current_mode !== undefined) {
|
||||
const mode = output.modes[output.current_mode];
|
||||
if (mode) {
|
||||
width = mode.width || 1920;
|
||||
height = mode.height || 1080;
|
||||
refreshRate = Math.round((mode.refresh_rate || 60000) / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
const x = output.logical?.x ?? 0;
|
||||
const y = output.logical?.y ?? 0;
|
||||
const scale = output.logical?.scale ?? 1.0;
|
||||
const transform = transformToMango(output.logical?.transform ?? "Normal");
|
||||
const vrr = output.vrr_enabled ? 1 : 0;
|
||||
|
||||
// Anchor the name regex: mango matches `name:` unanchored (first-match
|
||||
// wins), so a bare "DP-1" would also match "eDP-1" and collapse outputs.
|
||||
const rule = ["name:^" + outputName + "$", "width:" + width, "height:" + height, "refresh:" + refreshRate, "x:" + x, "y:" + y, "scale:" + scale, "rr:" + transform, "vrr:" + vrr].join(",");
|
||||
|
||||
lines.push("monitorrule=" + rule);
|
||||
}
|
||||
|
||||
lines.push("");
|
||||
|
||||
const content = lines.join("\n");
|
||||
|
||||
Proc.runCommand("mango-write-outputs", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && cat > "${outputsPath}" << 'EOF'\n${content}EOF`], (output, exitCode) => {
|
||||
if (exitCode !== 0) {
|
||||
log.warn("Failed to write outputs config:", output);
|
||||
if (callback)
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
log.info("Generated outputs config at", outputsPath);
|
||||
if (CompositorService.isMango)
|
||||
reloadConfig();
|
||||
if (callback)
|
||||
callback(true);
|
||||
});
|
||||
}
|
||||
|
||||
function generateLayoutConfig() {
|
||||
if (!CompositorService.isMango)
|
||||
return;
|
||||
|
||||
const defaultRadius = typeof SettingsData !== "undefined" ? SettingsData.cornerRadius : 12;
|
||||
const defaultGaps = typeof SettingsData !== "undefined" ? Math.max(4, (SettingsData.barConfigs[0]?.spacing ?? 4)) : 4;
|
||||
const defaultBorderSize = 2;
|
||||
|
||||
const cornerRadius = (typeof SettingsData !== "undefined" && SettingsData.mangoLayoutRadiusOverride >= 0) ? SettingsData.mangoLayoutRadiusOverride : defaultRadius;
|
||||
const gaps = (typeof SettingsData !== "undefined" && SettingsData.mangoLayoutGapsOverride >= 0) ? SettingsData.mangoLayoutGapsOverride : defaultGaps;
|
||||
const borderSize = (typeof SettingsData !== "undefined" && SettingsData.mangoLayoutBorderSize >= 0) ? SettingsData.mangoLayoutBorderSize : defaultBorderSize;
|
||||
|
||||
let content = `# Auto-generated by DMS - do not edit manually
|
||||
border_radius=${cornerRadius}
|
||||
gappih=${gaps}
|
||||
gappiv=${gaps}
|
||||
gappoh=${gaps}
|
||||
gappov=${gaps}
|
||||
borderpx=${borderSize}
|
||||
`;
|
||||
|
||||
Proc.runCommand("mango-write-layout", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && cat > "${layoutPath}" << 'EOF'\n${content}EOF`], (output, exitCode) => {
|
||||
if (exitCode !== 0) {
|
||||
log.warn("Failed to write layout config:", output);
|
||||
return;
|
||||
}
|
||||
log.info("Generated layout config at", layoutPath);
|
||||
reloadConfig();
|
||||
});
|
||||
}
|
||||
|
||||
function generateCursorConfig() {
|
||||
if (!CompositorService.isMango)
|
||||
return;
|
||||
|
||||
const settings = typeof SettingsData !== "undefined" ? SettingsData.cursorSettings : null;
|
||||
if (!settings) {
|
||||
Proc.runCommand("mango-write-cursor", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && : > "${cursorPath}"`], (output, exitCode) => {
|
||||
if (exitCode !== 0)
|
||||
log.warn("Failed to write cursor config:", output);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const themeName = settings.theme === "System Default" ? (SettingsData.systemDefaultCursorTheme || "") : settings.theme;
|
||||
const size = settings.size || 24;
|
||||
const hideTimeout = settings.mango?.cursorHideTimeout || 0;
|
||||
|
||||
const isDefaultConfig = !themeName && size === 24 && hideTimeout === 0;
|
||||
if (isDefaultConfig) {
|
||||
Proc.runCommand("mango-write-cursor", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && : > "${cursorPath}"`], (output, exitCode) => {
|
||||
if (exitCode !== 0)
|
||||
log.warn("Failed to write cursor config:", output);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let content = `# Auto-generated by DMS - do not edit manually
|
||||
cursor_size=${size}`;
|
||||
|
||||
if (themeName)
|
||||
content += `\ncursor_theme=${themeName}`;
|
||||
|
||||
if (hideTimeout > 0)
|
||||
content += `\ncursor_hide_timeout=${hideTimeout}`;
|
||||
|
||||
content += `\n`;
|
||||
|
||||
Proc.runCommand("mango-write-cursor", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && cat > "${cursorPath}" << 'EOF'\n${content}EOF`], (output, exitCode) => {
|
||||
if (exitCode !== 0) {
|
||||
log.warn("Failed to write cursor config:", output);
|
||||
return;
|
||||
}
|
||||
log.info("Generated cursor config at", cursorPath);
|
||||
reloadConfig();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -319,6 +319,11 @@ Singleton {
|
||||
return;
|
||||
}
|
||||
|
||||
if (CompositorService.isMango) {
|
||||
MangoService.quit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (CompositorService.isLabwc) {
|
||||
LabwcService.quit();
|
||||
return;
|
||||
|
||||
@@ -36,6 +36,7 @@ Singleton {
|
||||
"isNiri": () => CompositorService.isNiri,
|
||||
"isHyprland": () => CompositorService.isHyprland,
|
||||
"isDwl": () => CompositorService.isDwl,
|
||||
"isMango": () => CompositorService.isMango,
|
||||
"keybindsAvailable": () => KeybindsService.available,
|
||||
"soundsAvailable": () => AudioService.soundsAvailable,
|
||||
"cupsAvailable": () => CupsService.cupsAvailable,
|
||||
|
||||
Reference in New Issue
Block a user