/// Attempt to connect to a wayland server using the contents of the environment variables
///
/// First of all, if the `WAYLAND_SOCKET` environment variable is set, it'll try to interpret
/// it as a FD number to use
///
/// Otherwise, it will try to connect to the socket name defined in the `WAYLAND_DISPLAY`
/// environment variable, and error if it is not set.
///
/// On success, you are given the `Display` object as well as the main `EventQueue` hosting
/// the `WlDisplay` wayland object.
///
/// This requires the `XDG_RUNTIME_DIR` variable to be properly set.
Attempt to connect to a wayland server using the contents of the environment variables
First of all, if the `WAYLAND_SOCKET` environment variable is set, it'll try to interpret
it as a FD number to use

Otherwise, it will try to connect to the socket name defined in the `WAYLAND_DISPLAY`
environment variable, and error if it is not set.



This requires the `XDG_RUNTIME_DIR` variable to be properly set.
Attempt to connect to a wayland server using the contents of the environment variables First of all if the ` WAYLAND_SOCKET ` environment variable is set it ' ll try to interpret it as a FD number to use Otherwise it will try to connect to the socket name defined in the ` WAYLAND_DISPLAY ` environment variable and error if it is not set . This requires the ` XDG_RUNTIME_DIR ` variable to be properly set .
pub fn connect_to_env() -> Result<(Display, EventQueue), ConnectError> {
        if let Ok(txt) = env::var("WAYLAND_SOCKET") {
            // We should connect to the provided WAYLAND_SOCKET
            let fd = txt.parse::<i32>().map_err(|_| ConnectError::InvalidFd)?;
            // set the CLOEXEC flag on this FD
            let flags = fcntl::fcntl(fd, fcntl::FcntlArg::F_GETFD);
            let result = flags
                .map(|f| fcntl::FdFlag::from_bits(f).unwrap() | fcntl::FdFlag::FD_CLOEXEC)
                .and_then(|f| fcntl::fcntl(fd, fcntl::FcntlArg::F_SETFD(f)));
            match result {
                Ok(_) => {
                    // setting the O_CLOEXEC worked
                    unsafe { Display::from_fd(fd) }
                }
                Err(_) => {
                    // something went wrong in F_GETFD or F_SETFD
                    let _ = ::nix::unistd::close(fd);
                    return Err(ConnectError::InvalidFd);
                }
            }
        } else {
            let mut socket_path = env::var_os("XDG_RUNTIME_DIR")
                .map(Into::<PathBuf>::into)
                .ok_or(ConnectError::XdgRuntimeDirNotSet)?;
            socket_path.push(env::var_os("WAYLAND_DISPLAY").ok_or(ConnectError::NoCompositorListening)?);
            let socket = UnixStream::connect(socket_path).map_err(|_| ConnectError::NoCompositorListening)?;
            unsafe { Display::from_fd(socket.into_raw_fd()) }
        }
    }
pub fn connect_to_env ( ) -> Result < ( Display , EventQueue ) , ConnectError > { if let Ok ( txt ) = env :: var ( " " ) { // We should connect to the provided WAYLAND_SOCKET let fd = txt . parse :: < i32 > ( ) . map_err ( | _ | ConnectError :: InvalidFd ) ? ; // set the CLOEXEC flag on this FD let flags = fcntl :: fcntl ( fd , fcntl :: FcntlArg :: F_GETFD ) ; let result = flags . map ( | f | fcntl :: FdFlag :: from_bits ( f ) . unwrap ( ) | fcntl :: FdFlag :: FD_CLOEXEC ) . and_then ( | f | fcntl :: fcntl ( fd , fcntl :: FcntlArg :: F_SETFD ( f ) ) ) ; match result { Ok ( _ ) => { // setting the O_CLOEXEC worked unsafe { Display :: from_fd ( fd ) } } Err ( _ ) => { // something went wrong in F_GETFD or F_SETFD let _ = :: nix :: unistd :: close ( fd ) ; return Err ( ConnectError :: InvalidFd ) ; } } } else { let mut socket_path = env :: var_os ( " " ) . map ( Into :: < PathBuf > :: into ) . ok_or ( ConnectError :: XdgRuntimeDirNotSet ) ? ; socket_path . push ( env :: var_os ( " " ) . ok_or ( ConnectError :: NoCompositorListening ) ? ) ; let socket = UnixStream :: connect ( socket_path ) . map_err ( | _ | ConnectError :: NoCompositorListening ) ? ; unsafe { Display :: from_fd ( socket . into_raw_fd ( ) ) } } }
Attempt to connect to a wayland server using the contents of the environment variables
First of all, if the `WAYLAND_SOCKET` environment variable is set, it'll try to interpret
it as a FD number to use
Attempt to connect to a wayland server using the contents of the environment variables First of all if the ` WAYLAND_SOCKET ` environment variable is set it ' ll try to interpret it as a FD number to use