Returns (physical_w, physical_h). Caller's `width`/`height` are *logical*; on a HiDPI X11 display we multiply by the monitor's scale factor so the window appears the right size while its surface is at the screen's physical resolution. `headless = true` keeps the X11 window + Vulkan surface alive (wgpu needs a surface) but never maps the window — so it never appears on screen and never steals focu
(width: f64, height: f64, title: &str, headless: bool)
| 141 | /// appears on screen and never steals focus. Mirrors the macOS |
| 142 | /// BLOOM_HEADLESS path for batch / CI rendering harnesses. |
| 143 | pub fn create_window(width: f64, height: f64, title: &str, headless: bool) -> (u32, u32) { |
| 144 | unsafe { |
| 145 | HEADLESS = headless; |
| 146 | DISPLAY = x11::xlib::XOpenDisplay(std::ptr::null()); |
| 147 | if DISPLAY.is_null() { |
| 148 | panic!("Failed to open X11 display"); |
| 149 | } |
| 150 | |
| 151 | let screen = x11::xlib::XDefaultScreen(DISPLAY); |
| 152 | let root = x11::xlib::XRootWindow(DISPLAY, screen); |
| 153 | |
| 154 | let scale = display_scale(DISPLAY, screen); |
| 155 | let phys_w = (width * scale).round() as u32; |
| 156 | let phys_h = (height * scale).round() as u32; |
| 157 | |
| 158 | // Off-screen origin is belt-and-braces: even if some WM |
| 159 | // chooses to map the window despite us never calling |
| 160 | // XMapWindow, it'll appear far off the visible desktop. |
| 161 | let origin_x: i32 = if headless { -20000 } else { 0 }; |
| 162 | X11_WINDOW = x11::xlib::XCreateSimpleWindow( |
| 163 | DISPLAY, root, |
| 164 | origin_x, 0, phys_w, phys_h, 0, |
| 165 | x11::xlib::XBlackPixel(DISPLAY, screen), |
| 166 | x11::xlib::XWhitePixel(DISPLAY, screen), |
| 167 | ); |
| 168 | |
| 169 | let title_cstr = std::ffi::CString::new(title).unwrap(); |
| 170 | x11::xlib::XStoreName(DISPLAY, X11_WINDOW, title_cstr.as_ptr()); |
| 171 | |
| 172 | x11::xlib::XSelectInput(DISPLAY, X11_WINDOW, |
| 173 | x11::xlib::ExposureMask | x11::xlib::KeyPressMask | x11::xlib::KeyReleaseMask | |
| 174 | x11::xlib::ButtonPressMask | x11::xlib::ButtonReleaseMask | |
| 175 | x11::xlib::PointerMotionMask | x11::xlib::StructureNotifyMask); |
| 176 | |
| 177 | if !headless { |
| 178 | x11::xlib::XMapWindow(DISPLAY, X11_WINDOW); |
| 179 | } |
| 180 | x11::xlib::XFlush(DISPLAY); |
| 181 | (phys_w, phys_h) |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | pub fn set_no_fullscreen(no_fs: bool) { unsafe { NO_FULLSCREEN = no_fs; } } |
| 186 | pub fn is_headless() -> bool { unsafe { HEADLESS } } |
no test coverage detected