Skip to content

Commit 3d5a70e

Browse files
committed
Merge branch 'composition-event' into pr/2147
2 parents c942bfd + 6a27687 commit 3d5a70e

37 files changed

+1954
-1685
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
88

99
# Unreleased
1010

11+
- macOS: Remove the need to call `set_ime_position` after moving the window.
1112
- Added `Window::is_visible`.
1213
- Added `Window::is_resizable`.
1314
- Added `Window::is_decorated`.
@@ -21,7 +22,10 @@ And please only add new entries to the top of this list, right below the `# Unre
2122
- **Breaking:** Replaced `EventLoopExtMacOS` with `EventLoopBuilderExtMacOS` (which also has renamed methods).
2223
- **Breaking:** Replaced `EventLoopExtWindows` with `EventLoopBuilderExtWindows` (which also has renamed methods).
2324
- **Breaking:** Replaced `EventLoopExtUnix` with `EventLoopBuilderExtUnix` (which also has renamed methods).
25+
- **Breaking:** The platform specific extensions for Windows `winit::platform::windows` have changed. All `HANDLE`-like types e.g. `HWND` and `HMENU` were converted from winapi types or `*mut c_void` to `isize`. This was done to be consistent with the type definitions in windows-sys and to not expose internal dependencies.
26+
- The internal bindings to the [Windows API](https://docs.microsoft.com/en-us/windows/) were changed from the unofficial [winapi](https://github.com/retep998/winapi-rs) bindings to the official Microsoft [windows-sys](https://github.com/microsoft/windows-rs) bindings.
2427
- On Wayland, fix resize and scale factor changes not being propagated properly.
28+
- On Wayland, fix polling during consecutive `EventLoop::run_return` invocations.
2529

2630
# 0.26.1 (2022-01-05)
2731

@@ -30,6 +34,7 @@ And please only add new entries to the top of this list, right below the `# Unre
3034
- On X11, add mappings for numpad comma, numpad enter, numlock and pause.
3135
- On macOS, fix Pinyin IME input by reverting a change that intended to improve IME.
3236
- On Windows, fix a crash with transparent windows on Windows 11.
37+
- **Breaking:**: Reverse horizontal scrolling sign in `MouseScrollDelta` to match the direction of vertical scrolling. A positive X value now means moving the content to the right. The meaning of vertical scrolling stays the same: a positive Y value means moving the content down.
3338

3439
# 0.26.0 (2021-12-01)
3540

Cargo.toml

+28-26
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,35 @@ default_features = false
5555
features = ["display_link"]
5656

5757
[target.'cfg(target_os = "windows")'.dependencies]
58-
parking_lot = "0.11"
58+
parking_lot = "0.12"
5959

60-
[target.'cfg(target_os = "windows")'.dependencies.winapi]
61-
version = "0.3.9"
60+
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
61+
version = "0.33"
6262
features = [
63-
"combaseapi",
64-
"commctrl",
65-
"dwmapi",
66-
"errhandlingapi",
67-
"imm",
68-
"hidusage",
69-
"libloaderapi",
70-
"objbase",
71-
"ole2",
72-
"processthreadsapi",
73-
"shellapi",
74-
"shellscalingapi",
75-
"shobjidl_core",
76-
"unknwnbase",
77-
"winbase",
78-
"windowsx",
79-
"winerror",
80-
"wingdi",
81-
"winnt",
82-
"winuser",
83-
"mmsystem",
84-
"timeapi"
63+
"Win32_Devices_HumanInterfaceDevice",
64+
"Win32_Foundation",
65+
"Win32_Globalization",
66+
"Win32_Graphics_Dwm",
67+
"Win32_Graphics_Gdi",
68+
"Win32_Media",
69+
"Win32_System_Com_StructuredStorage",
70+
"Win32_System_Com",
71+
"Win32_System_LibraryLoader",
72+
"Win32_System_Ole",
73+
"Win32_System_SystemInformation",
74+
"Win32_System_SystemServices",
75+
"Win32_System_Threading",
76+
"Win32_System_WindowsProgramming",
77+
"Win32_UI_Accessibility",
78+
"Win32_UI_Controls",
79+
"Win32_UI_HiDpi",
80+
"Win32_UI_Input_Ime",
81+
"Win32_UI_Input_KeyboardAndMouse",
82+
"Win32_UI_Input_Pointer",
83+
"Win32_UI_Input_Touch",
84+
"Win32_UI_Shell",
85+
"Win32_UI_TextServices",
86+
"Win32_UI_WindowsAndMessaging",
8587
]
8688

8789
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dependencies]
@@ -91,7 +93,7 @@ sctk = { package = "smithay-client-toolkit", version = "0.15.1", default_feature
9193
mio = { version = "0.8", features = ["os-ext"], optional = true }
9294
x11-dl = { version = "2.18.5", optional = true }
9395
percent-encoding = { version = "2.0", optional = true }
94-
parking_lot = { version = "0.11.0", optional = true }
96+
parking_lot = { version = "0.12.0", optional = true }
9597
libc = "0.2.64"
9698

9799
[target.'cfg(target_arch = "wasm32")'.dependencies.web_sys]

examples/mouse_wheel.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use simple_logger::SimpleLogger;
22
use winit::{
3-
event::{DeviceEvent, Event, WindowEvent},
3+
event::{Event, WindowEvent},
44
event_loop::{ControlFlow, EventLoop},
55
window::WindowBuilder,
66
};
@@ -14,29 +14,41 @@ fn main() {
1414
.build(&event_loop)
1515
.unwrap();
1616

17+
println!(
18+
r"
19+
When using so called 'natural scrolling' (scrolling that acts like on a touch screen), this is what to expect:
20+
21+
Moving your finger downwards on a scroll wheel should make the window move down, and you should see a positive Y scroll value.
22+
23+
When moving fingers on a trackpad down and to the right, you should see positive X and Y deltas, and the window should move down and to the right.
24+
25+
With reverse scrolling, you should see the inverse behavior.
26+
27+
In both cases the example window should move like the content of a scroll area in any other application.
28+
29+
In other words, the deltas indicate the direction in which to move the content (in this case the window)."
30+
);
31+
1732
event_loop.run(move |event, _, control_flow| {
1833
*control_flow = ControlFlow::Wait;
1934

2035
match event {
2136
Event::WindowEvent { event, .. } => match event {
2237
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
23-
_ => (),
24-
},
25-
Event::DeviceEvent { event, .. } => match event {
26-
DeviceEvent::MouseWheel { delta } => match delta {
38+
WindowEvent::MouseWheel { delta, .. } => match delta {
2739
winit::event::MouseScrollDelta::LineDelta(x, y) => {
2840
println!("mouse wheel Line Delta: ({},{})", x, y);
2941
let pixels_per_line = 120.0;
3042
let mut pos = window.outer_position().unwrap();
31-
pos.x -= (x * pixels_per_line) as i32;
32-
pos.y -= (y * pixels_per_line) as i32;
43+
pos.x += (x * pixels_per_line) as i32;
44+
pos.y += (y * pixels_per_line) as i32;
3345
window.set_outer_position(pos)
3446
}
3547
winit::event::MouseScrollDelta::PixelDelta(p) => {
3648
println!("mouse wheel Pixel Delta: ({},{})", p.x, p.y);
3749
let mut pos = window.outer_position().unwrap();
38-
pos.x -= p.x as i32;
39-
pos.y -= p.y as i32;
50+
pos.x += p.x as i32;
51+
pos.y += p.y as i32;
4052
window.set_outer_position(pos)
4153
}
4254
},

src/event.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -785,15 +785,23 @@ pub enum MouseScrollDelta {
785785
/// Amount in lines or rows to scroll in the horizontal
786786
/// and vertical directions.
787787
///
788-
/// Positive values indicate movement forward
789-
/// (away from the user) or rightwards.
788+
/// Positive values indicate that the content that is being scrolled should move
789+
/// right and down (revealing more content left and up).
790790
LineDelta(f32, f32),
791+
791792
/// Amount in pixels to scroll in the horizontal and
792793
/// vertical direction.
793794
///
794795
/// Scroll events are expressed as a PixelDelta if
795796
/// supported by the device (eg. a touchpad) and
796797
/// platform.
798+
///
799+
/// Positive values indicate that the content being scrolled should
800+
/// move right/down.
801+
///
802+
/// For a 'natural scrolling' touch pad (that acts like a touch screen)
803+
/// this means moving your fingers right and down should give positive values,
804+
/// and move the content right and down (to reveal more things left and up).
797805
PixelDelta(PhysicalPosition<f64>),
798806
}
799807

src/platform/windows.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
#![cfg(target_os = "windows")]
22

3-
use std::os::raw::c_void;
43
use std::path::Path;
54

6-
use winapi::shared::minwindef::WORD;
7-
use winapi::shared::windef::{HMENU, HWND};
8-
95
use crate::{
106
dpi::PhysicalSize,
117
event::DeviceId,
@@ -15,6 +11,15 @@ use crate::{
1511
window::{BadIcon, Icon, Theme, Window, WindowBuilder},
1612
};
1713

14+
/// Window Handle type used by Win32 API
15+
pub type HWND = isize;
16+
/// Menu Handle type used by Win32 API
17+
pub type HMENU = isize;
18+
/// Monitor Handle type used by Win32 API
19+
pub type HMONITOR = isize;
20+
/// Instance Handle type used by Win32 API
21+
pub type HINSTANCE = isize;
22+
1823
/// Additional methods on `EventLoop` that are specific to Windows.
1924
pub trait EventLoopBuilderExtWindows {
2025
/// Whether to allow the event loop to be created off of the main thread.
@@ -70,11 +75,11 @@ impl<T> EventLoopBuilderExtWindows for EventLoopBuilder<T> {
7075
/// Additional methods on `Window` that are specific to Windows.
7176
pub trait WindowExtWindows {
7277
/// Returns the HINSTANCE of the window
73-
fn hinstance(&self) -> *mut c_void;
78+
fn hinstance(&self) -> HINSTANCE;
7479
/// Returns the native handle that is used by this window.
7580
///
7681
/// The pointer will become invalid when the native window was destroyed.
77-
fn hwnd(&self) -> *mut c_void;
82+
fn hwnd(&self) -> HWND;
7883

7984
/// Enables or disables mouse and keyboard input to the specified window.
8085
///
@@ -100,13 +105,13 @@ pub trait WindowExtWindows {
100105

101106
impl WindowExtWindows for Window {
102107
#[inline]
103-
fn hinstance(&self) -> *mut c_void {
104-
self.window.hinstance() as *mut _
108+
fn hinstance(&self) -> HINSTANCE {
109+
self.window.hinstance()
105110
}
106111

107112
#[inline]
108-
fn hwnd(&self) -> *mut c_void {
109-
self.window.hwnd() as *mut _
113+
fn hwnd(&self) -> HWND {
114+
self.window.hwnd()
110115
}
111116

112117
#[inline]
@@ -150,10 +155,12 @@ pub trait WindowBuilderExtWindows {
150155
///
151156
/// Parent and menu are mutually exclusive; a child window cannot have a menu!
152157
///
153-
/// The menu must have been manually created beforehand with [`winapi::um::winuser::CreateMenu`] or similar.
158+
/// The menu must have been manually created beforehand with [`CreateMenu`] or similar.
154159
///
155160
/// Note: Dark mode cannot be supported for win32 menus, it's simply not possible to change how the menus look.
156161
/// If you use this, it is recommended that you combine it with `with_theme(Some(Theme::Light))` to avoid a jarring effect.
162+
///
163+
/// [`CreateMenu`]: windows_sys::Win32::UI::WindowsAndMessaging::CreateMenu
157164
fn with_menu(self, menu: HMENU) -> WindowBuilder;
158165

159166
/// This sets `ICON_BIG`. A good ceiling here is 256x256.
@@ -224,7 +231,7 @@ pub trait MonitorHandleExtWindows {
224231
fn native_id(&self) -> String;
225232

226233
/// Returns the handle of the monitor - `HMONITOR`.
227-
fn hmonitor(&self) -> *mut c_void;
234+
fn hmonitor(&self) -> HMONITOR;
228235
}
229236

230237
impl MonitorHandleExtWindows for MonitorHandle {
@@ -234,8 +241,8 @@ impl MonitorHandleExtWindows for MonitorHandle {
234241
}
235242

236243
#[inline]
237-
fn hmonitor(&self) -> *mut c_void {
238-
self.inner.hmonitor() as *mut _
244+
fn hmonitor(&self) -> HMONITOR {
245+
self.inner.hmonitor()
239246
}
240247
}
241248

@@ -273,7 +280,7 @@ pub trait IconExtWindows: Sized {
273280
///
274281
/// In cases where the specified size does not exist in the file, Windows may perform scaling
275282
/// to get an icon of the desired size.
276-
fn from_resource(ordinal: WORD, size: Option<PhysicalSize<u32>>) -> Result<Self, BadIcon>;
283+
fn from_resource(ordinal: u16, size: Option<PhysicalSize<u32>>) -> Result<Self, BadIcon>;
277284
}
278285

279286
impl IconExtWindows for Icon {
@@ -285,7 +292,7 @@ impl IconExtWindows for Icon {
285292
Ok(Icon { inner: win_icon })
286293
}
287294

288-
fn from_resource(ordinal: WORD, size: Option<PhysicalSize<u32>>) -> Result<Self, BadIcon> {
295+
fn from_resource(ordinal: u16, size: Option<PhysicalSize<u32>>) -> Result<Self, BadIcon> {
289296
let win_icon = WinIcon::from_resource(ordinal, size)?;
290297
Ok(Icon { inner: win_icon })
291298
}

0 commit comments

Comments
 (0)