mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
Remove the is_closed function
This commit is contained in:
parent
eb73c2514e
commit
39128dd7e1
10
README.md
10
README.md
|
@ -49,12 +49,14 @@ fn main() {
|
||||||
gl::ClearColor(0.0, 1.0, 0.0, 1.0);
|
gl::ClearColor(0.0, 1.0, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
while !window.is_closed() {
|
for event in window.wait_events() {
|
||||||
window.wait_events();
|
|
||||||
|
|
||||||
unsafe { gl::Clear(gl::COLOR_BUFFER_BIT) };
|
unsafe { gl::Clear(gl::COLOR_BUFFER_BIT) };
|
||||||
|
|
||||||
window.swap_buffers();
|
window.swap_buffers();
|
||||||
|
|
||||||
|
match event {
|
||||||
|
glutin::Event::Closed => break,
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -25,25 +25,22 @@ fn main() {
|
||||||
let cursors = [MouseCursor::Default, MouseCursor::Crosshair, MouseCursor::Hand, MouseCursor::Arrow, MouseCursor::Move, MouseCursor::Text, MouseCursor::Wait, MouseCursor::Help, MouseCursor::Progress, MouseCursor::NotAllowed, MouseCursor::ContextMenu, MouseCursor::NoneCursor, MouseCursor::Cell, MouseCursor::VerticalText, MouseCursor::Alias, MouseCursor::Copy, MouseCursor::NoDrop, MouseCursor::Grab, MouseCursor::Grabbing, MouseCursor::AllScroll, MouseCursor::ZoomIn, MouseCursor::ZoomOut, MouseCursor::EResize, MouseCursor::NResize, MouseCursor::NeResize, MouseCursor::NwResize, MouseCursor::SResize, MouseCursor::SeResize, MouseCursor::SwResize, MouseCursor::WResize, MouseCursor::EwResize, MouseCursor::NsResize, MouseCursor::NeswResize, MouseCursor::NwseResize, MouseCursor::ColResize, MouseCursor::RowResize];
|
let cursors = [MouseCursor::Default, MouseCursor::Crosshair, MouseCursor::Hand, MouseCursor::Arrow, MouseCursor::Move, MouseCursor::Text, MouseCursor::Wait, MouseCursor::Help, MouseCursor::Progress, MouseCursor::NotAllowed, MouseCursor::ContextMenu, MouseCursor::NoneCursor, MouseCursor::Cell, MouseCursor::VerticalText, MouseCursor::Alias, MouseCursor::Copy, MouseCursor::NoDrop, MouseCursor::Grab, MouseCursor::Grabbing, MouseCursor::AllScroll, MouseCursor::ZoomIn, MouseCursor::ZoomOut, MouseCursor::EResize, MouseCursor::NResize, MouseCursor::NeResize, MouseCursor::NwResize, MouseCursor::SResize, MouseCursor::SeResize, MouseCursor::SwResize, MouseCursor::WResize, MouseCursor::EwResize, MouseCursor::NsResize, MouseCursor::NeswResize, MouseCursor::NwseResize, MouseCursor::ColResize, MouseCursor::RowResize];
|
||||||
let mut cursor_idx = 0;
|
let mut cursor_idx = 0;
|
||||||
|
|
||||||
while !window.is_closed() {
|
for event in window.wait_events() {
|
||||||
context.draw_frame((0.0, 1.0, 0.0, 1.0));
|
match event {
|
||||||
window.swap_buffers();
|
Event::KeyboardInput(ElementState::Pressed, _, _) => {
|
||||||
|
println!("Setting cursor to \"{:?}\"", cursors[cursor_idx]);
|
||||||
for event in window.wait_events() {
|
window.set_cursor(cursors[cursor_idx]);
|
||||||
match event {
|
if cursor_idx < cursors.len() - 1 {
|
||||||
Event::KeyboardInput(ElementState::Pressed, _, _) => {
|
cursor_idx += 1;
|
||||||
println!("Setting cursor to \"{:?}\"", cursors[cursor_idx]);
|
} else {
|
||||||
window.set_cursor(cursors[cursor_idx]);
|
cursor_idx = 0;
|
||||||
if cursor_idx < cursors.len() - 1 {
|
}
|
||||||
cursor_idx += 1;
|
},
|
||||||
} else {
|
Event::Closed => break,
|
||||||
cursor_idx = 0;
|
_ => (),
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.draw_frame((0.0, 1.0, 0.0, 1.0));
|
||||||
|
window.swap_buffers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,10 +46,15 @@ fn main() {
|
||||||
|
|
||||||
let context = support::load(&window);
|
let context = support::load(&window);
|
||||||
|
|
||||||
while !window.is_closed() {
|
for event in window.wait_events() {
|
||||||
context.draw_frame((0.0, 1.0, 0.0, 1.0));
|
context.draw_frame((0.0, 1.0, 0.0, 1.0));
|
||||||
window.swap_buffers();
|
window.swap_buffers();
|
||||||
|
|
||||||
println!("{:?}", window.wait_events().next());
|
println!("{:?}", event);
|
||||||
|
|
||||||
|
match event {
|
||||||
|
glutin::Event::Closed => break,
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,33 +23,29 @@ fn main() {
|
||||||
let context = support::load(&window);
|
let context = support::load(&window);
|
||||||
let mut grabbed = false;
|
let mut grabbed = false;
|
||||||
|
|
||||||
while !window.is_closed() {
|
for event in window.poll_events() {
|
||||||
context.draw_frame((0.0, 1.0, 0.0, 1.0));
|
match event {
|
||||||
window.swap_buffers();
|
Event::KeyboardInput(ElementState::Pressed, _, _) => {
|
||||||
|
if grabbed {
|
||||||
|
grabbed = false;
|
||||||
|
window.set_cursor_state(glutin::CursorState::Normal)
|
||||||
|
.ok().expect("could not ungrab mouse cursor");
|
||||||
|
} else {
|
||||||
|
grabbed = true;
|
||||||
|
window.set_cursor_state(glutin::CursorState::Grab)
|
||||||
|
.ok().expect("could not grab mouse cursor");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
for event in window.poll_events() {
|
a @ Event::MouseMoved(_) => {
|
||||||
match event {
|
println!("{:?}", a);
|
||||||
Event::KeyboardInput(ElementState::Pressed, _, _) => {
|
},
|
||||||
if grabbed {
|
|
||||||
grabbed = false;
|
|
||||||
window.set_cursor_state(glutin::CursorState::Normal)
|
|
||||||
.ok().expect("could not ungrab mouse cursor");
|
|
||||||
} else {
|
|
||||||
grabbed = true;
|
|
||||||
window.set_cursor_state(glutin::CursorState::Grab)
|
|
||||||
.ok().expect("could not grab mouse cursor");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
a @ Event::MouseMoved(_) => {
|
|
||||||
println!("{:?}", a);
|
|
||||||
},
|
|
||||||
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.draw_frame((0.0, 1.0, 0.0, 1.0));
|
||||||
|
window.swap_buffers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,13 @@ fn run(window: glutin::Window, color: (f32, f32, f32, f32)) {
|
||||||
|
|
||||||
let context = support::load(&window);
|
let context = support::load(&window);
|
||||||
|
|
||||||
while !window.is_closed() {
|
for event in window.wait_events() {
|
||||||
context.draw_frame(color);
|
context.draw_frame(color);
|
||||||
window.swap_buffers();
|
window.swap_buffers();
|
||||||
|
|
||||||
window.wait_events().next();
|
match event {
|
||||||
|
glutin::Event::Closed => break,
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,15 @@ fn main() {
|
||||||
|
|
||||||
let context = support::load(&window);
|
let context = support::load(&window);
|
||||||
|
|
||||||
while !window.is_closed() {
|
for event in window.wait_events() {
|
||||||
context.draw_frame((0.0, 0.0, 0.0, 0.0));
|
context.draw_frame((0.0, 0.0, 0.0, 0.0));
|
||||||
window.swap_buffers();
|
window.swap_buffers();
|
||||||
|
|
||||||
println!("{:?}", window.wait_events().next());
|
println!("{:?}", event);
|
||||||
|
|
||||||
|
match event {
|
||||||
|
glutin::Event::Closed => break,
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate android_glue;
|
|
||||||
|
|
||||||
extern crate clock_ticks;
|
|
||||||
extern crate glutin;
|
|
||||||
|
|
||||||
mod support;
|
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
android_start!(main);
|
|
||||||
|
|
||||||
#[cfg(not(feature = "window"))]
|
|
||||||
fn main() { println!("This example requires glutin to be compiled with the `window` feature"); }
|
|
||||||
|
|
||||||
#[cfg(feature = "window")]
|
|
||||||
fn resize_callback(width: u32, height: u32) {
|
|
||||||
println!("Window resized to {}x{}", width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "window")]
|
|
||||||
fn main() {
|
|
||||||
println!("Vsync example. This example may panic if your driver or your system forces \
|
|
||||||
you out of vsync. This is intended when `build_strict` is used.");
|
|
||||||
|
|
||||||
let mut window = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility)
|
|
||||||
.with_vsync()
|
|
||||||
.build_strict().unwrap();
|
|
||||||
window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
|
|
||||||
unsafe { window.make_current() };
|
|
||||||
|
|
||||||
let context = support::load(&window);
|
|
||||||
|
|
||||||
while !window.is_closed() {
|
|
||||||
let before = clock_ticks::precise_time_ns();
|
|
||||||
|
|
||||||
context.draw_frame((0.0, 1.0, 0.0, 1.0));
|
|
||||||
window.swap_buffers();
|
|
||||||
|
|
||||||
for ev in window.poll_events() {
|
|
||||||
println!("{:?}", ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
let after = clock_ticks::precise_time_ns();
|
|
||||||
println!("Vsync example - Time of previous frame: {}ms",
|
|
||||||
(after - before) as f32 / 1000000.0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,10 +28,15 @@ fn main() {
|
||||||
|
|
||||||
let context = support::load(&window);
|
let context = support::load(&window);
|
||||||
|
|
||||||
while !window.is_closed() {
|
for event in window.wait_events() {
|
||||||
context.draw_frame((0.0, 1.0, 0.0, 1.0));
|
context.draw_frame((0.0, 1.0, 0.0, 1.0));
|
||||||
window.swap_buffers();
|
window.swap_buffers();
|
||||||
|
|
||||||
println!("{:?}", window.wait_events().next());
|
println!("{:?}", event);
|
||||||
|
|
||||||
|
match event {
|
||||||
|
glutin::Event::Closed => break,
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,10 +129,6 @@ impl Window {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_closed(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_title(&self, title: &str) {
|
pub fn set_title(&self, title: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,6 @@ static mut win_pressed: bool = false;
|
||||||
static mut alt_pressed: bool = false;
|
static mut alt_pressed: bool = false;
|
||||||
|
|
||||||
struct DelegateState {
|
struct DelegateState {
|
||||||
is_closed: bool,
|
|
||||||
context: IdRef,
|
context: IdRef,
|
||||||
view: IdRef,
|
view: IdRef,
|
||||||
window: IdRef,
|
window: IdRef,
|
||||||
|
@ -83,8 +82,6 @@ impl WindowDelegate {
|
||||||
unsafe {
|
unsafe {
|
||||||
let state: *mut libc::c_void = *this.get_ivar("glutinState");
|
let state: *mut libc::c_void = *this.get_ivar("glutinState");
|
||||||
let state = state as *mut DelegateState;
|
let state = state as *mut DelegateState;
|
||||||
(*state).is_closed = true;
|
|
||||||
|
|
||||||
(*state).pending_events.lock().unwrap().push_back(Closed);
|
(*state).pending_events.lock().unwrap().push_back(Closed);
|
||||||
}
|
}
|
||||||
YES
|
YES
|
||||||
|
@ -366,7 +363,6 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
let ds = DelegateState {
|
let ds = DelegateState {
|
||||||
is_closed: false,
|
|
||||||
context: context.clone(),
|
context: context.clone(),
|
||||||
view: view.clone(),
|
view: view.clone(),
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
|
@ -588,10 +584,6 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_closed(&self) -> bool {
|
|
||||||
self.delegate.state.is_closed
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_title(&self, title: &str) {
|
pub fn set_title(&self, title: &str) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let title = IdRef::new(NSString::alloc(nil).init_str(title));
|
let title = IdRef::new(NSString::alloc(nil).init_str(title));
|
||||||
|
|
|
@ -108,11 +108,6 @@ impl Window {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_closed(&self) -> bool {
|
|
||||||
use std::ptr;
|
|
||||||
unsafe { ffi::emscripten_is_webgl_context_lost(ptr::null()) != 0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_title(&self, _title: &str) {
|
pub fn set_title(&self, _title: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,11 +184,6 @@ impl Window {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_closed(&self) -> bool {
|
|
||||||
// TODO
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_title(&self, title: &str) {
|
pub fn set_title(&self, title: &str) {
|
||||||
let ctitle = CString::new(title).unwrap();
|
let ctitle = CString::new(title).unwrap();
|
||||||
self.shell_surface.set_title(&ctitle);
|
self.shell_surface.set_title(&ctitle);
|
||||||
|
|
|
@ -257,7 +257,6 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
|
||||||
window: real_window,
|
window: real_window,
|
||||||
context: context,
|
context: context,
|
||||||
events_receiver: events_receiver,
|
events_receiver: events_receiver,
|
||||||
is_closed: AtomicBool::new(false),
|
|
||||||
cursor_state: cursor_state,
|
cursor_state: cursor_state,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,6 @@ pub struct Window {
|
||||||
/// Receiver for the events dispatched by the window callback.
|
/// Receiver for the events dispatched by the window callback.
|
||||||
events_receiver: Receiver<Event>,
|
events_receiver: Receiver<Event>,
|
||||||
|
|
||||||
/// True if a `Closed` event has been received.
|
|
||||||
is_closed: AtomicBool,
|
|
||||||
|
|
||||||
/// The current cursor state.
|
/// The current cursor state.
|
||||||
cursor_state: Arc<Mutex<CursorState>>,
|
cursor_state: Arc<Mutex<CursorState>>,
|
||||||
}
|
}
|
||||||
|
@ -97,12 +94,6 @@ impl Window {
|
||||||
init::new_window(builder, sharing)
|
init::new_window(builder, sharing)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See the docs in the crate root file.
|
|
||||||
pub fn is_closed(&self) -> bool {
|
|
||||||
use std::sync::atomic::Ordering::Relaxed;
|
|
||||||
self.is_closed.load(Relaxed)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// See the docs in the crate root file.
|
/// See the docs in the crate root file.
|
||||||
///
|
///
|
||||||
/// Calls SetWindowText on the HWND.
|
/// Calls SetWindowText on the HWND.
|
||||||
|
@ -366,17 +357,7 @@ impl<'a> Iterator for PollEventsIterator<'a> {
|
||||||
type Item = Event;
|
type Item = Event;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Event> {
|
fn next(&mut self) -> Option<Event> {
|
||||||
use events::Event::Closed;
|
self.window.events_receiver.try_recv().ok()
|
||||||
|
|
||||||
match self.window.events_receiver.try_recv() {
|
|
||||||
Ok(Closed) => {
|
|
||||||
use std::sync::atomic::Ordering::Relaxed;
|
|
||||||
self.window.is_closed.store(true, Relaxed);
|
|
||||||
Some(Closed)
|
|
||||||
},
|
|
||||||
Ok(ev) => Some(ev),
|
|
||||||
Err(_) => None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,17 +369,7 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
|
||||||
type Item = Event;
|
type Item = Event;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Event> {
|
fn next(&mut self) -> Option<Event> {
|
||||||
use events::Event::Closed;
|
self.window.events_receiver.recv().ok()
|
||||||
|
|
||||||
match self.window.events_receiver.recv() {
|
|
||||||
Ok(Closed) => {
|
|
||||||
use std::sync::atomic::Ordering::Relaxed;
|
|
||||||
self.window.is_closed.store(true, Relaxed);
|
|
||||||
Some(Closed)
|
|
||||||
},
|
|
||||||
Ok(ev) => Some(ev),
|
|
||||||
Err(_) => None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -263,9 +263,10 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
|
||||||
type Item = Event;
|
type Item = Event;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Event> {
|
fn next(&mut self) -> Option<Event> {
|
||||||
|
use std::sync::atomic::Ordering::Relaxed;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
while !self.window.is_closed() {
|
while !self.window.is_closed.load(Relaxed) {
|
||||||
if let Some(ev) = self.window.pending_events.lock().unwrap().pop_front() {
|
if let Some(ev) = self.window.pending_events.lock().unwrap().pop_front() {
|
||||||
return Some(ev);
|
return Some(ev);
|
||||||
}
|
}
|
||||||
|
@ -596,11 +597,6 @@ impl Window {
|
||||||
Ok(window)
|
Ok(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_closed(&self) -> bool {
|
|
||||||
use std::sync::atomic::Ordering::Relaxed;
|
|
||||||
self.is_closed.load(Relaxed)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_title(&self, title: &str) {
|
pub fn set_title(&self, title: &str) {
|
||||||
with_c_str(title, |title| unsafe {
|
with_c_str(title, |title| unsafe {
|
||||||
(self.x.display.xlib.XStoreName)(self.x.display.display, self.x.window, title);
|
(self.x.display.xlib.XStoreName)(self.x.display.display, self.x.window, title);
|
||||||
|
|
|
@ -154,13 +154,6 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_closed(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.is_closed(),
|
|
||||||
&Window::Wayland(ref w) => w.is_closed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_title(&self, title: &str) {
|
pub fn set_title(&self, title: &str) {
|
||||||
match self {
|
match self {
|
||||||
&Window::X(ref w) => w.set_title(title),
|
&Window::X(ref w) => w.set_title(title),
|
||||||
|
|
|
@ -224,12 +224,6 @@ impl Window {
|
||||||
builder.build()
|
builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the window has previously been closed by the user.
|
|
||||||
#[inline]
|
|
||||||
pub fn is_closed(&self) -> bool {
|
|
||||||
self.window.is_closed()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Modifies the title of the window.
|
/// Modifies the title of the window.
|
||||||
///
|
///
|
||||||
/// This is a no-op if the window has already been closed.
|
/// This is a no-op if the window has already been closed.
|
||||||
|
|
Loading…
Reference in a new issue