diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index ff486efbd43..cfbed72075e 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -39,6 +39,8 @@ use std::mem; use std::os::raw::c_void; use std::ptr; use std::rc::Rc; +use std::thread; +use std::time; use style_traits::DevicePixel; use style_traits::cursor::Cursor; #[cfg(target_os = "windows")] @@ -684,7 +686,13 @@ impl Window { close_event = self.handle_window_event(event) || close_event; } } - WindowKind::Headless(..) => {} + WindowKind::Headless(..) => { + // Sleep the main thread to avoid using 100% CPU + // This can be done better, see comments in #18777 + if events.is_empty() { + thread::sleep(time::Duration::from_millis(5)); + } + } } } else { close_event = self.handle_next_event();