@@ -33,13 +33,54 @@ struct Args {
3333 #[ cfg( feature = "gui" ) ]
3434 #[ arg( long) ]
3535 headless : bool ,
36+
37+ /// Force X11 display backend (default on WSL2, option on native Linux)
38+ #[ cfg( feature = "gui" ) ]
39+ #[ arg( long) ]
40+ x11 : bool ,
41+
42+ /// Force Wayland display backend (default on native Linux, option on WSL2)
43+ #[ cfg( feature = "gui" ) ]
44+ #[ arg( long) ]
45+ wayland : bool ,
46+ }
47+
48+ /// Detect if running under WSL (Windows Subsystem for Linux).
49+ #[ cfg( feature = "gui" ) ]
50+ fn is_wsl ( ) -> bool {
51+ std:: fs:: read_to_string ( "/proc/version" )
52+ . map ( |v| {
53+ let lower = v. to_lowercase ( ) ;
54+ lower. contains ( "microsoft" ) || lower. contains ( "wsl" )
55+ } )
56+ . unwrap_or ( false )
3657}
3758
3859fn main ( ) -> anyhow:: Result < ( ) > {
3960 // Parse command line arguments
4061 #[ cfg_attr( not( feature = "gui" ) , allow( unused_variables) ) ]
4162 let args = Args :: parse ( ) ;
4263
64+ // Select display backend based on platform and CLI flags
65+ // WSL2 has clipboard issues with Wayland (smithay-clipboard), so default to X11 there
66+ // Native Linux works better with Wayland by default
67+ // This must happen before any GUI initialization
68+ #[ cfg( feature = "gui" ) ]
69+ if !args. headless {
70+ let force_x11 = if args. x11 {
71+ true // Explicit --x11 flag
72+ } else if args. wayland {
73+ false // Explicit --wayland flag
74+ } else {
75+ // Default: X11 on WSL (clipboard compatibility), Wayland on native Linux
76+ is_wsl ( )
77+ } ;
78+
79+ if force_x11 {
80+ std:: env:: set_var ( "WAYLAND_DISPLAY" , "" ) ;
81+ }
82+ }
83+
4384 // Initialize logging - use RUST_LOG env var or default to info
4485 fmt ( )
4586 . with_env_filter (
0 commit comments