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