1717from ..export import Export
1818from ..file import ArrayResolutionMap , MovementMaps , TrackingProfile , TrackingProfileLoader , get_filename
1919from ..legacy import keyboard
20- from ..utils import keycodes , get_cursor_pos
21- from ..utils .math import calculate_line , calculate_distance , calculate_pixel_offset , logical_to_physical
20+ from ..utils import keycodes , RectList , get_cursor_pos
21+ from ..utils .math import calculate_line , calculate_distance
22+ from ..utils .monitor import MonitorData
2223from ..utils .network import Interfaces
23- from ..utils .system import monitor_locations
2424from ..constants import DEFAULT_PROFILE_NAME , UPDATES_PER_SECOND , DOUBLE_CLICK_MS , DOUBLE_CLICK_TOL , RADIAL_ARRAY_SIZE , DEBUG
2525from ..render import render , EmptyRenderError , LayerBlend
2626
@@ -46,7 +46,7 @@ def position(self) -> tuple[int, int]:
4646@dataclass
4747class Application :
4848 name : str
49- rects : list [ tuple [ int , int , int , int ]] = field (default_factory = list )
49+ rects : RectList = field (default_factory = RectList )
5050
5151
5252class Processing (Component ):
@@ -55,13 +55,13 @@ def __post_init__(self) -> None:
5555 self ._timestamp = - 1
5656
5757 self .previous_mouse_click : PreviousMouseClick | None = None
58- self .monitor_data = ( monitor_locations ( True ), monitor_locations ( False ) )
58+ self .monitor_data = MonitorData ( )
5959 self .previous_monitor = None
6060
6161 # Load in the default profile
6262 self .all_profiles = TrackingProfileLoader ()
63- self ._current_application = Application ('' , [] )
64- self .current_application = Application (DEFAULT_PROFILE_NAME , [] )
63+ self ._current_application = Application ('' , RectList () )
64+ self .current_application = Application (DEFAULT_PROFILE_NAME , RectList () )
6565
6666 @property
6767 def timestamp (self ) -> int :
@@ -162,31 +162,12 @@ def profile_age_days(self) -> int:
162162
163163 def _monitor_offset (self , pixel : tuple [int , int ]) -> tuple [tuple [int , int ], tuple [int , int ]] | None :
164164 """Detect which monitor the pixel is on."""
165- physical_monitor_data , logical_monitor_data = self .monitor_data
166-
167- monitor_data = physical_monitor_data
165+ monitors = self .monitor_data .physical
168166 if self .current_application .rects :
169- monitor_data = self .current_application .rects
170-
171- single_monitor = CLI .single_monitor if self .profile .config .multi_monitor is None else not self .profile .config .multi_monitor
172- if single_monitor :
173- x_min , y_min , x_max , y_max = monitor_data [0 ]
174- for x1 , y1 , x2 , y2 in monitor_data [1 :]:
175- x_min = min (x_min , x1 )
176- y_min = min (y_min , y1 )
177- x_max = max (x_max , x2 )
178- y_max = max (y_max , y2 )
179- result = calculate_pixel_offset (pixel [0 ], pixel [1 ], x_min , y_min , x_max , y_max )
180- if result is not None :
181- return result
182-
183- else :
184- for x1 , y1 , x2 , y2 in monitor_data :
185- result = calculate_pixel_offset (pixel [0 ], pixel [1 ], x1 , y1 , x2 , y2 )
186- if result is not None :
187- return result
167+ monitors = self .current_application .rects
188168
189- return None
169+ single_monitor = bool (CLI .single_monitor ) if self .profile .config .multi_monitor is None else not self .profile .config .multi_monitor
170+ return monitors .calculate_offset (pixel , combined = single_monitor )
190171
191172 def _record_move (self , data : MovementMaps , position : tuple [int , int ],
192173 force_monitor : tuple [int , int ] | None = None ) -> float :
@@ -209,11 +190,11 @@ def _record_move(self, data: MovementMaps, position: tuple[int, int],
209190 moving, and will always skip the first frame of movement.
210191 """
211192 # Convert logical to physical
212- old_position = logical_to_physical ( position , self .monitor_data [ 1 ], self . monitor_data [ 0 ] )
193+ old_position = self .monitor_data . coordinate ( position )
213194 if data .position is None :
214195 new_position = old_position
215196 else :
216- new_position = logical_to_physical ( data . position , self .monitor_data [ 1 ], self . monitor_data [ 0 ] )
197+ new_position = self .monitor_data . coordinate ( data . position )
217198
218199 # If the ticks match then overwrite the old data
219200 if self .tick == data .tick :
@@ -711,7 +692,7 @@ def _process_message(self, message: ipc.Message) -> None:
711692
712693 case ipc .MonitorsChanged ():
713694 print (f'[Processing] Monitors changed.' )
714- self .monitor_data = message .physical_data , message . logical_data
695+ self .monitor_data = message .data
715696
716697 case ipc .ThumbstickMove ():
717698 if not self .profile .config .track_gamepad :
0 commit comments