Skip to content

Commit

Permalink
Fix Linux and Web platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
jgcodes2020 committed Oct 18, 2024
1 parent c5e7d62 commit cf4143c
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/platform_impl/linux/wayland/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl EventLoop {
});
for event in buffer_sink.drain() {
match event {
Event::WindowEvent { window_id, event } => {
Event::SurfaceEvent { window_id, event } => {
app.window_event(&self.active_event_loop, window_id, event)
},
Event::DeviceEvent { device_id, event } => {
Expand All @@ -391,7 +391,7 @@ impl EventLoop {
});
for event in buffer_sink.drain() {
match event {
Event::WindowEvent { window_id, event } => {
Event::SurfaceEvent { window_id, event } => {
app.window_event(&self.active_event_loop, window_id, event)
},
Event::DeviceEvent { device_id, event } => {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/wayland/event_loop/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl EventSink {
/// Add new window event to a queue.
#[inline]
pub fn push_window_event(&mut self, event: SurfaceEvent, window_id: SurfaceId) {
self.window_events.push(Event::WindowEvent { event, window_id });
self.window_events.push(Event::SurfaceEvent { event, window_id });
}

#[inline]
Expand Down
64 changes: 32 additions & 32 deletions src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl EventProcessor {
_ => continue,
};

callback(&self.target, Event::WindowEvent { window_id, event });
callback(&self.target, Event::SurfaceEvent { window_id, event });
}
}

Expand Down Expand Up @@ -371,7 +371,7 @@ impl EventProcessor {
let window_id = mkwid(window);

if xev.data.get_long(0) as xproto::Atom == self.target.wm_delete_window {
let event = Event::WindowEvent { window_id, event: SurfaceEvent::CloseRequested };
let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::CloseRequested };
callback(&self.target, event);
return;
}
Expand Down Expand Up @@ -521,7 +521,7 @@ impl EventProcessor {
let (source_window, state) = if let Some(source_window) = self.dnd.source_window {
if let Some(Ok(ref path_list)) = self.dnd.result {
for path in path_list {
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::DroppedFile(path.clone()),
};
Expand All @@ -548,7 +548,7 @@ impl EventProcessor {

if xev.message_type == atoms[XdndLeave] as c_ulong {
self.dnd.reset();
let event = Event::WindowEvent { window_id, event: SurfaceEvent::HoveredFileCancelled };
let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::HoveredFileCancelled };
callback(&self.target, event);
}
}
Expand All @@ -575,7 +575,7 @@ impl EventProcessor {
let parse_result = self.dnd.parse_data(&mut data);
if let Ok(ref path_list) = parse_result {
for path in path_list {
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::HoveredFile(path.clone()),
};
Expand Down Expand Up @@ -659,7 +659,7 @@ impl EventProcessor {
if moved {
callback(
&self.target,
Event::WindowEvent { window_id, event: SurfaceEvent::Moved(outer.into()) },
Event::SurfaceEvent { window_id, event: SurfaceEvent::Moved(outer.into()) },
);
}
outer
Expand Down Expand Up @@ -708,7 +708,7 @@ impl EventProcessor {
let surface_size = Arc::new(Mutex::new(new_surface_size));
callback(
&self.target,
Event::WindowEvent {
Event::SurfaceEvent {
window_id,
event: SurfaceEvent::ScaleFactorChanged {
scale_factor: new_scale_factor,
Expand Down Expand Up @@ -769,7 +769,7 @@ impl EventProcessor {
if resized {
callback(
&self.target,
Event::WindowEvent {
Event::SurfaceEvent {
window_id,
event: SurfaceEvent::SurfaceResized(new_surface_size.into()),
},
Expand Down Expand Up @@ -803,7 +803,7 @@ impl EventProcessor {
// window, given that we can't rely on `CreateNotify`, due to it being not
// sent.
let focus = self.with_window(window, |window| window.has_focus()).unwrap_or_default();
let event = Event::WindowEvent { window_id, event: SurfaceEvent::Focused(focus) };
let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::Focused(focus) };

callback(&self.target, event);
}
Expand All @@ -827,7 +827,7 @@ impl EventProcessor {
.expect("Failed to destroy input context");
}

callback(&self.target, Event::WindowEvent { window_id, event: SurfaceEvent::Destroyed });
callback(&self.target, Event::SurfaceEvent { window_id, event: SurfaceEvent::Destroyed });
}

fn property_notify<F>(&mut self, xev: &XPropertyEvent, mut callback: F)
Expand All @@ -850,7 +850,7 @@ impl EventProcessor {
{
let xwindow = xev.window as xproto::Window;

let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id: mkwid(xwindow),
event: SurfaceEvent::Occluded(xev.state == xlib::VisibilityFullyObscured),
};
Expand All @@ -871,7 +871,7 @@ impl EventProcessor {
let window = xev.window as xproto::Window;
let window_id = mkwid(window);

let event = Event::WindowEvent { window_id, event: SurfaceEvent::RedrawRequested };
let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::RedrawRequested };

callback(&self.target, event);
}
Expand Down Expand Up @@ -951,7 +951,7 @@ impl EventProcessor {

if let Some(mut key_processor) = self.xkb_context.key_context() {
let event = key_processor.process_key_event(keycode, state, repeat);
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::KeyboardInput {
device_id: None,
Expand All @@ -975,14 +975,14 @@ impl EventProcessor {
{
let written = self.target.xconn.lookup_utf8(ic, xev);
if !written.is_empty() {
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::Ime(Ime::Preedit(String::new(), None)),
};
callback(&self.target, event);

let event =
Event::WindowEvent { window_id, event: SurfaceEvent::Ime(Ime::Commit(written)) };
Event::SurfaceEvent { window_id, event: SurfaceEvent::Ime(Ime::Commit(written)) };

self.is_composing = false;
callback(&self.target, event);
Expand Down Expand Up @@ -1017,7 +1017,7 @@ impl EventProcessor {
let mods: ModifiersState = xkb_state.modifiers().into();

let event =
Event::WindowEvent { window_id, event: SurfaceEvent::ModifiersChanged(mods.into()) };
Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(mods.into()) };

callback(&self.target, event);
}
Expand Down Expand Up @@ -1096,7 +1096,7 @@ impl EventProcessor {
},
};

let event = Event::WindowEvent { window_id, event };
let event = Event::SurfaceEvent { window_id, event };
callback(&self.target, event);
}

Expand All @@ -1120,7 +1120,7 @@ impl EventProcessor {
if cursor_moved == Some(true) {
let position = PhysicalPosition::new(event.event_x, event.event_y);

let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::PointerMoved {
device_id,
Expand Down Expand Up @@ -1166,7 +1166,7 @@ impl EventProcessor {
};

let event = SurfaceEvent::MouseWheel { device_id, delta, phase: TouchPhase::Moved };
events.push(Event::WindowEvent { window_id, event });
events.push(Event::SurfaceEvent { window_id, event });
}

value = unsafe { value.offset(1) };
Expand Down Expand Up @@ -1209,7 +1209,7 @@ impl EventProcessor {
let device_id = Some(device_id);
let position = PhysicalPosition::new(event.event_x, event.event_y);

let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::PointerEntered {
device_id,
Expand All @@ -1233,7 +1233,7 @@ impl EventProcessor {
// Leave, FocusIn, and FocusOut can be received by a window that's already
// been destroyed, which the user presumably doesn't want to deal with.
if self.window_exists(window) {
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id: mkwid(window),
event: SurfaceEvent::PointerLeft {
device_id: Some(mkdid(event.deviceid as xinput::DeviceId)),
Expand Down Expand Up @@ -1273,7 +1273,7 @@ impl EventProcessor {
window.shared_state_lock().has_focus = true;
}

let event = Event::WindowEvent { window_id, event: SurfaceEvent::Focused(true) };
let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::Focused(true) };
callback(&self.target, event);

// Issue key press events for all pressed keys
Expand All @@ -1295,7 +1295,7 @@ impl EventProcessor {
.get(&mkdid(xev.deviceid as xinput::DeviceId))
.map(|device| mkdid(device.attachment as xinput::DeviceId));

let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::PointerMoved { device_id, position, source: PointerSource::Mouse },
};
Expand Down Expand Up @@ -1348,7 +1348,7 @@ impl EventProcessor {
window.shared_state_lock().has_focus = false;
}

let event = Event::WindowEvent { window_id, event: SurfaceEvent::Focused(false) };
let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::Focused(false) };
callback(&self.target, event)
}
}
Expand All @@ -1369,7 +1369,7 @@ impl EventProcessor {
// Mouse cursor position changes when touch events are received.
// Only the first concurrently active touch ID moves the mouse cursor.
if is_first_touch(&mut self.first_touch, &mut self.num_touch, id, phase) {
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::PointerMoved {
device_id: None,
Expand All @@ -1385,7 +1385,7 @@ impl EventProcessor {

match phase {
xinput2::XI_TouchBegin => {
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::PointerEntered {
device_id,
Expand All @@ -1394,7 +1394,7 @@ impl EventProcessor {
},
};
callback(&self.target, event);
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::PointerButton {
device_id,
Expand All @@ -1406,7 +1406,7 @@ impl EventProcessor {
callback(&self.target, event);
},
xinput2::XI_TouchUpdate => {
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::PointerMoved {
device_id,
Expand All @@ -1417,7 +1417,7 @@ impl EventProcessor {
callback(&self.target, event);
},
xinput2::XI_TouchEnd => {
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::PointerButton {
device_id,
Expand All @@ -1427,7 +1427,7 @@ impl EventProcessor {
},
};
callback(&self.target, event);
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::PointerLeft {
device_id,
Expand Down Expand Up @@ -1777,7 +1777,7 @@ impl EventProcessor {
// NOTE: Always update the modifiers to account for case when they've changed
// and forced was `true`.
if self.modifiers.replace(modifiers) != modifiers || force {
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::ModifiersChanged(self.modifiers.get().into()),
};
Expand Down Expand Up @@ -1814,7 +1814,7 @@ impl EventProcessor {

for keycode in target.xconn.query_keymap().into_iter().filter(|k| *k >= KEYCODE_OFFSET) {
let event = key_processor.process_key_event(keycode as u32, state, false);
let event = Event::WindowEvent {
let event = Event::SurfaceEvent {
window_id,
event: SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: true },
};
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,12 @@ impl EventLoop {
while unsafe { self.event_processor.poll_one_event(xev.as_mut_ptr()) } {
let mut xev = unsafe { xev.assume_init() };
self.event_processor.process_event(&mut xev, |window_target, event: Event| {
if let Event::WindowEvent { window_id, event: SurfaceEvent::RedrawRequested } = event
if let Event::SurfaceEvent { window_id, event: SurfaceEvent::RedrawRequested } = event
{
window_target.redraw_sender.send(window_id);
} else {
match event {
Event::WindowEvent { window_id, event } => {
Event::SurfaceEvent { window_id, event } => {
app.window_event(window_target, window_id, event)
},
Event::DeviceEvent { device_id, event } => {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ impl UnownedWindow {

let old_surface_size = PhysicalSize::new(width, height);
let surface_size = Arc::new(Mutex::new(PhysicalSize::new(new_width, new_height)));
callback(Event::WindowEvent {
callback(Event::SurfaceEvent {
window_id: self.id(),
event: SurfaceEvent::ScaleFactorChanged {
scale_factor: new_monitor.scale_factor,
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/web/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl EventLoop {
fn handle_event<A: ApplicationHandler>(app: &mut A, target: &ActiveEventLoop, event: Event) {
match event {
Event::NewEvents(cause) => app.new_events(target, cause),
Event::WindowEvent { window_id, event } => app.window_event(target, window_id, event),
Event::SurfaceEvent { window_id, event } => app.window_event(target, window_id, event),
Event::DeviceEvent { device_id, event } => app.device_event(target, device_id, event),
Event::UserWakeUp => app.proxy_wake_up(target),
Event::Suspended => app.suspended(target),
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/web/event_loop/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl Shared {
if let (false, Some(true) | None) | (true, Some(true)) =
(is_visible, canvas.is_intersecting.get())
{
runner.send_event(Event::WindowEvent {
runner.send_event(Event::SurfaceEvent {
window_id: *id,
event: SurfaceEvent::Occluded(!is_visible),
});
Expand Down Expand Up @@ -566,7 +566,7 @@ impl Shared {
fn process_destroy_pending_windows(&self) {
while let Some(id) = self.0.destroy_pending.borrow_mut().pop_front() {
self.0.all_canvases.borrow_mut().retain(|&(item_id, ..)| item_id != id);
self.handle_event(Event::WindowEvent {
self.handle_event(Event::SurfaceEvent {
window_id: id,
event: crate::event::SurfaceEvent::Destroyed,
});
Expand All @@ -587,7 +587,7 @@ impl Shared {
// Collect all of the redraw events to avoid double-locking the RefCell
let redraw_events: Vec<SurfaceId> = self.0.redraw_pending.borrow_mut().drain().collect();
for window_id in redraw_events {
self.handle_event(Event::WindowEvent {
self.handle_event(Event::SurfaceEvent {
window_id,
event: SurfaceEvent::RedrawRequested,
});
Expand Down
Loading

0 comments on commit cf4143c

Please sign in to comment.