Prevent shortcut reset collisions
This commit is contained in:
@@ -13,9 +13,16 @@ ShellRoot {
|
||||
return Keybinds.rebind(current, next);
|
||||
}
|
||||
|
||||
function resetBind(current: string): void { Keybinds.resetBind(current); }
|
||||
function resetBind(current: string): bool { return Keybinds.resetBind(current); }
|
||||
function resetAll(): void { Keybinds.resetAll(); }
|
||||
|
||||
function seedResetCollision(shipped: string, current: string, occupantShipped: string): void {
|
||||
const overrides = {};
|
||||
overrides[shipped] = current;
|
||||
overrides[occupantShipped] = shipped;
|
||||
DesktopPreferences.set("keybindOverrides", overrides);
|
||||
}
|
||||
|
||||
function chordFor(description: string): string {
|
||||
const found = Keybinds.binds.find(bind => bind.description === description);
|
||||
return found ? found.luaChord : "";
|
||||
@@ -24,7 +31,8 @@ ShellRoot {
|
||||
function overrideState(): string {
|
||||
return JSON.stringify({
|
||||
overrides: Keybinds.overrides,
|
||||
count: Object.keys(Keybinds.overrides).length
|
||||
count: Object.keys(Keybinds.overrides).length,
|
||||
lastError: Keybinds.lastError
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,17 @@ Singleton {
|
||||
return "";
|
||||
}
|
||||
|
||||
// A moved shortcut vacates its shipped chord, so another override may use
|
||||
// it legitimately. Refuse to reset the first shortcut until that occupant
|
||||
// moves away; otherwise Hyprland would receive two binds on one chord.
|
||||
function overrideOccupantFor(chord: string, exceptShipped: string): string {
|
||||
for (const shipped in root.overrides) {
|
||||
if (shipped !== exceptShipped && root.overrides[shipped] === chord)
|
||||
return shipped;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function rebind(currentChord: string, newChord: string): bool {
|
||||
if (newChord === "" || newChord === currentChord)
|
||||
return false;
|
||||
@@ -133,14 +144,25 @@ Singleton {
|
||||
return true;
|
||||
}
|
||||
|
||||
function resetBind(currentChord: string): void {
|
||||
function resetBind(currentChord: string): bool {
|
||||
const shipped = root.shippedChordFor(currentChord);
|
||||
if (shipped === currentChord)
|
||||
return;
|
||||
return true;
|
||||
|
||||
const occupant = root.overrideOccupantFor(shipped, shipped);
|
||||
if (occupant !== "") {
|
||||
root.lastError = `${shipped} is used by another rebound shortcut. Reset that shortcut first.`;
|
||||
return false;
|
||||
}
|
||||
|
||||
const next = Object.assign({}, root.overrides);
|
||||
delete next[shipped];
|
||||
DesktopPreferences.set("keybindOverrides", next);
|
||||
if (!DesktopPreferences.set("keybindOverrides", next)) {
|
||||
root.lastError = "That shortcut could not be reset.";
|
||||
return false;
|
||||
}
|
||||
root.applyReload();
|
||||
return true;
|
||||
}
|
||||
|
||||
function resetAll(): void {
|
||||
|
||||
Reference in New Issue
Block a user