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());