winit icon indicating copy to clipboard operation
winit copied to clipboard

Add drag-resizing with cursor feature

Open MrGibus opened this issue 3 years ago • 3 comments

  • [X] Tested on all platforms changed
  • [x] Compilation warnings were addressed
  • [X] cargo fmt has been run on this branch
  • [X] cargo doc builds successfully
  • [X] Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • [X] Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • [X] Created or updated an example program if it would help users understand this functionality
  • [X] Updated feature matrix, if new features were added or implemented

Fix for https://github.com/rust-windowing/winit/issues/725 on windows Similar in scope to https://github.com/rust-windowing/winit/pull/1840

This has only been implemented for windows:
This comment offer insight as to how this would translate to Linux platforms.

As far as using this to make a borderless window in similar fashion to electron, the approach has several drawbacks:

  • No window resizing from win-hotkeys
  • No shadows on the borders

To solve those issues this SO Question and this windows dev tutorial seem to be the standard. I don't understand how this would fit into winit at this time however.

I briefly experimented with removing the title bar and not the border through winapi, which also seems to mostly solve the issues above and this may be preferable to hiding all decorations and implementing standard window functionality manually.

MrGibus avatar Aug 21 '21 14:08 MrGibus

A few other PRs are failing the nightly wasm32 target build check. usage of `--profile` requires `-Z unstable-options` looks like a workflow bug?

MrGibus avatar Sep 01 '21 12:09 MrGibus

Hi all. It's been several months since this issue was last touched. I'm curious if this is something that's still being considered. I'm working on an app and recently added a custom (hacky) implementation of this feature for it, but something officially supported out-of-the-box would be great.

acid1103 avatar Feb 21 '22 11:02 acid1103

@acid1103 I ended up making my own borderless window proof of concept by using the windows API directly as the way winnit deals with the messaging system in the api doesn't lend itself well to rebuilding the decorations.

MrGibus avatar Mar 02 '22 14:03 MrGibus

I think the best way of doing borderless windows on windows is to use the following on a WM_CREATE event: (Using windows-rs)

/// with shadows
const BORDERLESS_MARGINS: MARGINS = MARGINS {
    cxLeftWidth: 1,
    cxRightWidth: 1,
    cyTopHeight: 1,
    cyBottomHeight: 1,
};

/// no shadows
const FLAT_MARGINS: MARGINS = MARGINS {
    cxLeftWidth: 0,
    cxRightWidth: 0,
    cyTopHeight: 0,
    cyBottomHeight: 0,
};

/// Primarily used to create borderless windows
/// https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Graphics/Dwm/fn.DwmExtendFrameIntoClientArea.html
/// https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmextendframeintoclientarea
pub fn extend_frame_into_client_area(handle: HWND, style: &WindowStyle) -> Result<()> {
    let margins = match style {
        WindowStyle::FlatBorderless => FLAT_MARGINS,
        WindowStyle::Borderless => BORDERLESS_MARGINS,
    };

    if handle.is_invalid() {
        panic!("Cannot extend frame into client area due to invalid window handle")
    }

    unsafe { DwmExtendFrameIntoClientArea(handle, &margins) }
}

See below example using wgpu to render over borders: https://github.com/MrGibus/windows_borderless_rust

MrGibus avatar Oct 29 '22 18:10 MrGibus

Btw, this PR is superseded by https://github.com/rust-windowing/winit/pull/2515 and https://github.com/rust-windowing/winit/pull/2966

amrbashir avatar Nov 13 '23 23:11 amrbashir

Thanks @amrbashir!

daxpedda avatar Nov 14 '23 11:11 daxpedda