From 53a1a1a70efbab98fdd7e75c230b98d1297374e9 Mon Sep 17 00:00:00 2001 From: Snekxs <26660858+snekxs@users.noreply.github.com> Date: Fri, 4 Dec 2026 20:56:14 -0600 Subject: [PATCH 1/3] feat(wlmouse): full Beast X V2 dongle/macro/curve parity & fix #76, #77, #79 --- crates/openmouse-hid/src/lib.rs | 71 ++++++++++---- gpui/js/controls.ts | 166 ++++++++++++++++++++++++-------- gpui/js/extra-controls.ts | 4 +- gpui/js/macros.ts | 44 ++++++++- gpui/src/app/controls.rs | 3 +- gpui/src/app/curve_panel.rs | 6 +- gpui/src/app/device_state.rs | 9 ++ gpui/src/app/safety.rs | 21 ++++ gpui/src/app/text_controls.rs | 93 ++++++++++++++++++ package-lock.json | 8 +- package.json | 2 +- 11 files changed, 359 insertions(+), 68 deletions(-) diff --git a/crates/openmouse-hid/src/lib.rs b/crates/openmouse-hid/src/lib.rs index d6d904b8..0b7f5ef9 100644 --- a/crates/openmouse-hid/src/lib.rs +++ b/crates/openmouse-hid/src/lib.rs @@ -289,12 +289,28 @@ const RAZER_VENDOR_ID: u16 = 0x1532; /// command of every connect. OpenRazer only ever uses wIndex 0 for this model. const RAZER_VIPER_8K_PRODUCT_ID: u16 = 0x0091; +/// Razer DeathAdder V2 Pro wireless receiver (issue #79). Only interface 0 +/// declares the 90-byte vendor feature report (id 0); fanning writes out to +/// interfaces 1-4 overwrites the receiver's single pending-command buffer so +/// every read echoes status 0x00. +const RAZER_DEATHADDER_V2_PRO_WIRELESS_PRODUCT_ID: u16 = 0x007d; + +/// Razer Basilisk V3 wired (issue #76). Same firmware behaviour as Viper 8KHz: +/// sending a Razer feature report to non-declaring interfaces makes the mouse +/// drop off USB and re-enumerate in a 5-second loop on Linux. +const RAZER_BASILISK_V3_PRODUCT_ID: u16 = 0x0099; + /// Devices whose feature reports must go *only* to an interface whose /// descriptor declares the report, never to a sibling, for writes and reads /// alike: no Razer fan-out and no falling through to the other interfaces. -/// Deliberately a single model: every other device keeps its existing routing. fn feature_reports_declaring_only(vendor_id: u16, product_id: u16) -> bool { - (vendor_id, product_id) == (RAZER_VENDOR_ID, RAZER_VIPER_8K_PRODUCT_ID) + vendor_id == RAZER_VENDOR_ID + && matches!( + product_id, + RAZER_VIPER_8K_PRODUCT_ID + | RAZER_DEATHADDER_V2_PRO_WIRELESS_PRODUCT_ID + | RAZER_BASILISK_V3_PRODUCT_ID + ) } /// The split indices a declaring-only request may use: those that declare the @@ -470,7 +486,7 @@ struct OpenGroup { /// the one that actually works, paid again on every one of the dozens of /// requests a full `readStatus()` walk makes. Once a split answers for a /// report id, remember it and try that one first next time. - routes: Mutex>, + routes: Mutex>, /// Splits that accepted a request and answered with an empty packet - /// an interface that is up but not carrying the device's traffic (the /// usual cause: a composite wireless receiver, where the first split by @@ -1579,7 +1595,7 @@ pub fn hid_get_input_report( applog!("[hid] hid_get_input_report {vendor_id:04x}:{product_id:04x} reportId=0x{report_id:02x} length={length}"); let result = with_open_group(registry, vendor_id, product_id, |group| { let mut result: Option> = None; - let outcome = try_each(&group.splits, &group.routes, &group.silent, report_id, false, false, |device, _layout| { + let outcome = try_each(&group.splits, &group.routes, &group.silent, report_id, false, false, None, |device, _layout| { let mut buffer = vec![0u8; length + 1]; buffer[0] = report_id; let read = device @@ -1612,6 +1628,11 @@ pub fn hid_get_feature_report( applog!("[hid] hid_get_feature_report {vendor_id:04x}:{product_id:04x} reportId=0x{report_id:02x} length={length}"); let result = with_open_group(registry, vendor_id, product_id, |group| { let mut result: Option> = None; + let expected_len = group + .last_sent + .lock() + .get(&report_id) + .map(|d| d.len() + 1); let outcome = try_each( &group.splits, &group.routes, @@ -1619,6 +1640,7 @@ pub fn hid_get_feature_report( report_id, true, feature_reports_declaring_only(vendor_id, product_id), + expected_len, |device, layout| { // `length` is the caller's idea of how much to ask for and is often // far too small: the adapter in this app passes a flat 90 for every @@ -1759,11 +1781,21 @@ fn send_each( .iter() .map(|split| split.layout.declares(report_id, feature)) .collect(); - let order = if declaring_only { + let mut order = if declaring_only { declaring_only_splits(&declares) } else { declaring_first(&declares) }; + // When multiple interfaces declare the same feature report id with + // different sizes (e.g. WLMouse Beast X V2's 64-byte config interface and + // 512-byte LCD interface, both on report id 0), try exact-length matches + // before other declaring interfaces. + if feature { + order.sort_by_key(|&index| { + let exact = splits[index].layout.feature_buffer_len(report_id) == Some(frame.len()); + (!exact, !declares[index]) + }); + } for index in order { let split = &splits[index]; let declares = declares[index]; @@ -1910,18 +1942,20 @@ fn feature_read_len(layout: &ReportLayout, report_id: u8, requested: usize) -> u fn try_each( splits: &[Arc], - routes: &Mutex>, + routes: &Mutex>, silent: &Mutex>, report_id: u8, feature: bool, declaring_only: bool, + expected_len: Option, mut operation: impl FnMut(&hidapi::HidDevice, &ReportLayout) -> Result, ) -> Result<(), String> { - // Try whichever split answered this exact report id last time first - - // see `OpenGroup::routes`. Falls through to the rest in order on a miss - // (first call for this report id, or the routed split stopped working), + // Try whichever split answered this exact (report_id, expected_len) last + // time first - see `OpenGroup::routes`. Falls through to the rest in order + // on a miss (first call for this key, or the routed split stopped working), // so this is a pure optimization, never a correctness change. - let hinted = routes.lock().get(&report_id).copied(); + let route_key = (report_id, expected_len.unwrap_or(0)); + let hinted = routes.lock().get(&route_key).copied(); let known_silent = silent.lock().clone(); // An interface whose descriptor declares this report id comes first: it is // the one that can answer, and asking the others first is what made a @@ -1943,19 +1977,18 @@ fn try_each( } else { (0..splits.len()).collect() }; - // Order: hinted route (when not silent) -> declaring non-silent -> - // declaring silent -> non-declaring non-silent -> non-declaring silent. - // Crucially, a silent split is ranked *after* non-silent ones rather than - // dropped: if a device's only declaring feature-report interface answers - // with zeros/echo on the first poll while a wireless receiver is still - // processing (e.g. Keychron 1k's ~200ms delay), subsequent retries must - // still poll that interface instead of skipping it for non-declaring splits. + // Order: exact-length match (for feature reports when multiple interfaces + // share a report id at different sizes, e.g. 64B vs 512B) -> hinted route + // (when not silent) -> declaring non-silent -> declaring silent -> + // non-declaring non-silent -> non-declaring silent. let mut order: Vec = allowed; order.sort_by_key(|&index| { + let is_exact = feature + && expected_len.is_some_and(|want| splits[index].layout.feature_buffer_len(report_id) == Some(want)); let is_hint = hinted == Some(index) && !known_silent.contains(&index); let is_declaring = declares[index]; let is_silent = known_silent.contains(&index); - (!is_hint, !is_declaring, is_silent) + (!is_exact, !is_hint, !is_declaring, is_silent) }); let mut last_error = None; @@ -1974,7 +2007,7 @@ fn try_each( match outcome { Ok(SplitAnswer::Answered) => { silent.lock().remove(&index); - routes.lock().insert(report_id, index); + routes.lock().insert(route_key, index); return Ok(()); } Ok(SplitAnswer::Silent) => { diff --git a/gpui/js/controls.ts b/gpui/js/controls.ts index c9b82dbf..1d5f0018 100644 --- a/gpui/js/controls.ts +++ b/gpui/js/controls.ts @@ -259,14 +259,6 @@ export function extras(s: any): Section[] { current: wl.lodMode, }); } - if (typeof s.supportsSeparateDpiAxes === "boolean") { - sensorControls.push({ - id: "wl.separateAxes", - label: "Independent X/Y DPI", - kind: "toggle", - current: s.supportsSeparateDpiAxes, - }); - } if (wl.sensorPosition) { sensorControls.push({ id: "wl.sensorX", @@ -286,6 +278,13 @@ export function extras(s: any): Section[] { step: 1, current: wl.sensorPosition.y, }); + sensorControls.push({ + id: "wl.sensorReset", + label: "Sensor position", + kind: "button", + options: [{ value: true, label: "Restore (0, 0)" }], + current: null, + }); } if (wl.bhopWheel) { sensorControls.push({ @@ -294,40 +293,51 @@ export function extras(s: any): Section[] { kind: "toggle", current: Boolean(wl.bhopWheel.enabled), }); - if (wl.bhopWheel.enabled) { - sensorControls.push({ - id: "wl.bhopDir", - label: "BHop filter direction", - kind: "choice", - options: [ - { value: "both", label: "Both" }, - { value: "up", label: "Up" }, - { value: "down", label: "Down" }, - ], - current: wl.bhopWheel.direction, - }); - sensorControls.push({ - id: "wl.bhopWindow", - label: "BHop filter window", - kind: "number", - min: 0, - max: 750, - step: 10, - unit: "ms", - current: wl.bhopWheel.windowMs, - }); - } - } - if (wl.dynamicDpi) { sensorControls.push({ - id: "wl.dynDpi", - label: "Dynamic DPI", - kind: "toggle", - current: Boolean(wl.dynamicDpi.enabled), + id: "wl.bhopDir", + label: "BHop filter direction", + kind: "choice", + options: [ + { value: "both", label: "Both" }, + { value: "up", label: "Up" }, + { value: "down", label: "Down" }, + ], + current: wl.bhopWheel.direction, + }); + sensorControls.push({ + id: "wl.bhopWindow", + label: "BHop filter window", + kind: "number", + min: 0, + max: 750, + step: 10, + unit: "ms", + current: wl.bhopWheel.windowMs, }); } if (sensorControls.length) out.push({ title: "WLMouse · Sensor & scroll", controls: sensorControls }); + if (wl.dynamicDpi) { + const pts: Array<{ speed: number; ratio: number }> = Array.isArray(wl.dynamicDpi.points) && wl.dynamicDpi.points.length + ? wl.dynamicDpi.points + : [{ speed: 0, ratio: 1 }, { speed: 20, ratio: 2.62 }, { speed: 40, ratio: 4.8 }]; + const curveControls: Control[] = [ + { + id: "wl.dynDpi", + label: "Dynamic DPI", + kind: "toggle", + current: Boolean(wl.dynamicDpi.enabled), + }, + ]; + pts.forEach((pt, idx) => { + curveControls.push( + { id: `wl.curve.${idx}.speed`, label: `Point ${idx + 1} speed`, kind: "number", min: 0, max: 100, step: 1, current: pt.speed }, + { id: `wl.curve.${idx}.gain`, label: `Point ${idx + 1} ratio`, kind: "number", min: 0.1, max: 10, step: 0.01, current: pt.ratio }, + ); + }); + out.push({ title: "WLMouse · Dynamic DPI", controls: curveControls }); + } + if (wl.dongleScreen) { const lcd = wl.dongleScreen; out.push({ @@ -357,6 +367,22 @@ export function extras(s: any): Section[] { kind: "toggle", current: Boolean(lcd.doubleTapEnabled), }, + { + id: "wl.lcdUpload", + label: "Custom visuals", + description: "Pick 1 Main + up to 5 Random images or GIFs (320×170, max 13 MB).", + kind: "openImage", + options: [{ value: true, label: "Upload images / GIFs" }], + current: null, + }, + { + id: "wl.lcdDelete", + label: "Reset visuals", + description: "Deletes uploaded images and restores the default dongle visuals.", + kind: "button", + options: [{ value: true, label: "Delete custom images" }], + current: null, + }, ], }); } @@ -904,9 +930,9 @@ export async function writeControl(info: HidInterfaceInfo, status: any, id: stri if (status.wlmouse) { status.wlmouse.lodMode = mode; status.wlmouse.lodMm = mm; } return; } - case "wl.separateAxes": - await callClientMethod(info, "setSeparateDpiAxes", Boolean(value)); - status.supportsSeparateDpiAxes = Boolean(value); + case "wl.sensorReset": + await callClientMethod(info, "setSensorPosition", 0, 0); + if (status.wlmouse) status.wlmouse.sensorPosition = { x: 0, y: 0 }; return; case "wl.sensorX": case "wl.sensorY": { const cur = status.wlmouse?.sensorPosition ?? { x: 0, y: 0 }; @@ -934,6 +960,16 @@ export async function writeControl(info: HidInterfaceInfo, status: any, id: stri if (status.wlmouse) status.wlmouse.dynamicDpi = next; return; } + case "wl.curve": { + const cur = status.wlmouse?.dynamicDpi ?? { enabled: true, points: [{ speed: 0, ratio: 1 }, { speed: 20, ratio: 2.62 }, { speed: 40, ratio: 4.8 }] }; + const points = Array.isArray(value) + ? value.map((pair: any) => ({ speed: Math.round(Number(pair[0])), ratio: Number(pair[1]) })) + : cur.points; + const next = { ...cur, points }; + await callClientMethod(info, "setDynamicDpi", next); + if (status.wlmouse) status.wlmouse.dynamicDpi = next; + return; + } case "wl.lcdEnabled": await callClientMethod(info, "setDongleScreenEnabled", Boolean(value)); if (status.wlmouse?.dongleScreen) status.wlmouse.dongleScreen.enabled = Boolean(value); @@ -946,6 +982,21 @@ export async function writeControl(info: HidInterfaceInfo, status: any, id: stri await callClientMethod(info, "setDongleDoubleTap", Boolean(value)); if (status.wlmouse?.dongleScreen) status.wlmouse.dongleScreen.doubleTapEnabled = Boolean(value); return; + case "wl.lcdUpload": { + const items = Array.isArray(value) ? value : []; + if (!items.length) return; + const images = items.map((item: any) => ({ + width: Number(item.width) || 320, + height: Number(item.height) || 170, + format: item.format === "gif" ? "gif" : "rgb565", + data: decodeBase64(String(item.base64 ?? "")), + })); + await callClientMethod(info, "uploadDongleImages", images); + return; + } + case "wl.lcdDelete": + await callClientMethod(info, "deleteDongleImages"); + return; case "gen.profile": return w.setProfile(info, Number(value)); case "gen.powerMode": return callClientMethod(info, "setPowerMode", value); case "perf.sleep": return w.setSleepTimeout(info, Number(value)); @@ -1005,3 +1056,38 @@ export async function writeLighting(info: HidInterfaceInfo, status: any, edit: { writeOnly: l.writeOnly, } as any); } + +const B64_LOOKUP = (() => { + const table = new Uint8Array(128).fill(255); + const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + for (let i = 0; i < chars.length; i += 1) table[chars.charCodeAt(i)] = i; + return table; +})(); + +function decodeBase64(input: string): Uint8Array { + const clean = input.replace(/[^A-Za-z0-9+/]/g, ""); + const out = new Uint8Array(Math.floor((clean.length * 3) / 4)); + let pos = 0; + for (let i = 0; i + 3 < clean.length; i += 4) { + const a = B64_LOOKUP[clean.charCodeAt(i)]!; + const b = B64_LOOKUP[clean.charCodeAt(i + 1)]!; + const c = B64_LOOKUP[clean.charCodeAt(i + 2)]!; + const d = B64_LOOKUP[clean.charCodeAt(i + 3)]!; + out[pos++] = (a << 2) | (b >> 4); + out[pos++] = ((b & 15) << 4) | (c >> 2); + out[pos++] = ((c & 3) << 6) | d; + } + const rem = clean.length & 3; + if (rem === 2) { + const a = B64_LOOKUP[clean.charCodeAt(clean.length - 2)]!; + const b = B64_LOOKUP[clean.charCodeAt(clean.length - 1)]!; + out[pos++] = (a << 2) | (b >> 4); + } else if (rem === 3) { + const a = B64_LOOKUP[clean.charCodeAt(clean.length - 3)]!; + const b = B64_LOOKUP[clean.charCodeAt(clean.length - 2)]!; + const c = B64_LOOKUP[clean.charCodeAt(clean.length - 1)]!; + out[pos++] = (a << 2) | (b >> 4); + out[pos++] = ((b & 15) << 4) | (c >> 2); + } + return out.subarray(0, pos); +} diff --git a/gpui/js/extra-controls.ts b/gpui/js/extra-controls.ts index 8f1341c6..ef872d74 100644 --- a/gpui/js/extra-controls.ts +++ b/gpui/js/extra-controls.ts @@ -133,8 +133,10 @@ const SPECS: Spec[] = [ toggle("perf.x.ot.responsive", "setMotionSyncResponsive", "performance", "Motion sync tuning", "otMotionSyncResponsive", "Responsive motion sync"), toggle("perf.x.ot.smooth", "setMotionSyncSmooth", "performance", "Motion sync tuning", "otMotionSyncSmooth", "Smooth motion sync"), + // ── Sensor (shared) ───────────────────────────────────────────────────── + toggle("perf.x.hit.separate", "setSeparateDpiAxes", "performance", "Sensor", "supportsSeparateDpiAxes", "Separate X and Y DPI"), + // ── Hitscan ───────────────────────────────────────────────────────────── - toggle("perf.x.hit.separate", "setSeparateDpiAxes", "performance", "Hitscan sensor", "supportsSeparateDpiAxes", "Separate X and Y DPI"), toggle("perf.x.hit.competitive", "setTrackingMode", "performance", "Hitscan sensor", "hitscanCompetitiveMode", "Competitive mode"), toggle("x.hit.scroll", "setScrollHighPerformance", "advanced", "Hitscan", "hitscanTournamentScroll", "High-performance scroll wheel"), ...(["left", "right"] as const).map((side): Spec => ({ diff --git a/gpui/js/macros.ts b/gpui/js/macros.ts index 02463fc0..286d4f00 100644 --- a/gpui/js/macros.ts +++ b/gpui/js/macros.ts @@ -145,9 +145,49 @@ const BRANDS: Record = { steps: i === slot ? steps.map((s) => ({ type: 2, action: s.down ? 1 : 2, delayMs: s.delay, code: hidUsage(s.key) })) : [], }))), }, + WLMouseHidClient: { + method: "writeMacro", + panel: () => ({ + slots: numbered(4, "Macro"), buttons: [], maxSteps: 64, modifiers: true, mouse: true, readable: true, warning: null, + note: "Put a macro on a button by choosing Macro 1–4 in the Buttons tab. Save an empty list to delete a slot.", + }), + read: async (info, slot) => { + const macro = (await callClientMethod(info, "readMacro", slot + 1)) as { events?: any[] } | null; + const events = macro?.events ?? []; + const out: MacroStep[] = []; + for (const ev of events) { + if (ev.type === "delay") { + if (out.length) out[out.length - 1]!.delay += Number(ev.ms) || 0; + continue; + } + if (ev.type === "keyDown" || ev.type === "keyUp") { + out.push({ key: nameOf(Number(ev.keyCode)), down: ev.type === "keyDown", delay: 0 }); + } else if (ev.type === "mouseDown" || ev.type === "mouseUp") { + out.push({ key: `Mouse ${ev.button}`, down: ev.type === "mouseDown", delay: 0 }); + } + } + return out; + }, + write: (info, slot, _button, steps) => { + if (steps.length === 0) return callClientMethod(info, "deleteMacro", slot + 1); + const events: any[] = []; + for (const s of steps) { + if (s.key.startsWith("Mouse ")) { + events.push({ type: s.down ? "mouseDown" : "mouseUp", button: s.key.slice(6) }); + } else if (s.key in MODIFIERS) { + events.push({ type: s.down ? "keyDown" : "keyUp", keyCode: MODIFIERS[s.key]!, modifier: true }); + } else { + events.push({ type: s.down ? "keyDown" : "keyUp", keyCode: hidUsage(s.key) }); + } + if (s.delay > 0) events.push({ type: "delay", ms: s.delay }); + } + return callClientMethod(info, "writeMacro", slot + 1, events); + }, + }, }; export function macroPanel(status: any): MacroPanel | null { + if (status.driverName === "WLMouseHidClient" && !status.wlmouse?.macroSlots) return null; const brand = BRANDS[status.driverName]; return brand && (status.methods ?? []).includes(brand.method) ? brand.panel() : null; } @@ -171,7 +211,9 @@ export async function macroOp(info: HidInterfaceInfo, status: any, op: string, a if (op !== "save") throw new Error(`Unknown macro operation ${op}`); const steps = args.steps as MacroStep[]; if (steps.length > panel.maxSteps) throw new Error(`A macro holds at most ${panel.maxSteps} steps.`); - if (steps.length === 0 && status.driverName !== "WallhackMouseHidClient") throw new Error("Record at least one key first."); + if (steps.length === 0 && status.driverName !== "WallhackMouseHidClient" && status.driverName !== "WLMouseHidClient") { + throw new Error("Record at least one key first."); + } for (const step of steps) { if (!Number.isInteger(step.delay) || step.delay < 0 || step.delay > 65535) throw new Error("A delay must be 0 to 65535 ms."); if (step.key in MODIFIERS && !panel.modifiers) throw new Error("This mouse's macros can't hold Ctrl, Shift, Alt or Win."); diff --git a/gpui/src/app/controls.rs b/gpui/src/app/controls.rs index 43d101ae..bdbd06c7 100644 --- a/gpui/src/app/controls.rs +++ b/gpui/src/app/controls.rs @@ -257,7 +257,7 @@ impl AppView { } "text" => self.render_text_control(c, cx), "color" => self.render_color_control(c), - "button" | "saveFile" | "openFile" => { + "button" | "saveFile" | "openFile" | "openImage" => { let label = c.options.first().map(|o| o.label.clone()).unwrap_or_else(|| c.label.clone()); let (kind, value) = (c.kind.clone(), c.options.first().map(|o| o.value.clone()).unwrap_or(c.current.clone())); Button::new(SharedString::from(format!("btn-{id}"))) @@ -266,6 +266,7 @@ impl AppView { .on_click(cx.listener(move |this, _, _, cx| match kind.as_str() { "saveFile" => this.save_control_file(id.clone(), value.as_str().unwrap_or("layout.json").to_string(), cx), "openFile" => this.open_control_file(id.clone(), cx), + "openImage" => this.open_control_image(id.clone(), cx), _ => this.set_control(id.clone(), value.clone(), cx), })) .into_any_element() diff --git a/gpui/src/app/curve_panel.rs b/gpui/src/app/curve_panel.rs index f60aafa7..cb35e06f 100644 --- a/gpui/src/app/curve_panel.rs +++ b/gpui/src/app/curve_panel.rs @@ -8,7 +8,11 @@ use crate::hid::{ControlSpec, Section}; use gpui_kit::component::input::{Input, InputEvent, InputState}; /// Section titles drawn this way, with the control each writes its curve to. -const CURVES: [(&str, &str); 2] = [("Dynamic sensitivity", "keychron.curve"), ("Acceleration curve", "x.wall.curve")]; +const CURVES: [(&str, &str); 3] = [ + ("Dynamic sensitivity", "keychron.curve"), + ("Acceleration curve", "x.wall.curve"), + ("WLMouse · Dynamic DPI", "wl.curve"), +]; const GRAPH_HEIGHT: f32 = 200.0; /// The typed values of the curve on the open device. diff --git a/gpui/src/app/device_state.rs b/gpui/src/app/device_state.rs index 94772d20..df6a76fc 100644 --- a/gpui/src/app/device_state.rs +++ b/gpui/src/app/device_state.rs @@ -186,6 +186,10 @@ pub(super) struct DeviceReadout { pub(super) firmware: Vec, /// `ui.settingsReady` reported by the protocol driver (`true` when absent). pub(super) settings_ready: bool, + /// `ui.valuesVerified` reported by the protocol driver (`true` when absent). + /// `false` for write-only drivers (e.g. SteelSeries Prime Mini Wireless) + /// whose status read returns fallback defaults rather than hardware state. + pub(super) values_verified: bool, /// `ui.statusNote` reported by the protocol driver when settings could not /// be read (e.g. a sleeping wireless mouse behind a receiver). pub(super) status_note: Option, @@ -273,6 +277,11 @@ impl DeviceReadout { .and_then(|u| u.get("settingsReady")) .and_then(|v| v.as_bool()) .unwrap_or(true), + values_verified: s + .get("ui") + .and_then(|u| u.get("valuesVerified")) + .and_then(|v| v.as_bool()) + .unwrap_or(true), status_note: s .get("ui") .and_then(|u| u.get("statusNote")) diff --git a/gpui/src/app/safety.rs b/gpui/src/app/safety.rs index 1d7e13a3..aced1c32 100644 --- a/gpui/src/app/safety.rs +++ b/gpui/src/app/safety.rs @@ -264,6 +264,24 @@ impl AppView { if old.tabs.lighting.as_ref().is_some_and(|l| l.write_only) { new.tabs.lighting = old.tabs.lighting.clone(); } + // Write-only drivers (e.g. SteelSeries Prime Mini Wireless, issue #77) + // return hard-coded fallback defaults on a fresh status read; keep the + // values just written rather than snapping back to 400 DPI / 1000 Hz. + if !new.values_verified { + if expected.iter().any(|e| e.action == "dpi") { + new.dpi = old.dpi; + new.dpi_y = old.dpi_y; + } + if expected.iter().any(|e| e.action == "pollingRate") { + new.polling_hz = old.polling_hz; + } + if expected.iter().any(|e| e.action == "liftOff") { + new.lod = old.lod.clone(); + } + if expected.iter().any(|e| e.action == "surface") { + new.surface = old.surface.clone(); + } + } let differs: Vec = expected .iter() .filter(|e| !(stale_polling && e.action == "pollingRate")) @@ -429,6 +447,9 @@ impl AppView { /// The name of the setting, if the mouse does not report what was written. fn mismatch(readout: &DeviceReadout, expected: &Expected) -> Option { + if !readout.values_verified { + return None; + } let wrote = &expected.value; let number = |n: Option| n.map(Value::from); let text = |t: &Option| t.clone().map(Value::from); diff --git a/gpui/src/app/text_controls.rs b/gpui/src/app/text_controls.rs index 20b377b2..2cfe9742 100644 --- a/gpui/src/app/text_controls.rs +++ b/gpui/src/app/text_controls.rs @@ -178,6 +178,37 @@ impl AppView { .detach(); } + /// Picks 1–6 images or GIFs for a dongle screen (320×170), keeping GIFs + /// verbatim and converting static images to big-endian RGB565. + pub(super) fn open_control_image(&mut self, id: String, cx: &mut Context) { + let Some(key) = self.devices.tiles.get(self.devices.selected).map(|t| t.key.clone()) else { return }; + let picked = cx.prompt_for_paths(PathPromptOptions { + files: true, + directories: false, + multiple: true, + prompt: Some("Upload".into()), + }); + cx.spawn(async move |view, cx| { + let Ok(Ok(Some(paths))) = picked.await else { return }; + if paths.is_empty() { + return; + } + let encoded = cx + .background_executor() + .spawn(async move { encode_dongle_images(paths) }) + .await; + let _ = view.update(cx, |v: &mut Self, cx| { + let same = v.devices.tiles.get(v.devices.selected).is_some_and(|t| t.key == key) && v.editing_profile().is_none(); + match encoded { + Ok(_) if !same => v.show_toast("The device changed while picking images. Nothing was uploaded.", true, cx), + Ok(images) => v.set_control(id, images, cx), + Err(err) => v.show_toast(err, true, cx), + } + }); + }) + .detach(); + } + /// Click, press a key or combination, then Assign. pub(super) fn render_shortcut_control(&self, c: &ControlSpec, cx: &mut Context) -> AnyElement { let Some((key, handle)) = self.text_key(c).and_then(|k| self.text_controls.listening.get(&k).map(|h| (k, h.clone()))) @@ -224,3 +255,65 @@ impl AppView { h_flex().gap_2().items_center().child(boxed).child(assign).into_any_element() } } + +fn encode_dongle_images(paths: Vec) -> Result { + const MAX_SLOTS: usize = 6; + const MAX_BYTES: usize = 13 * 1024 * 1024; + const WIDTH: u32 = 320; + const HEIGHT: u32 = 170; + + if paths.len() > MAX_SLOTS { + return Err(format!("Pick at most {MAX_SLOTS} images (1 Main + up to 5 Random).")); + } + + let mut total_bytes = 0usize; + let mut out = Vec::with_capacity(paths.len()); + for path in paths { + let raw = std::fs::read(&path).map_err(|_| format!("Couldn't read {}.", path.display()))?; + let is_gif = raw.len() >= 10 && (&raw[..6] == b"GIF87a" || &raw[..6] == b"GIF89a"); + let (width, height, format, payload) = if is_gif { + let w = u16::from_le_bytes([raw[6], raw[7]]) as u32; + let h = u16::from_le_bytes([raw[8], raw[9]]) as u32; + (if w > 0 { w } else { WIDTH }, if h > 0 { h } else { HEIGHT }, "gif", raw) + } else { + let img = image::load_from_memory(&raw) + .map_err(|_| format!("Couldn't decode {} as an image or GIF.", path.display()))?; + let resized = img.resize_to_fill(WIDTH, HEIGHT, image::imageops::FilterType::Lanczos3).to_rgb8(); + let mut rgb565 = Vec::with_capacity((WIDTH * HEIGHT * 2) as usize); + for pixel in resized.pixels() { + let [r, g, b] = pixel.0; + let value = (((r as u16) & 0xf8) << 8) | (((g as u16) & 0xfc) << 3) | ((b as u16) >> 3); + rgb565.push((value >> 8) as u8); + rgb565.push((value & 0xff) as u8); + } + (WIDTH, HEIGHT, "rgb565", rgb565) + }; + total_bytes += payload.len(); + if total_bytes > MAX_BYTES { + return Err("Selected images exceed the dongle's 13 MB limit.".to_string()); + } + out.push(json!({ + "width": width, + "height": height, + "format": format, + "base64": base64_encode(&payload), + })); + } + Ok(serde_json::Value::Array(out)) +} + +fn base64_encode(bytes: &[u8]) -> String { + const TABLE: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + let mut out = String::with_capacity(bytes.len().div_ceil(3) * 4); + for chunk in bytes.chunks(3) { + let b0 = chunk[0] as u32; + let b1 = chunk.get(1).copied().unwrap_or(0) as u32; + let b2 = chunk.get(2).copied().unwrap_or(0) as u32; + let n = (b0 << 16) | (b1 << 8) | b2; + out.push(TABLE[((n >> 18) & 63) as usize] as char); + out.push(TABLE[((n >> 12) & 63) as usize] as char); + out.push(if chunk.len() > 1 { TABLE[((n >> 6) & 63) as usize] as char } else { '=' }); + out.push(if chunk.len() > 2 { TABLE[(n & 63) as usize] as char } else { '=' }); + } + out +} diff --git a/package-lock.json b/package-lock.json index e7640018..201ff3d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "AGPL-3.0-or-later", "dependencies": { "@openmouse/keyboard-protocol": "1.10.0", - "@openmouse/protocol": "0.68.0" + "@openmouse/protocol": "0.68.1" }, "devDependencies": { "esbuild": "^0.25.12" @@ -468,9 +468,9 @@ } }, "node_modules/@openmouse/protocol": { - "version": "0.68.0", - "resolved": "https://registry.npmjs.org/@openmouse/protocol/-/protocol-0.68.0.tgz", - "integrity": "sha512-0uj07ePYkftS+7LbI1D/wGU9usqWvPC3ExZZZzL6fkwZ1XU3G8Lm4PCjLKZaFdS2kOUeRrrRMQcsHasdv2ch+Q==", + "version": "0.68.1", + "resolved": "https://registry.npmjs.org/@openmouse/protocol/-/protocol-0.68.1.tgz", + "integrity": "sha512-qLGyDEUKFBcPmlycP4M7D+ZnhZoZpJQxTaxxcPJwgG7rjmUZnOSV9H1zJroevUgYRk5phXLuaP4uXKzGeqC1Fg==", "license": "AGPL-3.0-or-later", "engines": { "node": ">=20" diff --git a/package.json b/package.json index 78cdcf3b..8a2c56ff 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "description": "Build tooling for the native GPUI app: gpui/build.rs bundles the protocol drivers with esbuild.", "dependencies": { "@openmouse/keyboard-protocol": "1.10.0", - "@openmouse/protocol": "0.68.0" + "@openmouse/protocol": "0.68.1" }, "devDependencies": { "esbuild": "^0.25.12" From 993ca885f4e98235306278bde6c875acab74fa07 Mon Sep 17 00:00:00 2001 From: Snekxs <26660858+snekxs@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:04:15 -0600 Subject: [PATCH 2/3] fix: address Macroscope review findings (curve toggle/bounds, macro panel, profile compat, write-only readback, bounded image decode) --- gpui/js/controls.ts | 12 ++++++++---- gpui/js/macros.ts | 4 +++- gpui/src/app/safety.rs | 22 +++++++--------------- gpui/src/app/text_controls.rs | 23 +++++++++++++++++++++-- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/gpui/js/controls.ts b/gpui/js/controls.ts index 1d5f0018..f8d17fd1 100644 --- a/gpui/js/controls.ts +++ b/gpui/js/controls.ts @@ -323,7 +323,7 @@ export function extras(s: any): Section[] { : [{ speed: 0, ratio: 1 }, { speed: 20, ratio: 2.62 }, { speed: 40, ratio: 4.8 }]; const curveControls: Control[] = [ { - id: "wl.dynDpi", + id: "wl.curve/enabled", label: "Dynamic DPI", kind: "toggle", current: Boolean(wl.dynamicDpi.enabled), @@ -331,8 +331,8 @@ export function extras(s: any): Section[] { ]; pts.forEach((pt, idx) => { curveControls.push( - { id: `wl.curve.${idx}.speed`, label: `Point ${idx + 1} speed`, kind: "number", min: 0, max: 100, step: 1, current: pt.speed }, - { id: `wl.curve.${idx}.gain`, label: `Point ${idx + 1} ratio`, kind: "number", min: 0.1, max: 10, step: 0.01, current: pt.ratio }, + { id: `wl.curve.${idx}.speed`, label: `Point ${idx + 1} speed`, kind: "number", min: 0, max: 250, step: 1, current: pt.speed }, + { id: `wl.curve.${idx}.gain`, label: `Point ${idx + 1} ratio`, kind: "number", min: 0.1, max: 8, step: 0.01, current: pt.ratio }, ); }); out.push({ title: "WLMouse · Dynamic DPI", controls: curveControls }); @@ -930,6 +930,10 @@ export async function writeControl(info: HidInterfaceInfo, status: any, id: stri if (status.wlmouse) { status.wlmouse.lodMode = mode; status.wlmouse.lodMm = mm; } return; } + case "wl.separateAxes": + await callClientMethod(info, "setSeparateDpiAxes", Boolean(value)); + status.supportsSeparateDpiAxes = Boolean(value); + return; case "wl.sensorReset": await callClientMethod(info, "setSensorPosition", 0, 0); if (status.wlmouse) status.wlmouse.sensorPosition = { x: 0, y: 0 }; @@ -953,7 +957,7 @@ export async function writeControl(info: HidInterfaceInfo, status: any, id: stri if (status.wlmouse) status.wlmouse.bhopWheel = next; return; } - case "wl.dynDpi": { + case "wl.dynDpi": case "wl.curve/enabled": { const cur = status.wlmouse?.dynamicDpi ?? { enabled: false, points: [{ speed: 0, ratio: 1 }, { speed: 20, ratio: 2.62 }, { speed: 40, ratio: 4.8 }] }; const next = { ...cur, enabled: Boolean(value) }; await callClientMethod(info, "setDynamicDpi", next); diff --git a/gpui/js/macros.ts b/gpui/js/macros.ts index 286d4f00..30e64225 100644 --- a/gpui/js/macros.ts +++ b/gpui/js/macros.ts @@ -187,7 +187,9 @@ const BRANDS: Record = { }; export function macroPanel(status: any): MacroPanel | null { - if (status.driverName === "WLMouseHidClient" && !status.wlmouse?.macroSlots) return null; + if (status.driverName === "WLMouseHidClient") { + return status.wlmouse?.macroSlots ? BRANDS.WLMouseHidClient!.panel() : null; + } const brand = BRANDS[status.driverName]; return brand && (status.methods ?? []).includes(brand.method) ? brand.panel() : null; } diff --git a/gpui/src/app/safety.rs b/gpui/src/app/safety.rs index aced1c32..aee84acd 100644 --- a/gpui/src/app/safety.rs +++ b/gpui/src/app/safety.rs @@ -265,22 +265,14 @@ impl AppView { new.tabs.lighting = old.tabs.lighting.clone(); } // Write-only drivers (e.g. SteelSeries Prime Mini Wireless, issue #77) - // return hard-coded fallback defaults on a fresh status read; keep the - // values just written rather than snapping back to 400 DPI / 1000 Hz. + // return hard-coded fallback defaults on a fresh status read; preserve + // all previously known settings rather than snapping back to defaults. if !new.values_verified { - if expected.iter().any(|e| e.action == "dpi") { - new.dpi = old.dpi; - new.dpi_y = old.dpi_y; - } - if expected.iter().any(|e| e.action == "pollingRate") { - new.polling_hz = old.polling_hz; - } - if expected.iter().any(|e| e.action == "liftOff") { - new.lod = old.lod.clone(); - } - if expected.iter().any(|e| e.action == "surface") { - new.surface = old.surface.clone(); - } + new.dpi = old.dpi; + new.dpi_y = old.dpi_y; + new.polling_hz = old.polling_hz; + new.lod = old.lod.clone(); + new.surface = old.surface.clone(); } let differs: Vec = expected .iter() diff --git a/gpui/src/app/text_controls.rs b/gpui/src/app/text_controls.rs index 2cfe9742..dfc1c5c5 100644 --- a/gpui/src/app/text_controls.rs +++ b/gpui/src/app/text_controls.rs @@ -257,8 +257,11 @@ impl AppView { } fn encode_dongle_images(paths: Vec) -> Result { + use std::io::Read; + const MAX_SLOTS: usize = 6; const MAX_BYTES: usize = 13 * 1024 * 1024; + const MAX_INPUT_BYTES: usize = 32 * 1024 * 1024; const WIDTH: u32 = 320; const HEIGHT: u32 = 170; @@ -269,7 +272,14 @@ fn encode_dongle_images(paths: Vec) -> Result MAX_INPUT_BYTES { + return Err(format!("{} is too large (max 32 MB per file).", path.display())); + } let is_gif = raw.len() >= 10 && (&raw[..6] == b"GIF87a" || &raw[..6] == b"GIF89a"); let (width, height, format, payload) = if is_gif { let w = u16::from_le_bytes([raw[6], raw[7]]) as u32; @@ -278,7 +288,16 @@ fn encode_dongle_images(paths: Vec) -> Result u64::from(src_h) * u64::from(WIDTH) { + (((u64::from(src_h) * u64::from(WIDTH)) / u64::from(HEIGHT)).max(1) as u32, src_h) + } else { + (src_w, ((u64::from(src_w) * u64::from(HEIGHT)) / u64::from(WIDTH)).max(1) as u32) + }; + let cropped = img.crop_imm((src_w - crop_w) / 2, (src_h - crop_h) / 2, crop_w, crop_h); + let resized = cropped.resize_exact(WIDTH, HEIGHT, image::imageops::FilterType::Lanczos3).to_rgb8(); let mut rgb565 = Vec::with_capacity((WIDTH * HEIGHT * 2) as usize); for pixel in resized.pixels() { let [r, g, b] = pixel.0; From 96ad1c26011d580627c3be97258f3e299b122783 Mon Sep 17 00:00:00 2001 From: Snekxs <26660858+snekxs@users.noreply.github.com> Date: Sat, 5 Dec 2026 00:15:24 -0600 Subject: [PATCH 3/3] fix: disable one-shot actions in game profiles and hide bhopDir while BHop is off --- gpui/js/controls.ts | 24 +++++++++++++----------- gpui/src/app/controls.rs | 4 ++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/gpui/js/controls.ts b/gpui/js/controls.ts index f8d17fd1..7ed7491a 100644 --- a/gpui/js/controls.ts +++ b/gpui/js/controls.ts @@ -293,17 +293,19 @@ export function extras(s: any): Section[] { kind: "toggle", current: Boolean(wl.bhopWheel.enabled), }); - sensorControls.push({ - id: "wl.bhopDir", - label: "BHop filter direction", - kind: "choice", - options: [ - { value: "both", label: "Both" }, - { value: "up", label: "Up" }, - { value: "down", label: "Down" }, - ], - current: wl.bhopWheel.direction, - }); + if (wl.bhopWheel.enabled) { + sensorControls.push({ + id: "wl.bhopDir", + label: "BHop filter direction", + kind: "choice", + options: [ + { value: "both", label: "Both" }, + { value: "up", label: "Up" }, + { value: "down", label: "Down" }, + ], + current: wl.bhopWheel.direction, + }); + } sensorControls.push({ id: "wl.bhopWindow", label: "BHop filter window", diff --git a/gpui/src/app/controls.rs b/gpui/src/app/controls.rs index bdbd06c7..01fb1584 100644 --- a/gpui/src/app/controls.rs +++ b/gpui/src/app/controls.rs @@ -260,9 +260,13 @@ impl AppView { "button" | "saveFile" | "openFile" | "openImage" => { let label = c.options.first().map(|o| o.label.clone()).unwrap_or_else(|| c.label.clone()); let (kind, value) = (c.kind.clone(), c.options.first().map(|o| o.value.clone()).unwrap_or(c.current.clone())); + // One-shot hardware/file actions (e.g. dongle image upload/delete, + // sensor reset, layout import/export) are not per-game profile settings. + let in_profile = self.editing_profile().is_some(); Button::new(SharedString::from(format!("btn-{id}"))) .compact() .label(label) + .disabled(in_profile) .on_click(cx.listener(move |this, _, _, cx| match kind.as_str() { "saveFile" => this.save_control_file(id.clone(), value.as_str().unwrap_or("layout.json").to_string(), cx), "openFile" => this.open_control_file(id.clone(), cx),