From da98d83be52f3da0111988402dc032b374e2f8b3 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Thu, 3 Sep 2026 13:03:50 -0500 Subject: [PATCH] a mouse that is switched off does not follow the hand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The other half of technical note Mouse #3, and the same mistake as the interrupt: `moveTo` took the host's position whatever the mode said, and only declined to interrupt about it. The note's first sentence on what switching the mouse off does is "the mouse position is not tracked; any mouse motion is ignored". `moveTo` is the hand on the desk, and now returns without doing anything while the mouse is off. It is the only path that does: the note is careful that the program's own routines still work — "PosMouse and ClearMouse will change the mouse position, ClampMouse will set new clamp values" — and `positionTo`, `clear`, `home` and `clamp` all set the position directly rather than through here, so they already behaved. `setButton` keeps gating its interrupt on the mode instead of returning early, which is not an inconsistency: the note says the position is not tracked and says nothing of the kind about the buttons. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01SMvnfKpLVGm494n43AMhzY --- src/mouse.zig | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mouse.zig b/src/mouse.zig index 14aeb9f..317e56a 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -173,14 +173,23 @@ pub const Card = struct { } /// Where the host puts the mouse, in the units the program clamped it to. + /// + /// A mouse that is switched off does not move: "the mouse position is not + /// tracked; any mouse motion is ignored" (Apple Computer, Inc., 1985-1990, + /// No. 3). That is about the hand on the desk rather than about the + /// program, and the same note is careful to say so — `positionTo`, + /// `clear`, `home` and `clamp` all move it whatever the mode says, because + /// "PosMouse and ClearMouse will change the mouse position, ClampMouse + /// will set new clamp values". pub fn moveTo(self: *Card, x: i16, y: i16) void { + if (!self.on()) return; const to_x = std.math.clamp(x, self.low_x, self.high_x); const to_y = std.math.clamp(y, self.low_y, self.high_y); if (to_x == self.x and to_y == self.y) return; self.x = to_x; self.y = to_y; self.moved = true; - if (self.on() and self.mode & mode_move_interrupt != 0) { + if (self.mode & mode_move_interrupt != 0) { self.pending |= status_moved_interrupt; } } @@ -562,6 +571,17 @@ test "a mouse switched off still interrupts at the end of a frame" { card.setButton(0, true); try testing.expect(!card.interrupting()); + // Nor does the position follow the hand while it is off, which is the + // first thing that paragraph says: "the mouse position is not tracked; + // any mouse motion is ignored". The program's own routines are not the + // hand, and still move it. + try testing.expectEqual(@as(i16, 0), card.x); + try testing.expectEqual(@as(i16, 0), card.y); + card.positionTo(40, 40); + try testing.expectEqual(@as(i16, 40), card.x); + card.home(); + try testing.expectEqual(card.low_x, card.x); + // And a frame still reaches the line with those bits set as well. card.blanked(); try testing.expect(card.interrupting()); -- knotmirror 0.0.1