alexmercerind / flutter_acrylic

Flutter library for window acrylic, mica & transparency effects.
MIT License
605 stars 54 forks source link

can not get windows dark -> light switch, but macOS is OK #37

Open lucasjinreal opened 2 years ago

lucasjinreal commented 2 years ago

Hi, I have a same logic like this:

if (brightness == InterfaceBrightness.dark) {
                            brightness = InterfaceBrightness.light;
                          } else if (brightness == InterfaceBrightness.light) {
                            brightness = InterfaceBrightness.dark;
                          } else {
                            brightness = InterfaceBrightness.dark;
                          }
                          bool v = brightness == InterfaceBrightness.dark;
                          // aboutBloc.setForceDark(v);
                          if (v) {
                            Get.changeTheme(themeDataDark);
                          } else {
                            Get.changeTheme(themeData);
                          }
                          print('[brightness] crt brightness: ${brightness}');
                          this.setWindowEffect(WindowEffect.acrylic,
                              brightness == InterfaceBrightness.dark);

...

void setWindowEffect(WindowEffect value, bool dark) {
    Window.setEffect(
      effect: value,
      color: this.color,
      dark: dark,
    );
    if (Platform.isMacOS) {
      if (brightness != InterfaceBrightness.auto) {
        Window.overrideMacOSBrightness(
            dark: brightness == InterfaceBrightness.dark);
      }
    }
    this.setState(() => this.effect = value);
  }

the printed out brightness is dark and light when switch.

But the setWindowEffect can not make window to bright. While same code on macOS is ok.

what'sthe problem here?

alexmercerind commented 2 years ago

Hi @jinfagang,

The dark argument in Window.setEffect controls the "darkness" of the acrylic effect on Windows. This is only applicable for Windows 11!

alexmercerind commented 2 years ago

For Windows 10 or lower, changing the value of passed color can tint your acrylic darker/lighter. This API is made public/documented by Microsoft after Windows 11 release. Windows 10 still uses an old "hack".

lucasjinreal commented 2 years ago

@alexmercerind My windows verison exactly windows 11.

alexmercerind commented 2 years ago

Does the example app not work? What's your Windows 11 build number?

lucasjinreal commented 2 years ago

@alexmercerind The code above should be identical to example (copied from there). Am on latest windows 11

alexmercerind commented 2 years ago

Please try this: https://github.com/alexmercerind/flutter_acrylic/releases/download/v1.0.0/flutter_acrylic_example_windows_x64.7z

Switching dark & light.

lucasjinreal commented 2 years ago

@alexmercerind thank u, let me have a try.