Skip to content

Commit

Permalink
cargo +nightly fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jgcodes2020 committed Oct 24, 2024
1 parent a88dac3 commit ddde870
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 115 deletions.
3 changes: 1 addition & 2 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
use crate::event::{DeviceEvent, DeviceId, StartCause, SurfaceEvent};
use crate::event_loop::ActiveEventLoop;
use crate::window::SurfaceId;

#[cfg(any(docsrs, macos_platform))]
use crate::platform::macos::ApplicationHandlerExtMacOS;
use crate::window::SurfaceId;

/// The handler of the application events.
pub trait ApplicationHandler {
Expand Down
26 changes: 11 additions & 15 deletions src/platform_impl/apple/appkit/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,28 @@ fn maybe_dispatch_device_event(app_state: &Rc<AppState>, event: &NSEvent) {

if delta_x != 0.0 || delta_y != 0.0 {
app_state.maybe_queue_with_handler(move |app, event_loop| {
app.device_event(
event_loop,
None,
DeviceEvent::PointerMotion { delta: (delta_x, delta_y) },
);
app.device_event(event_loop, None, DeviceEvent::PointerMotion {
delta: (delta_x, delta_y),
});
});
}
},
NSEventType::LeftMouseDown | NSEventType::RightMouseDown | NSEventType::OtherMouseDown => {
let button = unsafe { event.buttonNumber() } as u32;
app_state.maybe_queue_with_handler(move |app, event_loop| {
app.device_event(
event_loop,
None,
DeviceEvent::Button { button, state: ElementState::Pressed },
);
app.device_event(event_loop, None, DeviceEvent::Button {
button,
state: ElementState::Pressed,
});
});
},
NSEventType::LeftMouseUp | NSEventType::RightMouseUp | NSEventType::OtherMouseUp => {
let button = unsafe { event.buttonNumber() } as u32;
app_state.maybe_queue_with_handler(move |app, event_loop| {
app.device_event(
event_loop,
None,
DeviceEvent::Button { button, state: ElementState::Released },
);
app.device_event(event_loop, None, DeviceEvent::Button {
button,
state: ElementState::Released,
});
});
},
_ => (),
Expand Down
28 changes: 14 additions & 14 deletions src/platform_impl/linux/x11/dnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ impl Dnd {
DndState::Rejected => (0, atoms[DndNone]),
};
self.xconn
.send_client_msg(
target_window,
target_window,
atoms[XdndStatus] as _,
None,
[this_window, accepted, 0, 0, action as _],
)?
.send_client_msg(target_window, target_window, atoms[XdndStatus] as _, None, [
this_window,
accepted,
0,
0,
action as _,
])?
.ignore_error();

Ok(())
Expand All @@ -97,13 +97,13 @@ impl Dnd {
DndState::Rejected => (0, atoms[DndNone]),
};
self.xconn
.send_client_msg(
target_window,
target_window,
atoms[XdndFinished] as _,
None,
[this_window, accepted, action as _, 0, 0],
)?
.send_client_msg(target_window, target_window, atoms[XdndFinished] as _, None, [
this_window,
accepted,
action as _,
0,
0,
])?
.ignore_error();

Ok(())
Expand Down
47 changes: 18 additions & 29 deletions src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,10 @@ impl EventProcessor {
drop(shared_state_lock);

if moved {
callback(
&self.target,
Event::SurfaceEvent { window_id, event: SurfaceEvent::Moved(outer.into()) },
);
callback(&self.target, Event::SurfaceEvent {
window_id,
event: SurfaceEvent::Moved(outer.into()),
});
}
outer
};
Expand Down Expand Up @@ -707,18 +707,13 @@ impl EventProcessor {
drop(shared_state_lock);

let surface_size = Arc::new(Mutex::new(new_surface_size));
callback(
&self.target,
Event::SurfaceEvent {
window_id,
event: SurfaceEvent::ScaleFactorChanged {
scale_factor: new_scale_factor,
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
&surface_size,
)),
},
callback(&self.target, Event::SurfaceEvent {
window_id,
event: SurfaceEvent::ScaleFactorChanged {
scale_factor: new_scale_factor,
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&surface_size)),
},
);
});

let new_surface_size = *surface_size.lock().unwrap();
drop(surface_size);
Expand Down Expand Up @@ -768,13 +763,10 @@ impl EventProcessor {
}

if resized {
callback(
&self.target,
Event::SurfaceEvent {
window_id,
event: SurfaceEvent::SurfaceResized(new_surface_size.into()),
},
);
callback(&self.target, Event::SurfaceEvent {
window_id,
event: SurfaceEvent::SurfaceResized(new_surface_size.into()),
});
}
}

Expand Down Expand Up @@ -1527,13 +1519,10 @@ impl EventProcessor {
}
let physical_key = xkb::raw_keycode_to_physicalkey(keycode);

callback(
&self.target,
Event::DeviceEvent {
device_id,
event: DeviceEvent::Key(RawKeyEvent { physical_key, state }),
},
);
callback(&self.target, Event::DeviceEvent {
device_id,
event: DeviceEvent::Key(RawKeyEvent { physical_key, state }),
});
}

fn xinput2_hierarchy_changed(&mut self, xev: &XIHierarchyEvent) {
Expand Down
19 changes: 8 additions & 11 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,18 +1032,15 @@ impl Device {
let ty = unsafe { (*class_ptr)._type };
if ty == ffi::XIScrollClass {
let info = unsafe { &*(class_ptr as *const ffi::XIScrollClassInfo) };
scroll_axes.push((
info.number,
ScrollAxis {
increment: info.increment,
orientation: match info.scroll_type {
ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal,
ffi::XIScrollTypeVertical => ScrollOrientation::Vertical,
_ => unreachable!(),
},
position: 0.0,
scroll_axes.push((info.number, ScrollAxis {
increment: info.increment,
orientation: match info.scroll_type {
ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal,
ffi::XIScrollTypeVertical => ScrollOrientation::Vertical,
_ => unreachable!(),
},
));
position: 0.0,
}));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/linux/x11/util/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ impl XConnection {
mask: xinput::XIEventMask,
) -> Result<VoidCookie<'_>, X11Error> {
self.xcb_connection()
.xinput_xi_select_events(
window,
&[xinput::EventMask { deviceid: device_id, mask: vec![mask] }],
)
.xinput_xi_select_events(window, &[xinput::EventMask {
deviceid: device_id,
mask: vec![mask],
}])
.map_err(Into::into)
}

Expand Down
36 changes: 13 additions & 23 deletions src/platform_impl/orbital/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,16 @@ impl EventLoop {
);
},
EventOption::Mouse(MouseEvent { x, y }) => {
app.window_event(
window_target,
window_id,
event::SurfaceEvent::PointerMoved {
device_id: None,
position: (x, y).into(),
source: event::PointerSource::Mouse,
},
);
app.window_event(window_target, window_id, event::SurfaceEvent::PointerMoved {
device_id: None,
position: (x, y).into(),
source: event::PointerSource::Mouse,
});
},
EventOption::MouseRelative(MouseRelativeEvent { dx, dy }) => {
app.device_event(
window_target,
None,
event::DeviceEvent::PointerMotion { delta: (dx as f64, dy as f64) },
);
app.device_event(window_target, None, event::DeviceEvent::PointerMotion {
delta: (dx as f64, dy as f64),
});
},
EventOption::Button(ButtonEvent { left, middle, right }) => {
while let Some((button, state)) = event_state.mouse(left, middle, right) {
Expand All @@ -434,15 +428,11 @@ impl EventLoop {
}
},
EventOption::Scroll(ScrollEvent { x, y }) => {
app.window_event(
window_target,
window_id,
event::SurfaceEvent::MouseWheel {
device_id: None,
delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32),
phase: event::TouchPhase::Moved,
},
);
app.window_event(window_target, window_id, event::SurfaceEvent::MouseWheel {
device_id: None,
delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32),
phase: event::TouchPhase::Moved,
});
},
EventOption::Quit(QuitEvent {}) => {
app.window_event(window_target, window_id, event::SurfaceEvent::CloseRequested);
Expand Down
22 changes: 8 additions & 14 deletions src/platform_impl/windows/window_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,26 +362,20 @@ impl WindowFlags {

if diff.contains(WindowFlags::MAXIMIZED) || new.contains(WindowFlags::MAXIMIZED) {
unsafe {
ShowWindow(
window,
match new.contains(WindowFlags::MAXIMIZED) {
true => SW_MAXIMIZE,
false => SW_RESTORE,
},
);
ShowWindow(window, match new.contains(WindowFlags::MAXIMIZED) {
true => SW_MAXIMIZE,
false => SW_RESTORE,
});
}
}

// Minimize operations should execute after maximize for proper window animations
if diff.contains(WindowFlags::MINIMIZED) {
unsafe {
ShowWindow(
window,
match new.contains(WindowFlags::MINIMIZED) {
true => SW_MINIMIZE,
false => SW_RESTORE,
},
);
ShowWindow(window, match new.contains(WindowFlags::MINIMIZED) {
true => SW_MINIMIZE,
false => SW_RESTORE,
});
}

diff.remove(WindowFlags::MINIMIZED);
Expand Down
7 changes: 4 additions & 3 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ pub trait Surface: AsAny + Send + Sync {
/// [`contentScaleFactor`]: https://developer.apple.com/documentation/uikit/uiview/1622657-contentscalefactor?language=objc
fn scale_factor(&self) -> f64;

/// Queues a [`SurfaceEvent::RedrawRequested`] event to be emitted that aligns with the windowing
/// system drawing loop.
/// Queues a [`SurfaceEvent::RedrawRequested`] event to be emitted that aligns with the
/// windowing system drawing loop.
///
/// This is the **strongly encouraged** method of redrawing windows, as it can integrate with
/// OS-requested redraws (e.g. when a window gets resized). To improve the event delivery
Expand Down Expand Up @@ -758,7 +758,8 @@ pub trait Surface: AsAny + Send + Sync {
#[cfg(feature = "rwh_06")]
fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle;

/// Tries to downcast this surface to a [`Window`]. Returns `None` if the surface is not a window.
/// Tries to downcast this surface to a [`Window`]. Returns `None` if the surface is not a
/// window.
fn as_window(&self) -> Option<&dyn Window> {
None
}
Expand Down

0 comments on commit ddde870

Please sign in to comment.