1111from send2trash import send2trash
1212
1313from . import ipc
14- from .abstract import Component
14+ from .abstract import AppComponent
1515from ..cli import CLI
1616from ..config import GlobalConfig
1717from ..exceptions import ExitRequest
1818from ..export import Export
1919from ..file import ArrayResolutionMap , MovementMaps , TrackingProfile , TrackingProfileLoader , get_filename
2020from ..legacy import keyboard
21- from ..types import RectList
21+ from ..types import Application
2222from ..utils import keycodes
2323from ..utils .math import calculate_line , calculate_distance
2424from ..utils .monitor import MonitorData
2525from ..utils .input import get_cursor_pos
2626from ..utils .interface import Interfaces
27- from ..utils .system import hide_child_process , UserResizeAppListener
28- from ..constants import DEFAULT_PROFILE_NAME , UPDATES_PER_SECOND , DOUBLE_CLICK_MS , DOUBLE_CLICK_TOL , RADIAL_ARRAY_SIZE , DEBUG
27+ from ..utils .system import hide_child_process
28+ from ..constants import UPDATES_PER_SECOND , DOUBLE_CLICK_MS , DOUBLE_CLICK_TOL , RADIAL_ARRAY_SIZE , DEBUG
2929from ..render import render , EmptyRenderError , LayerBlend
3030
3131
@@ -47,13 +47,7 @@ def position(self) -> tuple[int, int]:
4747 return self .message .position
4848
4949
50- @dataclass
51- class Application :
52- name : str
53- rects : RectList = field (default_factory = RectList )
54-
55-
56- class Processing (Component ):
50+ class Processing (AppComponent ):
5751 def __post_init__ (self ) -> None :
5852 hide_child_process ()
5953
@@ -66,11 +60,11 @@ def __post_init__(self) -> None:
6660
6761 # Load in the default profile
6862 self .all_profiles = TrackingProfileLoader ()
69- self ._current_application = Application ('' , RectList ())
70- self .current_application = Application (DEFAULT_PROFILE_NAME , RectList ())
7163
72- self ._resize_listener = UserResizeAppListener ()
73- self ._resize_listener .start ()
64+ # Reset the cursor position on focused application change
65+ def on_application_change (app : Application ) -> None :
66+ self .profile .cursor_map .position = None
67+ self .register_app_change_hook (on_application_change )
7468
7569 @property
7670 def timestamp (self ) -> int :
@@ -87,22 +81,7 @@ def timestamp(self, timestamp: int) -> None:
8781 @property
8882 def profile (self ) -> TrackingProfile :
8983 """Get the data for the current application."""
90- return self .all_profiles [self .current_application .name ]
91-
92- @property
93- def current_application (self ) -> Application :
94- """Get the currently loaded application."""
95- return self ._current_application
96-
97- @current_application .setter
98- def current_application (self , application : Application ) -> None :
99- """Update the currently loaded application."""
100- if application == self ._current_application :
101- return
102- self ._current_application = application
103-
104- # Reset the data
105- self .profile .cursor_map .position = None
84+ return self .all_profiles [self .focused_app .name ]
10685
10786 def _send_profile_data (self , profile : TrackingProfile ) -> None :
10887 """Send all the stats for the profile."""
@@ -169,18 +148,11 @@ def profile_age_days(self) -> int:
169148 current_day = self .timestamp // 86400
170149 return max (0 , current_day - creation_day )
171150
172- @property
173- def app_resizing (self ) -> bool :
174- """Determine if the focused application is being resized."""
175- if self .current_application .name == DEFAULT_PROFILE_NAME :
176- return False
177- return self ._resize_listener .triggered
178-
179151 def _monitor_offset (self , pixel : tuple [int , int ]) -> tuple [tuple [int , int ], tuple [int , int ]] | None :
180152 """Detect which monitor the pixel is on."""
181153 monitors = self .monitor_data .physical
182- if self .current_application .rects :
183- monitors = self .current_application .rects
154+ if self .focused_app .rects :
155+ monitors = self .focused_app .rects
184156
185157 single_monitor = bool (CLI .single_monitor ) if self .profile .config .multi_monitor is None else not self .profile .config .multi_monitor
186158 return monitors .calculate_offset (pixel , combined = single_monitor )
@@ -208,7 +180,7 @@ def _record_move(self, data: MovementMaps, position: tuple[int, int],
208180 # Convert pixels from logical coordinates to physical
209181 old_position = position
210182 new_position = data .position
211- if force_monitor is None and not self .current_application .rects :
183+ if force_monitor is None and not self .focused_app .rects :
212184 old_position = self .monitor_data .coordinate (position )
213185 if data .position is None :
214186 new_position = old_position
@@ -715,7 +687,7 @@ def _process_message(self, message: ipc.Message) -> None:
715687 raise ExitRequest
716688
717689 case ipc .CurrentProfileChanged ():
718- self .current_application = Application (message .name , message .rects )
690+ self .focused_app = Application (message .name , message .rects )
719691
720692 case ipc .Save ():
721693 # Keep track of what saved and what didn't
0 commit comments