mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-13 14:36:32 -04:00
Fix Hyprland Lua dispatch helpers (#2443)
This commit is contained in:
@@ -327,69 +327,106 @@ 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) {
|
||||||
if (Hyprland.usingLua) {
|
const selector = windowSelector(windowAddress);
|
||||||
Hyprland.dispatch(`hl.dsp.focus({window = "address:0x${windowAddress}"})`);
|
if (!selector)
|
||||||
} else {
|
return;
|
||||||
Hyprland.dispatch(`focuswindow address:${windowAddress}`);
|
|
||||||
}
|
if (Hyprland.usingLua) {
|
||||||
|
Hyprland.dispatch(`hl.dsp.focus({ window = ${luaString(selector)} })`);
|
||||||
|
} else {
|
||||||
|
Hyprland.dispatch(`focuswindow ${selector}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeWindow(windowAddress) {
|
function closeWindow(windowAddress) {
|
||||||
if (Hyprland.usingLua) {
|
const selector = windowSelector(windowAddress);
|
||||||
Hyprland.dispatch(`hl.dsp.window.close("address:${windowAddress}")`);
|
if (!selector)
|
||||||
} else {
|
return;
|
||||||
Hyprland.dispatch(`closewindow address:${windowAddress}`);
|
|
||||||
}
|
if (Hyprland.usingLua) {
|
||||||
|
Hyprland.dispatch(`hl.dsp.window.close(${luaString(selector)})`);
|
||||||
|
} else {
|
||||||
|
Hyprland.dispatch(`closewindow ${selector}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveToWorkspace(workspace, windowAddress, follow = true) {
|
function moveToWorkspace(workspace, windowAddress, follow = true) {
|
||||||
if (Hyprland.usingLua) {
|
const selector = windowSelector(windowAddress);
|
||||||
Hyprland.dispatch(`hl.dsp.window.move({workspace = "${workspace}", window="address:${windowAddress}", follow = ${follow}})`)
|
if (!selector)
|
||||||
} else {
|
return;
|
||||||
const dispatcher = follow ? "movetoworkspace" : "movetoworkspacesilent"
|
|
||||||
Hyprland.dispatch(`${dispatcher} ${workspace},address:${windowAddress}`);
|
if (Hyprland.usingLua) {
|
||||||
}
|
Hyprland.dispatch(`hl.dsp.window.move({ workspace = ${luaValue(workspace)}, window = ${luaString(selector)}, follow = ${follow ? "true" : "false"} })`);
|
||||||
|
} else {
|
||||||
|
const dispatcher = follow ? "movetoworkspace" : "movetoworkspacesilent";
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user