mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
niri: fix keybind handling of cooldown-ms parameter
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/keybinds"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/keybinds"
|
||||||
@@ -153,6 +154,7 @@ func (n *NiriProvider) convertKeybind(kb *NiriKeyBinding, subcategory string, co
|
|||||||
Subcategory: subcategory,
|
Subcategory: subcategory,
|
||||||
Source: source,
|
Source: source,
|
||||||
HideOnOverlay: kb.HideOnOverlay,
|
HideOnOverlay: kb.HideOnOverlay,
|
||||||
|
CooldownMs: kb.CooldownMs,
|
||||||
}
|
}
|
||||||
|
|
||||||
if source == "dms" && conflicts != nil {
|
if source == "dms" && conflicts != nil {
|
||||||
@@ -310,7 +312,9 @@ func (n *NiriProvider) extractOptions(node *document.Node) map[string]any {
|
|||||||
opts["repeat"] = val.String() == "true"
|
opts["repeat"] = val.String() == "true"
|
||||||
}
|
}
|
||||||
if val, ok := node.Properties.Get("cooldown-ms"); ok {
|
if val, ok := node.Properties.Get("cooldown-ms"); ok {
|
||||||
opts["cooldown-ms"] = val.String()
|
if ms, err := strconv.Atoi(val.String()); err == nil {
|
||||||
|
opts["cooldown-ms"] = ms
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if val, ok := node.Properties.Get("allow-when-locked"); ok {
|
if val, ok := node.Properties.Get("allow-when-locked"); ok {
|
||||||
opts["allow-when-locked"] = val.String() == "true"
|
opts["allow-when-locked"] = val.String() == "true"
|
||||||
@@ -336,7 +340,14 @@ func (n *NiriProvider) buildBindNode(bind *overrideBind) *document.Node {
|
|||||||
node.AddProperty("repeat", false, "")
|
node.AddProperty("repeat", false, "")
|
||||||
}
|
}
|
||||||
if v, ok := bind.Options["cooldown-ms"]; ok {
|
if v, ok := bind.Options["cooldown-ms"]; ok {
|
||||||
node.AddProperty("cooldown-ms", v, "")
|
switch val := v.(type) {
|
||||||
|
case int:
|
||||||
|
node.AddProperty("cooldown-ms", val, "")
|
||||||
|
case string:
|
||||||
|
if ms, err := strconv.Atoi(val); err == nil {
|
||||||
|
node.AddProperty("cooldown-ms", ms, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if v, ok := bind.Options["allow-when-locked"]; ok && v == true {
|
if v, ok := bind.Options["allow-when-locked"]; ok && v == true {
|
||||||
node.AddProperty("allow-when-locked", true, "")
|
node.AddProperty("allow-when-locked", true, "")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/sblinch/kdl-go"
|
"github.com/sblinch/kdl-go"
|
||||||
@@ -17,6 +18,7 @@ type NiriKeyBinding struct {
|
|||||||
Args []string
|
Args []string
|
||||||
Description string
|
Description string
|
||||||
HideOnOverlay bool
|
HideOnOverlay bool
|
||||||
|
CooldownMs int
|
||||||
Source string
|
Source string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,6 +277,7 @@ func (p *NiriParser) parseKeybindNode(node *document.Node, _ string) *NiriKeyBin
|
|||||||
|
|
||||||
var description string
|
var description string
|
||||||
var hideOnOverlay bool
|
var hideOnOverlay bool
|
||||||
|
var cooldownMs int
|
||||||
if node.Properties != nil {
|
if node.Properties != nil {
|
||||||
if val, ok := node.Properties.Get("hotkey-overlay-title"); ok {
|
if val, ok := node.Properties.Get("hotkey-overlay-title"); ok {
|
||||||
switch val.ValueString() {
|
switch val.ValueString() {
|
||||||
@@ -284,6 +287,9 @@ func (p *NiriParser) parseKeybindNode(node *document.Node, _ string) *NiriKeyBin
|
|||||||
description = val.ValueString()
|
description = val.ValueString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if val, ok := node.Properties.Get("cooldown-ms"); ok {
|
||||||
|
cooldownMs, _ = strconv.Atoi(val.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &NiriKeyBinding{
|
return &NiriKeyBinding{
|
||||||
@@ -293,6 +299,7 @@ func (p *NiriParser) parseKeybindNode(node *document.Node, _ string) *NiriKeyBin
|
|||||||
Args: args,
|
Args: args,
|
||||||
Description: description,
|
Description: description,
|
||||||
HideOnOverlay: hideOnOverlay,
|
HideOnOverlay: hideOnOverlay,
|
||||||
|
CooldownMs: cooldownMs,
|
||||||
Source: p.currentSource,
|
Source: p.currentSource,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ type Keybind struct {
|
|||||||
Subcategory string `json:"subcat,omitempty"`
|
Subcategory string `json:"subcat,omitempty"`
|
||||||
Source string `json:"source,omitempty"`
|
Source string `json:"source,omitempty"`
|
||||||
HideOnOverlay bool `json:"hideOnOverlay,omitempty"`
|
HideOnOverlay bool `json:"hideOnOverlay,omitempty"`
|
||||||
|
CooldownMs int `json:"cooldownMs,omitempty"`
|
||||||
Conflict *Keybind `json:"conflict,omitempty"`
|
Conflict *Keybind `json:"conflict,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -314,7 +314,8 @@ Singleton {
|
|||||||
const keyData = {
|
const keyData = {
|
||||||
key: bind.key || "",
|
key: bind.key || "",
|
||||||
source: bind.source || "config",
|
source: bind.source || "config",
|
||||||
isOverride: bind.source === "dms"
|
isOverride: bind.source === "dms",
|
||||||
|
cooldownMs: bind.cooldownMs || 0
|
||||||
};
|
};
|
||||||
if (actionMap[action]) {
|
if (actionMap[action]) {
|
||||||
actionMap[action].keys.push(keyData);
|
actionMap[action].keys.push(keyData);
|
||||||
@@ -378,6 +379,8 @@ Singleton {
|
|||||||
const cmd = ["dms", "keybinds", "set", currentProvider, bindData.key, bindData.action, "--desc", bindData.desc || ""];
|
const cmd = ["dms", "keybinds", "set", currentProvider, bindData.key, bindData.action, "--desc", bindData.desc || ""];
|
||||||
if (originalKey && originalKey !== bindData.key)
|
if (originalKey && originalKey !== bindData.key)
|
||||||
cmd.push("--replace-key", originalKey);
|
cmd.push("--replace-key", originalKey);
|
||||||
|
if (bindData.cooldownMs > 0)
|
||||||
|
cmd.push("--cooldown-ms", String(bindData.cooldownMs));
|
||||||
saveProcess.command = cmd;
|
saveProcess.command = cmd;
|
||||||
saveProcess.running = true;
|
saveProcess.running = true;
|
||||||
bindSaved(bindData.key);
|
bindSaved(bindData.key);
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ Item {
|
|||||||
property string editKey: ""
|
property string editKey: ""
|
||||||
property string editAction: ""
|
property string editAction: ""
|
||||||
property string editDesc: ""
|
property string editDesc: ""
|
||||||
|
property int editCooldownMs: 0
|
||||||
|
property int _savedCooldownMs: -1
|
||||||
property bool hasChanges: false
|
property bool hasChanges: false
|
||||||
property string _actionType: ""
|
property string _actionType: ""
|
||||||
property bool addingNewKey: false
|
property bool addingNewKey: false
|
||||||
@@ -90,6 +92,12 @@ Item {
|
|||||||
editKey = keyToFind;
|
editKey = keyToFind;
|
||||||
editAction = bindData.action || "";
|
editAction = bindData.action || "";
|
||||||
editDesc = bindData.desc || "";
|
editDesc = bindData.desc || "";
|
||||||
|
if (_savedCooldownMs >= 0) {
|
||||||
|
editCooldownMs = _savedCooldownMs;
|
||||||
|
_savedCooldownMs = -1;
|
||||||
|
} else {
|
||||||
|
editCooldownMs = keys[i].cooldownMs || 0;
|
||||||
|
}
|
||||||
hasChanges = false;
|
hasChanges = false;
|
||||||
_actionType = Actions.getActionType(editAction);
|
_actionType = Actions.getActionType(editAction);
|
||||||
useCustomCompositor = _actionType === "compositor" && editAction && !Actions.isKnownCompositorAction(editAction);
|
useCustomCompositor = _actionType === "compositor" && editAction && !Actions.isKnownCompositorAction(editAction);
|
||||||
@@ -109,6 +117,7 @@ Item {
|
|||||||
editKey = editingKeyIndex >= 0 ? keys[editingKeyIndex].key : "";
|
editKey = editingKeyIndex >= 0 ? keys[editingKeyIndex].key : "";
|
||||||
editAction = bindData.action || "";
|
editAction = bindData.action || "";
|
||||||
editDesc = bindData.desc || "";
|
editDesc = bindData.desc || "";
|
||||||
|
editCooldownMs = editingKeyIndex >= 0 ? (keys[editingKeyIndex].cooldownMs || 0) : 0;
|
||||||
hasChanges = false;
|
hasChanges = false;
|
||||||
_actionType = Actions.getActionType(editAction);
|
_actionType = Actions.getActionType(editAction);
|
||||||
useCustomCompositor = _actionType === "compositor" && editAction && !Actions.isKnownCompositorAction(editAction);
|
useCustomCompositor = _actionType === "compositor" && editAction && !Actions.isKnownCompositorAction(editAction);
|
||||||
@@ -127,6 +136,7 @@ Item {
|
|||||||
addingNewKey = false;
|
addingNewKey = false;
|
||||||
editingKeyIndex = index;
|
editingKeyIndex = index;
|
||||||
editKey = keys[index].key;
|
editKey = keys[index].key;
|
||||||
|
editCooldownMs = keys[index].cooldownMs || 0;
|
||||||
hasChanges = false;
|
hasChanges = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,8 +147,11 @@ Item {
|
|||||||
editAction = changes.action;
|
editAction = changes.action;
|
||||||
if (changes.desc !== undefined)
|
if (changes.desc !== undefined)
|
||||||
editDesc = changes.desc;
|
editDesc = changes.desc;
|
||||||
|
if (changes.cooldownMs !== undefined)
|
||||||
|
editCooldownMs = changes.cooldownMs;
|
||||||
const origKey = editingKeyIndex >= 0 && editingKeyIndex < keys.length ? keys[editingKeyIndex].key : "";
|
const origKey = editingKeyIndex >= 0 && editingKeyIndex < keys.length ? keys[editingKeyIndex].key : "";
|
||||||
hasChanges = editKey !== origKey || editAction !== (bindData.action || "") || editDesc !== (bindData.desc || "");
|
const origCooldown = editingKeyIndex >= 0 && editingKeyIndex < keys.length ? (keys[editingKeyIndex].cooldownMs || 0) : 0;
|
||||||
|
hasChanges = editKey !== origKey || editAction !== (bindData.action || "") || editDesc !== (bindData.desc || "") || editCooldownMs !== origCooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
function canSave() {
|
function canSave() {
|
||||||
@@ -156,10 +169,12 @@ Item {
|
|||||||
let desc = editDesc;
|
let desc = editDesc;
|
||||||
if (expandedLoader.item?.currentTitle !== undefined)
|
if (expandedLoader.item?.currentTitle !== undefined)
|
||||||
desc = expandedLoader.item.currentTitle;
|
desc = expandedLoader.item.currentTitle;
|
||||||
|
_savedCooldownMs = editCooldownMs;
|
||||||
saveBind(origKey, {
|
saveBind(origKey, {
|
||||||
key: editKey,
|
key: editKey,
|
||||||
action: editAction,
|
action: editAction,
|
||||||
desc: desc
|
desc: desc,
|
||||||
|
cooldownMs: editCooldownMs
|
||||||
});
|
});
|
||||||
hasChanges = false;
|
hasChanges = false;
|
||||||
addingNewKey = false;
|
addingNewKey = false;
|
||||||
@@ -1431,6 +1446,57 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
spacing: Theme.spacingM
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: I18n.tr("Cooldown")
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
font.weight: Font.Medium
|
||||||
|
color: Theme.surfaceVariantText
|
||||||
|
Layout.preferredWidth: 60
|
||||||
|
}
|
||||||
|
|
||||||
|
DankTextField {
|
||||||
|
id: cooldownField
|
||||||
|
Layout.preferredWidth: 100
|
||||||
|
Layout.preferredHeight: 40
|
||||||
|
placeholderText: "0"
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: root
|
||||||
|
function onEditCooldownMsChanged() {
|
||||||
|
const newText = root.editCooldownMs > 0 ? String(root.editCooldownMs) : "";
|
||||||
|
if (cooldownField.text !== newText)
|
||||||
|
cooldownField.text = newText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
text = root.editCooldownMs > 0 ? String(root.editCooldownMs) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
onTextChanged: {
|
||||||
|
const val = parseInt(text) || 0;
|
||||||
|
if (val !== root.editCooldownMs)
|
||||||
|
root.updateEdit({
|
||||||
|
cooldownMs: val
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: I18n.tr("ms")
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: Theme.surfaceVariantText
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.preferredHeight: 1
|
Layout.preferredHeight: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user