Re-format on stable rustfmt (#974)

This commit is contained in:
Osspial 2019-06-24 12:14:55 -04:00 committed by GitHub
parent 9dd15d00d8
commit a195ce8146
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 587 additions and 713 deletions

View file

@ -45,11 +45,10 @@ matrix:
install:
- rustup self update
- rustup target add $TARGET; true
- rustup install nightly
- rustup component add rustfmt --toolchain nightly
- rustup component add rustfmt
script:
- cargo +nightly fmt --all -- --check
- cargo fmt --all -- --check
- cargo build --target $TARGET --verbose
- cargo build --target $TARGET --features serde --verbose
# Running iOS apps on OSX requires the simulator so we skip that for now

View file

@ -12,37 +12,35 @@ fn main() {
let mut cursor_idx = 0;
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
event:
WindowEvent::KeyboardInput {
input:
KeyboardInput {
state: ElementState::Pressed,
..
},
..
},
..
} => {
println!("Setting cursor to \"{:?}\"", CURSORS[cursor_idx]);
window.set_cursor_icon(CURSORS[cursor_idx]);
if cursor_idx < CURSORS.len() - 1 {
cursor_idx += 1;
} else {
cursor_idx = 0;
}
},
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => {
*control_flow = ControlFlow::Exit;
return;
},
_ => (),
event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent {
event:
WindowEvent::KeyboardInput {
input:
KeyboardInput {
state: ElementState::Pressed,
..
},
..
},
..
} => {
println!("Setting cursor to \"{:?}\"", CURSORS[cursor_idx]);
window.set_cursor_icon(CURSORS[cursor_idx]);
if cursor_idx < CURSORS.len() - 1 {
cursor_idx += 1;
} else {
cursor_idx = 0;
}
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => {
*control_flow = ControlFlow::Exit;
return;
}
_ => (),
});
}

View file

@ -34,7 +34,7 @@ fn main() {
H => window.set_cursor_visible(modifiers.shift),
_ => (),
}
},
}
_ => (),
}
}

View file

@ -24,7 +24,7 @@ fn main() {
let num = num.trim().parse().ok().expect("Please enter a number");
match num {
2 => macos_use_simple_fullscreen = true,
_ => {},
_ => {}
}
// Prompt for monitor when using native fullscreen
@ -54,69 +54,62 @@ fn main() {
*control_flow = ControlFlow::Wait;
match event {
Event::WindowEvent { event, .. } => {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(virtual_code),
state,
..
},
..
} => {
match (virtual_code, state) {
(VirtualKeyCode::Escape, _) => *control_flow = ControlFlow::Exit,
(VirtualKeyCode::F, ElementState::Pressed) => {
#[cfg(target_os = "macos")]
{
if macos_use_simple_fullscreen {
use winit::platform::macos::WindowExtMacOS;
if WindowExtMacOS::set_simple_fullscreen(
&window,
!is_fullscreen,
) {
is_fullscreen = !is_fullscreen;
}
return;
}
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(virtual_code),
state,
..
},
..
} => match (virtual_code, state) {
(VirtualKeyCode::Escape, _) => *control_flow = ControlFlow::Exit,
(VirtualKeyCode::F, ElementState::Pressed) => {
#[cfg(target_os = "macos")]
{
if macos_use_simple_fullscreen {
use winit::platform::macos::WindowExtMacOS;
if WindowExtMacOS::set_simple_fullscreen(&window, !is_fullscreen) {
is_fullscreen = !is_fullscreen;
}
is_fullscreen = !is_fullscreen;
if !is_fullscreen {
window.set_fullscreen(None);
} else {
window.set_fullscreen(Some(window.current_monitor()));
}
},
(VirtualKeyCode::S, ElementState::Pressed) => {
println!("window.fullscreen {:?}", window.fullscreen());
#[cfg(target_os = "macos")]
{
use winit::platform::macos::WindowExtMacOS;
println!(
"window.simple_fullscreen {:?}",
WindowExtMacOS::simple_fullscreen(&window)
);
}
},
(VirtualKeyCode::M, ElementState::Pressed) => {
is_maximized = !is_maximized;
window.set_maximized(is_maximized);
},
(VirtualKeyCode::D, ElementState::Pressed) => {
decorations = !decorations;
window.set_decorations(decorations);
},
_ => (),
return;
}
}
},
is_fullscreen = !is_fullscreen;
if !is_fullscreen {
window.set_fullscreen(None);
} else {
window.set_fullscreen(Some(window.current_monitor()));
}
}
(VirtualKeyCode::S, ElementState::Pressed) => {
println!("window.fullscreen {:?}", window.fullscreen());
#[cfg(target_os = "macos")]
{
use winit::platform::macos::WindowExtMacOS;
println!(
"window.simple_fullscreen {:?}",
WindowExtMacOS::simple_fullscreen(&window)
);
}
}
(VirtualKeyCode::M, ElementState::Pressed) => {
is_maximized = !is_maximized;
window.set_maximized(is_maximized);
}
(VirtualKeyCode::D, ElementState::Pressed) => {
decorations = !decorations;
window.set_decorations(decorations);
}
_ => (),
}
},
_ => (),
},
_ => {},
_ => {}
}
});
}

View file

@ -40,7 +40,7 @@ fn main() {
// action from the user, this is generally where you'd handle cleanup before
// closing the window. How to close the window is detailed in the handler for
// the Y key.
},
}
WindowEvent::KeyboardInput {
input:
KeyboardInput {
@ -63,19 +63,19 @@ fn main() {
// sent.
*control_flow = ControlFlow::Exit;
}
},
}
N => {
if close_requested {
println!("Your window will continue to stay by your side.");
close_requested = false;
}
},
}
_ => (),
}
},
}
_ => (),
}
},
}
_ => (),
}
});

View file

@ -39,19 +39,15 @@ fn main() {
use self::VirtualKeyCode::*;
match key {
A => window.set_always_on_top(state),
C => {
window.set_cursor_icon(match state {
true => CursorIcon::Progress,
false => CursorIcon::Default,
})
},
C => window.set_cursor_icon(match state {
true => CursorIcon::Progress,
false => CursorIcon::Default,
}),
D => window.set_decorations(!state),
F => {
window.set_fullscreen(match state {
true => Some(window.current_monitor()),
false => None,
})
},
F => window.set_fullscreen(match state {
true => Some(window.current_monitor()),
false => None,
}),
G => window.set_cursor_grab(state).unwrap(),
H => window.set_cursor_visible(!state),
I => {
@ -60,49 +56,41 @@ fn main() {
println!("-> inner_position : {:?}", window.inner_position());
println!("-> outer_size : {:?}", window.outer_size());
println!("-> inner_size : {:?}", window.inner_size());
},
L => {
window.set_min_inner_size(match state {
true => Some(WINDOW_SIZE.into()),
false => None,
})
},
}
L => window.set_min_inner_size(match state {
true => Some(WINDOW_SIZE.into()),
false => None,
}),
M => window.set_maximized(state),
P => {
window.set_outer_position({
let mut position = window.outer_position().unwrap();
let sign = if state { 1.0 } else { -1.0 };
position.x += 10.0 * sign;
position.y += 10.0 * sign;
position
})
},
P => window.set_outer_position({
let mut position = window.outer_position().unwrap();
let sign = if state { 1.0 } else { -1.0 };
position.x += 10.0 * sign;
position.y += 10.0 * sign;
position
}),
Q => window.request_redraw(),
R => window.set_resizable(state),
S => {
window.set_inner_size(
match state {
true => (WINDOW_SIZE.0 + 100, WINDOW_SIZE.1 + 100),
false => WINDOW_SIZE,
}
.into(),
S => window.set_inner_size(
match state {
true => (WINDOW_SIZE.0 + 100, WINDOW_SIZE.1 + 100),
false => WINDOW_SIZE,
}
.into(),
),
W => window
.set_cursor_position(
(WINDOW_SIZE.0 as i32 / 2, WINDOW_SIZE.1 as i32 / 2).into(),
)
},
W => {
window
.set_cursor_position(
(WINDOW_SIZE.0 as i32 / 2, WINDOW_SIZE.1 as i32 / 2).into(),
)
.unwrap()
},
.unwrap(),
Z => {
window.set_visible(false);
thread::sleep(Duration::from_secs(1));
window.set_visible(true);
},
}
_ => (),
}
},
}
_ => (),
}
}
@ -114,25 +102,23 @@ fn main() {
false => ControlFlow::Exit,
};
match event {
Event::WindowEvent { event, window_id } => {
match event {
WindowEvent::CloseRequested
| WindowEvent::Destroyed
| WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape),
..
},
..
} => {
window_senders.remove(&window_id);
},
_ => {
if let Some(tx) = window_senders.get(&window_id) {
tx.send(event).unwrap();
}
},
Event::WindowEvent { event, window_id } => match event {
WindowEvent::CloseRequested
| WindowEvent::Destroyed
| WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape),
..
},
..
} => {
window_senders.remove(&window_id);
}
_ => {
if let Some(tx) = window_senders.get(&window_id) {
tx.send(event).unwrap();
}
}
},
_ => (),

View file

@ -28,7 +28,7 @@ fn main() {
if windows.is_empty() {
*control_flow = ControlFlow::Exit;
}
},
}
WindowEvent::KeyboardInput {
input:
KeyboardInput {
@ -39,10 +39,10 @@ fn main() {
} => {
let window = Window::new(&event_loop).unwrap();
windows.insert(window.id(), window);
},
}
_ => (),
}
},
}
_ => (),
}
})

View file

@ -25,7 +25,7 @@ fn main() {
Event::EventsCleared => {
window.request_redraw();
*control_flow = ControlFlow::WaitUntil(Instant::now() + Duration::new(1, 0))
},
}
_ => (),
}
});

View file

@ -19,24 +19,22 @@ fn main() {
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
match event {
Event::WindowEvent { event, .. } => {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Space),
state: ElementState::Released,
..
},
..
} => {
resizable = !resizable;
println!("Resizable: {}", resizable);
window.set_resizable(resizable);
},
_ => (),
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Space),
state: ElementState::Released,
..
},
..
} => {
resizable = !resizable;
println!("Resizable: {}", resizable);
window.set_resizable(resizable);
}
_ => (),
},
_ => (),
};

View file

@ -21,11 +21,11 @@ fn main() {
match event {
Event::NewEvents(StartCause::Init) => {
*control_flow = ControlFlow::WaitUntil(Instant::now() + timer_length)
},
}
Event::NewEvents(StartCause::ResumeTimeReached { .. }) => {
*control_flow = ControlFlow::WaitUntil(Instant::now() + timer_length);
println!("\nTimer\n");
},
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..

View file

@ -43,7 +43,7 @@ fn main() {
CloseRequested => *control_flow = ControlFlow::Exit,
DroppedFile(path) => {
window.set_window_icon(Some(load_icon(&path)));
},
}
_ => (),
}
}

View file

@ -14,14 +14,12 @@ fn main() {
.unwrap();
println!("Close the window to continue.");
event_loop.run_return(|event, _, control_flow| {
match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
}
event_loop.run_return(|event, _, control_flow| match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
});
drop(window);
@ -31,14 +29,12 @@ fn main() {
.unwrap();
println!("Wa ha ha! You thought that closing the window would finish this?!");
event_loop.run_return(|event, _, control_flow| {
match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
}
event_loop.run_return(|event, _, control_flow| match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
});
println!("Okay we're done now for real.");

View file

@ -1,7 +1,3 @@
merge_imports=true
match_block_trailing_comma=true
force_explicit_abi=true
format_macro_matchers=true
use_field_init_shorthand=true
format_code_in_doc_comments=true
force_multiline_blocks=true
# merge_imports=true

View file

@ -122,11 +122,9 @@ pub trait EventLoopExtUnix {
impl<T> EventLoopExtUnix for EventLoop<T> {
#[inline]
fn new_x11() -> Result<Self, XNotSupported> {
LinuxEventLoop::new_x11().map(|ev| {
EventLoop {
event_loop: ev,
_marker: ::std::marker::PhantomData,
}
LinuxEventLoop::new_x11().map(|ev| EventLoop {
event_loop: ev,
_marker: ::std::marker::PhantomData,
})
}
@ -294,7 +292,7 @@ impl WindowExtUnix for Window {
fn set_wayland_theme(&self, theme: WaylandTheme) {
match self.window {
LinuxWindow::Wayland(ref w) => w.set_theme(WaylandThemeObject(theme)),
_ => {},
_ => {}
}
}

View file

@ -79,21 +79,21 @@ impl EventLoop {
device_id: DEVICE_ID,
}),
})
},
}
android_glue::Event::InitWindow => {
// The activity went to foreground.
if let Some(cb) = self.suspend_callback.borrow().as_ref() {
(*cb)(false);
}
Some(Event::Resumed)
},
}
android_glue::Event::TermWindow => {
// The activity went to background.
if let Some(cb) = self.suspend_callback.borrow().as_ref() {
(*cb)(true);
}
Some(Event::Suspended)
},
}
android_glue::Event::WindowResized | android_glue::Event::ConfigChanged => {
// Activity Orientation changed or resized.
let native_window = unsafe { android_glue::native_window() };
@ -108,14 +108,14 @@ impl EventLoop {
event: WindowEvent::Resized(size),
})
}
},
}
android_glue::Event::WindowRedrawNeeded => {
// The activity needs to be redrawn.
Some(Event::WindowEvent {
window_id: RootWindowId(WindowId),
event: WindowEvent::Redraw,
})
},
}
android_glue::Event::Wake => Some(Event::Awakened),
_ => None,
};

View file

@ -251,7 +251,7 @@ extern "C" fn mouse_callback(
delta: ((*event).movementX as f64, (*event).movementY as f64),
},
});
},
}
mouse_input @ ffi::EMSCRIPTEN_EVENT_MOUSEDOWN
| mouse_input @ ffi::EMSCRIPTEN_EVENT_MOUSEUP => {
let button = match (*event).button {
@ -274,8 +274,8 @@ extern "C" fn mouse_callback(
modifiers,
},
})
},
_ => {},
}
_ => {}
}
}
ffi::EM_FALSE
@ -310,7 +310,7 @@ extern "C" fn keyboard_callback(
},
},
});
},
}
ffi::EMSCRIPTEN_EVENT_KEYUP => {
queue.lock().unwrap().push_back(::Event::WindowEvent {
window_id: ::WindowId(WindowId(0)),
@ -324,8 +324,8 @@ extern "C" fn keyboard_callback(
},
},
});
},
_ => {},
}
_ => {}
}
}
ffi::EM_FALSE
@ -757,7 +757,7 @@ fn error_to_str(code: ffi::EMSCRIPTEN_RESULT) -> &'static str {
match code {
ffi::EMSCRIPTEN_RESULT_SUCCESS | ffi::EMSCRIPTEN_RESULT_DEFERRED => {
"Internal error in the library (success detected as failure)"
},
}
ffi::EMSCRIPTEN_RESULT_NOT_SUPPORTED => "Not supported",
ffi::EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED => "Failed not deferred",
@ -778,7 +778,7 @@ fn key_translate(input: [ffi::EM_UTF8; ffi::EM_HTML5_SHORT_STRING_LEN_BYTES]) ->
Ok(key) => key,
Err(_) => {
return 0;
},
}
};
if key.chars().count() == 1 {
key.as_bytes()[0]
@ -797,25 +797,21 @@ fn key_translate_virt(
Ok(key) => key,
Err(_) => {
return None;
},
}
};
use VirtualKeyCode::*;
match key {
"Alt" => {
match location {
ffi::DOM_KEY_LOCATION_LEFT => Some(LAlt),
ffi::DOM_KEY_LOCATION_RIGHT => Some(RAlt),
_ => None,
}
"Alt" => match location {
ffi::DOM_KEY_LOCATION_LEFT => Some(LAlt),
ffi::DOM_KEY_LOCATION_RIGHT => Some(RAlt),
_ => None,
},
"AltGraph" => None,
"CapsLock" => None,
"Control" => {
match location {
ffi::DOM_KEY_LOCATION_LEFT => Some(LControl),
ffi::DOM_KEY_LOCATION_RIGHT => Some(RControl),
_ => None,
}
"Control" => match location {
ffi::DOM_KEY_LOCATION_LEFT => Some(LControl),
ffi::DOM_KEY_LOCATION_RIGHT => Some(RControl),
_ => None,
},
"Fn" => None,
"FnLock" => None,
@ -823,22 +819,18 @@ fn key_translate_virt(
"Meta" => None,
"NumLock" => Some(Numlock),
"ScrollLock" => Some(Scroll),
"Shift" => {
match location {
ffi::DOM_KEY_LOCATION_LEFT => Some(LShift),
ffi::DOM_KEY_LOCATION_RIGHT => Some(RShift),
_ => None,
}
"Shift" => match location {
ffi::DOM_KEY_LOCATION_LEFT => Some(LShift),
ffi::DOM_KEY_LOCATION_RIGHT => Some(RShift),
_ => None,
},
"Super" => None,
"Symbol" => None,
"SymbolLock" => None,
"Enter" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(NumpadEnter),
_ => Some(Return),
}
"Enter" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(NumpadEnter),
_ => Some(Return),
},
"Tab" => Some(Tab),
" " => Some(Space),
@ -1163,65 +1155,45 @@ fn key_translate_virt(
"Divide" => Some(Divide),
"Subtract" | "-" => Some(Subtract),
"Separator" => None,
"0" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad0),
_ => Some(Key0),
}
"0" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad0),
_ => Some(Key0),
},
"1" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad1),
_ => Some(Key1),
}
"1" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad1),
_ => Some(Key1),
},
"2" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad2),
_ => Some(Key2),
}
"2" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad2),
_ => Some(Key2),
},
"3" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad3),
_ => Some(Key3),
}
"3" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad3),
_ => Some(Key3),
},
"4" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad4),
_ => Some(Key4),
}
"4" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad4),
_ => Some(Key4),
},
"5" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad5),
_ => Some(Key5),
}
"5" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad5),
_ => Some(Key5),
},
"6" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad6),
_ => Some(Key6),
}
"6" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad6),
_ => Some(Key6),
},
"7" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad7),
_ => Some(Key7),
}
"7" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad7),
_ => Some(Key7),
},
"8" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad8),
_ => Some(Key8),
}
"8" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad8),
_ => Some(Key8),
},
"9" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad9),
_ => Some(Key9),
}
"9" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad9),
_ => Some(Key9),
},
"A" | "a" => Some(A),
@ -1254,17 +1226,13 @@ fn key_translate_virt(
"'" => Some(Apostrophe),
"\\" => Some(Backslash),
":" => Some(Colon),
"," => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(NumpadComma),
_ => Some(Comma),
}
"," => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(NumpadComma),
_ => Some(Comma),
},
"=" => {
match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(NumpadEquals),
_ => Some(Equals),
}
"=" => match location {
ffi::DOM_KEY_LOCATION_NUMPAD => Some(NumpadEquals),
_ => Some(Equals),
},
"{" => Some(LBracket),
"." => Some(Period),

View file

@ -71,7 +71,7 @@ impl Drop for AppStateImpl {
let () = msg_send![window, release];
}
},
_ => {},
_ => {}
}
}
}
@ -128,15 +128,13 @@ impl AppState {
queued_windows.push(window);
msg_send![window, retain];
return;
},
&mut AppStateImpl::ProcessingEvents { .. } => {},
&mut AppStateImpl::InUserCallback { .. } => {},
&mut AppStateImpl::Terminated => {
panic!(
"Attempt to create a `Window` \
after the app has terminated"
)
},
}
&mut AppStateImpl::ProcessingEvents { .. } => {}
&mut AppStateImpl::InUserCallback { .. } => {}
&mut AppStateImpl::Terminated => panic!(
"Attempt to create a `Window` \
after the app has terminated"
),
app_state => unreachable!("unexpected state: {:#?}", app_state), /* all other cases should be impossible */
}
drop(this);
@ -154,13 +152,11 @@ impl AppState {
let windows = ptr::read(queued_windows);
let events = ptr::read(queued_events);
(windows, events)
},
_ => {
panic!(
"winit iOS expected the app to be in a `NotLaunched` \
state, but was not - please file an issue"
)
},
}
_ => panic!(
"winit iOS expected the app to be in a `NotLaunched` \
state, but was not - please file an issue"
),
};
ptr::write(
&mut this.app_state,
@ -180,12 +176,10 @@ impl AppState {
ref mut queued_windows,
..
} => mem::replace(queued_windows, Vec::new()),
_ => {
panic!(
"winit iOS expected the app to be in a `Launching` \
state, but was not - please file an issue"
)
},
_ => panic!(
"winit iOS expected the app to be in a `Launching` \
state, but was not - please file an issue"
),
};
// have to drop RefMut because the window setup code below can trigger new events
drop(this);
@ -228,13 +222,11 @@ impl AppState {
let events = ptr::read(queued_events);
let event_handler = ptr::read(queued_event_handler);
(windows, events, event_handler)
},
_ => {
panic!(
"winit iOS expected the app to be in a `Launching` \
state, but was not - please file an issue"
)
},
}
_ => panic!(
"winit iOS expected the app to be in a `Launching` \
state, but was not - please file an issue"
),
};
ptr::write(
&mut this.app_state,
@ -283,7 +275,7 @@ impl AppState {
},
);
Event::NewEvents(StartCause::Poll)
},
}
ControlFlow::Wait => {
let (event_handler, start) = match &mut this.app_state {
&mut AppStateImpl::NotLaunched { .. }
@ -305,7 +297,7 @@ impl AppState {
start,
requested_resume: None,
})
},
}
ControlFlow::WaitUntil(requested_resume) => {
let (event_handler, start) = match &mut this.app_state {
&mut AppStateImpl::NotLaunched { .. }
@ -334,7 +326,7 @@ impl AppState {
requested_resume: Some(requested_resume),
})
}
},
}
ControlFlow::Exit => bug!("unexpected controlflow `Exit`"),
};
drop(this);
@ -365,7 +357,7 @@ impl AppState {
} => {
queued_events.extend(events);
return;
},
}
&mut AppStateImpl::ProcessingEvents {
ref mut event_handler,
ref mut active_control_flow,
@ -461,7 +453,7 @@ impl AppState {
let mut this = AppState::get_mut();
match &mut this.app_state {
&mut AppStateImpl::NotLaunched { .. } | &mut AppStateImpl::Launching { .. } => return,
&mut AppStateImpl::ProcessingEvents { .. } => {},
&mut AppStateImpl::ProcessingEvents { .. } => {}
_ => unreachable!(),
};
drop(this);
@ -474,25 +466,21 @@ impl AppState {
&mut AppStateImpl::ProcessingEvents {
ref mut event_handler,
ref mut active_control_flow,
} => {
(
ManuallyDrop::new(ptr::read(event_handler)),
*active_control_flow,
)
},
} => (
ManuallyDrop::new(ptr::read(event_handler)),
*active_control_flow,
),
_ => unreachable!(),
};
let new = this.control_flow;
match (old, new) {
(ControlFlow::Poll, ControlFlow::Poll) => {
ptr::write(
&mut this.app_state,
AppStateImpl::PollFinished {
waiting_event_handler: ManuallyDrop::into_inner(event_handler),
},
)
},
(ControlFlow::Poll, ControlFlow::Poll) => ptr::write(
&mut this.app_state,
AppStateImpl::PollFinished {
waiting_event_handler: ManuallyDrop::into_inner(event_handler),
},
),
(ControlFlow::Wait, ControlFlow::Wait) => {
let start = Instant::now();
ptr::write(
@ -502,7 +490,7 @@ impl AppState {
start,
},
)
},
}
(ControlFlow::WaitUntil(old_instant), ControlFlow::WaitUntil(new_instant))
if old_instant == new_instant =>
{
@ -525,7 +513,7 @@ impl AppState {
},
);
this.waker.stop()
},
}
(_, ControlFlow::WaitUntil(new_instant)) => {
let start = Instant::now();
ptr::write(
@ -536,7 +524,7 @@ impl AppState {
},
);
this.waker.start_at(new_instant)
},
}
(_, ControlFlow::Poll) => {
ptr::write(
&mut this.app_state,
@ -545,13 +533,13 @@ impl AppState {
},
);
this.waker.start()
},
}
(_, ControlFlow::Exit) => {
// https://developer.apple.com/library/archive/qa/qa1561/_index.html
// it is not possible to quit an iOS app gracefully and programatically
warn!("`ControlFlow::Exit` ignored on iOS");
this.control_flow = old
},
}
}
}

View file

@ -161,14 +161,14 @@ impl UIInterfaceOrientationMask {
match (valid_orientations, idiom) {
(ValidOrientations::LandscapeAndPortrait, Idiom::Phone) => {
UIInterfaceOrientationMask::AllButUpsideDown
},
}
(ValidOrientations::LandscapeAndPortrait, _) => UIInterfaceOrientationMask::All,
(ValidOrientations::Landscape, _) => UIInterfaceOrientationMask::Landscape,
(ValidOrientations::Portrait, Idiom::Phone) => UIInterfaceOrientationMask::Portrait,
(ValidOrientations::Portrait, _) => {
UIInterfaceOrientationMask::Portrait
| UIInterfaceOrientationMask::PortraitUpsideDown
},
}
}
}
}

View file

@ -170,7 +170,7 @@ impl Inner {
let () = msg_send![self.window, setScreen: uiscreen];
}
let () = msg_send![self.window, setFrame: bounds];
},
}
None => warn!("`Window::set_fullscreen(None)` ignored on iOS"),
}
}
@ -301,14 +301,12 @@ impl Window {
let screen_bounds: CGRect = msg_send![screen, bounds];
let frame = match window_attributes.inner_size {
Some(dim) => {
CGRect {
origin: screen_bounds.origin,
size: CGSize {
width: dim.width,
height: dim.height,
},
}
Some(dim) => CGRect {
origin: screen_bounds.origin,
size: CGSize {
width: dim.width,
height: dim.height,
},
},
None => screen_bounds,
};

View file

@ -158,10 +158,10 @@ impl Window {
match *window_target {
EventLoopWindowTarget::Wayland(ref window_target) => {
wayland::Window::new(window_target, attribs, pl_attribs).map(Window::Wayland)
},
}
EventLoopWindowTarget::X(ref window_target) => {
x11::Window::new(window_target, attribs, pl_attribs).map(Window::X)
},
}
}
}
@ -313,13 +313,9 @@ impl Window {
pub fn fullscreen(&self) -> Option<RootMonitorHandle> {
match self {
&Window::X(ref w) => w.fullscreen(),
&Window::Wayland(ref w) => {
w.fullscreen().map(|monitor_id| {
RootMonitorHandle {
inner: MonitorHandle::Wayland(monitor_id),
}
})
},
&Window::Wayland(ref w) => w.fullscreen().map(|monitor_id| RootMonitorHandle {
inner: MonitorHandle::Wayland(monitor_id),
}),
}
}
@ -374,15 +370,11 @@ impl Window {
#[inline]
pub fn current_monitor(&self) -> RootMonitorHandle {
match self {
&Window::X(ref window) => {
RootMonitorHandle {
inner: MonitorHandle::X(window.current_monitor()),
}
&Window::X(ref window) => RootMonitorHandle {
inner: MonitorHandle::X(window.current_monitor()),
},
&Window::Wayland(ref window) => {
RootMonitorHandle {
inner: MonitorHandle::Wayland(window.current_monitor()),
}
&Window::Wayland(ref window) => RootMonitorHandle {
inner: MonitorHandle::Wayland(window.current_monitor()),
},
}
}
@ -390,20 +382,16 @@ impl Window {
#[inline]
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
match self {
&Window::X(ref window) => {
window
.available_monitors()
.into_iter()
.map(MonitorHandle::X)
.collect()
},
&Window::Wayland(ref window) => {
window
.available_monitors()
.into_iter()
.map(MonitorHandle::Wayland)
.collect()
},
&Window::X(ref window) => window
.available_monitors()
.into_iter()
.map(MonitorHandle::X)
.collect(),
&Window::Wayland(ref window) => window
.available_monitors()
.into_iter()
.map(MonitorHandle::Wayland)
.collect(),
}
}
@ -464,16 +452,14 @@ impl<T: 'static> EventLoop<T> {
"x11" => {
// TODO: propagate
return EventLoop::new_x11().expect("Failed to initialize X11 backend");
},
}
"wayland" => {
return EventLoop::new_wayland().expect("Failed to initialize Wayland backend");
},
_ => {
panic!(
"Unknown environment variable value for {}, try one of `x11`,`wayland`",
BACKEND_PREFERENCE_ENV_VAR,
)
},
}
_ => panic!(
"Unknown environment variable value for {}, try one of `x11`,`wayland`",
BACKEND_PREFERENCE_ENV_VAR,
),
}
}
@ -511,19 +497,17 @@ impl<T: 'static> EventLoop<T> {
#[inline]
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
match *self {
EventLoop::Wayland(ref evlp) => {
evlp.available_monitors()
.into_iter()
.map(MonitorHandle::Wayland)
.collect()
},
EventLoop::X(ref evlp) => {
evlp.x_connection()
.available_monitors()
.into_iter()
.map(MonitorHandle::X)
.collect()
},
EventLoop::Wayland(ref evlp) => evlp
.available_monitors()
.into_iter()
.map(MonitorHandle::Wayland)
.collect(),
EventLoop::X(ref evlp) => evlp
.x_connection()
.available_monitors()
.into_iter()
.map(MonitorHandle::X)
.collect(),
}
}

View file

@ -137,22 +137,20 @@ impl<T: 'static> EventLoop<T> {
let env = Environment::from_display_with_cb(
&display,
&mut event_queue,
move |event, registry| {
match event {
GlobalEvent::New {
id,
ref interface,
version,
} => {
if interface == "wl_seat" {
seat_manager.add_seat(id, version, registry)
}
},
GlobalEvent::Removed { id, ref interface } => {
if interface == "wl_seat" {
seat_manager.remove_seat(id)
}
},
move |event, registry| match event {
GlobalEvent::New {
id,
ref interface,
version,
} => {
if interface == "wl_seat" {
seat_manager.add_seat(id, version, registry)
}
}
GlobalEvent::Removed { id, ref interface } => {
if interface == "wl_seat" {
seat_manager.remove_seat(id)
}
}
},
)
@ -299,7 +297,7 @@ impl<T: 'static> EventLoop<T> {
&self.window_target,
&mut control_flow,
);
},
}
ControlFlow::Wait => {
self.inner_loop.dispatch(None, &mut ()).unwrap();
callback(
@ -310,7 +308,7 @@ impl<T: 'static> EventLoop<T> {
&self.window_target,
&mut control_flow,
);
},
}
ControlFlow::WaitUntil(deadline) => {
let start = Instant::now();
// compute the blocking duration
@ -344,7 +342,7 @@ impl<T: 'static> EventLoop<T> {
&mut control_flow,
);
}
},
}
}
}
@ -536,7 +534,7 @@ impl SeatData {
}
}
}
},
}
_ => unreachable!(),
}
}
@ -648,12 +646,10 @@ impl MonitorHandle {
.with_info(&self.proxy, |_, info| info.modes.clone())
.unwrap_or(vec![])
.into_iter()
.map(|x| {
VideoMode {
size: (x.dimensions.0 as u32, x.dimensions.1 as u32),
refresh_rate: (x.refresh_rate as f32 / 1000.0).round() as u16,
bit_depth: 32,
}
.map(|x| VideoMode {
size: (x.dimensions.0 as u32, x.dimensions.1 as u32),
refresh_rate: (x.refresh_rate as f32 / 1000.0).round() as u16,
bit_depth: 32,
})
}
}
@ -674,11 +670,9 @@ pub fn primary_monitor(outputs: &OutputMgr) -> MonitorHandle {
pub fn available_monitors(outputs: &OutputMgr) -> VecDeque<MonitorHandle> {
outputs.with_all(|list| {
list.iter()
.map(|&(_, ref proxy, _)| {
MonitorHandle {
proxy: proxy.clone(),
mgr: outputs.clone(),
}
.map(|&(_, ref proxy, _)| MonitorHandle {
proxy: proxy.clone(),
mgr: outputs.clone(),
})
.collect()
})

View file

@ -31,12 +31,12 @@ pub fn init_keyboard(
let wid = make_wid(&surface);
my_sink.send((WindowEvent::Focused(true), wid)).unwrap();
*target.lock().unwrap() = Some(wid);
},
}
KbEvent::Leave { surface, .. } => {
let wid = make_wid(&surface);
my_sink.send((WindowEvent::Focused(false), wid)).unwrap();
*target.lock().unwrap() = None;
},
}
KbEvent::Key {
rawkey,
keysym,
@ -79,8 +79,8 @@ pub fn init_keyboard(
}
}
}
},
KbEvent::RepeatInfo { .. } => { /* Handled by smithay client toolkit */ },
}
KbEvent::RepeatInfo { .. } => { /* Handled by smithay client toolkit */ }
KbEvent::Modifiers {
modifiers: event_modifiers,
} => *modifiers_tracker.lock().unwrap() = event_modifiers.into(),
@ -133,53 +133,49 @@ pub fn init_keyboard(
// }
seat.get_keyboard(|keyboard| {
keyboard.implement_closure(
move |evt, _| {
match evt {
wl_keyboard::Event::Enter { surface, .. } => {
let wid = make_wid(&surface);
my_sink.send((WindowEvent::Focused(true), wid)).unwrap();
target = Some(wid);
},
wl_keyboard::Event::Leave { surface, .. } => {
let wid = make_wid(&surface);
my_sink.send((WindowEvent::Focused(false), wid)).unwrap();
target = None;
},
wl_keyboard::Event::Key { key, state, .. } => {
if let Some(wid) = target {
let state = match state {
wl_keyboard::KeyState::Pressed => ElementState::Pressed,
wl_keyboard::KeyState::Released => ElementState::Released,
_ => unreachable!(),
};
my_sink
.send((
WindowEvent::KeyboardInput {
device_id: crate::event::DeviceId(
crate::platform_impl::DeviceId::Wayland(
DeviceId,
),
),
input: KeyboardInput {
state,
scancode: key,
virtual_keycode: None,
modifiers: ModifiersState::default(),
},
},
wid,
))
.unwrap();
}
},
_ => (),
move |evt, _| match evt {
wl_keyboard::Event::Enter { surface, .. } => {
let wid = make_wid(&surface);
my_sink.send((WindowEvent::Focused(true), wid)).unwrap();
target = Some(wid);
}
wl_keyboard::Event::Leave { surface, .. } => {
let wid = make_wid(&surface);
my_sink.send((WindowEvent::Focused(false), wid)).unwrap();
target = None;
}
wl_keyboard::Event::Key { key, state, .. } => {
if let Some(wid) = target {
let state = match state {
wl_keyboard::KeyState::Pressed => ElementState::Pressed,
wl_keyboard::KeyState::Released => ElementState::Released,
_ => unreachable!(),
};
my_sink
.send((
WindowEvent::KeyboardInput {
device_id: crate::event::DeviceId(
crate::platform_impl::DeviceId::Wayland(DeviceId),
),
input: KeyboardInput {
state,
scancode: key,
virtual_keycode: None,
modifiers: ModifiersState::default(),
},
},
wid,
))
.unwrap();
}
}
_ => (),
},
(),
)
})
.unwrap()
},
}
}
}

View file

@ -56,7 +56,7 @@ pub fn implement_pointer(
wid,
);
}
},
}
PtrEvent::Leave { surface, .. } => {
mouse_focus = None;
let wid = store.find_wid(&surface);
@ -70,7 +70,7 @@ pub fn implement_pointer(
wid,
);
}
},
}
PtrEvent::Motion {
surface_x,
surface_y,
@ -88,7 +88,7 @@ pub fn implement_pointer(
wid,
);
}
},
}
PtrEvent::Button { button, state, .. } => {
if let Some(wid) = mouse_focus {
let state = match state {
@ -115,7 +115,7 @@ pub fn implement_pointer(
wid,
);
}
},
}
PtrEvent::Axis { axis, value, .. } => {
if let Some(wid) = mouse_focus {
if pointer.as_ref().version() < 5 {
@ -155,7 +155,7 @@ pub fn implement_pointer(
}
}
}
},
}
PtrEvent::Frame => {
let axis_buffer = axis_buffer.take();
let axis_discrete_buffer = axis_discrete_buffer.take();
@ -188,11 +188,11 @@ pub fn implement_pointer(
);
}
}
},
}
PtrEvent::AxisSource { .. } => (),
PtrEvent::AxisStop { .. } => {
axis_state = TouchPhase::Ended;
},
}
PtrEvent::AxisDiscrete { axis, discrete } => {
let (mut x, mut y) = axis_discrete_buffer.unwrap_or((0, 0));
match axis {
@ -206,7 +206,7 @@ pub fn implement_pointer(
TouchPhase::Started | TouchPhase::Moved => TouchPhase::Moved,
_ => TouchPhase::Started,
}
},
}
_ => unreachable!(),
}
},

View file

@ -49,7 +49,7 @@ pub(crate) fn implement_touch(
id,
});
}
},
}
TouchEvent::Up { id, .. } => {
let idx = pending_ids.iter().position(|p| p.id == id);
if let Some(idx) = idx {
@ -66,7 +66,7 @@ pub(crate) fn implement_touch(
pt.wid,
);
}
},
}
TouchEvent::Motion { id, x, y, .. } => {
let pt = pending_ids.iter_mut().find(|p| p.id == id);
if let Some(pt) = pt {
@ -83,7 +83,7 @@ pub(crate) fn implement_touch(
pt.wid,
);
}
},
}
TouchEvent::Frame => (),
TouchEvent::Cancel => {
for pt in pending_ids.drain(..) {
@ -99,7 +99,7 @@ pub(crate) fn implement_touch(
pt.wid,
);
}
},
}
_ => unreachable!(),
}
},

View file

@ -107,7 +107,7 @@ impl Window {
return;
}
}
},
}
WEvent::Refresh => {
let store = window_store.lock().unwrap();
for window in &store.windows {
@ -116,7 +116,7 @@ impl Window {
return;
}
}
},
}
WEvent::Close => {
let mut store = window_store.lock().unwrap();
for window in &mut store.windows {
@ -125,7 +125,7 @@ impl Window {
return;
}
}
},
}
}
},
)

View file

@ -118,7 +118,7 @@ impl<T: 'static> EventProcessor<T> {
wt.xconn
.check_errors()
.expect("Failed to call XRefreshKeyboardMapping");
},
}
ffi::ClientMessage => {
let client_msg: &ffi::XClientMessageEvent = xev.as_ref();
@ -236,7 +236,7 @@ impl<T: 'static> EventProcessor<T> {
event: WindowEvent::HoveredFileCancelled,
});
}
},
}
ffi::SelectionNotify => {
let xsel: &ffi::XSelectionEvent = xev.as_ref();
@ -263,7 +263,7 @@ impl<T: 'static> EventProcessor<T> {
self.dnd.result = result;
}
},
}
ffi::ConfigureNotify => {
#[derive(Debug, Default)]
@ -429,7 +429,7 @@ impl<T: 'static> EventProcessor<T> {
callback(Event::WindowEvent { window_id, event });
}
}
},
}
ffi::ReparentNotify => {
let xev: &ffi::XReparentEvent = xev.as_ref();
@ -444,7 +444,7 @@ impl<T: 'static> EventProcessor<T> {
self.with_window(xev.window, |window| {
window.invalidate_cached_frame_extents();
});
},
}
ffi::DestroyNotify => {
let xev: &ffi::XDestroyWindowEvent = xev.as_ref();
@ -467,7 +467,7 @@ impl<T: 'static> EventProcessor<T> {
window_id,
event: WindowEvent::Destroyed,
});
},
}
ffi::Expose => {
let xev: &ffi::XExposeEvent = xev.as_ref();
@ -479,7 +479,7 @@ impl<T: 'static> EventProcessor<T> {
window_id,
event: WindowEvent::RedrawRequested,
});
},
}
ffi::KeyPress | ffi::KeyRelease => {
use crate::event::ElementState::{Pressed, Released};
@ -554,7 +554,7 @@ impl<T: 'static> EventProcessor<T> {
callback(event);
}
}
},
}
ffi::GenericEvent => {
let guard = if let Some(e) = GenericEventCookie::from_event(&wt.xconn, *xev) {
@ -596,39 +596,33 @@ impl<T: 'static> EventProcessor<T> {
Released
};
match xev.detail as u32 {
ffi::Button1 => {
callback(Event::WindowEvent {
window_id,
event: MouseInput {
device_id,
state,
button: Left,
modifiers,
},
})
},
ffi::Button2 => {
callback(Event::WindowEvent {
window_id,
event: MouseInput {
device_id,
state,
button: Middle,
modifiers,
},
})
},
ffi::Button3 => {
callback(Event::WindowEvent {
window_id,
event: MouseInput {
device_id,
state,
button: Right,
modifiers,
},
})
},
ffi::Button1 => callback(Event::WindowEvent {
window_id,
event: MouseInput {
device_id,
state,
button: Left,
modifiers,
},
}),
ffi::Button2 => callback(Event::WindowEvent {
window_id,
event: MouseInput {
device_id,
state,
button: Middle,
modifiers,
},
}),
ffi::Button3 => callback(Event::WindowEvent {
window_id,
event: MouseInput {
device_id,
state,
button: Right,
modifiers,
},
}),
// Suppress emulated scroll wheel clicks, since we handle the real motion events for those.
// In practice, even clicky scroll wheels appear to be reported by evdev (and XInput2 in
@ -651,21 +645,19 @@ impl<T: 'static> EventProcessor<T> {
},
});
}
},
}
x => {
callback(Event::WindowEvent {
window_id,
event: MouseInput {
device_id,
state,
button: Other(x as u8),
modifiers,
},
})
},
x => callback(Event::WindowEvent {
window_id,
event: MouseInput {
device_id,
state,
button: Other(x as u8),
modifiers,
},
}),
}
},
}
ffi::XI_Motion => {
let xev: &ffi::XIDeviceEvent = unsafe { &*(xev.data as *const _) };
let device_id = mkdid(xev.deviceid);
@ -734,11 +726,11 @@ impl<T: 'static> EventProcessor<T> {
delta: match info.orientation {
ScrollOrientation::Horizontal => {
LineDelta(delta as f32, 0.0)
},
}
// X11 vertical scroll coordinates are opposite to winit's
ScrollOrientation::Vertical => {
LineDelta(0.0, -delta as f32)
},
}
},
phase: TouchPhase::Moved,
modifiers,
@ -761,7 +753,7 @@ impl<T: 'static> EventProcessor<T> {
for event in events {
callback(event);
}
},
}
ffi::XI_Enter => {
let xev: &ffi::XIEnterEvent = unsafe { &*(xev.data as *const _) };
@ -821,7 +813,7 @@ impl<T: 'static> EventProcessor<T> {
},
});
}
},
}
ffi::XI_Leave => {
let xev: &ffi::XILeaveEvent = unsafe { &*(xev.data as *const _) };
@ -836,7 +828,7 @@ impl<T: 'static> EventProcessor<T> {
},
});
}
},
}
ffi::XI_FocusIn => {
let xev: &ffi::XIFocusInEvent = unsafe { &*(xev.data as *const _) };
@ -878,7 +870,7 @@ impl<T: 'static> EventProcessor<T> {
modifiers: ModifiersState::from(xev.mods),
},
});
},
}
ffi::XI_FocusOut => {
let xev: &ffi::XIFocusOutEvent = unsafe { &*(xev.data as *const _) };
if !self.window_exists(xev.event) {
@ -892,7 +884,7 @@ impl<T: 'static> EventProcessor<T> {
window_id: mkwid(xev.event),
event: Focused(false),
})
},
}
ffi::XI_TouchBegin | ffi::XI_TouchUpdate | ffi::XI_TouchEnd => {
let xev: &ffi::XIDeviceEvent = unsafe { &*(xev.data as *const _) };
@ -920,7 +912,7 @@ impl<T: 'static> EventProcessor<T> {
}),
})
}
},
}
ffi::XI_RawButtonPress | ffi::XI_RawButtonRelease => {
let xev: &ffi::XIRawEvent = unsafe { &*(xev.data as *const _) };
@ -937,7 +929,7 @@ impl<T: 'static> EventProcessor<T> {
},
});
}
},
}
ffi::XI_RawMotion => {
let xev: &ffi::XIRawEvent = unsafe { &*(xev.data as *const _) };
@ -962,7 +954,7 @@ impl<T: 'static> EventProcessor<T> {
1 => mouse_delta.1 = x,
2 => scroll_delta.0 = x as f32,
3 => scroll_delta.1 = x as f32,
_ => {},
_ => {}
}
callback(Event::DeviceEvent {
device_id: did,
@ -988,7 +980,7 @@ impl<T: 'static> EventProcessor<T> {
},
});
}
},
}
ffi::XI_RawKeyPress | ffi::XI_RawKeyRelease => {
let xev: &ffi::XIRawEvent = unsafe { &*(xev.data as *const _) };
@ -1033,7 +1025,7 @@ impl<T: 'static> EventProcessor<T> {
modifiers: ModifiersState::default(),
}),
});
},
}
ffi::XI_HierarchyChanged => {
let xev: &ffi::XIHierarchyEvent = unsafe { &*(xev.data as *const _) };
@ -1056,11 +1048,11 @@ impl<T: 'static> EventProcessor<T> {
devices.remove(&DeviceId(info.deviceid));
}
}
},
}
_ => {},
_ => {}
}
},
}
_ => {
if event_type == self.randr_event_offset {
// In the future, it would be quite easy to emit monitor hotplug events.
@ -1101,13 +1093,13 @@ impl<T: 'static> EventProcessor<T> {
}
}
}
},
}
}
match self.ime_receiver.try_recv() {
Ok((window_id, x, y)) => {
wt.ime.borrow_mut().send_xim_spot(window_id, x, y);
},
}
Err(_) => (),
}
}

View file

@ -308,7 +308,7 @@ impl<T: 'static> EventLoop<T> {
&self.target,
&mut control_flow,
);
},
}
ControlFlow::Wait => {
self.inner_loop.dispatch(None, &mut ()).unwrap();
callback(
@ -319,7 +319,7 @@ impl<T: 'static> EventLoop<T> {
&self.target,
&mut control_flow,
);
},
}
ControlFlow::WaitUntil(deadline) => {
let start = ::std::time::Instant::now();
// compute the blocking duration
@ -353,7 +353,7 @@ impl<T: 'static> EventLoop<T> {
&mut control_flow,
);
}
},
}
}
}
@ -588,8 +588,8 @@ impl Device {
position: 0.0,
},
));
},
_ => {},
}
_ => {}
}
}
}
@ -619,8 +619,8 @@ impl Device {
{
axis.position = info.value;
}
},
_ => {},
}
_ => {}
}
}
}

View file

@ -384,7 +384,7 @@ impl UnownedWindow {
ImeContextCreationError::XError(err) => OsError::XError(err),
ImeContextCreationError::Null => {
OsError::XMisc("IME Context creation failed")
},
}
};
return Err(os_error!(e));
}
@ -558,7 +558,7 @@ impl UnownedWindow {
self.set_position_inner(position.0, position.1).queue();
}
flusher
},
}
Some(RootMonitorHandle {
inner: PlatformMonitorHandle::X(monitor),
}) => {
@ -568,7 +568,7 @@ impl UnownedWindow {
self.set_position_inner(monitor_origin.0, monitor_origin.1)
.queue();
self.set_fullscreen_hint(true)
},
}
_ => unreachable!(),
}
}
@ -1190,11 +1190,11 @@ impl UnownedWindow {
ffi::GrabSuccess => Ok(()),
ffi::AlreadyGrabbed => {
Err("Cursor could not be grabbed: already grabbed by another client")
},
}
ffi::GrabInvalidTime => Err("Cursor could not be grabbed: invalid time"),
ffi::GrabNotViewable => {
Err("Cursor could not be grabbed: grab location not viewable")
},
}
ffi::GrabFrozen => Err("Cursor could not be grabbed: frozen by another client"),
_ => unreachable!(),
}

View file

@ -100,7 +100,7 @@ unsafe fn maybe_dispatch_device_event(event: id) {
}
AppState::queue_events(events);
},
}
_ => (),
}
}

View file

@ -213,11 +213,9 @@ impl AppState {
let start = HANDLER.get_start_time().unwrap();
let cause = match HANDLER.get_control_flow_and_update_prev() {
ControlFlow::Poll => StartCause::Poll,
ControlFlow::Wait => {
StartCause::WaitCancelled {
start,
requested_resume: None,
}
ControlFlow::Wait => StartCause::WaitCancelled {
start,
requested_resume: None,
},
ControlFlow::WaitUntil(requested_resume) => {
if Instant::now() >= requested_resume {
@ -231,7 +229,7 @@ impl AppState {
requested_resume: Some(requested_resume),
}
}
},
}
ControlFlow::Exit => StartCause::Poll, //panic!("unexpected `ControlFlow::Exit`"),
};
HANDLER.set_in_callback(true);

View file

@ -121,7 +121,7 @@ extern "C" fn control_flow_begin_handler(
//trace!("Triggered `CFRunLoopAfterWaiting`");
AppState::wakeup();
//trace!("Completed `CFRunLoopAfterWaiting`");
},
}
kCFRunLoopEntry => unimplemented!(), // not expected to ever happen
_ => unreachable!(),
}
@ -140,7 +140,7 @@ extern "C" fn control_flow_end_handler(
//trace!("Triggered `CFRunLoopBeforeWaiting`");
AppState::cleared();
//trace!("Completed `CFRunLoopBeforeWaiting`");
},
}
kCFRunLoopExit => (), //unimplemented!(), // not expected to ever happen
_ => unreachable!(),
}

View file

@ -25,7 +25,7 @@ impl From<CursorIcon> for Cursor {
CursorIcon::Alias => Cursor::Native("dragLinkCursor"),
CursorIcon::NotAllowed | CursorIcon::NoDrop => {
Cursor::Native("operationNotAllowedCursor")
},
}
CursorIcon::ContextMenu => Cursor::Native("contextualMenuCursor"),
CursorIcon::Crosshair => Cursor::Native("crosshairCursor"),
CursorIcon::EResize => Cursor::Native("resizeRightCursor"),
@ -57,7 +57,7 @@ impl From<CursorIcon> for Cursor {
// what's used in Safari and Chrome.
CursorIcon::Wait | CursorIcon::Progress => {
Cursor::Undocumented("busyButClickableCursor")
},
}
// For the rest, we can just snatch the cursors from WebKit...
// They fit the style of the native cursors, and will seem
@ -81,7 +81,7 @@ impl Cursor {
Cursor::Native(cursor_name) => {
let sel = Sel::register(cursor_name);
msg_send![class!(NSCursor), performSelector: sel]
},
}
Cursor::Undocumented(cursor_name) => {
let class = class!(NSCursor);
let sel = Sel::register(cursor_name);
@ -92,7 +92,7 @@ impl Cursor {
sel!(arrowCursor)
};
msg_send![class, performSelector: sel]
},
}
Cursor::WebKit(cursor_name) => load_webkit_cursor(cursor_name),
}
}

View file

@ -900,7 +900,7 @@ extern "C" fn scroll_wheel(this: &Object, _sel: Sel, event: id) {
let phase = match event.phase() {
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
TouchPhase::Started
},
}
NSEventPhase::NSEventPhaseEnded => TouchPhase::Ended,
_ => TouchPhase::Moved,
};

View file

@ -116,7 +116,7 @@ fn create_window(
Some(ref monitor_id) => {
let monitor_screen = monitor_id.inner.ns_screen();
Some(monitor_screen.unwrap_or(appkit::NSScreen::mainScreen(nil)))
},
}
_ => None,
};
let frame = match screen {
@ -127,7 +127,7 @@ fn create_window(
.map(|logical| (logical.width, logical.height))
.unwrap_or_else(|| (800.0, 600.0));
NSRect::new(NSPoint::new(0.0, 0.0), NSSize::new(width, height))
},
}
};
let mut masks = if !attrs.decorations && !screen.is_some() {
@ -649,7 +649,7 @@ impl UnownedWindow {
// Our best bet is probably to move to the origin of the
// target monitor.
unimplemented!()
},
}
(&None, None) | (&Some(_), Some(_)) => return,
_ => (),
}

View file

@ -285,14 +285,14 @@ pub fn handle_extended_keys(
} else {
winuser::VK_LCONTROL
}
},
}
winuser::VK_MENU => {
if extended {
winuser::VK_RMENU
} else {
winuser::VK_LMENU
}
},
}
_ => {
match scancode {
// This is only triggered when using raw input. Without this check, we get two events whenever VK_PAUSE is
@ -308,10 +308,10 @@ pub fn handle_extended_keys(
} else {
winuser::VK_SCROLL
}
},
}
_ => vkey,
}
},
}
};
Some((vkey, scancode))
}

View file

@ -162,7 +162,7 @@ impl<T: 'static> EventLoop<T> {
match event {
Some(e) => {
runner.process_event(e);
},
}
None => break,
}
}
@ -210,10 +210,10 @@ impl<T: 'static> EventLoop<T> {
break 'main;
}
msg_unprocessed = true;
},
}
ControlFlow::WaitUntil(resume_time) => {
wait_until_time_or_msg(resume_time);
},
}
ControlFlow::Poll => (),
}
}
@ -335,7 +335,7 @@ impl<T> EventLoopRunner<T> {
RunnerState::New => {
self.call_event_handler(Event::NewEvents(StartCause::Init));
RunnerState::HandlingEvents
},
}
// When `NewEvents` gets sent after an idle depends on the control flow...
RunnerState::Idle(wait_start) => {
@ -371,7 +371,7 @@ impl<T> EventLoopRunner<T> {
// `Exit` shouldn't really ever get sent here, but if it does do something somewhat sane.
ControlFlow::Exit => RunnerState::DeferredNewEvents(wait_start),
}
},
}
};
}
@ -405,27 +405,23 @@ impl<T> EventLoopRunner<T> {
start: wait_start,
requested_resume: None,
}))
},
}
ControlFlow::WaitUntil(resume_time) => {
let start_cause = match Instant::now() >= resume_time {
// If the current time is later than the requested resume time, the resume time
// has been reached.
true => {
StartCause::ResumeTimeReached {
start: wait_start,
requested_resume: resume_time,
}
true => StartCause::ResumeTimeReached {
start: wait_start,
requested_resume: resume_time,
},
// Otherwise, the requested resume time HASN'T been reached and we send a WaitCancelled.
false => {
StartCause::WaitCancelled {
start: wait_start,
requested_resume: Some(resume_time),
}
false => StartCause::WaitCancelled {
start: wait_start,
requested_resume: Some(resume_time),
},
};
self.call_event_handler(Event::NewEvents(start_cause));
},
}
// This can be reached if the control flow is changed to poll during a `RedrawRequested`
// that was sent after `EventsCleared`.
ControlFlow::Poll => self.call_event_handler(Event::NewEvents(StartCause::Poll)),
@ -442,7 +438,7 @@ impl<T> EventLoopRunner<T> {
RunnerState::HandlingEvents => {
self.call_event_handler(Event::EventsCleared);
self.runner_state = RunnerState::Idle(Instant::now());
},
}
// If we *weren't* handling events, we don't have to do anything.
RunnerState::New | RunnerState::Idle(..) => (),
@ -455,7 +451,7 @@ impl<T> EventLoopRunner<T> {
ControlFlow::Poll => {
self.call_event_handler(Event::NewEvents(StartCause::Poll));
self.call_event_handler(Event::EventsCleared);
},
}
// If we had deferred a WaitUntil and the resume time has since been reached,
// send the resume notification and EventsCleared event.
ControlFlow::WaitUntil(resume_time) => {
@ -468,27 +464,25 @@ impl<T> EventLoopRunner<T> {
));
self.call_event_handler(Event::EventsCleared);
}
},
}
// If we deferred a wait and no events were received, the user doesn't have to
// get an event.
ControlFlow::Wait | ControlFlow::Exit => (),
}
// Mark that we've entered an idle state.
self.runner_state = RunnerState::Idle(wait_start)
},
}
}
}
fn call_event_handler(&mut self, event: Event<T>) {
match event {
Event::NewEvents(_) => {
self.trigger_newevents_on_redraw
.store(true, Ordering::Relaxed)
},
Event::EventsCleared => {
self.trigger_newevents_on_redraw
.store(false, Ordering::Relaxed)
},
Event::NewEvents(_) => self
.trigger_newevents_on_redraw
.store(true, Ordering::Relaxed),
Event::EventsCleared => self
.trigger_newevents_on_redraw
.store(false, Ordering::Relaxed),
_ => (),
}
@ -825,18 +819,18 @@ unsafe extern "system" fn public_window_callback<T>(
runner.in_modal_loop = true;
}
0
},
}
winuser::WM_EXITSIZEMOVE => {
let mut runner = subclass_input.event_loop_runner.runner.borrow_mut();
if let Some(ref mut runner) = *runner {
runner.in_modal_loop = false;
}
0
},
}
winuser::WM_NCCREATE => {
enable_non_client_dpi_scaling(window);
commctrl::DefSubclassProc(window, msg, wparam, lparam)
},
}
winuser::WM_NCLBUTTONDOWN => {
// jumpstart the modal loop
@ -850,7 +844,7 @@ unsafe extern "system" fn public_window_callback<T>(
winuser::PostMessageW(window, winuser::WM_MOUSEMOVE, 0, 0);
}
commctrl::DefSubclassProc(window, msg, wparam, lparam)
},
}
winuser::WM_CLOSE => {
use crate::event::WindowEvent::CloseRequested;
@ -859,7 +853,7 @@ unsafe extern "system" fn public_window_callback<T>(
event: CloseRequested,
});
0
},
}
winuser::WM_DESTROY => {
use crate::event::WindowEvent::Destroyed;
@ -872,7 +866,7 @@ unsafe extern "system" fn public_window_callback<T>(
Box::from_raw(subclass_input);
drop(subclass_input);
0
},
}
_ if msg == *REQUEST_REDRAW_NO_NEWEVENTS_MSG_ID => {
use crate::event::WindowEvent::RedrawRequested;
@ -892,22 +886,20 @@ unsafe extern "system" fn public_window_callback<T>(
};
match runner_state {
RunnerState::Idle(..) | RunnerState::DeferredNewEvents(..) => request_redraw(),
RunnerState::HandlingEvents => {
match control_flow {
ControlFlow::Poll => request_redraw(),
ControlFlow::WaitUntil(resume_time) => {
if resume_time <= Instant::now() {
request_redraw()
}
},
_ => (),
RunnerState::HandlingEvents => match control_flow {
ControlFlow::Poll => request_redraw(),
ControlFlow::WaitUntil(resume_time) => {
if resume_time <= Instant::now() {
request_redraw()
}
}
_ => (),
},
_ => (),
}
}
0
},
}
winuser::WM_PAINT => {
use crate::event::WindowEvent::RedrawRequested;
subclass_input.send_event(Event::WindowEvent {
@ -915,7 +907,7 @@ unsafe extern "system" fn public_window_callback<T>(
event: RedrawRequested,
});
commctrl::DefSubclassProc(window, msg, wparam, lparam)
},
}
// WM_MOVE supplies client area positions, so we send Moved here instead.
winuser::WM_WINDOWPOSCHANGED => {
@ -934,7 +926,7 @@ unsafe extern "system" fn public_window_callback<T>(
// This is necessary for us to still get sent WM_SIZE.
commctrl::DefSubclassProc(window, msg, wparam, lparam)
},
}
winuser::WM_SIZE => {
use crate::event::WindowEvent::Resized;
@ -962,7 +954,7 @@ unsafe extern "system" fn public_window_callback<T>(
subclass_input.send_event(event);
0
},
}
winuser::WM_CHAR => {
use crate::event::WindowEvent::ReceivedCharacter;
@ -972,7 +964,7 @@ unsafe extern "system" fn public_window_callback<T>(
event: ReceivedCharacter(chr),
});
0
},
}
// Prevents default windows menu hotkeys playing unwanted
// "ding" sounds. Alternatively could check for WM_SYSCOMMAND
@ -1024,7 +1016,7 @@ unsafe extern "system" fn public_window_callback<T>(
});
0
},
}
winuser::WM_MOUSELEAVE => {
use crate::event::WindowEvent::CursorLeft;
@ -1043,7 +1035,7 @@ unsafe extern "system" fn public_window_callback<T>(
});
0
},
}
winuser::WM_MOUSEWHEEL => {
use crate::event::MouseScrollDelta::LineDelta;
@ -1063,7 +1055,7 @@ unsafe extern "system" fn public_window_callback<T>(
});
0
},
}
winuser::WM_MOUSEHWHEEL => {
use crate::event::MouseScrollDelta::LineDelta;
@ -1083,7 +1075,7 @@ unsafe extern "system" fn public_window_callback<T>(
});
0
},
}
winuser::WM_KEYDOWN | winuser::WM_SYSKEYDOWN => {
use crate::event::{ElementState::Pressed, VirtualKeyCode};
@ -1114,7 +1106,7 @@ unsafe extern "system" fn public_window_callback<T>(
}
0
}
},
}
winuser::WM_KEYUP | winuser::WM_SYSKEYUP => {
use crate::event::ElementState::Released;
@ -1133,7 +1125,7 @@ unsafe extern "system" fn public_window_callback<T>(
});
}
0
},
}
winuser::WM_LBUTTONDOWN => {
use crate::event::{ElementState::Pressed, MouseButton::Left, WindowEvent::MouseInput};
@ -1150,7 +1142,7 @@ unsafe extern "system" fn public_window_callback<T>(
},
});
0
},
}
winuser::WM_LBUTTONUP => {
use crate::event::{
@ -1169,7 +1161,7 @@ unsafe extern "system" fn public_window_callback<T>(
},
});
0
},
}
winuser::WM_RBUTTONDOWN => {
use crate::event::{
@ -1188,7 +1180,7 @@ unsafe extern "system" fn public_window_callback<T>(
},
});
0
},
}
winuser::WM_RBUTTONUP => {
use crate::event::{
@ -1207,7 +1199,7 @@ unsafe extern "system" fn public_window_callback<T>(
},
});
0
},
}
winuser::WM_MBUTTONDOWN => {
use crate::event::{
@ -1226,7 +1218,7 @@ unsafe extern "system" fn public_window_callback<T>(
},
});
0
},
}
winuser::WM_MBUTTONUP => {
use crate::event::{
@ -1245,7 +1237,7 @@ unsafe extern "system" fn public_window_callback<T>(
},
});
0
},
}
winuser::WM_XBUTTONDOWN => {
use crate::event::{
@ -1265,7 +1257,7 @@ unsafe extern "system" fn public_window_callback<T>(
},
});
0
},
}
winuser::WM_XBUTTONUP => {
use crate::event::{
@ -1285,7 +1277,7 @@ unsafe extern "system" fn public_window_callback<T>(
},
});
0
},
}
winuser::WM_INPUT_DEVICE_CHANGE => {
let event = match wparam as _ {
@ -1300,7 +1292,7 @@ unsafe extern "system" fn public_window_callback<T>(
});
0
},
}
winuser::WM_INPUT => {
use crate::event::{
@ -1399,7 +1391,7 @@ unsafe extern "system" fn public_window_callback<T>(
}
commctrl::DefSubclassProc(window, msg, wparam, lparam)
},
}
winuser::WM_TOUCH => {
let pcount = LOWORD(wparam as DWORD) as usize;
@ -1439,7 +1431,7 @@ unsafe extern "system" fn public_window_callback<T>(
}
winuser::CloseTouchInputHandle(htouch);
0
},
}
winuser::WM_SETFOCUS => {
use crate::event::WindowEvent::Focused;
@ -1449,7 +1441,7 @@ unsafe extern "system" fn public_window_callback<T>(
});
0
},
}
winuser::WM_KILLFOCUS => {
use crate::event::WindowEvent::Focused;
@ -1458,7 +1450,7 @@ unsafe extern "system" fn public_window_callback<T>(
event: Focused(false),
});
0
},
}
winuser::WM_SETCURSOR => {
let set_cursor_to = {
@ -1479,15 +1471,15 @@ unsafe extern "system" fn public_window_callback<T>(
let cursor = winuser::LoadCursorW(ptr::null_mut(), cursor.to_windows_cursor());
winuser::SetCursor(cursor);
0
},
}
None => winuser::DefWindowProcW(window, msg, wparam, lparam),
}
},
}
winuser::WM_DROPFILES => {
// See `FileDropHandler` for implementation.
0
},
}
winuser::WM_GETMINMAXINFO => {
let mmi = lparam as *mut winuser::MINMAXINFO;
@ -1516,7 +1508,7 @@ unsafe extern "system" fn public_window_callback<T>(
}
0
},
}
// Only sent on Windows 8.1 or newer. On Windows 7 and older user has to log out to change
// DPI, therefore all applications are closed while DPI is changing.
@ -1560,7 +1552,7 @@ unsafe extern "system" fn public_window_callback<T>(
});
0
},
}
_ => {
if msg == *DESTROY_MSG_ID {
@ -1613,7 +1605,7 @@ unsafe extern "system" fn public_window_callback<T>(
} else {
commctrl::DefSubclassProc(window, msg, wparam, lparam)
}
},
}
}
}
@ -1631,7 +1623,7 @@ unsafe extern "system" fn thread_event_target_callback<T>(
Box::from_raw(subclass_input);
drop(subclass_input);
0
},
}
// Because WM_PAINT comes after all other messages, we use it during modal loops to detect
// when the event queue has been emptied. See `process_event` for more details.
winuser::WM_PAINT => {
@ -1669,13 +1661,13 @@ unsafe extern "system" fn thread_event_target_callback<T>(
winuser::TranslateMessage(&mut msg);
winuser::DispatchMessageW(&mut msg);
}
},
}
// If the message isn't one of those three, it may be handled by the modal
// loop so we should return control flow to it.
_ => {
queue_call_again();
return 0;
},
}
}
}
@ -1689,27 +1681,27 @@ unsafe extern "system" fn thread_event_target_callback<T>(
wait_until_time_or_msg(resume_time);
runner.new_events();
queue_call_again();
},
}
ControlFlow::Poll => {
runner.new_events();
queue_call_again();
},
}
}
}
}
0
},
}
_ if msg == *USER_EVENT_MSG_ID => {
if let Ok(event) = subclass_input.user_event_receiver.recv() {
subclass_input.send_event(Event::UserEvent(event));
}
0
},
}
_ if msg == *EXEC_MSG_ID => {
let mut function: ThreadExecFn = Box::from_raw(wparam as usize as *mut _);
function();
0
},
}
_ => commctrl::DefSubclassProc(window, msg, wparam, lparam),
}
}

View file

@ -129,7 +129,7 @@ impl CursorIcon {
CursorIcon::NotAllowed | CursorIcon::NoDrop => winuser::IDC_NO,
CursorIcon::Grab | CursorIcon::Grabbing | CursorIcon::Move | CursorIcon::AllScroll => {
winuser::IDC_SIZEALL
},
}
CursorIcon::EResize
| CursorIcon::WResize
| CursorIcon::EwResize
@ -140,10 +140,10 @@ impl CursorIcon {
| CursorIcon::RowResize => winuser::IDC_SIZENS,
CursorIcon::NeResize | CursorIcon::SwResize | CursorIcon::NeswResize => {
winuser::IDC_SIZENESW
},
}
CursorIcon::NwResize | CursorIcon::SeResize | CursorIcon::NwseResize => {
winuser::IDC_SIZENWSE
},
}
CursorIcon::Wait => winuser::IDC_WAIT,
CursorIcon::Progress => winuser::IDC_APPSTARTING,
CursorIcon::Help => winuser::IDC_HELP,

View file

@ -464,7 +464,7 @@ impl Window {
mark_fullscreen(window.0, true);
});
},
}
&None => {
self.thread_executor.execute_in_thread(move || {
let mut window_state_lock = window_state.lock();
@ -487,7 +487,7 @@ impl Window {
mark_fullscreen(window.0, false);
});
},
}
}
}
}

View file

@ -170,7 +170,7 @@ impl MouseProperties {
Err(e) => {
self.cursor_flags = old_flags;
return Err(e);
},
}
}
Ok(())
@ -309,7 +309,7 @@ impl WindowFlags {
h,
winuser::SWP_NOZORDER | winuser::SWP_FRAMECHANGED,
);
},
}
None => {
// Refresh the window frame.
winuser::SetWindowPos(
@ -324,7 +324,7 @@ impl WindowFlags {
| winuser::SWP_NOSIZE
| winuser::SWP_FRAMECHANGED,
);
},
}
}
winuser::SendMessageW(window, *event_loop::SET_RETAIN_STATE_ON_SIZE_MSG_ID, 0, 0);
}