diff --git a/core/src/window/settings.rs b/core/src/window/settings.rs index 115becbc..103d4052 100644 --- a/core/src/window/settings.rs +++ b/core/src/window/settings.rs @@ -56,6 +56,9 @@ pub struct Settings { /// Whether the window should be resizable or not. pub resizable: bool, + /// The border area for the drag resize handle. + pub resize_border: u32, + /// Whether the title bar has Close button or not pub closeable: bool, @@ -120,6 +123,7 @@ impl Default for Settings { icon: None, exit_on_close_request: true, platform_specific: PlatformSpecific::default(), + resize_border: 8, } } } diff --git a/winit/src/application/drag_resize.rs b/winit/src/application/drag_resize.rs index d7a30a6c..6d575b52 100644 --- a/winit/src/application/drag_resize.rs +++ b/winit/src/application/drag_resize.rs @@ -1,4 +1,5 @@ -use winit::window::{CursorIcon, ResizeDirection}; +use cursor_icon::CursorIcon; +use winit::window::ResizeDirection; #[cfg(any( all( @@ -44,8 +45,9 @@ pub fn event_func( -> bool { // Keep track of border resize state and set cursor icon when in range match window_event { - winit::event::WindowEvent::CursorMoved { - position, .. + winit::event::WindowEvent::PointerMoved { + position, + .. } => { if !window.is_decorated() { let location = cursor_resize_direction( @@ -63,9 +65,16 @@ pub fn event_func( } } } - winit::event::WindowEvent::MouseInput { + winit::event::WindowEvent::PointerButton { state: winit::event::ElementState::Pressed, - button: winit::event::MouseButton::Left, + button: + winit::event::ButtonSource::Mouse( + winit::event::MouseButton::Left, + ) + | winit::event::ButtonSource::Touch { + finger_id: _, .. + }, + primary: true, .. } => { if let Some(direction) = cursor_prev_resize_direction { diff --git a/winit/src/lib.rs b/winit/src/lib.rs index ac70bbbd..42bccd14 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -18,6 +18,10 @@ html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" )] #![cfg_attr(docsrs, feature(doc_cfg))] + +#[path = "application/drag_resize.rs"] +mod drag_resize; + use dnd::DndSurface; pub use iced_debug as debug; pub use iced_program as program; @@ -404,7 +408,7 @@ where #[cfg(target_arch = "wasm32")] let target = settings.platform_specific.target.clone(); - + let resize_border = settings.resize_border; let window_attributes = conversion::window_attributes( settings, @@ -500,6 +504,7 @@ where exit_on_close_request, make_visible: visible, on_open, + resize_border, }), ); } @@ -667,6 +672,7 @@ enum Event { exit_on_close_request: bool, make_visible: bool, on_open: oneshot::Sender, + resize_border: u32, }, Exit, Dnd(dnd::DndEvent), @@ -824,6 +830,7 @@ async fn run_instance

( exit_on_close_request, make_visible, on_open, + resize_border } => { #[cfg(feature = "a11y")] control_sender @@ -882,6 +889,7 @@ async fn run_instance

( compositor, exit_on_close_request, system_theme, + resize_border ); window.raw.set_theme(conversion::window_theme( @@ -1287,7 +1295,14 @@ async fn run_instance

( else { continue; }; - + // 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) { + continue; + } + } match event { winit::event::WindowEvent::SurfaceResized(_) => { window.raw.request_redraw(); diff --git a/winit/src/platform_specific/wayland/sctk_event.rs b/winit/src/platform_specific/wayland/sctk_event.rs index 3399ea4d..522db945 100755 --- a/winit/src/platform_specific/wayland/sctk_event.rs +++ b/winit/src/platform_specific/wayland/sctk_event.rs @@ -795,6 +795,7 @@ impl SctkEvent { compositor, false, // TODO do we want to get this value here? theme::Mode::None, // TODO do we really need to track the system theme here? + 0, ); _ = surface_ids.insert(object_id, wrapper.clone()); let logical_size = window.logical_size(); @@ -1009,6 +1010,7 @@ impl SctkEvent { compositor, false, // TODO do we want to get this value here? theme::Mode::None, // TODO do we really need to track the system theme here? + 0, ); window.state.ready = false; let logical_size = window.logical_size(); @@ -1098,21 +1100,22 @@ impl SctkEvent { proxy.wake_up(); } let physical = w.raw.surface_size(); - let (p_w, p_h) = if physical.width > 0 - && physical.height > 0 - { - (physical.width, physical.height) - } else { - // Fallback if backend has not reported an updated - // surface size yet for this configure. - let scale = w.state.scale_factor(); - ( - (configure.width.max(1) as f64 * scale) - .ceil() as u32, - (configure.height.max(1) as f64 * scale) - .ceil() as u32, - ) - }; + let (p_w, p_h) = + if physical.width > 0 && physical.height > 0 { + (physical.width, physical.height) + } else { + // Fallback if backend has not reported an updated + // surface size yet for this configure. + let scale = w.state.scale_factor(); + ( + (configure.width.max(1) as f64 * scale) + .ceil() + as u32, + (configure.height.max(1) as f64 * scale) + .ceil() + as u32, + ) + }; w.state.update( program, @@ -1261,6 +1264,7 @@ impl SctkEvent { compositor, false, // TODO do we want to get this value here? theme::Mode::None, // TODO do we really need to track the system theme here? + 0, ); _ = surface_ids.insert(object_id, wrapper.clone()); let logical_size = window.logical_size(); @@ -1575,6 +1579,7 @@ impl SctkEvent { compositor, false, // TODO do we want to get this value here? theme::Mode::None, + 0, ); let logical_size = window.logical_size(); diff --git a/winit/src/window.rs b/winit/src/window.rs index 7548ce6f..bcf55732 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -61,6 +61,7 @@ where compositor: &mut C, exit_on_close_request: bool, system_theme: theme::Mode, + resize_border: u32, ) -> &mut Window { let state = State::new(program, id, system_theme, window.as_ref()); let surface_size = state.physical_size(); @@ -79,6 +80,10 @@ where let _ = self.entries.insert( id, Window { + drag_resize_window_func: super::drag_resize::event_func( + window.as_ref(), + resize_border as f64 * window.scale_factor(), + ), raw: window, state, exit_on_close_request, @@ -89,7 +94,6 @@ where redraw_at: None, preedit: None, ime_state: None, - drag_resize_window_func: None, prev_dnd_destination_rectangles_count: 0, viewport_version: 0, redraw_requested: false,