mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-29 04:40:04 -04:00
Change instances of "events_loop" to "event_loop"
This commit is contained in:
@@ -5,14 +5,14 @@ use winit::event::{Event, WindowEvent, ElementState, KeyboardInput};
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let window = WindowBuilder::new().build(&events_loop).unwrap();
|
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
||||||
window.set_title("A fantastic window!");
|
window.set_title("A fantastic window!");
|
||||||
|
|
||||||
let mut cursor_idx = 0;
|
let mut cursor_idx = 0;
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event: WindowEvent::KeyboardInput { input: KeyboardInput { state: ElementState::Pressed, .. }, .. }, .. } => {
|
Event::WindowEvent { event: WindowEvent::KeyboardInput { input: KeyboardInput { state: ElementState::Pressed, .. }, .. }, .. } => {
|
||||||
println!("Setting cursor to \"{:?}\"", CURSORS[cursor_idx]);
|
println!("Setting cursor to \"{:?}\"", CURSORS[cursor_idx]);
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ use winit::event::{Event, WindowEvent, ElementState, KeyboardInput};
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
|
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
if let Event::WindowEvent { event, .. } = event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
match event {
|
match event {
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ use winit::event::{Event, WindowEvent, VirtualKeyCode, ElementState, KeyboardInp
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
// enumerating monitors
|
// enumerating monitors
|
||||||
let monitor = {
|
let monitor = {
|
||||||
for (num, monitor) in events_loop.get_available_monitors().enumerate() {
|
for (num, monitor) in event_loop.get_available_monitors().enumerate() {
|
||||||
println!("Monitor #{}: {:?}", num, monitor.get_name());
|
println!("Monitor #{}: {:?}", num, monitor.get_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ fn main() {
|
|||||||
let mut num = String::new();
|
let mut num = String::new();
|
||||||
io::stdin().read_line(&mut num).unwrap();
|
io::stdin().read_line(&mut num).unwrap();
|
||||||
let num = num.trim().parse().ok().expect("Please enter a number");
|
let num = num.trim().parse().ok().expect("Please enter a number");
|
||||||
let monitor = events_loop.get_available_monitors().nth(num).expect("Please enter a valid ID");
|
let monitor = event_loop.get_available_monitors().nth(num).expect("Please enter a valid ID");
|
||||||
|
|
||||||
println!("Using {:?}", monitor.get_name());
|
println!("Using {:?}", monitor.get_name());
|
||||||
|
|
||||||
@@ -30,14 +30,14 @@ fn main() {
|
|||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_title("Hello world!")
|
.with_title("Hello world!")
|
||||||
.with_fullscreen(Some(monitor))
|
.with_fullscreen(Some(monitor))
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut is_fullscreen = true;
|
let mut is_fullscreen = true;
|
||||||
let mut is_maximized = false;
|
let mut is_maximized = false;
|
||||||
let mut decorations = true;
|
let mut decorations = true;
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,16 @@ use winit::event::{Event, WindowEvent, KeyboardInput};
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let _window = WindowBuilder::new()
|
let _window = WindowBuilder::new()
|
||||||
.with_title("Your faithful window")
|
.with_title("Your faithful window")
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut close_requested = false;
|
let mut close_requested = false;
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
use winit::event::ElementState::Released;
|
use winit::event::ElementState::Released;
|
||||||
use winit::event::VirtualKeyCode::{N, Y};
|
use winit::event::VirtualKeyCode::{N, Y};
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ use winit::event::{Event, WindowEvent};
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
window.set_min_dimensions(Some(LogicalSize::new(400.0, 200.0)));
|
window.set_min_dimensions(Some(LogicalSize::new(400.0, 200.0)));
|
||||||
window.set_max_dimensions(Some(LogicalSize::new(800.0, 400.0)));
|
window.set_max_dimensions(Some(LogicalSize::new(800.0, 400.0)));
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ use winit::event::{Event, WindowEvent, ElementState, KeyboardInput};
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let mut windows = HashMap::new();
|
let mut windows = HashMap::new();
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
let window = Window::new(&events_loop).unwrap();
|
let window = Window::new(&event_loop).unwrap();
|
||||||
windows.insert(window.id(), window);
|
windows.insert(window.id(), window);
|
||||||
}
|
}
|
||||||
|
|
||||||
events_loop.run(move |event, events_loop, control_flow| {
|
event_loop.run(move |event, event_loop, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, window_id } => {
|
Event::WindowEvent { event, window_id } => {
|
||||||
@@ -30,7 +30,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
WindowEvent::KeyboardInput { input: KeyboardInput { state: ElementState::Pressed, .. }, .. } => {
|
WindowEvent::KeyboardInput { input: KeyboardInput { state: ElementState::Pressed, .. }, .. } => {
|
||||||
let window = Window::new(&events_loop).unwrap();
|
let window = Window::new(&event_loop).unwrap();
|
||||||
windows.insert(window.id(), window);
|
windows.insert(window.id(), window);
|
||||||
},
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
|
|||||||
@@ -4,18 +4,18 @@ use winit::event::{Event, WindowEvent};
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop: EventLoop<i32> = EventLoop::new_user_event();
|
let event_loop: EventLoop<i32> = EventLoop::new_user_event();
|
||||||
|
|
||||||
let _window = WindowBuilder::new()
|
let _window = WindowBuilder::new()
|
||||||
.with_title("A fantastic window!")
|
.with_title("A fantastic window!")
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let proxy = events_loop.create_proxy();
|
let proxy = event_loop.create_proxy();
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
// Wake up the `events_loop` once every second.
|
// Wake up the `event_loop` once every second.
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
proxy.send_event(counter).unwrap();
|
proxy.send_event(counter).unwrap();
|
||||||
@@ -23,7 +23,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
|
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ use winit::event::{Event, WindowEvent};
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_title("A fantastic window!")
|
.with_title("A fantastic window!")
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use winit::event::{Event, WindowEvent, VirtualKeyCode, ElementState, KeyboardInp
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let mut resizable = false;
|
let mut resizable = false;
|
||||||
|
|
||||||
@@ -12,10 +12,10 @@ fn main() {
|
|||||||
.with_title("Hit space to toggle resizability.")
|
.with_title("Hit space to toggle resizability.")
|
||||||
.with_dimensions((400, 200).into())
|
.with_dimensions((400, 200).into())
|
||||||
.with_resizable(resizable)
|
.with_resizable(resizable)
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ use winit::event::{Event, WindowEvent, StartCause};
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let _window = WindowBuilder::new()
|
let _window = WindowBuilder::new()
|
||||||
.with_title("A fantastic window!")
|
.with_title("A fantastic window!")
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ use winit::event::{Event, WindowEvent};
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let window = WindowBuilder::new().with_decorations(false)
|
let window = WindowBuilder::new().with_decorations(false)
|
||||||
.with_transparency(true)
|
.with_transparency(true)
|
||||||
.build(&events_loop).unwrap();
|
.build(&event_loop).unwrap();
|
||||||
|
|
||||||
window.set_title("A fantastic window!");
|
window.set_title("A fantastic window!");
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ use winit::event::{Event, WindowEvent};
|
|||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let _window = WindowBuilder::new()
|
let _window = WindowBuilder::new()
|
||||||
.with_title("A fantastic window!")
|
.with_title("A fantastic window!")
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
events_loop.run(|event, _, control_flow| {
|
event_loop.run(|event, _, control_flow| {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
|||||||
@@ -23,17 +23,17 @@ fn main() {
|
|||||||
// feature enabled).
|
// feature enabled).
|
||||||
let icon = Icon::from_path(path).expect("Failed to open icon");
|
let icon = Icon::from_path(path).expect("Failed to open icon");
|
||||||
|
|
||||||
let events_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_title("An iconic window!")
|
.with_title("An iconic window!")
|
||||||
// At present, this only does anything on Windows and X11, so if you want to save load
|
// At present, this only does anything on Windows and X11, so if you want to save load
|
||||||
// time, you can put icon loading behind a function that returns `None` on other platforms.
|
// time, you can put icon loading behind a function that returns `None` on other platforms.
|
||||||
.with_window_icon(Some(icon))
|
.with_window_icon(Some(icon))
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
events_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
if let Event::WindowEvent { event, .. } = event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
use winit::event::WindowEvent::*;
|
use winit::event::WindowEvent::*;
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ use winit::event_loop::{EventLoop, ControlFlow};
|
|||||||
use winit::platform::desktop::EventLoopExtDesktop;
|
use winit::platform::desktop::EventLoopExtDesktop;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = EventLoop::new();
|
let mut event_loop = EventLoop::new();
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_title("A fantastic window!")
|
.with_title("A fantastic window!")
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("Close the window to continue.");
|
println!("Close the window to continue.");
|
||||||
events_loop.run_return(|event, _, control_flow| {
|
event_loop.run_return(|event, _, control_flow| {
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
@@ -27,11 +27,11 @@ fn main() {
|
|||||||
|
|
||||||
let _window_2 = WindowBuilder::new()
|
let _window_2 = WindowBuilder::new()
|
||||||
.with_title("A second, fantasticer window!")
|
.with_title("A second, fantasticer window!")
|
||||||
.build(&events_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("Wa ha ha! You thought that closing the window would finish this?!");
|
println!("Wa ha ha! You thought that closing the window would finish this?!");
|
||||||
events_loop.run_return(|event, _, control_flow| {
|
event_loop.run_return(|event, _, control_flow| {
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use monitor::{AvailableMonitorsIter, MonitorId};
|
|||||||
/// `Window` created from this `EventLoop` _can_ be sent to an other thread, and the
|
/// `Window` created from this `EventLoop` _can_ be sent to an other thread, and the
|
||||||
/// `EventLoopProxy` allows you to wakeup an `EventLoop` from an other thread.
|
/// `EventLoopProxy` allows you to wakeup an `EventLoop` from an other thread.
|
||||||
pub struct EventLoop<T> {
|
pub struct EventLoop<T> {
|
||||||
pub(crate) events_loop: platform_impl::EventLoop<T>,
|
pub(crate) event_loop: platform_impl::EventLoop<T>,
|
||||||
pub(crate) _marker: ::std::marker::PhantomData<*mut ()> // Not Send nor Sync
|
pub(crate) _marker: ::std::marker::PhantomData<*mut ()> // Not Send nor Sync
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ impl<T> EventLoop<T> {
|
|||||||
/// fallback on x11. If this variable is set with any other value, winit will panic.
|
/// fallback on x11. If this variable is set with any other value, winit will panic.
|
||||||
pub fn new_user_event() -> EventLoop<T> {
|
pub fn new_user_event() -> EventLoop<T> {
|
||||||
EventLoop {
|
EventLoop {
|
||||||
events_loop: platform_impl::EventLoop::new(),
|
event_loop: platform_impl::EventLoop::new(),
|
||||||
_marker: ::std::marker::PhantomData,
|
_marker: ::std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,14 +95,14 @@ impl<T> EventLoop<T> {
|
|||||||
// Note: should be replaced with `-> impl Iterator` once stable.
|
// Note: should be replaced with `-> impl Iterator` once stable.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_available_monitors(&self) -> AvailableMonitorsIter {
|
pub fn get_available_monitors(&self) -> AvailableMonitorsIter {
|
||||||
let data = self.events_loop.get_available_monitors();
|
let data = self.event_loop.get_available_monitors();
|
||||||
AvailableMonitorsIter{ data: data.into_iter() }
|
AvailableMonitorsIter{ data: data.into_iter() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the primary monitor of the system.
|
/// Returns the primary monitor of the system.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_primary_monitor(&self) -> MonitorId {
|
pub fn get_primary_monitor(&self) -> MonitorId {
|
||||||
MonitorId { inner: self.events_loop.get_primary_monitor() }
|
MonitorId { inner: self.event_loop.get_primary_monitor() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hijacks the calling thread and initializes the `winit` event loop with the provided
|
/// Hijacks the calling thread and initializes the `winit` event loop with the provided
|
||||||
@@ -114,14 +114,14 @@ impl<T> EventLoop<T> {
|
|||||||
pub fn run<F>(self, event_handler: F) -> !
|
pub fn run<F>(self, event_handler: F) -> !
|
||||||
where F: 'static + FnMut(Event<T>, &EventLoop<T>, &mut ControlFlow)
|
where F: 'static + FnMut(Event<T>, &EventLoop<T>, &mut ControlFlow)
|
||||||
{
|
{
|
||||||
self.events_loop.run(event_handler)
|
self.event_loop.run(event_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an `EventLoopProxy` that can be used to wake up the `EventLoop` from another
|
/// Creates an `EventLoopProxy` that can be used to wake up the `EventLoop` from another
|
||||||
/// thread.
|
/// thread.
|
||||||
pub fn create_proxy(&self) -> EventLoopProxy<T> {
|
pub fn create_proxy(&self) -> EventLoopProxy<T> {
|
||||||
EventLoopProxy {
|
EventLoopProxy {
|
||||||
events_loop_proxy: self.events_loop.create_proxy(),
|
event_loop_proxy: self.event_loop.create_proxy(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ impl<T> EventLoop<T> {
|
|||||||
/// Used to send custom events to `EventLoop`.
|
/// Used to send custom events to `EventLoop`.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EventLoopProxy<T> {
|
pub struct EventLoopProxy<T> {
|
||||||
events_loop_proxy: platform_impl::EventLoopProxy<T>,
|
event_loop_proxy: platform_impl::EventLoopProxy<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> EventLoopProxy<T> {
|
impl<T> EventLoopProxy<T> {
|
||||||
@@ -139,7 +139,7 @@ impl<T> EventLoopProxy<T> {
|
|||||||
///
|
///
|
||||||
/// Returns an `Err` if the associated `EventLoop` no longer exists.
|
/// Returns an `Err` if the associated `EventLoop` no longer exists.
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
||||||
self.events_loop_proxy.send_event(event)
|
self.event_loop_proxy.send_event(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/lib.rs
12
src/lib.rs
@@ -7,13 +7,13 @@
|
|||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use winit::event_loop::EventLoop;
|
//! use winit::event_loop::EventLoop;
|
||||||
//! let events_loop = EventLoop::new();
|
//! let event_loop = EventLoop::new();
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Once this is done there are two ways to create a [`Window`]:
|
//! Once this is done there are two ways to create a [`Window`]:
|
||||||
//!
|
//!
|
||||||
//! - Calling [`Window::new(&events_loop)`][window_new].
|
//! - Calling [`Window::new(&event_loop)`][window_new].
|
||||||
//! - Calling [`let builder = WindowBuilder::new()`][window_builder_new] then [`builder.build(&events_loop)`][window_builder_build].
|
//! - Calling [`let builder = WindowBuilder::new()`][window_builder_new] then [`builder.build(&event_loop)`][window_builder_build].
|
||||||
//!
|
//!
|
||||||
//! The first way is the simplest way and will give you default values for everything.
|
//! The first way is the simplest way and will give you default values for everything.
|
||||||
//!
|
//!
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
//! The events generated by a [`Window`] can be retreived from the [`EventLoop`] the [`Window`] was created
|
//! The events generated by a [`Window`] can be retreived from the [`EventLoop`] the [`Window`] was created
|
||||||
//! with.
|
//! with.
|
||||||
//!
|
//!
|
||||||
//! You do this by calling [`events_loop.run(...)`][event_loop_run]. This function will run forever
|
//! You do this by calling [`event_loop.run(...)`][event_loop_run]. This function will run forever
|
||||||
//! unless `control_flow` is set to [`ControlFlow`]`::`[`Exit`], at which point [`Event`]`::`[`LoopDestroyed`]
|
//! unless `control_flow` is set to [`ControlFlow`]`::`[`Exit`], at which point [`Event`]`::`[`LoopDestroyed`]
|
||||||
//! is emitted and the entire program terminates.
|
//! is emitted and the entire program terminates.
|
||||||
//!
|
//!
|
||||||
@@ -36,9 +36,9 @@
|
|||||||
//! use winit::event_loop::ControlFlow;
|
//! use winit::event_loop::ControlFlow;
|
||||||
//! use winit::event::{Event, WindowEvent};
|
//! use winit::event::{Event, WindowEvent};
|
||||||
//! # use winit::event_loop::EventLoop;
|
//! # use winit::event_loop::EventLoop;
|
||||||
//! # let events_loop = EventLoop::new();
|
//! # let event_loop = EventLoop::new();
|
||||||
//!
|
//!
|
||||||
//! events_loop.run(move |event, _, control_flow| {
|
//! event_loop.run(move |event, _, control_flow| {
|
||||||
//! match event {
|
//! match event {
|
||||||
//! Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
//! Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
||||||
//! println!("The close button was pressed; stopping");
|
//! println!("The close button was pressed; stopping");
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ pub trait EventLoopExtAndroid {
|
|||||||
|
|
||||||
impl EventLoopExtAndroid for EventLoop {
|
impl EventLoopExtAndroid for EventLoop {
|
||||||
fn set_suspend_callback(&self, cb: Option<Box<Fn(bool) -> ()>>) {
|
fn set_suspend_callback(&self, cb: Option<Box<Fn(bool) -> ()>>) {
|
||||||
self.events_loop.set_suspend_callback(cb);
|
self.event_loop.set_suspend_callback(cb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ impl<T> EventLoopExtDesktop for EventLoop<T> {
|
|||||||
fn run_return<F>(&mut self, event_handler: F)
|
fn run_return<F>(&mut self, event_handler: F)
|
||||||
where F: FnMut(Event<T>, &EventLoop<T>, &mut ControlFlow)
|
where F: FnMut(Event<T>, &EventLoop<T>, &mut ControlFlow)
|
||||||
{
|
{
|
||||||
self.events_loop.run_return(event_handler)
|
self.event_loop.run_return(event_handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ impl EventLoopExtUnix for EventLoop {
|
|||||||
fn new_x11() -> Result<Self, XNotSupported> {
|
fn new_x11() -> Result<Self, XNotSupported> {
|
||||||
LinuxEventLoop::new_x11().map(|ev|
|
LinuxEventLoop::new_x11().map(|ev|
|
||||||
EventLoop {
|
EventLoop {
|
||||||
events_loop: ev,
|
event_loop: ev,
|
||||||
_marker: ::std::marker::PhantomData,
|
_marker: ::std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -59,7 +59,7 @@ impl EventLoopExtUnix for EventLoop {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn new_wayland() -> Self {
|
fn new_wayland() -> Self {
|
||||||
EventLoop {
|
EventLoop {
|
||||||
events_loop: match LinuxEventLoop::new_wayland() {
|
event_loop: match LinuxEventLoop::new_wayland() {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(_) => panic!() // TODO: propagate
|
Err(_) => panic!() // TODO: propagate
|
||||||
},
|
},
|
||||||
@@ -69,18 +69,18 @@ impl EventLoopExtUnix for EventLoop {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_wayland(&self) -> bool {
|
fn is_wayland(&self) -> bool {
|
||||||
self.events_loop.is_wayland()
|
self.event_loop.is_wayland()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_x11(&self) -> bool {
|
fn is_x11(&self) -> bool {
|
||||||
!self.events_loop.is_wayland()
|
!self.event_loop.is_wayland()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn get_xlib_xconnection(&self) -> Option<Arc<XConnection>> {
|
fn get_xlib_xconnection(&self) -> Option<Arc<XConnection>> {
|
||||||
self.events_loop.x_connection().cloned()
|
self.event_loop.x_connection().cloned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ impl<T> EventLoopExtWindows for EventLoop<T> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn new_dpi_unaware() -> Self {
|
fn new_dpi_unaware() -> Self {
|
||||||
EventLoop {
|
EventLoop {
|
||||||
events_loop: WindowsEventLoop::with_dpi_awareness(false),
|
event_loop: WindowsEventLoop::with_dpi_awareness(false),
|
||||||
_marker: ::std::marker::PhantomData,
|
_marker: ::std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,11 +366,11 @@ fn em_try(res: ffi::EMSCRIPTEN_RESULT) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(events_loop: &EventLoop, attribs: ::WindowAttributes,
|
pub fn new(event_loop: &EventLoop, attribs: ::WindowAttributes,
|
||||||
_pl_attribs: PlatformSpecificWindowBuilderAttributes)
|
_pl_attribs: PlatformSpecificWindowBuilderAttributes)
|
||||||
-> Result<Window, ::CreationError>
|
-> Result<Window, ::CreationError>
|
||||||
{
|
{
|
||||||
if events_loop.window.lock().unwrap().is_some() {
|
if event_loop.window.lock().unwrap().is_some() {
|
||||||
return Err(::CreationError::OsError("Cannot create another window".to_owned()));
|
return Err(::CreationError::OsError("Cannot create another window".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,7 +419,7 @@ impl Window {
|
|||||||
window.set_inner_size(size);
|
window.set_inner_size(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
*events_loop.window.lock().unwrap() = Some(window.window.clone());
|
*event_loop.window.lock().unwrap() = Some(window.window.clone());
|
||||||
Ok(window)
|
Ok(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,9 +613,9 @@ impl Window {
|
|||||||
|
|
||||||
impl Drop for Window {
|
impl Drop for Window {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// Delete window from events_loop
|
// Delete window from event_loop
|
||||||
// TODO: ?
|
// TODO: ?
|
||||||
/*if let Some(ev) = self.events_loop.upgrade() {
|
/*if let Some(ev) = self.event_loop.upgrade() {
|
||||||
let _ = ev.window.lock().unwrap().take().unwrap();
|
let _ = ev.window.lock().unwrap().take().unwrap();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ impl MonitorId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EventsLoop {
|
pub struct EventLoop {
|
||||||
events_queue: Arc<RefCell<VecDeque<Event>>>,
|
events_queue: Arc<RefCell<VecDeque<Event>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ impl EventLoop {
|
|||||||
panic!("`EventLoop` can only be created on the main thread on iOS");
|
panic!("`EventLoop` can only be created on the main thread on iOS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EventsLoop { events_queue: Default::default() }
|
EventLoop { events_queue: Default::default() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -238,7 +238,7 @@ impl EventLoop {
|
|||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// jump hack, so we won't quit on willTerminate event before processing it
|
// jump hack, so we won't quit on willTerminate event before processing it
|
||||||
assert!(JMPBUF.is_some(), "`EventsLoop::poll_events` must be called after window creation on iOS");
|
assert!(JMPBUF.is_some(), "`EventLoop::poll_events` must be called after window creation on iOS");
|
||||||
if setjmp(mem::transmute_copy(&mut JMPBUF)) != 0 {
|
if setjmp(mem::transmute_copy(&mut JMPBUF)) != 0 {
|
||||||
if let Some(event) = self.events_queue.borrow_mut().pop_front() {
|
if let Some(event) = self.events_queue.borrow_mut().pop_front() {
|
||||||
callback(event);
|
callback(event);
|
||||||
|
|||||||
@@ -122,16 +122,16 @@ impl MonitorId {
|
|||||||
impl Window {
|
impl Window {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
events_loop: &EventLoop,
|
event_loop: &EventLoop,
|
||||||
attribs: WindowAttributes,
|
attribs: WindowAttributes,
|
||||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||||
) -> Result<Self, CreationError> {
|
) -> Result<Self, CreationError> {
|
||||||
match *events_loop {
|
match *event_loop {
|
||||||
EventLoop::Wayland(ref events_loop) => {
|
EventLoop::Wayland(ref event_loop) => {
|
||||||
wayland::Window::new(events_loop, attribs).map(Window::Wayland)
|
wayland::Window::new(event_loop, attribs).map(Window::Wayland)
|
||||||
},
|
},
|
||||||
EventLoop::X(ref events_loop) => {
|
EventLoop::X(ref event_loop) => {
|
||||||
x11::Window::new(events_loop, attribs, pl_attribs).map(Window::X)
|
x11::Window::new(event_loop, attribs, pl_attribs).map(Window::X)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ impl EventLoop {
|
|||||||
},
|
},
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
Ok(EventsLoop {
|
Ok(EventLoop {
|
||||||
display,
|
display,
|
||||||
evq: RefCell::new(event_queue),
|
evq: RefCell::new(event_queue),
|
||||||
sink,
|
sink,
|
||||||
@@ -282,7 +282,7 @@ struct SeatManager {
|
|||||||
sink: Arc<Mutex<EventLoopSink>>,
|
sink: Arc<Mutex<EventLoopSink>>,
|
||||||
store: Arc<Mutex<WindowStore>>,
|
store: Arc<Mutex<WindowStore>>,
|
||||||
seats: Arc<Mutex<Vec<(u32, Proxy<wl_seat::WlSeat>)>>>,
|
seats: Arc<Mutex<Vec<(u32, Proxy<wl_seat::WlSeat>)>>>,
|
||||||
events_loop_proxy: EventsLoopProxy,
|
event_loop_proxy: EventLoopProxy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SeatManager {
|
impl SeatManager {
|
||||||
@@ -308,12 +308,25 @@ impl SeatManager {
|
|||||||
modifiers_tracker: Arc::new(Mutex::new(ModifiersState::default())),
|
modifiers_tracker: Arc::new(Mutex::new(ModifiersState::default())),
|
||||||
};
|
};
|
||||||
let seat = registry
|
let seat = registry
|
||||||
|
<<<<<<< HEAD
|
||||||
.bind(min(version, 5), id, move |seat| {
|
.bind(min(version, 5), id, move |seat| {
|
||||||
seat.implement(move |event, seat| {
|
seat.implement(move |event, seat| {
|
||||||
seat_data.receive(event, seat)
|
seat_data.receive(event, seat)
|
||||||
}, ())
|
}, ())
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
=======
|
||||||
|
.bind::<wl_seat::WlSeat>(min(version, 5), id)
|
||||||
|
.unwrap()
|
||||||
|
.implement(SeatData {
|
||||||
|
sink: self.sink.clone(),
|
||||||
|
store: self.store.clone(),
|
||||||
|
pointer: None,
|
||||||
|
keyboard: None,
|
||||||
|
touch: None,
|
||||||
|
event_loop_proxy: self.event_loop_proxy.clone(),
|
||||||
|
});
|
||||||
|
>>>>>>> Change instances of "events_loop" to "event_loop"
|
||||||
self.store.lock().unwrap().new_seat(&seat);
|
self.store.lock().unwrap().new_seat(&seat);
|
||||||
self.seats.lock().unwrap().push((id, seat));
|
self.seats.lock().unwrap().push((id, seat));
|
||||||
}
|
}
|
||||||
@@ -337,8 +350,12 @@ struct SeatData {
|
|||||||
pointer: Option<Proxy<wl_pointer::WlPointer>>,
|
pointer: Option<Proxy<wl_pointer::WlPointer>>,
|
||||||
keyboard: Option<Proxy<wl_keyboard::WlKeyboard>>,
|
keyboard: Option<Proxy<wl_keyboard::WlKeyboard>>,
|
||||||
touch: Option<Proxy<wl_touch::WlTouch>>,
|
touch: Option<Proxy<wl_touch::WlTouch>>,
|
||||||
|
<<<<<<< HEAD
|
||||||
events_loop_proxy: EventsLoopProxy,
|
events_loop_proxy: EventsLoopProxy,
|
||||||
modifiers_tracker: Arc<Mutex<ModifiersState>>,
|
modifiers_tracker: Arc<Mutex<ModifiersState>>,
|
||||||
|
=======
|
||||||
|
event_loop_proxy: EventLoopProxy,
|
||||||
|
>>>>>>> Change instances of "events_loop" to "event_loop"
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SeatData {
|
impl SeatData {
|
||||||
@@ -369,8 +386,12 @@ impl SeatData {
|
|||||||
self.keyboard = Some(super::keyboard::init_keyboard(
|
self.keyboard = Some(super::keyboard::init_keyboard(
|
||||||
&seat,
|
&seat,
|
||||||
self.sink.clone(),
|
self.sink.clone(),
|
||||||
|
<<<<<<< HEAD
|
||||||
self.events_loop_proxy.clone(),
|
self.events_loop_proxy.clone(),
|
||||||
self.modifiers_tracker.clone(),
|
self.modifiers_tracker.clone(),
|
||||||
|
=======
|
||||||
|
self.event_loop_proxy.clone(),
|
||||||
|
>>>>>>> Change instances of "events_loop" to "event_loop"
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
// destroy keyboard if applicable
|
// destroy keyboard if applicable
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use super::{make_wid, DeviceId, EventsLoopProxy, EventsLoopSink};
|
use super::{make_wid, DeviceId, EventLoopProxy, EventLoopSink};
|
||||||
use sctk::keyboard::{
|
use sctk::keyboard::{
|
||||||
self, map_keyboard_auto_with_repeat, Event as KbEvent, KeyRepeatEvent, KeyRepeatKind,
|
self, map_keyboard_auto_with_repeat, Event as KbEvent, KeyRepeatEvent, KeyRepeatKind,
|
||||||
};
|
};
|
||||||
@@ -14,7 +14,7 @@ use {ElementState, KeyboardInput, ModifiersState, VirtualKeyCode, WindowEvent};
|
|||||||
pub fn init_keyboard(
|
pub fn init_keyboard(
|
||||||
seat: &Proxy<wl_seat::WlSeat>,
|
seat: &Proxy<wl_seat::WlSeat>,
|
||||||
sink: Arc<Mutex<EventLoopSink>>,
|
sink: Arc<Mutex<EventLoopSink>>,
|
||||||
events_loop_proxy: EventLoopProxy,
|
event_loop_proxy: EventLoopProxy,
|
||||||
modifiers_tracker: Arc<Mutex<ModifiersState>>,
|
modifiers_tracker: Arc<Mutex<ModifiersState>>,
|
||||||
) -> Proxy<wl_keyboard::WlKeyboard> {
|
) -> Proxy<wl_keyboard::WlKeyboard> {
|
||||||
// { variables to be captured by the closures
|
// { variables to be captured by the closures
|
||||||
@@ -108,7 +108,7 @@ pub fn init_keyboard(
|
|||||||
guard.send_event(WindowEvent::ReceivedCharacter(chr), wid);
|
guard.send_event(WindowEvent::ReceivedCharacter(chr), wid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
events_loop_proxy.wakeup().unwrap();
|
event_loop_proxy.wakeup().unwrap();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#![cfg(target_os = "macos")]
|
#![cfg(target_os = "macos")]
|
||||||
|
|
||||||
pub use self::events_loop::{EventLoop, Proxy as EventLoopProxy};
|
pub use self::event_loop::{EventLoop, Proxy as EventLoopProxy};
|
||||||
pub use self::monitor::MonitorId;
|
pub use self::monitor::MonitorId;
|
||||||
pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window2};
|
pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window2};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -24,20 +24,20 @@ impl ::std::ops::Deref for Window {
|
|||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
|
|
||||||
pub fn new(events_loop: &EventLoop,
|
pub fn new(event_loop: &EventLoop,
|
||||||
attributes: ::WindowAttributes,
|
attributes: ::WindowAttributes,
|
||||||
pl_attribs: PlatformSpecificWindowBuilderAttributes) -> Result<Self, CreationError>
|
pl_attribs: PlatformSpecificWindowBuilderAttributes) -> Result<Self, CreationError>
|
||||||
{
|
{
|
||||||
let weak_shared = Arc::downgrade(&events_loop.shared);
|
let weak_shared = Arc::downgrade(&event_loop.shared);
|
||||||
let window = Arc::new(try!(Window2::new(weak_shared, attributes, pl_attribs)));
|
let window = Arc::new(try!(Window2::new(weak_shared, attributes, pl_attribs)));
|
||||||
let weak_window = Arc::downgrade(&window);
|
let weak_window = Arc::downgrade(&window);
|
||||||
events_loop.shared.windows.lock().unwrap().push(weak_window);
|
event_loop.shared.windows.lock().unwrap().push(weak_window);
|
||||||
Ok(Window { window: window })
|
Ok(Window { window: window })
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod events_loop;
|
mod event_loop;
|
||||||
mod ffi;
|
mod ffi;
|
||||||
mod monitor;
|
mod monitor;
|
||||||
mod util;
|
mod util;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use objc::declare::ClassDecl;
|
|||||||
use objc::runtime::{Class, Object, Protocol, Sel, BOOL, YES};
|
use objc::runtime::{Class, Object, Protocol, Sel, BOOL, YES};
|
||||||
|
|
||||||
use {ElementState, Event, KeyboardInput, MouseButton, WindowEvent, WindowId};
|
use {ElementState, Event, KeyboardInput, MouseButton, WindowEvent, WindowId};
|
||||||
use platform_impl::platform::events_loop::{DEVICE_ID, event_mods, Shared, to_virtual_key_code, check_additional_virtual_key_codes};
|
use platform_impl::platform::event_loop::{DEVICE_ID, event_mods, Shared, to_virtual_key_code, check_additional_virtual_key_codes};
|
||||||
use platform_impl::platform::util;
|
use platform_impl::platform::util;
|
||||||
use platform_impl::platform::ffi::*;
|
use platform_impl::platform::ffi::*;
|
||||||
use platform_impl::platform::window::{get_window_id, IdRef};
|
use platform_impl::platform::window::{get_window_id, IdRef};
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ use {
|
|||||||
use CreationError::OsError;
|
use CreationError::OsError;
|
||||||
use os::macos::{ActivationPolicy, WindowExt};
|
use os::macos::{ActivationPolicy, WindowExt};
|
||||||
use platform_impl::platform::{ffi, util};
|
use platform_impl::platform::{ffi, util};
|
||||||
use platform_impl::platform::events_loop::{EventLoop, Shared};
|
use platform_impl::platform::event_loop::{EventLoop, Shared};
|
||||||
use platform_impl::platform::view::{new_view, set_ime_spot};
|
use platform_impl::platform::view::{new_view, set_ime_spot};
|
||||||
use window::MonitorId as RootMonitorId;
|
use window::MonitorId as RootMonitorId;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use winapi;
|
use winapi;
|
||||||
use winapi::shared::windef::HWND;
|
use winapi::shared::windef::HWND;
|
||||||
|
|
||||||
pub use self::events_loop::{EventLoop, EventLoopProxy};
|
pub use self::event_loop::{EventLoop, EventLoopProxy};
|
||||||
pub use self::monitor::MonitorId;
|
pub use self::monitor::MonitorId;
|
||||||
pub use self::window::Window;
|
pub use self::window::Window;
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ unsafe impl Sync for WindowId {}
|
|||||||
mod dpi;
|
mod dpi;
|
||||||
mod drop_handler;
|
mod drop_handler;
|
||||||
mod event;
|
mod event;
|
||||||
mod events_loop;
|
mod event_loop;
|
||||||
mod icon;
|
mod icon;
|
||||||
mod monitor;
|
mod monitor;
|
||||||
mod raw_input;
|
mod raw_input;
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ use dpi::{LogicalPosition, LogicalSize, PhysicalSize};
|
|||||||
use monitor::MonitorId as RootMonitorId;
|
use monitor::MonitorId as RootMonitorId;
|
||||||
use platform_impl::platform::{Cursor, PlatformSpecificWindowBuilderAttributes, WindowId};
|
use platform_impl::platform::{Cursor, PlatformSpecificWindowBuilderAttributes, WindowId};
|
||||||
use platform_impl::platform::dpi::{dpi_to_scale_factor, get_hwnd_dpi};
|
use platform_impl::platform::dpi::{dpi_to_scale_factor, get_hwnd_dpi};
|
||||||
use platform_impl::platform::events_loop::{self, EventLoop, DESTROY_MSG_ID, INITIAL_DPI_MSG_ID, REQUEST_REDRAW_NO_NEWEVENTS_MSG_ID};
|
use platform_impl::platform::event_loop::{self, EventLoop, DESTROY_MSG_ID, INITIAL_DPI_MSG_ID, REQUEST_REDRAW_NO_NEWEVENTS_MSG_ID};
|
||||||
use platform_impl::platform::events_loop::WindowState;
|
use platform_impl::platform::event_loop::WindowState;
|
||||||
use platform_impl::platform::icon::{self, IconType, WinIcon};
|
use platform_impl::platform::icon::{self, IconType, WinIcon};
|
||||||
use platform_impl::platform::monitor;
|
use platform_impl::platform::monitor;
|
||||||
use platform_impl::platform::raw_input::register_all_mice_and_keyboards_for_raw_input;
|
use platform_impl::platform::raw_input::register_all_mice_and_keyboards_for_raw_input;
|
||||||
@@ -42,7 +42,7 @@ pub struct Window {
|
|||||||
window_state: Arc<Mutex<WindowState>>,
|
window_state: Arc<Mutex<WindowState>>,
|
||||||
|
|
||||||
// The events loop proxy.
|
// The events loop proxy.
|
||||||
thread_executor: events_loop::EventLoopThreadExecutor,
|
thread_executor: event_loop::EventLoopThreadExecutor,
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://blogs.msdn.microsoft.com/oldnewthing/20131017-00/?p=2903
|
// https://blogs.msdn.microsoft.com/oldnewthing/20131017-00/?p=2903
|
||||||
@@ -98,13 +98,13 @@ impl Window {
|
|||||||
file_drop_handler
|
file_drop_handler
|
||||||
};
|
};
|
||||||
|
|
||||||
let subclass_input = events_loop::SubclassInput {
|
let subclass_input = event_loop::SubclassInput {
|
||||||
window_state: win.window_state.clone(),
|
window_state: win.window_state.clone(),
|
||||||
event_loop_runner: event_loop.runner_shared.clone(),
|
event_loop_runner: event_loop.runner_shared.clone(),
|
||||||
file_drop_handler,
|
file_drop_handler,
|
||||||
};
|
};
|
||||||
|
|
||||||
events_loop::subclass_window(win.window.0, subclass_input);
|
event_loop::subclass_window(win.window.0, subclass_input);
|
||||||
win
|
win
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -517,7 +517,7 @@ impl Window {
|
|||||||
if window_state.fullscreen.is_none() || window_state.saved_window_info.is_none() {
|
if window_state.fullscreen.is_none() || window_state.saved_window_info.is_none() {
|
||||||
let rect = util::get_window_rect(self.window.0).expect("`GetWindowRect` failed");
|
let rect = util::get_window_rect(self.window.0).expect("`GetWindowRect` failed");
|
||||||
let dpi_factor = Some(window_state.dpi_factor);
|
let dpi_factor = Some(window_state.dpi_factor);
|
||||||
window_state.saved_window_info = Some(events_loop::SavedWindowInfo {
|
window_state.saved_window_info = Some(event_loop::SavedWindowInfo {
|
||||||
style: winuser::GetWindowLongW(self.window.0, winuser::GWL_STYLE),
|
style: winuser::GetWindowLongW(self.window.0, winuser::GWL_STYLE),
|
||||||
ex_style: winuser::GetWindowLongW(self.window.0, winuser::GWL_EXSTYLE),
|
ex_style: winuser::GetWindowLongW(self.window.0, winuser::GWL_EXSTYLE),
|
||||||
rect,
|
rect,
|
||||||
@@ -852,7 +852,7 @@ pub unsafe fn adjust_size(
|
|||||||
unsafe fn init<T>(
|
unsafe fn init<T>(
|
||||||
mut attributes: WindowAttributes,
|
mut attributes: WindowAttributes,
|
||||||
mut pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
mut pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||||
event_loop: &events_loop::EventLoop<T>,
|
event_loop: &event_loop::EventLoop<T>,
|
||||||
) -> Result<Window, CreationError> {
|
) -> Result<Window, CreationError> {
|
||||||
let title = OsStr::new(&attributes.title)
|
let title = OsStr::new(&attributes.title)
|
||||||
.encode_wide()
|
.encode_wide()
|
||||||
@@ -1043,7 +1043,7 @@ unsafe fn init<T>(
|
|||||||
.map(|logical_size| PhysicalSize::from_logical(logical_size, dpi_factor));
|
.map(|logical_size| PhysicalSize::from_logical(logical_size, dpi_factor));
|
||||||
let min_size = attributes.min_dimensions
|
let min_size = attributes.min_dimensions
|
||||||
.map(|logical_size| PhysicalSize::from_logical(logical_size, dpi_factor));
|
.map(|logical_size| PhysicalSize::from_logical(logical_size, dpi_factor));
|
||||||
let mut window_state = events_loop::WindowState {
|
let mut window_state = event_loop::WindowState {
|
||||||
max_size,
|
max_size,
|
||||||
min_size,
|
min_size,
|
||||||
dpi_factor,
|
dpi_factor,
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ pub use icon::*;
|
|||||||
/// use winit::event::{Event, WindowEvent};
|
/// use winit::event::{Event, WindowEvent};
|
||||||
/// use winit::event_loop::{EventLoop, ControlFlow};
|
/// use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
///
|
///
|
||||||
/// let mut events_loop = EventLoop::new();
|
/// let mut event_loop = EventLoop::new();
|
||||||
/// let window = Window::new(&events_loop).unwrap();
|
/// let window = Window::new(&event_loop).unwrap();
|
||||||
///
|
///
|
||||||
/// events_loop.run(move |event, _, control_flow| {
|
/// event_loop.run(move |event, _, control_flow| {
|
||||||
/// match event {
|
/// match event {
|
||||||
/// Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
/// Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
||||||
/// *control_flow = ControlFlow::Exit
|
/// *control_flow = ControlFlow::Exit
|
||||||
@@ -283,7 +283,7 @@ impl WindowBuilder {
|
|||||||
/// Error should be very rare and only occur in case of permission denied, incompatible system,
|
/// Error should be very rare and only occur in case of permission denied, incompatible system,
|
||||||
/// out of memory, etc.
|
/// out of memory, etc.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn build<T>(mut self, events_loop: &EventLoop<T>) -> Result<Window, CreationError> {
|
pub fn build<T>(mut self, event_loop: &EventLoop<T>) -> Result<Window, CreationError> {
|
||||||
self.window.dimensions = Some(self.window.dimensions.unwrap_or_else(|| {
|
self.window.dimensions = Some(self.window.dimensions.unwrap_or_else(|| {
|
||||||
if let Some(ref monitor) = self.window.fullscreen {
|
if let Some(ref monitor) = self.window.fullscreen {
|
||||||
// resizing the window to the dimensions of the monitor when fullscreen
|
// resizing the window to the dimensions of the monitor when fullscreen
|
||||||
@@ -296,7 +296,7 @@ impl WindowBuilder {
|
|||||||
|
|
||||||
// building
|
// building
|
||||||
platform_impl::Window::new(
|
platform_impl::Window::new(
|
||||||
&events_loop.events_loop,
|
&event_loop.event_loop,
|
||||||
self.window,
|
self.window,
|
||||||
self.platform_specific,
|
self.platform_specific,
|
||||||
).map(|window| Window { window })
|
).map(|window| Window { window })
|
||||||
@@ -306,14 +306,14 @@ impl WindowBuilder {
|
|||||||
impl Window {
|
impl Window {
|
||||||
/// Creates a new Window for platforms where this is appropriate.
|
/// Creates a new Window for platforms where this is appropriate.
|
||||||
///
|
///
|
||||||
/// This function is equivalent to `WindowBuilder::new().build(events_loop)`.
|
/// This function is equivalent to `WindowBuilder::new().build(event_loop)`.
|
||||||
///
|
///
|
||||||
/// Error should be very rare and only occur in case of permission denied, incompatible system,
|
/// Error should be very rare and only occur in case of permission denied, incompatible system,
|
||||||
/// out of memory, etc.
|
/// out of memory, etc.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new<T>(events_loop: &EventLoop<T>) -> Result<Window, CreationError> {
|
pub fn new<T>(event_loop: &EventLoop<T>) -> Result<Window, CreationError> {
|
||||||
let builder = WindowBuilder::new();
|
let builder = WindowBuilder::new();
|
||||||
builder.build(events_loop)
|
builder.build(event_loop)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modifies the title of the window.
|
/// Modifies the title of the window.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ extern crate winit;
|
|||||||
fn needs_send<T:Send>() {}
|
fn needs_send<T:Send>() {}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn events_loop_proxy_send() {
|
fn event_loop_proxy_send() {
|
||||||
// ensures that `winit::EventLoopProxy` implements `Send`
|
// ensures that `winit::EventLoopProxy` implements `Send`
|
||||||
needs_send::<winit::event_loop::EventLoopProxy<()>>();
|
needs_send::<winit::event_loop::EventLoopProxy<()>>();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user