Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 2b0331c

Browse files
committed
Fixes. Finish ratbagd wrapper
1 parent 0f32232 commit 2b0331c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

nodecg-io-dbus/extension/ratbag.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,27 +369,27 @@ export class RatBagButton extends DBusObject {
369369
*/
370370
public async mapping(): Promise<RatBagMapping> {
371371
// eslint-disable-next-line @typescript-eslint/no-explicit-any
372-
const raw: [number, any] = (await this.getProperty("org.freedesktop.ratbag1.Button", "Mapping")).value;
372+
const raw: [number, Variant] = (await this.getProperty("org.freedesktop.ratbag1.Button", "Mapping")).value;
373373
if (raw[0] === 0) {
374374
return {
375375
type: "none",
376376
};
377377
} else if (raw[0] === 1) {
378378
return {
379379
type: "button",
380-
button: raw[1],
380+
button: raw[1].value,
381381
};
382382
} else if (raw[0] === 2) {
383383
const id = Object.keys(RatBagButton.SPECIAL_ACTION_MAP).find(
384-
(key) => RatBagButton.SPECIAL_ACTION_MAP[key as RatBagSpecialAction] === raw[1],
384+
(key) => RatBagButton.SPECIAL_ACTION_MAP[key as RatBagSpecialAction] === raw[1].value,
385385
) as RatBagSpecialAction | undefined;
386386
return {
387387
type: "special",
388388
action: id === undefined ? "unknown" : id,
389389
};
390390
} else if (raw[0] === 3) {
391391
const macro: RatBagMacroAction[] = [];
392-
for (const entry of raw[1] as [number, number][]) {
392+
for (const entry of raw[1].value as [number, number][]) {
393393
macro.push({
394394
type: entry[0] === 0 ? "release" : "press",
395395
keyCode: entry[1],
@@ -410,22 +410,27 @@ export class RatBagButton extends DBusObject {
410410
* Binds this button to the given action.
411411
*/
412412
public async setMapping(mapping: RatBagMapping): Promise<void> {
413-
let variant: Variant = new Variant<[number, number]>("(uu)", [1000, 0]);
413+
let id = 1000;
414+
let variant: Variant = new Variant<number>("u", 0);
414415
if (mapping.type === "none") {
415-
variant = new Variant<[number, number]>("(uu)", [0, 0]);
416+
id = 1000;
417+
variant = new Variant<number>("u", 0);
416418
} else if (mapping.type === "button") {
417-
variant = new Variant<[number, number]>("(uu)", [1, mapping.button]);
419+
id = 1;
420+
variant = new Variant<number>("u", mapping.button);
418421
} else if (mapping.type === "special") {
422+
id = 2;
419423
const func = RatBagButton.SPECIAL_ACTION_MAP[mapping.action];
420-
variant = new Variant<[number, number]>("(uu)", [2, func === undefined ? 0x40000000 : func]);
424+
variant = new Variant<number>("u", func === undefined ? 0x40000000 : func);
421425
} else if (mapping.type === "macro") {
426+
id = 3;
422427
const actions: [number, number][] = [];
423428
for (const action of mapping.macro) {
424429
actions.push([action.type === "press" ? 1 : 0, action.keyCode]);
425430
}
426-
variant = new Variant<[number, [number, number][]]>("(ua(uu))", [3, actions]);
431+
variant = new Variant<[number, number][]>("a(uu)", actions);
427432
}
428-
await this.setProperty("org.freedesktop.ratbag1.Button", "Mapping", variant);
433+
await this.setProperty("org.freedesktop.ratbag1.Button", "Mapping", new Variant("(uv)", [id, variant]));
429434
}
430435
}
431436

0 commit comments

Comments
 (0)