pop-os / libcosmic

WIP library for COSMIC applications
https://pop-os.github.io/libcosmic/cosmic/
Mozilla Public License 2.0
461 stars 47 forks source link

Windows 10: Window Resizing Triggered on Launch #593

Open Fidifis opened 2 months ago

Fidifis commented 2 months ago

On Windows 10 (possibly other versions), any app built with libcosmic opens with triggered window resizing on right edge, following mouse. You must click somewhere to release the drag. This happens on every lanuch.

Steps to Reproduce:

  1. Be on Windows
  2. Download example project libcosmic/examples/application
  3. Edit Cargo.toml and put away xdg-portal feature (crashes the build)
  4. Compile and run
  5. The window is resizing immediately upon launch

Expected Behavior: The window should open normally without being in resizing mode.

Tested with Windows 10, on physical and virtual machine. Affects all libcosmic apps I tried.

libcosmic revision: 0a1922d (latest master) rustc version: 1.80.1 (3f5fd8dd4 2024-08-06) cargo version: 1.80.1 (376290515 2024-07-16)

https://github.com/user-attachments/assets/2cddfaa7-6456-43ca-ae2a-27f1ba5c4bdf

netraptor commented 1 month ago

Does anyone know of a workaround for this (that is, is there a way to manually cancel a window resize on launch)?

netraptor commented 1 month ago

Ok, I think I've figured out where the bug is. At the very least, I found out what to change to stop it, but I'm not sure what the actual fix should be because I don't fully understand the reasoning behind the code here.

In iced_winit::application::run_instance(), there is this call around line 413:

    // Creates closure for handling the window drag resize state with winit.
    let mut drag_resize_window_func = drag_resize::event_func(
        &window,
        resize_border as f64 * window.scale_factor(),
    );

That function is in the drag_resize submodule of application and appears to return a closure only if the following evaluates to true:

window.drag_resize_window(ResizeDirection::East).is_ok()

According to the winit docs, this starts a window drag event.

If I alter drag_resize::event_func to always return the closure and not perform that check, the resize on launch bug disappears and everything seems to work fine.

Now, that function does have this comment on it:

/// If supported by winit, returns a closure that implements cursor resize support.

So...is there a different way to perform this check without triggering a resize on launch? Or am I completely off base here?