Giter Site home page Giter Site logo

Use with window viberancy about fltk-rs HOT 12 CLOSED

NoelJacob avatar NoelJacob commented on June 9, 2024
Use with window viberancy

from fltk-rs.

Comments (12)

MoAlyousef avatar MoAlyousef commented on June 9, 2024 1

That's the functions documentation, the passed data is undocumented:
https://learn.microsoft.com/en-us/windows/win32/dwm/windowcompositionattrib

The same system updated to windows11 and I get the appearance in your screenshot, whereas when I was using windows 10, I had the previous appearance. So it's not something related to FLTK. Some info can be found here in relation to the attributes:
https://gist.github.com/xv/43bd4c944202a593ac8ec6daa299b471

from fltk-rs.

MoAlyousef avatar MoAlyousef commented on June 9, 2024 1

set_opacity requires the window’s handle which you won’t get until after the window is shown.
Can you place it after the show call.

from fltk-rs.

MoAlyousef avatar MoAlyousef commented on June 9, 2024 1

I don’t believe so. The default background color is applied, then the vibrancy effect takes place. You can change the background color by either changing the window’s color or by setting app::set_background_color().
I don’t think you can create an opaque button on top of a transparent or vibrant window, because FLTK uses drawing routines on top of the window. It doesn’t use subwindows for its widgets.

from fltk-rs.

MoAlyousef avatar MoAlyousef commented on June 9, 2024

The issue seems related to this discussion here:
#1324

For opacity, it should work for the whole window, and for vibrancy, it excludes the decorations (this is os specific and fltk has no say in this).
One thing you can try is to disable the decorations/border, create your own and that way it would benefit from the vibrancy effects.
The api itself is non-documented as far as I understand, and certain effects might not be available on all platforms.

from fltk-rs.

NoelJacob avatar NoelJacob commented on June 9, 2024

I don't know if I should raise issue here or with window-vibrancy. For me it doesn't apply in the background, only at title bar.

Mica Blur Acrylic
With background color Screenshot-7 Screenshot-6 Screenshot-5
No background color Screenshot-2 Screenshot-3 Screenshot-4
Mica/Blur/Acrylic
Without background color and border Screenshot-8

from fltk-rs.

NoelJacob avatar NoelJacob commented on June 9, 2024

It is actually documented -
Use dwmapi setwindowattribute to set DWMWA_SYSTEMBACKDROP_TYPE and DWMSBT_MAINWINDOW.
I probably should've showed it int window-viberancy issues.

from fltk-rs.

MoAlyousef avatar MoAlyousef commented on June 9, 2024

Can you try the following progam:

use fltk::{prelude::*, *};

#[repr(C)]
struct Policy {
    state: u32,
    flags: u32,
    gradient: u32,
    anim: u32,
}

#[repr(C)]
struct Data {
    attrib: u32,
    pv_data: *mut (),
    cb_data: usize,
}

extern "system" {
    fn SetWindowCompositionAttribute(hwnd: *mut (), pwcad: *const Data) -> i32;
}

fn main() {
    let a = app::App::default();
    let mut w = window::Window::default().with_size(400, 300);
    w.end();
    w.show();

    let mut policy = Policy {
        state: 4, // acrylic
        flags: 0,
        gradient: 0x3b3b3b3b,
        anim: 0,
    };

    let mut data = Data {
        attrib: 0x13,
        pv_data: &mut policy as *mut _ as _,
        cb_data: std::mem::size_of_val(&policy),
    };
    
    unsafe { SetWindowCompositionAttribute(w.raw_handle() as _, &mut data as *mut _ as _); }

    a.run().unwrap();
}

This uses the older, undocumented, api and gives the previous effect that window-vibrancy gave on windows 10.

from fltk-rs.

NoelJacob avatar NoelJacob commented on June 9, 2024

Screenshot (9)
It's good but the title bar only seems to have only close button only on hover over the area.

Is there anyway to make it look like this - #1324 (reply in thread).
Also, this is the function's documentation right?

from fltk-rs.

NoelJacob avatar NoelJacob commented on June 9, 2024

With tabbed window, I've got minor success.
Screenshot-10

use fltk::{prelude::*, *};
use raw_window_handle::{HasWindowHandle};
use windows_sys::Win32::Foundation::{BOOL, TRUE};
use windows_sys::Win32::Graphics::Dwm::*;
use windows_sys::Win32::UI::Controls::*;

fn main() {
    let a = app::App::default();
    let mut w = window::Window::default().with_size(400, 300);
    w.set_opacity(0.0);
    w.end();
    w.show();

    match w.window_handle().unwrap().as_raw() {
        raw_window_handle::RawWindowHandle::Win32(handle) => {
            unsafe {
                DwmExtendFrameIntoClientArea(
                    handle.hwnd.get() as _,
                    &MARGINS {
                        cxLeftWidth: -1,
                        cxRightWidth: -1,
                        cyTopHeight: -1,
                        cyBottomHeight: -1,
                    },
                );
                let value: BOOL = TRUE;
                DwmSetWindowAttribute(
                    handle.hwnd.get() as _,
                    DWMWA_USE_IMMERSIVE_DARK_MODE as _,
                    &value as *const BOOL as _,
                    std::mem::size_of::<BOOL>() as _,
                );
                DwmSetWindowAttribute(
                    handle.hwnd.get() as _,
                    DWMWA_SYSTEMBACKDROP_TYPE as _,
                    &DWMSBT_TABBEDWINDOW as *const DWM_SYSTEMBACKDROP_TYPE as _,
                    std::mem::size_of::<DWM_SYSTEMBACKDROP_TYPE>() as _,
                );
            }
        }
        _ => panic!("Unsupported platform"),
    }
    
    a.run().unwrap();
}

But not having mica/MAINWINDOW is killing me. There seems to be very slight tint change on Mica. But it might not be true. Could there be any problem with opacity? 🤷
FYI: I use latest Windows.

from fltk-rs.

MoAlyousef avatar MoAlyousef commented on June 9, 2024

The code for window transparency is defined in cfltk here:
https://github.com/MoAlyousef/cfltk/blob/27514b94e06c2133453059529aa4b663d40c8cdb/src/cfl_window.cpp#L56

I’m not sure if it affects the vibrancy code but I think it shouldn’t.

from fltk-rs.

NoelJacob avatar NoelJacob commented on June 9, 2024

Screenshot-11

use fltk::{prelude::*, *};

fn main() {
    let a = app::App::default();
    let mut w = window::Window::default().with_size(400, 300);
    w.set_opacity(0.0);
    w.end();
    w.show();
    
    a.run().unwrap();
}

Opacity 0 should make it completely transparent, right?

Screenshot-12

use fltk::{prelude::*, *};

fn main() {
    let a = app::App::default();
    let mut w = window::Window::default().with_size(400, 300);
    w.end();
    w.show();

    w.set_opacity(0.5);
    
    a.run().unwrap();
}

from fltk-rs.

NoelJacob avatar NoelJacob commented on June 9, 2024

This seems like an issue in fltk, make sure you can create a fully transparent window using fltk then add the window-vibrancy effect.

tauri-apps/window-vibrancy#128 (comment) This is what the window-vibrancy team said. I also think that vibrancy is being applied but a color is being applied over it. Can you show an example with vibrancy window on windows and and opaque button over it?

set_opacity requires the window’s handle which you won’t get until after the window is shown.
Can you place it after the show call.

This gives me transparency but still can't solve vibrancy.

from fltk-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.