@@ -7,6 +7,7 @@ extern crate simple_error;
77use crate :: cli:: { parse_args, Method } ;
88use crate :: errors:: { print_error, AnyErr , ErrorWithHint } ;
99use crate :: util:: { exec_command, have_command, run_command, sd_booted} ;
10+ use crate :: x11:: x11_add_acl;
1011use log:: { debug, info, log, warn, Level } ;
1112use nix:: libc:: uid_t;
1213use nix:: unistd:: { Uid , User } ;
@@ -28,6 +29,7 @@ mod logging;
2829#[ cfg( test) ]
2930mod tests;
3031mod util;
32+ mod x11;
3133
3234#[ derive( Clone ) ]
3335struct EgoContext {
@@ -60,7 +62,7 @@ fn main_inner() -> Result<(), AnyErr> {
6062 Err ( msg) => bail ! ( "Error preparing Wayland: {msg}" ) ,
6163 Ok ( ret) => vars. extend ( ret) ,
6264 }
63- match prepare_x11 ( & ctx) {
65+ match prepare_x11 ( & ctx, args . old_xhost ) {
6466 Err ( msg) => bail ! ( "Error preparing X11: {msg}" ) ,
6567 Ok ( ret) => vars. extend ( ret) ,
6668 }
@@ -233,17 +235,23 @@ fn prepare_wayland(ctx: &EgoContext) -> Result<Vec<String>, AnyErr> {
233235 Ok ( vec ! [ format!( "WAYLAND_DISPLAY={}" , path. to_str( ) . unwrap( ) ) ] )
234236}
235237
236- /// Detect `DISPLAY` and run `xhost` to grant permissions.
238+ /// Detect `DISPLAY` and grant permissions via X11 protocol `ChangeHosts` command
239+ /// (or run `xhost` command if `--old-xhost` was used).
237240/// Return environment vars for `DISPLAY`
238- fn prepare_x11 ( ctx : & EgoContext ) -> Result < Vec < String > , AnyErr > {
241+ fn prepare_x11 ( ctx : & EgoContext , old_xhost : bool ) -> Result < Vec < String > , AnyErr > {
239242 let display = getenv_optional ( "DISPLAY" ) ?;
240243 if display. is_none ( ) {
241244 debug ! ( "X11: DISPLAY not set, skipping" ) ;
242245 return Ok ( vec ! [ ] ) ;
243246 }
244247
245- let grant = format ! ( "+si:localuser:{}" , ctx. target_user) ;
246- run_command ( "xhost" , & [ grant] ) ?;
248+ if old_xhost {
249+ warn ! ( "--old-xhost is deprecated. If there are issues with the new method, please report a bug." ) ;
250+ let grant = format ! ( "+si:localuser:{}" , ctx. target_user) ;
251+ run_command ( "xhost" , & [ grant] ) ?;
252+ } else {
253+ x11_add_acl ( "localuser" , & ctx. target_user ) ?;
254+ }
247255 // TODO should also test /tmp/.X11-unix/X0 permissions?
248256
249257 Ok ( vec ! [ format!( "DISPLAY={}" , display. unwrap( ) ) ] )
0 commit comments