Commit 39cbe28
Add Screen and Mouse Coordinate Modes (#15)
* Add Screen Coordinates and Live Mouse modes to ClickIt Lite
Implements two coordinate modes for the Lite version:
- Screen Coordinates Mode: Clicks at a static, user-defined position
- Live Mouse Mode: Clicks follow cursor position, triggered by right-click
Changes:
- SimpleViewModel: Added CoordinateMode enum and mode switching logic
- SimpleHotkeyManager: Extended with right-click monitoring and debouncing
- SimpleClickEngine: Added dynamic point provider support for cursor-following
- SimplifiedMainView: Added mode selector UI with context-aware controls
Both modes continue to use ESC/SPACEBAR for emergency stop.
* Fix Swift concurrency actor isolation issues
- Mark stopMonitoring() and stopMouseMonitoring() as nonisolated
to allow calling from deinit without actor context
- Wrap checkPermissions() call in Task { @mainactor in } block
to properly handle async call from notification observer
Resolves build errors in ClickIt Lite.
* Mark event monitor properties as nonisolated(unsafe)
The event monitor properties need to be accessible from nonisolated
stop methods that are called from deinit. Marking them as
nonisolated(unsafe) is safe because:
- They are opaque tokens from NSEvent.addMonitorForEvents
- NSEvent.removeMonitor is thread-safe
- We only read them to pass to removeMonitor
This resolves the MainActor isolation compilation errors.
* Fix coordinate conversion for Live Mouse Mode
The previous implementation used NSScreen.main for coordinate conversion,
which caused clicks to drift towards the top of the screen, especially
in multi-monitor setups.
Changes:
- Find the screen that contains the mouse cursor location
- Use that specific screen's frame for accurate coordinate conversion
- Add fallback logic for edge cases using the full desktop bounds
This ensures clicks happen exactly where the cursor is positioned.
* Fix coordinate conversion and resource leaks from code review
Coordinate conversion (SimpleViewModel.swift):
- Fixed multi-monitor coordinate conversion to use global maxY
- Previous per-screen logic was incorrect and caused wrong Y positions
- Now properly accounts for entire virtual screen space
Resource management (SimpleHotkeyManager.swift):
- Restored stopMonitoring() to MainActor with proper cleanup
- Fixed stopMouseMonitoring() to dispatch cleanup to MainActor
- Both methods now properly nil out monitor properties and callbacks
- Prevents memory leaks from retained closures in singleton
- Removed nonisolated(unsafe) annotations (no longer needed)
These fixes address all issues identified in code review.
---------
Co-authored-by: Claude <[email protected]>1 parent 398935d commit 39cbe28
File tree
5 files changed
+257
-38
lines changed- Sources/ClickIt/Lite
5 files changed
+257
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
36 | 51 | | |
37 | 52 | | |
38 | 53 | | |
| |||
43 | 58 | | |
44 | 59 | | |
45 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
46 | 64 | | |
47 | 65 | | |
48 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
22 | 28 | | |
23 | 29 | | |
24 | 30 | | |
| |||
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
69 | 111 | | |
70 | 112 | | |
71 | 113 | | |
| |||
76 | 118 | | |
77 | 119 | | |
78 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
79 | 131 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
15 | 23 | | |
16 | 24 | | |
17 | 25 | | |
| |||
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
| 31 | + | |
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
| |||
36 | 45 | | |
37 | 46 | | |
38 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
39 | 52 | | |
40 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
41 | 71 | | |
42 | 72 | | |
43 | 73 | | |
| |||
50 | 80 | | |
51 | 81 | | |
52 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
53 | 96 | | |
54 | | - | |
| 97 | + | |
55 | 98 | | |
56 | 99 | | |
57 | 100 | | |
| |||
84 | 127 | | |
85 | 128 | | |
86 | 129 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
91 | 147 | | |
92 | 148 | | |
0 commit comments