chore: remove platform WindowId's
WindowId is a window _identifier_, and as such doesn't store anything (unlike a _handle_). So we can safely make only be defined once, in the core crate. There are a few backends where we still use `into_raw` internally; I consider these patterns discouraged, we should not be passing around important state in the window id.
This commit is contained in:
parent
eccd9e415d
commit
da2268ae22
35 changed files with 226 additions and 379 deletions
|
|
@ -80,14 +80,12 @@ use crate::platform_impl::platform::window::InitData;
|
|||
use crate::platform_impl::platform::window_state::{
|
||||
CursorFlags, ImeState, WindowFlags, WindowState,
|
||||
};
|
||||
use crate::platform_impl::platform::{
|
||||
raw_input, util, wrap_device_id, FingerId, Fullscreen, WindowId,
|
||||
};
|
||||
use crate::platform_impl::platform::{raw_input, util, wrap_device_id, FingerId, Fullscreen};
|
||||
use crate::platform_impl::Window;
|
||||
use crate::utils::Lazy;
|
||||
use crate::window::{
|
||||
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow,
|
||||
WindowAttributes, WindowId as CoreWindowId,
|
||||
WindowAttributes, WindowId,
|
||||
};
|
||||
|
||||
pub(crate) struct WindowData {
|
||||
|
|
@ -920,7 +918,7 @@ fn update_modifiers(window: HWND, userdata: &WindowData) {
|
|||
drop(window_state);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: ModifiersChanged(modifiers.into()),
|
||||
});
|
||||
}
|
||||
|
|
@ -932,7 +930,7 @@ unsafe fn gain_active_focus(window: HWND, userdata: &WindowData) {
|
|||
update_modifiers(window, userdata);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: Focused(true),
|
||||
});
|
||||
}
|
||||
|
|
@ -942,12 +940,12 @@ unsafe fn lose_active_focus(window: HWND, userdata: &WindowData) {
|
|||
|
||||
userdata.window_state_lock().modifiers_state = ModifiersState::empty();
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: ModifiersChanged(ModifiersState::empty().into()),
|
||||
});
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: Focused(false),
|
||||
});
|
||||
}
|
||||
|
|
@ -1045,7 +1043,7 @@ unsafe fn public_window_callback_inner(
|
|||
userdata.key_event_builder.process_message(window, msg, wparam, lparam, &mut result);
|
||||
for event in events {
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: KeyboardInput {
|
||||
device_id: None,
|
||||
event: event.event,
|
||||
|
|
@ -1130,7 +1128,7 @@ unsafe fn public_window_callback_inner(
|
|||
WM_CLOSE => {
|
||||
use crate::event::WindowEvent::CloseRequested;
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: CloseRequested,
|
||||
});
|
||||
result = ProcResult::Value(0);
|
||||
|
|
@ -1140,7 +1138,7 @@ unsafe fn public_window_callback_inner(
|
|||
use crate::event::WindowEvent::Destroyed;
|
||||
unsafe { RevokeDragDrop(window) };
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: Destroyed,
|
||||
});
|
||||
result = ProcResult::Value(0);
|
||||
|
|
@ -1161,7 +1159,7 @@ unsafe fn public_window_callback_inner(
|
|||
// and request a normal redraw with `RedrawWindow`.
|
||||
if !userdata.event_loop_runner.should_buffer() {
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::RedrawRequested,
|
||||
});
|
||||
}
|
||||
|
|
@ -1264,7 +1262,7 @@ unsafe fn public_window_callback_inner(
|
|||
let physical_position =
|
||||
unsafe { PhysicalPosition::new((*windowpos).x, (*windowpos).y) };
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: Moved(physical_position),
|
||||
});
|
||||
}
|
||||
|
|
@ -1280,7 +1278,7 @@ unsafe fn public_window_callback_inner(
|
|||
|
||||
let physical_size = PhysicalSize::new(w, h);
|
||||
let event = Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: SurfaceResized(physical_size),
|
||||
};
|
||||
|
||||
|
|
@ -1395,7 +1393,7 @@ unsafe fn public_window_callback_inner(
|
|||
userdata.window_state_lock().ime_state = ImeState::Enabled;
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::Ime(Ime::Enabled),
|
||||
});
|
||||
}
|
||||
|
|
@ -1415,7 +1413,7 @@ unsafe fn public_window_callback_inner(
|
|||
|
||||
if lparam == 0 {
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
|
||||
});
|
||||
}
|
||||
|
|
@ -1427,11 +1425,11 @@ unsafe fn public_window_callback_inner(
|
|||
userdata.window_state_lock().ime_state = ImeState::Enabled;
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
|
||||
});
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::Ime(Ime::Commit(text)),
|
||||
});
|
||||
}
|
||||
|
|
@ -1446,7 +1444,7 @@ unsafe fn public_window_callback_inner(
|
|||
let cursor_range = first.map(|f| (f, last.unwrap_or(f)));
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::Ime(Ime::Preedit(text, cursor_range)),
|
||||
});
|
||||
}
|
||||
|
|
@ -1469,11 +1467,11 @@ unsafe fn public_window_callback_inner(
|
|||
let ime_context = unsafe { ImeContext::current(window) };
|
||||
if let Some(text) = unsafe { ime_context.get_composed_text() } {
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
|
||||
});
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::Ime(Ime::Commit(text)),
|
||||
});
|
||||
}
|
||||
|
|
@ -1482,7 +1480,7 @@ unsafe fn public_window_callback_inner(
|
|||
userdata.window_state_lock().ime_state = ImeState::Disabled;
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::Ime(Ime::Disabled),
|
||||
});
|
||||
}
|
||||
|
|
@ -1541,7 +1539,7 @@ unsafe fn public_window_callback_inner(
|
|||
|
||||
drop(w);
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerEntered {
|
||||
device_id: None,
|
||||
position,
|
||||
|
|
@ -1566,7 +1564,7 @@ unsafe fn public_window_callback_inner(
|
|||
|
||||
drop(w);
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerLeft {
|
||||
device_id: None,
|
||||
position: Some(position),
|
||||
|
|
@ -1589,7 +1587,7 @@ unsafe fn public_window_callback_inner(
|
|||
update_modifiers(window, userdata);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerMoved { device_id: None, position, source: PointerSource::Mouse },
|
||||
});
|
||||
}
|
||||
|
|
@ -1607,7 +1605,7 @@ unsafe fn public_window_callback_inner(
|
|||
}
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerLeft { device_id: None, position: None, kind: Mouse },
|
||||
});
|
||||
|
||||
|
|
@ -1623,7 +1621,7 @@ unsafe fn public_window_callback_inner(
|
|||
update_modifiers(window, userdata);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::MouseWheel {
|
||||
device_id: None,
|
||||
delta: LineDelta(0.0, value),
|
||||
|
|
@ -1643,7 +1641,7 @@ unsafe fn public_window_callback_inner(
|
|||
update_modifiers(window, userdata);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: WindowEvent::MouseWheel {
|
||||
device_id: None,
|
||||
delta: LineDelta(value, 0.0),
|
||||
|
|
@ -1682,7 +1680,7 @@ unsafe fn public_window_callback_inner(
|
|||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerButton {
|
||||
device_id: None,
|
||||
state: Pressed,
|
||||
|
|
@ -1707,7 +1705,7 @@ unsafe fn public_window_callback_inner(
|
|||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerButton {
|
||||
device_id: None,
|
||||
state: Released,
|
||||
|
|
@ -1732,7 +1730,7 @@ unsafe fn public_window_callback_inner(
|
|||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerButton {
|
||||
device_id: None,
|
||||
state: Pressed,
|
||||
|
|
@ -1757,7 +1755,7 @@ unsafe fn public_window_callback_inner(
|
|||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerButton {
|
||||
device_id: None,
|
||||
state: Released,
|
||||
|
|
@ -1782,7 +1780,7 @@ unsafe fn public_window_callback_inner(
|
|||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerButton {
|
||||
device_id: None,
|
||||
state: Pressed,
|
||||
|
|
@ -1807,7 +1805,7 @@ unsafe fn public_window_callback_inner(
|
|||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerButton {
|
||||
device_id: None,
|
||||
state: Released,
|
||||
|
|
@ -1833,7 +1831,7 @@ unsafe fn public_window_callback_inner(
|
|||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerButton {
|
||||
device_id: None,
|
||||
state: Pressed,
|
||||
|
|
@ -1864,7 +1862,7 @@ unsafe fn public_window_callback_inner(
|
|||
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: PointerButton {
|
||||
device_id: None,
|
||||
state: Released,
|
||||
|
|
@ -1919,7 +1917,7 @@ unsafe fn public_window_callback_inner(
|
|||
let y = position.y as f64 + (input.y % 100) as f64 / 100f64;
|
||||
let position = PhysicalPosition::new(x, y);
|
||||
|
||||
let window_id = CoreWindowId(WindowId(window));
|
||||
let window_id = WindowId::from_raw(window as usize);
|
||||
let finger_id = RootFingerId(FingerId {
|
||||
id: input.dwID,
|
||||
primary: util::has_flag(input.dwFlags, TOUCHEVENTF_PRIMARY),
|
||||
|
|
@ -2087,7 +2085,7 @@ unsafe fn public_window_callback_inner(
|
|||
let y = location.y as f64 + y.fract();
|
||||
let position = PhysicalPosition::new(x, y);
|
||||
|
||||
let window_id = CoreWindowId(WindowId(window));
|
||||
let window_id = WindowId::from_raw(window as usize);
|
||||
let finger_id = RootFingerId(FingerId {
|
||||
id: pointer_info.pointerId,
|
||||
primary: util::has_flag(pointer_info.pointerFlags, POINTER_FLAG_PRIMARY),
|
||||
|
|
@ -2320,7 +2318,7 @@ unsafe fn public_window_callback_inner(
|
|||
|
||||
let new_surface_size = Arc::new(Mutex::new(new_physical_surface_size));
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: ScaleFactorChanged {
|
||||
scale_factor: new_scale_factor,
|
||||
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
|
||||
|
|
@ -2472,7 +2470,7 @@ unsafe fn public_window_callback_inner(
|
|||
window_state.current_theme = new_theme;
|
||||
drop(window_state);
|
||||
userdata.send_event(Event::WindowEvent {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
window_id: WindowId::from_raw(window as usize),
|
||||
event: ThemeChanged(new_theme),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue