merge: pop-os/iced a l'etat pinne par libcosmic 7f715bc5d (epoch-1.10.0)
Some checks are pending
Audit / vulnerabilities (push) Waiting to run
Check / wasm (push) Waiting to run
Check / widget (push) Waiting to run
Document / all (push) Waiting to run
Format / all (push) Waiting to run
Lint / all (push) Waiting to run
Test / all (macOS-latest, 1.88) (push) Waiting to run
Test / all (macOS-latest, beta) (push) Waiting to run
Test / all (macOS-latest, stable) (push) Waiting to run
Test / all (ubuntu-latest, 1.88) (push) Waiting to run
Test / all (ubuntu-latest, beta) (push) Waiting to run
Test / all (ubuntu-latest, stable) (push) Waiting to run
Test / all (windows-latest, 1.88) (push) Waiting to run
Test / all (windows-latest, beta) (push) Waiting to run
Test / all (windows-latest, stable) (push) Waiting to run

This commit is contained in:
Lionel DARNIS 2026-10-11 06:57:56 +02:00
commit f8ac890b9c
7 changed files with 118 additions and 40 deletions

View file

@ -1,3 +1,5 @@
use crate::conversion;
use crate::core::mouse;
use cursor_icon::CursorIcon;
use winit::window::ResizeDirection;
@ -24,6 +26,9 @@ const DRAG_RESIZE_SUPPORTED: bool = true;
const DRAG_RESIZE_SUPPORTED: bool = false;
/// If supported by winit, returns a closure that implements cursor resize support.
///
/// The closure takes the cursor last set by the UI, which it restores when
/// the pointer leaves the resize border.
pub fn event_func(
window: &dyn winit::window::Window,
border_size: f64,
@ -32,6 +37,7 @@ pub fn event_func(
dyn FnMut(
&dyn winit::window::Window,
&winit::event::WindowEvent,
mouse::Interaction,
) -> bool,
>,
> {
@ -41,7 +47,8 @@ pub fn event_func(
Some(Box::new(
move |window: &dyn winit::window::Window,
window_event: &winit::event::WindowEvent|
window_event: &winit::event::WindowEvent,
ui_interaction: mouse::Interaction|
-> bool {
// Keep track of border resize state and set cursor icon when in range
match window_event {
@ -49,23 +56,30 @@ pub fn event_func(
position,
..
} => {
let resizable = !window.is_decorated()
&& !window.is_maximized()
&& window.fullscreen().is_none();
if resizable {
let location = cursor_resize_direction(
let location = if is_resizable(window) {
cursor_resize_direction(
window.surface_size(),
*position,
border_size,
);
if location != cursor_prev_resize_direction {
window.set_cursor(
resize_direction_cursor_icon(location)
)
} else {
None
};
if location != cursor_prev_resize_direction {
match location {
Some(direction) => window.set_cursor(
resize_direction_cursor_icon(direction)
.into(),
);
cursor_prev_resize_direction = location;
return true;
),
None => restore_cursor(window, ui_interaction),
}
cursor_prev_resize_direction = location;
return true;
}
}
winit::event::WindowEvent::PointerLeft { .. } => {
if cursor_prev_resize_direction.take().is_some() {
restore_cursor(window, ui_interaction);
}
}
winit::event::WindowEvent::PointerButton {
@ -80,7 +94,9 @@ pub fn event_func(
primary: true,
..
} => {
if let Some(direction) = cursor_prev_resize_direction {
if let Some(direction) = cursor_prev_resize_direction
&& is_resizable(window)
{
let _res = window.drag_resize_window(direction);
return true;
}
@ -96,22 +112,37 @@ pub fn event_func(
}
}
/// Whether the window can currently be resized from its border.
fn is_resizable(window: &dyn winit::window::Window) -> bool {
!window.is_decorated()
&& !window.is_maximized()
&& window.fullscreen().is_none()
}
/// Set the cursor back to the one the UI last set.
fn restore_cursor(
window: &dyn winit::window::Window,
ui_interaction: mouse::Interaction,
) {
// `None` means the UI hid the cursor, which a cursor icon doesn't undo.
if let Some(icon) = conversion::mouse_interaction(ui_interaction) {
window.set_cursor(icon.into());
}
}
/// Get the cursor icon that corresponds to the resize direction.
fn resize_direction_cursor_icon(
resize_direction: Option<ResizeDirection>,
resize_direction: ResizeDirection,
) -> CursorIcon {
match resize_direction {
Some(resize_direction) => match resize_direction {
ResizeDirection::East => CursorIcon::EResize,
ResizeDirection::North => CursorIcon::NResize,
ResizeDirection::NorthEast => CursorIcon::NeResize,
ResizeDirection::NorthWest => CursorIcon::NwResize,
ResizeDirection::South => CursorIcon::SResize,
ResizeDirection::SouthEast => CursorIcon::SeResize,
ResizeDirection::SouthWest => CursorIcon::SwResize,
ResizeDirection::West => CursorIcon::WResize,
},
None => CursorIcon::Default,
ResizeDirection::East => CursorIcon::EResize,
ResizeDirection::North => CursorIcon::NResize,
ResizeDirection::NorthEast => CursorIcon::NeResize,
ResizeDirection::NorthWest => CursorIcon::NwResize,
ResizeDirection::South => CursorIcon::SResize,
ResizeDirection::SouthEast => CursorIcon::SeResize,
ResizeDirection::SouthWest => CursorIcon::SwResize,
ResizeDirection::West => CursorIcon::WResize,
}
}

View file

@ -1326,7 +1326,11 @@ async fn run_instance<P>(
};
// Initiates a drag resize window state when found.
if let Some(func) = window.drag_resize_window_func.as_mut() {
if func(window.raw.as_ref(), &event) {
if func(
window.raw.as_ref(),
&event,
window.mouse_interaction,
) {
continue;
}
}

View file

@ -191,6 +191,7 @@ where
dyn FnMut(
&dyn winit::window::Window,
&winit::event::WindowEvent,
mouse::Interaction,
) -> bool,
>,
>,