mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-06 21:48:30 -04:00
mango: add separate dispatch socket
port 1.5
(cherry picked from commit 296b3a3d7e)
This commit is contained in:
@@ -1086,7 +1086,7 @@ Item {
|
|||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: Quickshell.execDetached(["mmsg", "dispatch", "toggleoverview"])
|
onClicked: MangoService.dispatch("toggleoverview")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,6 +131,60 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mango closes the connection after each non-watch command; queued
|
||||||
|
// dispatches drain one per reconnect cycle.
|
||||||
|
DankSocket {
|
||||||
|
id: dispatchSocket
|
||||||
|
path: root.socketPath
|
||||||
|
connected: root.available
|
||||||
|
reconnectBaseMs: 25
|
||||||
|
|
||||||
|
onConnectionStateChanged: {
|
||||||
|
if (linkUp) {
|
||||||
|
root._dispatchConnectionUsed = false;
|
||||||
|
root._flushDispatch();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const entry = root._dispatchInFlight;
|
||||||
|
root._dispatchInFlight = null;
|
||||||
|
if (entry?.callback)
|
||||||
|
entry.callback("");
|
||||||
|
}
|
||||||
|
|
||||||
|
parser: SplitParser {
|
||||||
|
onRead: line => root._onDispatchReply(line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
property var _dispatchQueue: []
|
||||||
|
property var _dispatchInFlight: null
|
||||||
|
property bool _dispatchConnectionUsed: false
|
||||||
|
|
||||||
|
function dispatch(command, callback) {
|
||||||
|
if (!root.available)
|
||||||
|
return;
|
||||||
|
_dispatchQueue.push({
|
||||||
|
"command": command,
|
||||||
|
"callback": callback ?? null
|
||||||
|
});
|
||||||
|
_flushDispatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
function _flushDispatch() {
|
||||||
|
if (_dispatchInFlight || _dispatchConnectionUsed || _dispatchQueue.length === 0 || !dispatchSocket.linkUp)
|
||||||
|
return;
|
||||||
|
_dispatchConnectionUsed = true;
|
||||||
|
_dispatchInFlight = _dispatchQueue.shift();
|
||||||
|
dispatchSocket.send("dispatch " + _dispatchInFlight.command);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _onDispatchReply(line) {
|
||||||
|
const entry = _dispatchInFlight;
|
||||||
|
_dispatchInFlight = null;
|
||||||
|
if (entry?.callback)
|
||||||
|
entry.callback(line);
|
||||||
|
}
|
||||||
|
|
||||||
function _handleMonitors(line) {
|
function _handleMonitors(line) {
|
||||||
if (!line || !line.trim())
|
if (!line || !line.trim())
|
||||||
return;
|
return;
|
||||||
@@ -398,7 +452,7 @@ Singleton {
|
|||||||
return _matchAndEnrich(toplevels, clients);
|
return _matchAndEnrich(toplevels, clients);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Commands (mango verb IPC: mmsg dispatch <func>,<args>) ─────────────
|
// ── Commands (mango verb IPC: dispatch <func>,<args> over the socket) ──
|
||||||
|
|
||||||
function suppressWatchedConfigReloads(ms) {
|
function suppressWatchedConfigReloads(ms) {
|
||||||
root._ignoreWatchedReloadUntil = Math.max(root._ignoreWatchedReloadUntil, Date.now() + (ms || 1500));
|
root._ignoreWatchedReloadUntil = Math.max(root._ignoreWatchedReloadUntil, Date.now() + (ms || 1500));
|
||||||
@@ -423,11 +477,15 @@ Singleton {
|
|||||||
const shouldSuppressWatch = suppressWatch !== false;
|
const shouldSuppressWatch = suppressWatch !== false;
|
||||||
if (shouldSuppressWatch)
|
if (shouldSuppressWatch)
|
||||||
suppressWatchedConfigReloads(1500);
|
suppressWatchedConfigReloads(1500);
|
||||||
Proc.runCommand("mango-reload", ["mmsg", "dispatch", "reload_config"], (output, exitCode) => {
|
dispatch("reload_config", line => {
|
||||||
if (exitCode !== 0) {
|
let ok = false;
|
||||||
log.warn("mmsg reload_config failed:", output);
|
try {
|
||||||
|
ok = JSON.parse(line).success === true;
|
||||||
|
} catch (e) {}
|
||||||
|
if (!ok) {
|
||||||
|
log.warn("reload_config dispatch failed:", line);
|
||||||
if (shouldShowToast)
|
if (shouldShowToast)
|
||||||
ToastService.showError(I18n.tr("mango: failed to reload config"), output || "", "", "mango-config");
|
ToastService.showError(I18n.tr("mango: failed to reload config"), line || "", "", "mango-config");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (shouldShowToast)
|
if (shouldShowToast)
|
||||||
@@ -436,17 +494,17 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function quit() {
|
function quit() {
|
||||||
Quickshell.execDetached(["mmsg", "dispatch", "quit"]);
|
dispatch("quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
// mango tag dispatches act on the focused monitor; tagIndex is 0-based
|
// mango tag dispatches act on the focused monitor; tagIndex is 0-based
|
||||||
// (dwl model), mango `view`/`toggleview` take a 1-based tag number.
|
// (dwl model), mango `view`/`toggleview` take a 1-based tag number.
|
||||||
function switchToTag(outputName, tagIndex) {
|
function switchToTag(outputName, tagIndex) {
|
||||||
Quickshell.execDetached(["mmsg", "dispatch", "view," + (tagIndex + 1)]);
|
dispatch("view," + (tagIndex + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleTag(outputName, tagIndex) {
|
function toggleTag(outputName, tagIndex) {
|
||||||
Quickshell.execDetached(["mmsg", "dispatch", "toggleview," + (tagIndex + 1)]);
|
dispatch("toggleview," + (tagIndex + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// mango's tiling layouts are a fixed compiled-in set the IPC doesn't expose,
|
// mango's tiling layouts are a fixed compiled-in set the IPC doesn't expose,
|
||||||
@@ -458,18 +516,18 @@ Singleton {
|
|||||||
function setLayout(outputName, index) {
|
function setLayout(outputName, index) {
|
||||||
const name = _layoutNames[index];
|
const name = _layoutNames[index];
|
||||||
if (name)
|
if (name)
|
||||||
Quickshell.execDetached(["mmsg", "dispatch", "setlayout," + name]);
|
dispatch("setlayout," + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function cycleKeyboardLayout() {
|
function cycleKeyboardLayout() {
|
||||||
Quickshell.execDetached(["mmsg", "dispatch", "switch_keyboard_layout"]);
|
dispatch("switch_keyboard_layout");
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerOffMonitors() {
|
function powerOffMonitors() {
|
||||||
const screens = Quickshell.screens || [];
|
const screens = Quickshell.screens || [];
|
||||||
for (let i = 0; i < screens.length; i++) {
|
for (let i = 0; i < screens.length; i++) {
|
||||||
if (screens[i] && screens[i].name)
|
if (screens[i] && screens[i].name)
|
||||||
Quickshell.execDetached(["mmsg", "dispatch", "sleep_monitor," + screens[i].name]);
|
dispatch("sleep_monitor," + screens[i].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,7 +535,7 @@ Singleton {
|
|||||||
const screens = Quickshell.screens || [];
|
const screens = Quickshell.screens || [];
|
||||||
for (let i = 0; i < screens.length; i++) {
|
for (let i = 0; i < screens.length; i++) {
|
||||||
if (screens[i] && screens[i].name)
|
if (screens[i] && screens[i].name)
|
||||||
Quickshell.execDetached(["mmsg", "dispatch", "wakeup_monitor," + screens[i].name]);
|
dispatch("wakeup_monitor," + screens[i].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,6 +631,7 @@ Singleton {
|
|||||||
|
|
||||||
const content = lines.join("\n");
|
const content = lines.join("\n");
|
||||||
|
|
||||||
|
suppressWatchedConfigReloads(1500);
|
||||||
Proc.runCommand("mango-write-outputs", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && cat > "${outputsPath}" << 'EOF'\n${content}EOF`], (output, exitCode) => {
|
Proc.runCommand("mango-write-outputs", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && cat > "${outputsPath}" << 'EOF'\n${content}EOF`], (output, exitCode) => {
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
log.warn("Failed to write outputs config:", output);
|
log.warn("Failed to write outputs config:", output);
|
||||||
@@ -582,7 +641,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
log.info("Generated outputs config at", outputsPath);
|
log.info("Generated outputs config at", outputsPath);
|
||||||
if (CompositorService.isMango)
|
if (CompositorService.isMango)
|
||||||
reloadConfig();
|
reloadConfig(false);
|
||||||
if (callback)
|
if (callback)
|
||||||
callback(true);
|
callback(true);
|
||||||
});
|
});
|
||||||
@@ -615,13 +674,14 @@ gappoh=${gapsOut}
|
|||||||
gappov=${gapsOut}
|
gappov=${gapsOut}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
suppressWatchedConfigReloads(1500);
|
||||||
Proc.runCommand("mango-write-layout", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && cat > "${layoutPath}" << 'EOF'\n${content}EOF`], (output, exitCode) => {
|
Proc.runCommand("mango-write-layout", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && cat > "${layoutPath}" << 'EOF'\n${content}EOF`], (output, exitCode) => {
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
log.warn("Failed to write layout config:", output);
|
log.warn("Failed to write layout config:", output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("Generated layout config at", layoutPath);
|
log.info("Generated layout config at", layoutPath);
|
||||||
reloadConfig();
|
reloadConfig(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,6 +691,7 @@ gappov=${gapsOut}
|
|||||||
|
|
||||||
const settings = typeof SettingsData !== "undefined" ? SettingsData.cursorSettings : null;
|
const settings = typeof SettingsData !== "undefined" ? SettingsData.cursorSettings : null;
|
||||||
if (!settings) {
|
if (!settings) {
|
||||||
|
suppressWatchedConfigReloads(1500);
|
||||||
Proc.runCommand("mango-write-cursor", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && : > "${cursorPath}"`], (output, exitCode) => {
|
Proc.runCommand("mango-write-cursor", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && : > "${cursorPath}"`], (output, exitCode) => {
|
||||||
if (exitCode !== 0)
|
if (exitCode !== 0)
|
||||||
log.warn("Failed to write cursor config:", output);
|
log.warn("Failed to write cursor config:", output);
|
||||||
@@ -655,13 +716,14 @@ cursor_size=${size}`;
|
|||||||
|
|
||||||
content += `\n`;
|
content += `\n`;
|
||||||
|
|
||||||
|
suppressWatchedConfigReloads(1500);
|
||||||
Proc.runCommand("mango-write-cursor", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && cat > "${cursorPath}" << 'EOF'\n${content}EOF`], (output, exitCode) => {
|
Proc.runCommand("mango-write-cursor", ["sh", "-c", `mkdir -p "${mangoDmsDir}" && cat > "${cursorPath}" << 'EOF'\n${content}EOF`], (output, exitCode) => {
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
log.warn("Failed to write cursor config:", output);
|
log.warn("Failed to write cursor config:", output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("Generated cursor config at", cursorPath);
|
log.info("Generated cursor config at", cursorPath);
|
||||||
reloadConfig();
|
reloadConfig(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ Singleton {
|
|||||||
running: true
|
running: true
|
||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
|
detectUwsmProcess.running = true;
|
||||||
detectElogindProcess.running = true;
|
detectElogindProcess.running = true;
|
||||||
detectLoginctlProcess.running = true;
|
detectLoginctlProcess.running = true;
|
||||||
detectSystemctlProcess.running = true;
|
detectSystemctlProcess.running = true;
|
||||||
@@ -73,7 +74,7 @@ Singleton {
|
|||||||
Process {
|
Process {
|
||||||
id: detectUwsmProcess
|
id: detectUwsmProcess
|
||||||
running: false
|
running: false
|
||||||
command: ["sh", "-c", "command -v uwsm"]
|
command: ["sh", "-c", "command -v uwsm > /dev/null 2>&1 && systemctl --user is-active --quiet 'wayland-wm@*.service' 2> /dev/null"]
|
||||||
|
|
||||||
onExited: function (exitCode) {
|
onExited: function (exitCode) {
|
||||||
hasUwsm = (exitCode === 0);
|
hasUwsm = (exitCode === 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user