1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-06-13 22:46:34 -04:00

Fix Hyprland Lua dispatch helpers (#2443)

This commit is contained in:
sima
2026-05-19 01:34:49 +08:00
committed by GitHub
parent 0b55bf5dac
commit 4528552610
+52 -15
View File
@@ -327,67 +327,104 @@ hl.config({
return; return;
const fullName = wsId + " " + newName; const fullName = wsId + " " + newName;
if (Hyprland.usingLua) { if (Hyprland.usingLua) {
Hyprland.dispatch(`hl.dsp.workspace.rename({workspace = "${wsId}", name = "${fullName}"})`) Hyprland.dispatch(`hl.dsp.workspace.rename({ workspace = ${luaValue(wsId)}, name = ${luaString(fullName)} })`);
} else { } else {
Hyprland.dispatch(`renameworkspace ${wsId} ${fullName}`) Hyprland.dispatch(`renameworkspace ${wsId} ${fullName}`);
} }
} }
function focusWorkspace(workspace) { function focusWorkspace(workspace) {
if (Hyprland.usingLua) { if (Hyprland.usingLua) {
Hyprland.dispatch(`hl.dsp.focus({workspace = "${workspace}"})`) Hyprland.dispatch(`hl.dsp.focus({ workspace = ${luaValue(workspace)} })`);
} else { } else {
Hyprland.dispatch(`workspace ${workspace}`) Hyprland.dispatch(`workspace ${workspace}`);
} }
} }
function luaString(value) {
return `"${String(value ?? "").replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
}
function luaValue(value) {
const text = String(value ?? "");
return /^[-+]?\d+$/.test(text) ? text : luaString(text);
}
function windowSelector(windowAddress) {
if (!windowAddress)
return "";
const text = String(windowAddress);
if (text.startsWith("address:"))
return text;
return `address:${text.startsWith("0x") ? text : "0x" + text}`;
}
function focusWindow(windowAddress) { function focusWindow(windowAddress) {
const selector = windowSelector(windowAddress);
if (!selector)
return;
if (Hyprland.usingLua) { if (Hyprland.usingLua) {
Hyprland.dispatch(`hl.dsp.focus({window = "address:0x${windowAddress}"})`); Hyprland.dispatch(`hl.dsp.focus({ window = ${luaString(selector)} })`);
} else { } else {
Hyprland.dispatch(`focuswindow address:${windowAddress}`); Hyprland.dispatch(`focuswindow ${selector}`);
} }
} }
function closeWindow(windowAddress) { function closeWindow(windowAddress) {
const selector = windowSelector(windowAddress);
if (!selector)
return;
if (Hyprland.usingLua) { if (Hyprland.usingLua) {
Hyprland.dispatch(`hl.dsp.window.close("address:${windowAddress}")`); Hyprland.dispatch(`hl.dsp.window.close(${luaString(selector)})`);
} else { } else {
Hyprland.dispatch(`closewindow address:${windowAddress}`); Hyprland.dispatch(`closewindow ${selector}`);
} }
} }
function moveToWorkspace(workspace, windowAddress, follow = true) { function moveToWorkspace(workspace, windowAddress, follow = true) {
const selector = windowSelector(windowAddress);
if (!selector)
return;
if (Hyprland.usingLua) { if (Hyprland.usingLua) {
Hyprland.dispatch(`hl.dsp.window.move({workspace = "${workspace}", window="address:${windowAddress}", follow = ${follow}})`) Hyprland.dispatch(`hl.dsp.window.move({ workspace = ${luaValue(workspace)}, window = ${luaString(selector)}, follow = ${follow ? "true" : "false"} })`);
} else { } else {
const dispatcher = follow ? "movetoworkspace" : "movetoworkspacesilent" const dispatcher = follow ? "movetoworkspace" : "movetoworkspacesilent";
Hyprland.dispatch(`${dispatcher} ${workspace},address:${windowAddress}`); Hyprland.dispatch(`${dispatcher} ${workspace},${selector}`);
} }
} }
function toggleSpecial(specialName) { function toggleSpecial(specialName) {
if (Hyprland.usingLua) { if (Hyprland.usingLua) {
Hyprland.dispatch(`hl.dsp.workspace.toggle_special(${specialName})`) Hyprland.dispatch(`hl.dsp.workspace.toggle_special(${luaString(specialName)})`);
} else { } else {
Hyprland.dispatch("togglespecialworkspace " + specialName); Hyprland.dispatch("togglespecialworkspace " + specialName);
} }
} }
function exit() { function exit() {
if (Hyprland.usingLua) { if (Hyprland.usingLua) {
Hyprland.dispatch("hl.dsp.exit()") Hyprland.dispatch("hl.dsp.exit()");
} else { } else {
Hyprland.dispatch("exit"); Hyprland.dispatch("exit");
} }
} }
function dpmsOff() { function dpmsOff() {
if (Hyprland.usingLua) { if (Hyprland.usingLua) {
Hyprland.dispatch(`hl.dsp.dpms({action = "disable"})`) Hyprland.dispatch(`hl.dsp.dpms({ action = "disable" })`);
} else { } else {
Hyprland.dispatch("dpms off"); Hyprland.dispatch("dpms off");
} }
} }
function dpmsOn() { function dpmsOn() {
if (Hyprland.usingLua) { if (Hyprland.usingLua) {
Hyprland.dispatch(`hl.dsp.dpms({action = "enable"})`) Hyprland.dispatch(`hl.dsp.dpms({ action = "enable" })`);
} else { } else {
Hyprland.dispatch("dpms on"); Hyprland.dispatch("dpms on");
} }