11using System ;
2+ using System . Diagnostics ;
23using System . Runtime . Versioning ;
34using Microsoft . Extensions . DependencyInjection ;
45using YMouseButtonControl . Core . Services . BackgroundTasks ;
@@ -51,8 +52,33 @@ private static void RegisterLinuxServices(IServiceCollection services)
5152 services
5253 . AddScoped < IStartupInstallerService , Linux . Services . StartupInstallerService > ( )
5354 . AddScoped < IProcessMonitorService , Linux . Services . ProcessMonitorService > ( )
54- . AddScoped < ICurrentWindowService , Linux . Services . CurrentWindowService > ( )
5555 . AddScoped < IBackgroundTasksRunner , Linux . Services . BackgroundTasksRunner > ( ) ;
56+ if ( Environment . GetEnvironmentVariable ( "XDG_SESSION_TYPE" ) == "x11" )
57+ {
58+ var startInfo = new ProcessStartInfo
59+ {
60+ FileName = "/bin/bash" ,
61+ Arguments = "-c \" xdotool\" " ,
62+ RedirectStandardOutput = true ,
63+ RedirectStandardError = true
64+ } ;
65+ using var proc = new Process ( ) ;
66+ proc . StartInfo = startInfo ;
67+ proc . Start ( ) ;
68+ proc . WaitForExit ( ) ;
69+ if ( proc . ExitCode == 1 )
70+ {
71+ services . AddScoped < ICurrentWindowService , Linux . Services . CurrentWindowServiceX11 > ( ) ;
72+ }
73+ else
74+ {
75+ services . AddScoped < ICurrentWindowService , Linux . Services . CurrentWindowService > ( ) ;
76+ }
77+ }
78+ else
79+ {
80+ services . AddScoped < ICurrentWindowService , Linux . Services . CurrentWindowService > ( ) ;
81+ }
5682 }
5783
5884 [ SupportedOSPlatform ( "windows5.1.2600" ) ]
@@ -73,4 +99,4 @@ private static void RegisterMacOsServices(IServiceCollection services)
7399 . AddScoped < ICurrentWindowService , MacOS . Services . CurrentWindowService > ( )
74100 . AddScoped < IBackgroundTasksRunner , MacOS . Services . BackgroundTasksRunner > ( ) ;
75101 }
76- }
102+ }
0 commit comments