feat: Move Event to winit-core

This requires a lot of restructuring on the backend side, as we need to
accommodate for backends not being able to construct these types
implicitly. In addition, we also need to expose some new APIs on these
types to make them usable.

Several breaking changes occurred in this commit.

Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
John Nunley
2024-02-04 15:28:25 -08:00
parent 859a6f109c
commit 284f4c0558
34 changed files with 1555 additions and 1476 deletions

View File

@@ -23,3 +23,7 @@ bitflags.workspace = true
cursor-icon.workspace = true
serde = { workspace = true, optional = true }
smol_str.workspace = true
web-time = "1"
[build-dependencies]
cfg_aliases = "0.2.0"

24
winit-core/build.rs Normal file
View File

@@ -0,0 +1,24 @@
use cfg_aliases::cfg_aliases;
fn main() {
// The script doesn't depend on our code
println!("cargo:rerun-if-changed=build.rs");
// Setup cfg aliases
cfg_aliases! {
// Systems.
android_platform: { target_os = "android" },
web_platform: { all(target_family = "wasm", target_os = "unknown") },
macos_platform: { target_os = "macos" },
ios_platform: { target_os = "ios" },
windows_platform: { target_os = "windows" },
apple: { any(target_os = "ios", target_os = "macos") },
free_unix: { all(unix, not(apple), not(android_platform), not(target_os = "emscripten")) },
redox: { target_os = "redox" },
// Native displays.
x11_platform: { all(feature = "x11", free_unix, not(redox)) },
wayland_platform: { all(feature = "wayland", free_unix, not(redox)) },
orbital_platform: { redox },
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,28 @@
//! Types needed to define the event loop.
use std::sync::atomic::{AtomicU64, Ordering};
/// A unique identifier of the winit's async request.
///
/// This could be used to identify the async request once it's done
/// and a specific action must be taken.
///
/// One of the handling scenarious could be to maintain a working list
/// containing [`AsyncRequestSerial`] and some closure associated with it.
/// Then once event is arriving the working list is being traversed and a job
/// executed and removed from the list.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AsyncRequestSerial {
serial: u64,
}
impl AsyncRequestSerial {
/// Get the next serial in the sequence.
pub fn get() -> Self {
static CURRENT_SERIAL: AtomicU64 = AtomicU64::new(0);
// NOTE: we rely on wrap around here, while the user may just request
// in the loop u64::MAX times that's issue is considered on them.
let serial = CURRENT_SERIAL.fetch_add(1, Ordering::Relaxed);
Self { serial }
}
}

View File

@@ -1454,6 +1454,29 @@ pub enum NamedKey {
F35,
}
// NOTE: the exact modifier key is not used to represent modifiers state in the
// first place due to a fact that modifiers state could be changed without any
// key being pressed and on some platforms like Wayland/X11 which key resulted
// in modifiers change is hidden, also, not that it really matters.
//
// The reason this API is even exposed is mostly to provide a way for users
// to treat modifiers differently based on their position, which is required
// on macOS due to their AltGr/Option situation.
bitflags! {
#[doc(hidden)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ModifiersKeys: u8 {
const LSHIFT = 0b0000_0001;
const RSHIFT = 0b0000_0010;
const LCONTROL = 0b0000_0100;
const RCONTROL = 0b0000_1000;
const LALT = 0b0001_0000;
const RALT = 0b0010_0000;
const LSUPER = 0b0100_0000;
const RSUPER = 0b1000_0000;
}
}
/// Key represents the meaning of a keypress.
///
/// This is a superset of the UI Events Specification's [`KeyboardEvent.key`] with

View File

@@ -13,5 +13,6 @@ compile_error! { "no-std and no-alloc usage are not yet supported" }
pub mod dpi;
pub mod error;
pub mod event;
pub mod event_loop;
pub mod keyboard;
pub mod window;

View File

@@ -191,3 +191,25 @@ impl Default for ImePurpose {
Self::Normal
}
}
/// An opaque token used to activate the [`Window`].
///
/// [`Window`]: crate::window::Window
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ActivationToken {
pub(crate) token: String,
}
impl ActivationToken {
pub fn new(_token: String) -> Self {
Self { token: _token }
}
pub fn token(&self) -> &str {
&self.token
}
pub fn into_token(self) -> String {
self.token
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@ use std::marker::PhantomData;
use std::ops::Deref;
#[cfg(any(x11_platform, wayland_platform))]
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use std::sync::atomic::{AtomicBool, Ordering};
use std::{error, fmt};
#[cfg(not(web_platform))]
@@ -22,6 +22,9 @@ use web_time::{Duration, Instant};
use crate::error::EventLoopError;
use crate::{event::Event, monitor::MonitorHandle, platform_impl};
#[doc(inline)]
pub use winit_core::event_loop::AsyncRequestSerial;
/// Provides a way to retrieve events from the system and from the windows that were registered to
/// the events loop.
///
@@ -506,29 +509,3 @@ pub enum DeviceEvents {
/// Never capture device events.
Never,
}
/// A unique identifier of the winit's async request.
///
/// This could be used to identify the async request once it's done
/// and a specific action must be taken.
///
/// One of the handling scenarious could be to maintain a working list
/// containing [`AsyncRequestSerial`] and some closure associated with it.
/// Then once event is arriving the working list is being traversed and a job
/// executed and removed from the list.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AsyncRequestSerial {
serial: u64,
}
impl AsyncRequestSerial {
// TODO(kchibisov) remove `cfg` when the clipboard will be added.
#[allow(dead_code)]
pub(crate) fn get() -> Self {
static CURRENT_SERIAL: AtomicU64 = AtomicU64::new(0);
// NOTE: we rely on wrap around here, while the user may just request
// in the loop u64::MAX times that's issue is considered on them.
let serial = CURRENT_SERIAL.fetch_add(1, Ordering::Relaxed);
Self { serial }
}
}

View File

@@ -2,27 +2,3 @@
#[doc(inline)]
pub use winit_core::keyboard::*;
use bitflags::bitflags;
// NOTE: the exact modifier key is not used to represent modifiers state in the
// first place due to a fact that modifiers state could be changed without any
// key being pressed and on some platforms like Wayland/X11 which key resulted
// in modifiers change is hidden, also, not that it really matters.
//
// The reason this API is even exposed is mostly to provide a way for users
// to treat modifiers differently based on their position, which is required
// on macOS due to their AltGr/Option situation.
bitflags! {
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct ModifiersKeys: u8 {
const LSHIFT = 0b0000_0001;
const RSHIFT = 0b0000_0010;
const LCONTROL = 0b0000_0100;
const RCONTROL = 0b0000_1000;
const LALT = 0b0001_0000;
const RALT = 0b0010_0000;
const LSUPER = 0b0100_0000;
const RSUPER = 0b1000_0000;
}
}

View File

@@ -25,7 +25,8 @@ pub trait KeyEventExtModifierSupplement {
impl KeyEventExtModifierSupplement for KeyEvent {
#[inline]
fn text_with_all_modifiers(&self) -> Option<&str> {
self.platform_specific
self.extra
.extra
.text_with_all_modifiers
.as_ref()
.map(|s| s.as_str())
@@ -33,6 +34,6 @@ impl KeyEventExtModifierSupplement for KeyEvent {
#[inline]
fn key_without_modifiers(&self) -> Key {
self.platform_specific.key_without_modifiers.clone()
self.extra.extra.key_without_modifiers.clone()
}
}

View File

@@ -64,7 +64,7 @@ impl EventLoopExtStartupNotify for EventLoopWindowTarget {
crate::platform_impl::EventLoopWindowTarget::X(_) => env::var(X11_VAR),
}
.ok()
.map(ActivationToken::_new)
.map(ActivationToken::new)
}
}
@@ -94,6 +94,6 @@ pub fn reset_activation_token_env() {
///
/// This could be used before running daemon processes.
pub fn set_activation_token_env(token: ActivationToken) {
env::set_var(X11_VAR, &token._token);
env::set_var(WAYLAND_VAR, token._token);
env::set_var(X11_VAR, token.token());
env::set_var(WAYLAND_VAR, token.token());
}

View File

@@ -465,7 +465,9 @@ impl<T: 'static> EventLoop<T> {
location: keycodes::to_location(keycode),
repeat: key.repeat_count() > 0,
text: None,
platform_specific: KeyEventExtra {},
extra: event::KeyExtra {
extra: KeyEventExtra {},
},
},
is_synthetic: false,
},

View File

@@ -92,16 +92,14 @@ enum UserCallbackTransitionResult<'a> {
},
}
impl Event<HandlePendingUserEvents> {
fn is_redraw(&self) -> bool {
matches!(
self,
Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
}
)
}
fn is_redraw(event: &Event<HandlePendingUserEvents>) -> bool {
matches!(
event,
Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
}
)
}
// this is the state machine for the app lifecycle
@@ -621,9 +619,9 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
for wrapper in events {
match wrapper {
EventWrapper::StaticEvent(event) => {
if !processing_redraws && event.is_redraw() {
if !processing_redraws && is_redraw(&event) {
log::info!("processing `RedrawRequested` during the main event loop");
} else if processing_redraws && !event.is_redraw() {
} else if processing_redraws && !is_redraw(&event) {
log::warn!(
"processing non `RedrawRequested` event after the main event loop: {:#?}",
event
@@ -675,9 +673,9 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
for wrapper in queued_events {
match wrapper {
EventWrapper::StaticEvent(event) => {
if !processing_redraws && event.is_redraw() {
if !processing_redraws && is_redraw(&event) {
log::info!("processing `RedrawRequested` during the main event loop");
} else if processing_redraws && !event.is_redraw() {
} else if processing_redraws && !is_redraw(&event) {
log::warn!(
"processing non-`RedrawRequested` event after the main event loop: {:#?}",
event

View File

@@ -409,7 +409,9 @@ impl KbdState {
location,
state,
repeat,
platform_specific,
extra: crate::event::KeyExtra {
extra: platform_specific,
},
}
}

View File

@@ -26,10 +26,8 @@ impl EventSink {
/// Add new device event to a queue.
#[inline]
pub fn push_device_event(&mut self, event: DeviceEvent, device_id: DeviceId) {
self.window_events.push(Event::DeviceEvent {
event,
device_id,
});
self.window_events
.push(Event::DeviceEvent { event, device_id });
}
/// Add new window event to a queue.

View File

@@ -11,8 +11,8 @@ use winit_core::event::DeviceId;
use crate::dpi::LogicalPosition;
use crate::event::{Touch, TouchPhase, WindowEvent};
use crate::platform_impl::wayland::state::WinitState;
use crate::platform_impl::wayland;
use crate::platform_impl::wayland::state::WinitState;
impl TouchHandler for WinitState {
fn down(

View File

@@ -82,7 +82,7 @@ impl Dispatch<XdgActivationTokenV1, XdgActivationTokenData, WinitState> for XdgA
state.events_sink.push_window_event(
crate::event::WindowEvent::ActivationTokenDone {
serial: *serial,
token: ActivationToken::_new(token),
token: ActivationToken::new(token),
},
*window_id,
);

View File

@@ -177,7 +177,7 @@ impl Window {
xdg_activation.as_ref(),
attributes.platform_specific.activation_token,
) {
xdg_activation.activate(token._token, &surface);
xdg_activation.activate(token.into_token(), &surface);
}
// XXX Do initial commit.

View File

@@ -17,13 +17,15 @@ use x11rb::{
};
use super::{
atoms::*, ffi, get_xtarget, mkdid, mkwid, util, CookieResultExt, Device, DeviceInfo,
Dnd, DndState, GenericEventCookie, ImeReceiver, ScrollOrientation, UnownedWindow,
atoms::*, ffi, get_xtarget, mkdid, mkwid, util, CookieResultExt, Device, DeviceInfo, Dnd,
DndState, GenericEventCookie, ImeReceiver, ScrollOrientation, UnownedWindow,
};
use crate::{
dpi::{PhysicalPosition, PhysicalSize},
event::{DeviceEvent, ElementState, Event, Ime, RawKeyEvent, TouchPhase, WindowEvent, DeviceId},
event::{
DeviceEvent, DeviceId, ElementState, Event, Ime, RawKeyEvent, TouchPhase, WindowEvent,
},
event_loop::EventLoopWindowTarget as RootELW,
keyboard::ModifiersState,
platform_impl::platform::common::{keymap, xkb_state::KbdState},
@@ -719,10 +721,10 @@ impl EventProcessor {
MouseButton::{Back, Forward, Left, Middle, Other, Right},
MouseScrollDelta::LineDelta,
Touch,
WindowEvent::{
AxisMotion, CursorEntered, CursorLeft, CursorMoved, Focused, MouseInput,
MouseWheel,
},
};
use winit_core::event::WindowEvent::{
AxisMotion, CursorEntered, CursorLeft, CursorMoved, Focused, MouseInput,
MouseWheel,
};
match xev.evtype {
@@ -858,12 +860,11 @@ impl EventProcessor {
)
};
let mut devices = self.devices.borrow_mut();
let physical_device = match devices
.get_mut(&mkdid(xev.sourceid as xinput::DeviceId))
{
Some(device) => device,
None => return,
};
let physical_device =
match devices.get_mut(&mkdid(xev.sourceid as xinput::DeviceId)) {
Some(device) => device,
None => return,
};
let mut value = xev.valuators.values;
for i in 0..xev.valuators.mask_len * 8 {

View File

@@ -569,7 +569,7 @@ impl<T: 'static> EventLoop<T> {
window_id,
event: crate::event::WindowEvent::ActivationTokenDone {
serial,
token: crate::window::ActivationToken::_new(token),
token: crate::window::ActivationToken::new(token),
},
},
&self.target,

View File

@@ -588,7 +588,7 @@ impl UnownedWindow {
// Remove the startup notification if we have one.
if let Some(startup) = window_attrs.platform_specific.activation_token.as_ref() {
leap!(xconn.remove_activation_token(xwindow, &startup._token));
leap!(xconn.remove_activation_token(xwindow, startup.token()));
}
// We never want to give the user a broken window, since by then, it's too late to handle.

View File

@@ -188,9 +188,11 @@ pub(crate) fn create_key_event(
repeat: is_repeat,
state,
text,
platform_specific: KeyEventExtra {
text_with_all_modifiers,
key_without_modifiers,
extra: crate::event::KeyExtra {
extra: KeyEventExtra {
text_with_all_modifiers,
key_without_modifiers,
},
},
}
}
@@ -393,10 +395,7 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers {
flags_contains(flags, NX_DEVICERCMDKEYMASK),
);
Modifiers {
state,
pressed_mods,
}
Modifiers::new(state, pressed_mods)
}
pub(super) fn dummy_event() -> Option<Id<NSEvent>> {

View File

@@ -1076,7 +1076,7 @@ fn mouse_button(event: &NSEvent) -> MouseButton {
// we're getting from the operating system, which makes it
// impossible to provide such events as extra in `KeyEvent`.
fn replace_event(event: &NSEvent, option_as_alt: OptionAsAlt) -> Id<NSEvent> {
let ev_mods = event_mods(event).state;
let ev_mods = event_mods(event).state();
let ignore_alt_characters = match option_as_alt {
OptionAsAlt::OnlyLeft if lalt_pressed(event) => true,
OptionAsAlt::OnlyRight if ralt_pressed(event) => true,

View File

@@ -25,8 +25,8 @@ use crate::{
};
use super::{
KeyEventExtra, MonitorHandle, OsError, PlatformSpecificEventLoopAttributes,
RedoxSocket, TimeSocket, WindowProperties,
KeyEventExtra, MonitorHandle, OsError, PlatformSpecificEventLoopAttributes, RedoxSocket,
TimeSocket, WindowProperties,
};
fn convert_scancode(scancode: u8) -> PhysicalKey {
@@ -265,10 +265,7 @@ impl EventState {
self.keyboard.contains(KeyboardModifierState::RSUPER),
);
Modifiers {
state,
pressed_mods,
}
Modifiers::new(state, pressed_mods)
}
}
@@ -353,7 +350,9 @@ impl<T: 'static> EventLoop<T> {
repeat: false,
text: None,
platform_specific: KeyEventExtra {},
extra: event::KeyExtra {
extra: KeyEventExtra {},
},
},
is_synthetic: false,
},

View File

@@ -1,9 +1,9 @@
use super::super::backend::event::mouse_button_to_id;
use super::super::main_thread::MainThreadMarker;
use super::{backend, state::State};
use crate::dpi::PhysicalSize;
use crate::event::{
DeviceEvent, DeviceId, ElementState, Event, RawKeyEvent, StartCause,
WindowEvent,
DeviceEvent, DeviceId, ElementState, Event, RawKeyEvent, StartCause, WindowEvent,
};
use crate::event_loop::{ControlFlow, DeviceEvents};
use crate::platform::web::PollStrategy;
@@ -281,7 +281,7 @@ impl Shared {
runner.send_event(Event::DeviceEvent {
device_id,
event: DeviceEvent::Button {
button: button.to_id(),
button: mouse_button_to_id(button),
state,
},
});
@@ -359,7 +359,7 @@ impl Shared {
runner.send_event(Event::DeviceEvent {
device_id: DeviceId::from(event.pointer_id() as u64),
event: DeviceEvent::Button {
button: button.to_id(),
button: mouse_button_to_id(button),
state: ElementState::Pressed,
},
});
@@ -382,7 +382,7 @@ impl Shared {
runner.send_event(Event::DeviceEvent {
device_id: DeviceId::from(event.pointer_id() as u64),
event: DeviceEvent::Button {
button: button.to_id(),
button: mouse_button_to_id(button),
state: ElementState::Released,
},
});
@@ -398,7 +398,7 @@ impl Shared {
}
runner.send_event(Event::DeviceEvent {
device_id: unsafe { DeviceId::dummy() },
device_id: unsafe { DeviceId::dummy() },
event: DeviceEvent::Key(RawKeyEvent {
physical_key: backend::event::key_code(&event),
state: ElementState::Pressed,

View File

@@ -9,12 +9,9 @@ use web_sys::Element;
use super::runner::{EventWrapper, Execution};
use super::{
super::{monitor::MonitorHandle, KeyEventExtra},
backend,
runner,
};
use crate::event::{
DeviceId, ElementState, Event, KeyEvent, Touch, TouchPhase, WindowEvent,
backend, runner,
};
use crate::event::{DeviceId, ElementState, Event, KeyEvent, Touch, TouchPhase, WindowEvent};
use crate::event_loop::{ControlFlow, DeviceEvents};
use crate::keyboard::ModifiersState;
use crate::platform::web::PollStrategy;
@@ -151,7 +148,9 @@ impl EventLoopWindowTarget {
location,
state: ElementState::Pressed,
repeat,
platform_specific: KeyEventExtra,
extra: crate::event::KeyExtra {
extra: KeyEventExtra,
},
},
is_synthetic: false,
},
@@ -187,7 +186,9 @@ impl EventLoopWindowTarget {
location,
state: ElementState::Released,
repeat,
platform_specific: KeyEventExtra,
extra: crate::event::KeyExtra {
extra: KeyEventExtra,
},
},
is_synthetic: false,
},

View File

@@ -67,16 +67,14 @@ pub fn mouse_button(event: &MouseEvent) -> Option<MouseButton> {
}
}
impl MouseButton {
pub fn to_id(self) -> u32 {
match self {
MouseButton::Left => 0,
MouseButton::Right => 1,
MouseButton::Middle => 2,
MouseButton::Back => 3,
MouseButton::Forward => 4,
MouseButton::Other(value) => value.into(),
}
pub fn mouse_button_to_id(mb: MouseButton) -> u32 {
match mb {
MouseButton::Left => 0,
MouseButton::Right => 1,
MouseButton::Middle => 2,
MouseButton::Back => 3,
MouseButton::Forward => 4,
MouseButton::Other(value) => value.into(),
}
}

View File

@@ -92,7 +92,7 @@ impl FileDropHandler {
_pt: *const POINTL,
pdwEffect: *mut u32,
) -> HRESULT {
use crate::event::WindowEvent::HoveredFile;
use winit_core::event::WindowEvent::HoveredFile;
let drop_handler = unsafe { Self::from_interface(this) };
let hdrop = unsafe {
Self::iterate_filenames(pDataObj, |filename| {
@@ -130,7 +130,7 @@ impl FileDropHandler {
}
pub unsafe extern "system" fn DragLeave(this: *mut IDropTarget) -> HRESULT {
use crate::event::WindowEvent::HoveredFileCancelled;
use winit_core::event::WindowEvent::HoveredFileCancelled;
let drop_handler = unsafe { Self::from_interface(this) };
if drop_handler.hovered_is_valid {
drop_handler.send_event(Event::WindowEvent {
@@ -149,7 +149,7 @@ impl FileDropHandler {
_pt: *const POINTL,
_pdwEffect: *mut u32,
) -> HRESULT {
use crate::event::WindowEvent::DroppedFile;
use winit_core::event::WindowEvent::DroppedFile;
let drop_handler = unsafe { Self::from_interface(this) };
let hdrop = unsafe {
Self::iterate_filenames(pDataObj, |filename| {

View File

@@ -944,7 +944,7 @@ fn normalize_pointer_pressure(pressure: u32) -> Option<Force> {
/// Emit a `ModifiersChanged` event whenever modifiers have changed.
/// Returns the current modifier state
fn update_modifiers(window: HWND, userdata: &WindowData) {
use crate::event::WindowEvent::ModifiersChanged;
use winit_core::event::WindowEvent::ModifiersChanged;
let modifiers = {
let mut layouts = LAYOUT_CACHE.lock().unwrap();
@@ -966,7 +966,7 @@ fn update_modifiers(window: HWND, userdata: &WindowData) {
}
unsafe fn gain_active_focus(window: HWND, userdata: &WindowData) {
use crate::event::WindowEvent::Focused;
use winit_core::event::WindowEvent::Focused;
update_modifiers(window, userdata);
@@ -977,7 +977,7 @@ unsafe fn gain_active_focus(window: HWND, userdata: &WindowData) {
}
unsafe fn lose_active_focus(window: HWND, userdata: &WindowData) {
use crate::event::WindowEvent::{Focused, ModifiersChanged};
use winit_core::event::WindowEvent::{Focused, ModifiersChanged};
userdata.window_state_lock().modifiers_state = ModifiersState::empty();
userdata.send_event(Event::WindowEvent {
@@ -1080,7 +1080,7 @@ unsafe fn public_window_callback_inner(
.unwrap_or_else(|| result = ProcResult::Value(-1));
let keyboard_callback = || {
use crate::event::WindowEvent::KeyboardInput;
use winit_core::event::WindowEvent::KeyboardInput;
let events =
userdata
.key_event_builder
@@ -1170,7 +1170,7 @@ unsafe fn public_window_callback_inner(
}
WM_CLOSE => {
use crate::event::WindowEvent::CloseRequested;
use winit_core::event::WindowEvent::CloseRequested;
userdata.send_event(Event::WindowEvent {
window_id: WindowId::from(window as u64),
event: CloseRequested,
@@ -1179,7 +1179,7 @@ unsafe fn public_window_callback_inner(
}
WM_DESTROY => {
use crate::event::WindowEvent::Destroyed;
use winit_core::event::WindowEvent::Destroyed;
unsafe { RevokeDragDrop(window) };
userdata.send_event(Event::WindowEvent {
window_id: WindowId::from(window as u64),
@@ -1297,7 +1297,7 @@ unsafe fn public_window_callback_inner(
// WM_MOVE supplies client area positions, so we send Moved here instead.
WM_WINDOWPOSCHANGED => {
use crate::event::WindowEvent::Moved;
use winit_core::event::WindowEvent::Moved;
let windowpos = lparam as *const WINDOWPOS;
if unsafe { (*windowpos).flags & SWP_NOMOVE != SWP_NOMOVE } {
@@ -1314,7 +1314,7 @@ unsafe fn public_window_callback_inner(
}
WM_SIZE => {
use crate::event::WindowEvent::Resized;
use winit_core::event::WindowEvent::Resized;
let w = super::loword(lparam as u32) as u32;
let h = super::hiword(lparam as u32) as u32;
@@ -1474,7 +1474,7 @@ unsafe fn public_window_callback_inner(
}
WM_MOUSEMOVE => {
use crate::event::WindowEvent::{CursorEntered, CursorLeft, CursorMoved};
use winit_core::event::WindowEvent::{CursorEntered, CursorLeft, CursorMoved};
let x = super::get_x_lparam(lparam as u32) as i32;
let y = super::get_y_lparam(lparam as u32) as i32;
@@ -1550,7 +1550,7 @@ unsafe fn public_window_callback_inner(
}
WM_MOUSELEAVE => {
use crate::event::WindowEvent::CursorLeft;
use winit_core::event::WindowEvent::CursorLeft;
{
let mut w = userdata.window_state_lock();
w.mouse
@@ -1623,7 +1623,9 @@ unsafe fn public_window_callback_inner(
}
WM_LBUTTONDOWN => {
use crate::event::{ElementState::Pressed, MouseButton::Left, WindowEvent::MouseInput};
use winit_core::event::{
ElementState::Pressed, MouseButton::Left, WindowEvent::MouseInput,
};
unsafe { capture_mouse(window, &mut userdata.window_state_lock()) };
@@ -1641,7 +1643,7 @@ unsafe fn public_window_callback_inner(
}
WM_LBUTTONUP => {
use crate::event::{
use winit_core::event::{
ElementState::Released, MouseButton::Left, WindowEvent::MouseInput,
};
@@ -1661,7 +1663,7 @@ unsafe fn public_window_callback_inner(
}
WM_RBUTTONDOWN => {
use crate::event::{
use winit_core::event::{
ElementState::Pressed, MouseButton::Right, WindowEvent::MouseInput,
};
@@ -1681,7 +1683,7 @@ unsafe fn public_window_callback_inner(
}
WM_RBUTTONUP => {
use crate::event::{
use winit_core::event::{
ElementState::Released, MouseButton::Right, WindowEvent::MouseInput,
};
@@ -1701,7 +1703,7 @@ unsafe fn public_window_callback_inner(
}
WM_MBUTTONDOWN => {
use crate::event::{
use winit_core::event::{
ElementState::Pressed, MouseButton::Middle, WindowEvent::MouseInput,
};
@@ -1721,7 +1723,7 @@ unsafe fn public_window_callback_inner(
}
WM_MBUTTONUP => {
use crate::event::{
use winit_core::event::{
ElementState::Released, MouseButton::Middle, WindowEvent::MouseInput,
};
@@ -1741,7 +1743,7 @@ unsafe fn public_window_callback_inner(
}
WM_XBUTTONDOWN => {
use crate::event::{
use winit_core::event::{
ElementState::Pressed, MouseButton::Back, MouseButton::Forward, MouseButton::Other,
WindowEvent::MouseInput,
};
@@ -1767,7 +1769,7 @@ unsafe fn public_window_callback_inner(
}
WM_XBUTTONUP => {
use crate::event::{
use winit_core::event::{
ElementState::Released, MouseButton::Back, MouseButton::Forward,
MouseButton::Other, WindowEvent::MouseInput,
};
@@ -2097,7 +2099,7 @@ unsafe fn public_window_callback_inner(
// 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.
WM_DPICHANGED => {
use crate::event::WindowEvent::ScaleFactorChanged;
use winit_core::event::WindowEvent::ScaleFactorChanged;
// This message actually provides two DPI values - x and y. However MSDN says that
// "you only need to use either the X-axis or the Y-axis value when scaling your
@@ -2308,7 +2310,7 @@ unsafe fn public_window_callback_inner(
}
WM_SETTINGCHANGE => {
use crate::event::WindowEvent::ThemeChanged;
use winit_core::event::WindowEvent::ThemeChanged;
let preferred_theme = userdata.window_state_lock().preferred_theme;

View File

@@ -381,16 +381,9 @@ impl<T> BufferedEvent<T> {
inner_size_writer,
},
window_id,
} => BufferedEvent::ScaleFactorChanged(
window_id,
scale_factor,
*inner_size_writer
.new_inner_size
.upgrade()
.unwrap()
.lock()
.unwrap(),
),
} => {
BufferedEvent::ScaleFactorChanged(window_id, scale_factor, inner_size_writer.get())
}
event => BufferedEvent::Event(event),
}
}

View File

@@ -483,7 +483,7 @@ impl KeyEventBuilder {
let mut event = event_info.finalize();
event.logical_key = logical_key;
event.platform_specific.text_with_all_modifiers = text;
event.extra.extra.text_with_all_modifiers = text;
Some(MessageAsKeyEvent {
event,
is_synthetic: true,
@@ -664,9 +664,11 @@ impl PartialKeyEventInfo {
location: self.location,
state: self.key_state,
repeat: self.is_repeat,
platform_specific: KeyEventExtra {
text_with_all_modifiers: char_with_all_modifiers,
key_without_modifiers: self.key_without_modifiers,
extra: crate::event::KeyExtra {
extra: KeyEventExtra {
text_with_all_modifiers: char_with_all_modifiers,
key_without_modifiers: self.key_without_modifiers,
},
},
}
}

View File

@@ -75,14 +75,14 @@ pub struct Cursor(pub *const u16);
unsafe impl Send for Cursor {}
unsafe impl Sync for Cursor {}
pub fn persistent_identifier(id: DeviceId) -> Option<String> {
let val: u64 = id.into();
if val != 0 {
raw_input::get_raw_input_device_name(val as HANDLE)
} else {
None
}
pub fn persistent_identifier(id: DeviceId) -> Option<String> {
let val: u64 = id.into();
if val != 0 {
raw_input::get_raw_input_device_name(val as HANDLE)
} else {
None
}
}
// Constant device ID, to be removed when this backend is updated to report real device IDs.
const DEVICE_ID: DeviceId = unsafe { DeviceId::dummy() };

View File

@@ -1596,17 +1596,3 @@ pub enum Fullscreen {
/// Providing `None` to `Borderless` will fullscreen on the current monitor.
Borderless(Option<MonitorHandle>),
}
/// An opaque token used to activate the [`Window`].
///
/// [`Window`]: crate::window::Window
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ActivationToken {
pub(crate) _token: String,
}
impl ActivationToken {
pub(crate) fn _new(_token: String) -> Self {
Self { _token }
}
}