Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparent Window #133

Open
4 tasks done
nyovaya opened this issue Jan 20, 2020 · 7 comments · Fixed by #164
Open
4 tasks done

Transparent Window #133

nyovaya opened this issue Jan 20, 2020 · 7 comments · Fixed by #164

Comments

@nyovaya
Copy link
Contributor

nyovaya commented Jan 20, 2020

Should transparency be allowed for bordered windows?
no
Platforms support:

  • Windows [TODO]
  • OSX [TODO]
  • Linux(X11/Wayland)
  • Redox

How should it be enabled?
A: Set a flag in struct WindowOptions.

@nyovaya nyovaya mentioned this issue Jan 20, 2020
@nyovaya nyovaya mentioned this issue Apr 7, 2020
@nyovaya
Copy link
Contributor Author

nyovaya commented Apr 7, 2020

@FloVanGH Does Redox support window transparency?

@nyovaya
Copy link
Contributor Author

nyovaya commented Apr 15, 2020

@emoon We might let this open as its not implemented on Windows and OSX

@emoon emoon reopened this Apr 15, 2020
@emoon
Copy link
Owner

emoon commented Apr 15, 2020

Do you plan to implement support for Windows and macOS also?

@nyovaya
Copy link
Contributor Author

nyovaya commented Apr 15, 2020

@emoon I will definitely try to implement it on windows but not on osx because I dont have a device to test on it.

@nyovaya
Copy link
Contributor Author

nyovaya commented Apr 15, 2020

I will link to some working implementation for alpha transparency on OSX as well as the Windows one:
godotengine/godot@ddae098#diff-65f347288a42e15c028ce4f494698fa1R2137-R2142

@emoon
Copy link
Owner

emoon commented Apr 16, 2020

Alright. That code uses OpenGL on macOS which is deprecated. I use Metal on macOS which is the supported API but I guess it should be possible to do the same thing.

@rupansh
Copy link
Contributor

rupansh commented May 29, 2020

@nifker
Manually using winapi isn't working either

    let wind = Window::new("", w as usize, h as usize, WindowOptions {
        title: false,
        borderless: true,
        ..WindowOptions::default()
    }).unwrap();
    match wind.raw_window_handle() {
        RawWindowHandle::Windows(wnd) => {
            let hwnd = wnd.hwnd as HWND;
            unsafe { SetWindowLongA(hwnd, GWL_EXSTYLE, (WS_EX_LAYERED | WS_EX_TRANSPARENT) as i32) };
            unsafe { SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA)};
            let mut margs = MARGINS {
                cxLeftWidth: -1,
                cxRightWidth: -1,
                cyTopHeight: -1,
                cyBottomHeight: -1,
            };
            unsafe { DwmExtendFrameIntoClientArea(hwnd, &mut margs) };
            unsafe { UpdateWindow(hwnd) };
            unsafe { SetWindowPos(hwnd, HWND_TOPMOST, l, t, w as i32, h as i32, SWP_SHOWWINDOW) };
        }
        _ => {}
    }

However the same code works fine with sfml window and Style::NONE

    let mut set = ContextSettings::default();
    set.antialiasing_level = 4;
    let wind = RenderWindow::new((w, h), "", Style::NONE, &set);
    let hwnd = wind.system_handle() as HWND;
    unsafe { SetWindowLongA(hwnd, GWL_EXSTYLE, (WS_EX_LAYERED | WS_EX_TRANSPARENT) as i32) };
    unsafe { SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA)};
    let mut margs = MARGINS {
        cxLeftWidth: -1,
        cxRightWidth: -1,
        cyTopHeight: -1,
        cyBottomHeight: -1,
    };
    unsafe { DwmExtendFrameIntoClientArea(hwnd, &mut margs) };
    unsafe { UpdateWindow(hwnd) };
    unsafe { SetWindowPos(hwnd, HWND_TOPMOST, l, t, w as i32, h as i32, SWP_SHOWWINDOW) };

EDIT: If i force flags to be like this, it works fine.
https://github.com/rupansh/rust_minifb/commit/70dd9b1ff424ea32f8e679d60ad84e5c4c093ec7#diff-592c2d0944cb99fd96ad100fb80c1956R545

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants