mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
keybinds: fix sh, fix screenshot-window options, empty args
part of #914
This commit is contained in:
@@ -325,24 +325,30 @@ func (n *NiriProvider) buildActionFromNode(bindNode *document.Node) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actionNode := bindNode.Children[0]
|
actionNode := bindNode.Children[0]
|
||||||
|
actionName := actionNode.Name.String()
|
||||||
kdlStr := strings.TrimSpace(actionNode.String())
|
if actionName == "" {
|
||||||
if kdlStr == "" {
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return n.kdlActionToInternal(kdlStr)
|
parts := []string{actionName}
|
||||||
|
for _, arg := range actionNode.Arguments {
|
||||||
|
val := arg.ValueString()
|
||||||
|
if val == "" {
|
||||||
|
parts = append(parts, `""`)
|
||||||
|
} else {
|
||||||
|
parts = append(parts, val)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NiriProvider) kdlActionToInternal(kdlAction string) string {
|
if actionNode.Properties != nil {
|
||||||
parts := n.parseActionParts(kdlAction)
|
if val, ok := actionNode.Properties.Get("focus"); ok {
|
||||||
if len(parts) == 0 {
|
parts = append(parts, "focus="+val.String())
|
||||||
return kdlAction
|
|
||||||
}
|
}
|
||||||
|
if val, ok := actionNode.Properties.Get("show-pointer"); ok {
|
||||||
for i, part := range parts {
|
parts = append(parts, "show-pointer="+val.String())
|
||||||
if part == "" {
|
}
|
||||||
parts[i] = `""`
|
if val, ok := actionNode.Properties.Get("write-to-disk"); ok {
|
||||||
|
parts = append(parts, "write-to-disk="+val.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -450,10 +450,7 @@ const NIRI_ACTION_ARGS = {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"screenshot-window": {
|
"screenshot-window": {
|
||||||
args: [
|
args: [{ name: "write-to-disk", type: "bool", label: "Save to disk" }]
|
||||||
{ name: "show-pointer", type: "bool", label: "Show pointer" },
|
|
||||||
{ name: "write-to-disk", type: "bool", label: "Save to disk" }
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -841,7 +838,7 @@ function getActionType(action) {
|
|||||||
return "compositor";
|
return "compositor";
|
||||||
if (action.startsWith("spawn dms ipc call "))
|
if (action.startsWith("spawn dms ipc call "))
|
||||||
return "dms";
|
return "dms";
|
||||||
if (action.startsWith("spawn sh -c ") || action.startsWith("spawn bash -c ") || action.startsWith("spawn_shell "))
|
if (/^spawn \w+ -c /.test(action) || action.startsWith("spawn_shell "))
|
||||||
return "shell";
|
return "shell";
|
||||||
if (action.startsWith("spawn "))
|
if (action.startsWith("spawn "))
|
||||||
return "spawn";
|
return "spawn";
|
||||||
@@ -888,12 +885,13 @@ function buildSpawnAction(command, args) {
|
|||||||
return "spawn " + parts.join(" ");
|
return "spawn " + parts.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildShellAction(compositor, shellCmd) {
|
function buildShellAction(compositor, shellCmd, shell) {
|
||||||
if (!shellCmd)
|
if (!shellCmd)
|
||||||
return "";
|
return "";
|
||||||
if (compositor === "mangowc")
|
if (compositor === "mangowc")
|
||||||
return "spawn_shell " + shellCmd;
|
return "spawn_shell " + shellCmd;
|
||||||
return "spawn sh -c \"" + shellCmd.replace(/"/g, "\\\"") + "\"";
|
var shellBin = shell || "sh";
|
||||||
|
return "spawn " + shellBin + " -c \"" + shellCmd.replace(/"/g, "\\\"") + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseSpawnCommand(action) {
|
function parseSpawnCommand(action) {
|
||||||
@@ -910,8 +908,9 @@ function parseSpawnCommand(action) {
|
|||||||
function parseShellCommand(action) {
|
function parseShellCommand(action) {
|
||||||
if (!action)
|
if (!action)
|
||||||
return "";
|
return "";
|
||||||
if (action.startsWith("spawn sh -c ")) {
|
var match = action.match(/^spawn (\w+) -c (.+)$/);
|
||||||
var content = action.slice(12);
|
if (match) {
|
||||||
|
var content = match[2];
|
||||||
if ((content.startsWith('"') && content.endsWith('"')) || (content.startsWith("'") && content.endsWith("'")))
|
if ((content.startsWith('"') && content.endsWith('"')) || (content.startsWith("'") && content.endsWith("'")))
|
||||||
content = content.slice(1, -1);
|
content = content.slice(1, -1);
|
||||||
return content.replace(/\\"/g, "\"");
|
return content.replace(/\\"/g, "\"");
|
||||||
@@ -921,6 +920,13 @@ function parseShellCommand(action) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getShellFromAction(action) {
|
||||||
|
if (!action)
|
||||||
|
return "sh";
|
||||||
|
var match = action.match(/^spawn (\w+) -c /);
|
||||||
|
return match ? match[1] : "sh";
|
||||||
|
}
|
||||||
|
|
||||||
function getActionArgConfig(compositor, action) {
|
function getActionArgConfig(compositor, action) {
|
||||||
if (!action)
|
if (!action)
|
||||||
return null;
|
return null;
|
||||||
@@ -1107,12 +1113,27 @@ function buildCompositorAction(compositor, base, args) {
|
|||||||
parts.push("focus=false");
|
parts.push("focus=false");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (base.startsWith("screenshot")) {
|
switch (base) {
|
||||||
|
case "screenshot":
|
||||||
if (args["show-pointer"] === true)
|
if (args["show-pointer"] === true)
|
||||||
parts.push("show-pointer=true");
|
parts.push("show-pointer=true");
|
||||||
|
else if (args["show-pointer"] === false)
|
||||||
|
parts.push("show-pointer=false");
|
||||||
|
break;
|
||||||
|
case "screenshot-screen":
|
||||||
|
if (args["show-pointer"] === true)
|
||||||
|
parts.push("show-pointer=true");
|
||||||
|
else if (args["show-pointer"] === false)
|
||||||
|
parts.push("show-pointer=false");
|
||||||
if (args["write-to-disk"] === true)
|
if (args["write-to-disk"] === true)
|
||||||
parts.push("write-to-disk=true");
|
parts.push("write-to-disk=true");
|
||||||
} else if (args.value) {
|
break;
|
||||||
|
case "screenshot-window":
|
||||||
|
if (args["write-to-disk"] === true)
|
||||||
|
parts.push("write-to-disk=true");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (args.value) {
|
||||||
parts.push(args.value);
|
parts.push(args.value);
|
||||||
} else if (args.index) {
|
} else if (args.index) {
|
||||||
parts.push(args.index);
|
parts.push(args.index);
|
||||||
|
|||||||
@@ -501,8 +501,12 @@ Singleton {
|
|||||||
return Actions.buildSpawnAction(command, args);
|
return Actions.buildSpawnAction(command, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildShellAction(shellCmd) {
|
function buildShellAction(shellCmd, shell) {
|
||||||
return Actions.buildShellAction(currentProvider, shellCmd);
|
return Actions.buildShellAction(currentProvider, shellCmd, shell);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getShellFromAction(action) {
|
||||||
|
return Actions.getShellFromAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseSpawnCommand(action) {
|
function parseSpawnCommand(action) {
|
||||||
|
|||||||
@@ -1273,6 +1273,7 @@ Item {
|
|||||||
spacing: Theme.spacingM
|
spacing: Theme.spacingM
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
|
visible: optionsRow.argConfig?.base !== "screenshot-window"
|
||||||
spacing: Theme.spacingXS
|
spacing: Theme.spacingXS
|
||||||
|
|
||||||
DankToggle {
|
DankToggle {
|
||||||
@@ -1441,8 +1442,9 @@ Item {
|
|||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
if (root._actionType !== "shell")
|
if (root._actionType !== "shell")
|
||||||
return;
|
return;
|
||||||
|
var shell = Actions.getShellFromAction(root.editAction);
|
||||||
root.updateEdit({
|
root.updateEdit({
|
||||||
"action": Actions.buildShellAction(KeybindsService.currentProvider, text)
|
"action": Actions.buildShellAction(KeybindsService.currentProvider, text, shell)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user