windows: Update crate Windows
from 0.53
to 0.56
(#11662)
Version 0.56 has fixed many of the previous bugs, and one of the bugs prevent me implementing some functions. Release Notes: - N/A
This commit is contained in:
parent
d1ee2d0749
commit
5154910c64
8 changed files with 117 additions and 87 deletions
|
@ -129,6 +129,7 @@ xkbcommon = { version = "0.7", features = ["wayland", "x11"] }
|
|||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows.workspace = true
|
||||
windows-core = "0.56"
|
||||
|
||||
[target.'cfg(windows)'.build-dependencies]
|
||||
embed-resource = "2.4"
|
||||
|
|
|
@ -81,7 +81,7 @@ impl DirectWriteComponent {
|
|||
// `DirectWriteTextSystem` to run on `win10 1703`+.
|
||||
let in_memory_loader = factory.CreateInMemoryFontFileLoader()?;
|
||||
factory.RegisterFontFileLoader(&in_memory_loader)?;
|
||||
let builder = factory.CreateFontSetBuilder2()?;
|
||||
let builder = factory.CreateFontSetBuilder()?;
|
||||
let mut locale_vec = vec![0u16; LOCALE_NAME_MAX_LENGTH as usize];
|
||||
GetUserDefaultLocaleName(&mut locale_vec);
|
||||
let locale = String::from_utf16_lossy(&locale_vec);
|
||||
|
@ -107,7 +107,7 @@ impl DirectWriteTextSystem {
|
|||
let mut result = std::mem::zeroed();
|
||||
components
|
||||
.factory
|
||||
.GetSystemFontCollection2(false, &mut result, true)?;
|
||||
.GetSystemFontCollection(false, &mut result, true)?;
|
||||
result.unwrap()
|
||||
};
|
||||
let custom_font_set = unsafe { components.builder.CreateFontSet()? };
|
||||
|
@ -303,7 +303,7 @@ impl DirectWriteState {
|
|||
let mut collection = std::mem::zeroed();
|
||||
self.components
|
||||
.factory
|
||||
.GetSystemFontCollection2(false, &mut collection, true)
|
||||
.GetSystemFontCollection(false, &mut collection, true)
|
||||
.unwrap();
|
||||
self.system_font_collection = collection.unwrap();
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ impl DirectWriteState {
|
|||
unsafe {
|
||||
let font_info = &self.fonts[font_id.0];
|
||||
let mut metrics = std::mem::zeroed();
|
||||
font_info.font_face.GetMetrics2(&mut metrics);
|
||||
font_info.font_face.GetMetrics(&mut metrics);
|
||||
|
||||
FontMetrics {
|
||||
units_per_em: metrics.Base.designUnitsPerEm as _,
|
||||
|
@ -549,10 +549,11 @@ impl DirectWriteState {
|
|||
};
|
||||
self.components.factory.CreateGlyphRunAnalysis(
|
||||
&glyph_run as _,
|
||||
1.0,
|
||||
Some(&transform as _),
|
||||
DWRITE_RENDERING_MODE_NATURAL,
|
||||
DWRITE_RENDERING_MODE1_NATURAL,
|
||||
DWRITE_MEASURING_MODE_NATURAL,
|
||||
DWRITE_GRID_FIT_MODE_DEFAULT,
|
||||
DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE,
|
||||
0.0,
|
||||
0.0,
|
||||
)
|
||||
|
@ -707,7 +708,7 @@ impl DirectWriteState {
|
|||
render_target.BeginDraw();
|
||||
if params.is_emoji {
|
||||
// WARN: only DWRITE_GLYPH_IMAGE_FORMATS_COLR has been tested
|
||||
let enumerator = self.components.factory.TranslateColorGlyphRun2(
|
||||
let enumerator = self.components.factory.TranslateColorGlyphRun(
|
||||
baseline_origin,
|
||||
&glyph_run as _,
|
||||
None,
|
||||
|
@ -721,7 +722,7 @@ impl DirectWriteState {
|
|||
0,
|
||||
)?;
|
||||
while enumerator.MoveNext().is_ok() {
|
||||
let Ok(color_glyph) = enumerator.GetCurrentRun2() else {
|
||||
let Ok(color_glyph) = enumerator.GetCurrentRun() else {
|
||||
break;
|
||||
};
|
||||
let color_glyph = &*color_glyph;
|
||||
|
@ -746,7 +747,7 @@ impl DirectWriteState {
|
|||
color_glyph.Base.paletteIndex as u32,
|
||||
color_glyph.measuringMode,
|
||||
),
|
||||
_ => render_target.DrawGlyphRun2(
|
||||
_ => render_target.DrawGlyphRun(
|
||||
baseline_origin,
|
||||
&color_glyph.Base.glyphRun,
|
||||
Some(color_glyph.Base.glyphRunDescription as *const _),
|
||||
|
@ -759,6 +760,7 @@ impl DirectWriteState {
|
|||
render_target.DrawGlyphRun(
|
||||
baseline_origin,
|
||||
&glyph_run,
|
||||
None,
|
||||
&brush,
|
||||
DWRITE_MEASURING_MODE_NATURAL,
|
||||
);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use itertools::Itertools;
|
||||
use smallvec::SmallVec;
|
||||
use std::rc::Rc;
|
||||
use util::ResultExt;
|
||||
use uuid::Uuid;
|
||||
use windows::{
|
||||
core::*,
|
||||
|
@ -158,7 +159,9 @@ fn available_monitors() -> SmallVec<[HMONITOR; 4]> {
|
|||
None,
|
||||
Some(monitor_enum_proc),
|
||||
LPARAM(&mut monitors as *mut _ as _),
|
||||
);
|
||||
)
|
||||
.ok()
|
||||
.log_err();
|
||||
}
|
||||
monitors
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ fn handle_paint_msg(handle: HWND, state_ptr: Rc<WindowsWindowStatePtr>) -> Optio
|
|||
request_frame();
|
||||
state_ptr.state.borrow_mut().callbacks.request_frame = Some(request_frame);
|
||||
}
|
||||
unsafe { EndPaint(handle, &paint_struct) };
|
||||
unsafe { EndPaint(handle, &paint_struct).ok().log_err() };
|
||||
Some(0)
|
||||
}
|
||||
|
||||
|
@ -509,7 +509,7 @@ fn handle_mouse_wheel_msg(
|
|||
x: lparam.signed_loword().into(),
|
||||
y: lparam.signed_hiword().into(),
|
||||
};
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point) };
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point).ok().log_err() };
|
||||
let event = ScrollWheelEvent {
|
||||
position: logical_point(cursor_point.x as f32, cursor_point.y as f32, scale_factor),
|
||||
delta: ScrollDelta::Lines(Point {
|
||||
|
@ -549,7 +549,7 @@ fn handle_mouse_horizontal_wheel_msg(
|
|||
x: lparam.signed_loword().into(),
|
||||
y: lparam.signed_hiword().into(),
|
||||
};
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point) };
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point).ok().log_err() };
|
||||
let event = ScrollWheelEvent {
|
||||
position: logical_point(cursor_point.x as f32, cursor_point.y as f32, scale_factor),
|
||||
delta: ScrollDelta::Lines(Point {
|
||||
|
@ -598,8 +598,8 @@ fn handle_ime_position(handle: HWND, state_ptr: Rc<WindowsWindowStatePtr>) -> Op
|
|||
},
|
||||
..Default::default()
|
||||
};
|
||||
ImmSetCandidateWindow(ctx, &config as _);
|
||||
ImmReleaseContext(handle, ctx);
|
||||
ImmSetCandidateWindow(ctx, &config as _).ok().log_err();
|
||||
ImmReleaseContext(handle, ctx).ok().log_err();
|
||||
Some(0)
|
||||
}
|
||||
}
|
||||
|
@ -694,7 +694,11 @@ fn handle_activate_msg(
|
|||
let activated = wparam.loword() > 0;
|
||||
if state_ptr.hide_title_bar {
|
||||
if let Some(titlebar_rect) = state_ptr.state.borrow().get_titlebar_rect().log_err() {
|
||||
unsafe { InvalidateRect(handle, Some(&titlebar_rect), FALSE) };
|
||||
unsafe {
|
||||
InvalidateRect(handle, Some(&titlebar_rect), FALSE)
|
||||
.ok()
|
||||
.log_err()
|
||||
};
|
||||
}
|
||||
}
|
||||
let this = state_ptr.clone();
|
||||
|
@ -811,7 +815,7 @@ fn handle_hit_test_msg(
|
|||
x: lparam.signed_loword().into(),
|
||||
y: lparam.signed_hiword().into(),
|
||||
};
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point) };
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point).ok().log_err() };
|
||||
if cursor_point.y > 0 && cursor_point.y < frame_y + padding {
|
||||
return Some(HTTOP as _);
|
||||
}
|
||||
|
@ -853,7 +857,7 @@ fn handle_nc_mouse_move_msg(
|
|||
x: lparam.signed_loword().into(),
|
||||
y: lparam.signed_hiword().into(),
|
||||
};
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point) };
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point).ok().log_err() };
|
||||
let event = MouseMoveEvent {
|
||||
position: logical_point(cursor_point.x as f32, cursor_point.y as f32, scale_factor),
|
||||
pressed_button: None,
|
||||
|
@ -890,7 +894,7 @@ fn handle_nc_mouse_down_msg(
|
|||
x: lparam.signed_loword().into(),
|
||||
y: lparam.signed_hiword().into(),
|
||||
};
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point) };
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point).ok().log_err() };
|
||||
let physical_point = point(DevicePixels(cursor_point.x), DevicePixels(cursor_point.y));
|
||||
let click_count = lock.click_state.update(button, physical_point);
|
||||
drop(lock);
|
||||
|
@ -936,7 +940,7 @@ fn handle_nc_mouse_up_msg(
|
|||
x: lparam.signed_loword().into(),
|
||||
y: lparam.signed_hiword().into(),
|
||||
};
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point) };
|
||||
unsafe { ScreenToClient(handle, &mut cursor_point).ok().log_err() };
|
||||
let event = MouseUpEvent {
|
||||
button,
|
||||
position: logical_point(cursor_point.x as f32, cursor_point.y as f32, scale_factor),
|
||||
|
@ -959,13 +963,13 @@ fn handle_nc_mouse_up_msg(
|
|||
if button == MouseButton::Left {
|
||||
match wparam.0 as u32 {
|
||||
HTMINBUTTON => unsafe {
|
||||
ShowWindowAsync(handle, SW_MINIMIZE);
|
||||
ShowWindowAsync(handle, SW_MINIMIZE).ok().log_err();
|
||||
},
|
||||
HTMAXBUTTON => unsafe {
|
||||
if state_ptr.state.borrow().is_maximized() {
|
||||
ShowWindowAsync(handle, SW_NORMAL);
|
||||
ShowWindowAsync(handle, SW_NORMAL).ok().log_err();
|
||||
} else {
|
||||
ShowWindowAsync(handle, SW_MAXIMIZE);
|
||||
ShowWindowAsync(handle, SW_MAXIMIZE).ok().log_err();
|
||||
}
|
||||
},
|
||||
HTCLOSE => unsafe {
|
||||
|
@ -1140,7 +1144,7 @@ fn parse_char_msg_keystroke(wparam: WPARAM) -> Option<Keystroke> {
|
|||
/// mark window client rect to be re-drawn
|
||||
/// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-invalidaterect
|
||||
pub(crate) fn invalidate_client_area(handle: HWND) {
|
||||
unsafe { InvalidateRect(handle, None, FALSE) };
|
||||
unsafe { InvalidateRect(handle, None, FALSE).ok().log_err() };
|
||||
}
|
||||
|
||||
fn parse_ime_compostion_string(handle: HWND) -> Option<(String, usize)> {
|
||||
|
@ -1164,7 +1168,7 @@ fn parse_ime_compostion_string(handle: HWND) -> Option<(String, usize)> {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
ImmReleaseContext(handle, ctx);
|
||||
ImmReleaseContext(handle, ctx).ok().log_err();
|
||||
result
|
||||
}
|
||||
}
|
||||
|
@ -1173,7 +1177,7 @@ fn retrieve_composition_cursor_position(handle: HWND) -> usize {
|
|||
unsafe {
|
||||
let ctx = ImmGetContext(handle);
|
||||
let ret = ImmGetCompositionStringW(ctx, GCS_CURSORPOS, None, 0);
|
||||
ImmReleaseContext(handle, ctx);
|
||||
ImmReleaseContext(handle, ctx).ok().log_err();
|
||||
ret as usize
|
||||
}
|
||||
}
|
||||
|
@ -1199,7 +1203,7 @@ fn parse_ime_compostion_result(handle: HWND) -> Option<String> {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
ImmReleaseContext(handle, ctx);
|
||||
ImmReleaseContext(handle, ctx).ok().log_err();
|
||||
result
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,9 @@ impl WindowsPlatform {
|
|||
None,
|
||||
HRGN::default(),
|
||||
RDW_INVALIDATE | RDW_UPDATENOW,
|
||||
);
|
||||
)
|
||||
.ok()
|
||||
.log_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -219,7 +221,9 @@ impl Platform for WindowsPlatform {
|
|||
}
|
||||
WM_SETTINGCHANGE => self.update_system_settings(),
|
||||
_ => {
|
||||
TranslateMessage(&msg);
|
||||
// todo(windows)
|
||||
// crate `windows 0.56` reports true as Err
|
||||
TranslateMessage(&msg).as_bool();
|
||||
DispatchMessageW(&msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -303,7 +303,7 @@ impl WindowsWindow {
|
|||
placement.rcNormalPosition.bottom = params.bounds.bottom().0;
|
||||
SetWindowPlacement(raw_hwnd, &placement).log_err();
|
||||
}
|
||||
unsafe { ShowWindow(raw_hwnd, SW_SHOW) };
|
||||
unsafe { ShowWindow(raw_hwnd, SW_SHOW).ok().log_err() };
|
||||
|
||||
wnd
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ impl PlatformWindow for WindowsWindow {
|
|||
GetCursorPos(&mut point)
|
||||
.context("unable to get cursor position")
|
||||
.log_err();
|
||||
ScreenToClient(self.0.hwnd, &mut point);
|
||||
ScreenToClient(self.0.hwnd, &mut point).ok().log_err();
|
||||
point
|
||||
};
|
||||
logical_point(point.x as f32, point.y as f32, scale_factor)
|
||||
|
@ -481,7 +481,9 @@ impl PlatformWindow for WindowsWindow {
|
|||
let hwnd = self.0.hwnd;
|
||||
unsafe { SetActiveWindow(hwnd) };
|
||||
unsafe { SetFocus(hwnd) };
|
||||
unsafe { SetForegroundWindow(hwnd) };
|
||||
// todo(windows)
|
||||
// crate `windows 0.56` reports true as Err
|
||||
unsafe { SetForegroundWindow(hwnd).as_bool() };
|
||||
}
|
||||
|
||||
fn is_active(&self) -> bool {
|
||||
|
@ -511,11 +513,11 @@ impl PlatformWindow for WindowsWindow {
|
|||
fn show_character_palette(&self) {}
|
||||
|
||||
fn minimize(&self) {
|
||||
unsafe { ShowWindowAsync(self.0.hwnd, SW_MINIMIZE) };
|
||||
unsafe { ShowWindowAsync(self.0.hwnd, SW_MINIMIZE).ok().log_err() };
|
||||
}
|
||||
|
||||
fn zoom(&self) {
|
||||
unsafe { ShowWindowAsync(self.0.hwnd, SW_MAXIMIZE) };
|
||||
unsafe { ShowWindowAsync(self.0.hwnd, SW_MAXIMIZE).ok().log_err() };
|
||||
}
|
||||
|
||||
fn toggle_fullscreen(&self) {
|
||||
|
@ -702,7 +704,9 @@ impl IDropTarget_Impl for WindowsDragDropHandler {
|
|||
}
|
||||
ReleaseStgMedium(&mut idata);
|
||||
let mut cursor_position = POINT { x: pt.x, y: pt.y };
|
||||
ScreenToClient(self.0.hwnd, &mut cursor_position);
|
||||
ScreenToClient(self.0.hwnd, &mut cursor_position)
|
||||
.ok()
|
||||
.log_err();
|
||||
let scale_factor = self.0.state.borrow().scale_factor;
|
||||
let input = PlatformInput::FileDrop(FileDropEvent::Entered {
|
||||
position: logical_point(
|
||||
|
@ -728,7 +732,9 @@ impl IDropTarget_Impl for WindowsDragDropHandler {
|
|||
) -> windows::core::Result<()> {
|
||||
let mut cursor_position = POINT { x: pt.x, y: pt.y };
|
||||
unsafe {
|
||||
ScreenToClient(self.0.hwnd, &mut cursor_position);
|
||||
ScreenToClient(self.0.hwnd, &mut cursor_position)
|
||||
.ok()
|
||||
.log_err();
|
||||
}
|
||||
let scale_factor = self.0.state.borrow().scale_factor;
|
||||
let input = PlatformInput::FileDrop(FileDropEvent::Pending {
|
||||
|
@ -759,7 +765,9 @@ impl IDropTarget_Impl for WindowsDragDropHandler {
|
|||
) -> windows::core::Result<()> {
|
||||
let mut cursor_position = POINT { x: pt.x, y: pt.y };
|
||||
unsafe {
|
||||
ScreenToClient(self.0.hwnd, &mut cursor_position);
|
||||
ScreenToClient(self.0.hwnd, &mut cursor_position)
|
||||
.ok()
|
||||
.log_err();
|
||||
}
|
||||
let scale_factor = self.0.state.borrow().scale_factor;
|
||||
let input = PlatformInput::FileDrop(FileDropEvent::Submit {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue