@@ -199,9 +199,20 @@ public IntPtr GetHubWindowHandle()
199199 "OpenClawTray" ) ;
200200 private static readonly string CrashLogPath = Path . Combine ( DataPath , "crash.log" ) ;
201201 private static readonly AppRunMarker s_runMarker = new ( Path . Combine ( DataPath , "run.marker" ) ) ;
202+ private const string DisableMouseInPointerEnv = "OPENCLAW_DISABLE_MOUSE_IN_POINTER" ;
203+
204+ [ DllImport ( "user32.dll" , SetLastError = true ) ]
205+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
206+ private static extern bool EnableMouseInPointer ( [ MarshalAs ( UnmanagedType . Bool ) ] bool fEnable ) ;
207+
208+ [ DllImport ( "user32.dll" ) ]
209+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
210+ private static extern bool IsMouseInPointerEnabled ( ) ;
202211
203212 public App ( )
204213 {
214+ ConfigureMouseInPointerInput ( ) ;
215+
205216 // Language override for localization testing (e.g., OPENCLAW_LANGUAGE=zh-CN)
206217 var langOverride = Environment . GetEnvironmentVariable ( "OPENCLAW_LANGUAGE" ) ;
207218 if ( ! string . IsNullOrEmpty ( langOverride ) )
@@ -226,6 +237,56 @@ public App()
226237 AppDomain . CurrentDomain . ProcessExit += OnProcessExit ;
227238 }
228239
240+ private static void ConfigureMouseInPointerInput ( )
241+ {
242+ if ( IsTruthyEnvVar ( Environment . GetEnvironmentVariable ( DisableMouseInPointerEnv ) ) )
243+ {
244+ Logger . Warn ( $ "[Input] Mouse-in-pointer startup configuration disabled by { DisableMouseInPointerEnv } =1.") ;
245+ return ;
246+ }
247+
248+ try
249+ {
250+ var before = IsMouseInPointerEnabled ( ) ;
251+ if ( before )
252+ {
253+ Logger . Info ( "[Input] Mouse-in-pointer was already enabled before WinUI initialization." ) ;
254+ return ;
255+ }
256+
257+ var enabled = EnableMouseInPointer ( true ) ;
258+ var error = enabled ? 0 : Marshal . GetLastWin32Error ( ) ;
259+ var after = IsMouseInPointerEnabled ( ) ;
260+ if ( enabled && after )
261+ {
262+ Logger . Info ( "[Input] Enabled mouse-in-pointer before WinUI initialization for precision touchpad scrolling." ) ;
263+ }
264+ else
265+ {
266+ Logger . Warn ( $ "[Input] EnableMouseInPointer(true) did not enable mouse-in-pointer. Before={ before } , After={ after } , LastError={ error } .") ;
267+ }
268+ }
269+ catch ( DllNotFoundException ex )
270+ {
271+ Logger . Warn ( $ "[Input] EnableMouseInPointer startup configuration failed: { ex . Message } ") ;
272+ }
273+ catch ( EntryPointNotFoundException ex )
274+ {
275+ Logger . Warn ( $ "[Input] EnableMouseInPointer startup configuration failed: { ex . Message } ") ;
276+ }
277+ catch ( SEHException ex )
278+ {
279+ Logger . Warn ( $ "[Input] EnableMouseInPointer startup configuration failed: { ex . Message } ") ;
280+ }
281+ }
282+
283+ private static bool IsTruthyEnvVar ( string ? value ) =>
284+ value is not null &&
285+ ( string . Equals ( value , "1" , StringComparison . OrdinalIgnoreCase ) ||
286+ string . Equals ( value , "true" , StringComparison . OrdinalIgnoreCase ) ||
287+ string . Equals ( value , "yes" , StringComparison . OrdinalIgnoreCase ) ||
288+ string . Equals ( value , "on" , StringComparison . OrdinalIgnoreCase ) ) ;
289+
229290 private void OnUnhandledException ( object sender , Microsoft . UI . Xaml . UnhandledExceptionEventArgs e )
230291 {
231292 LogCrash ( "UnhandledException" , e . Exception ) ;
0 commit comments