Guerra24 / Firefox-UWP-Style

Sun Valley + MDL2 Theme for Firefox
MIT License
399 stars 9 forks source link

Mica is broken when switching light/dark theme #52

Closed maicol07 closed 2 years ago

maicol07 commented 2 years ago

Mica keeps being light, while I've switched to dark theme. Restarting firefox applies the new theme, but when switching back to light Mica keeps being dark.

Example recording: https://user-images.githubusercontent.com/9463142/164411021-6c01c808-e77a-4f65-b40b-f8c8bcdf615a.mp4

Guerra24 commented 2 years ago

Mica material is applied externally, Firefox does not call any of the apis that activate it or decide what theme to use. If you want to change it while it is open do it through MicaForEveryone.

image

maicol07 commented 2 years ago

Oh, yes you're right, I've missed that options (was set to Default). Switching that together with the Firefox theme works great!

Thank you.

Closing...

maicol07 commented 2 years ago

@Guerra24 I have to reopen this since there is an unfixed issue. When the theme changes and firefox is closed, the next reopening is still the previous Mica theme. See this issue for more details: MicaForEveryone/MicaForEveryone#64

Guerra24 commented 2 years ago

When the theme changes and firefox is closed, the next reopening is still the previous Mica theme.

https://user-images.githubusercontent.com/9023392/165211664-b699644d-e2b5-4592-8160-5c720a17ce6c.mp4

Works here. MFE's Firefox rule is set to System.

maicol07 commented 2 years ago

🤔 I already have the same rule but the issue persists...

dongle-the-gadget commented 2 years ago

@Guerra24 I can also reproduce the issue, however not in the order that you shown in the video, maybe do in this order instead:

  1. Open Firefox. Confirm that the correct theme (dark/light) is rendered.
  2. Close Firefox.
  3. Change the theme
  4. Reopen Firefox. Confirm that it renders the wrong theme.

In your video, you changed the theme before closing Firefox, which doesn't seem to trigger this bug.

EDIT: Reproducing video

https://user-images.githubusercontent.com/29563098/165994125-f82fb5a8-00d9-41c5-96d3-419fc79a39cf.mp4

Guerra24 commented 2 years ago

Well, that's acrylic... afaik it does not have theme-specific colors. Also since I'm running stable Win11 I have not tested any of the other backdrop types. Regardless, I tried and still works just fine.

https://user-images.githubusercontent.com/9023392/166085146-fdc4e9c0-7cd7-4e13-a9bd-7299301dd2a5.mp4

That aside this is something I can't fix from my side unfortunately.

dongle-the-gadget commented 2 years ago

The same happens with Mica actually (sorry for the horrible video btw). And also looks like we are running dev builds while you are running stable. I generally think this is a bug related to Firefox, since this behavior doesn't shown on any other apps, only Firefox.

https://user-images.githubusercontent.com/29563098/166085443-477d66c0-1a14-4dad-96ae-da8186843c9f.mp4

.

Guerra24 commented 2 years ago

Closing this since the issue is unfixable from my side.

maicol07 commented 2 years ago

I've found a workaround for this issue: I've written an AutoHotKey script that automatically triggers reload when theme has changed and Firefox window is active (or is opened):
https://github.com/maicol07/AHK-scripts/blob/main/FixFirefoxMFE.ahk

Feel free to improve the script if you want!

Guerra24 commented 2 years ago

Just upgraded to 22621 and so far no issues on my side in both stable and nightly.

dongle-the-gadget commented 2 years ago

Strange, it still happens on my machine (25140). It looks like Firefox is automatically changing DWMWA_USE_IMMSERIVE_DARK_MODE, because when I delay execution of DwmSetWindowAttribute, everything works perfectly.

dongle-the-gadget commented 2 years ago

After some Google digging, this problem is most likely caused by Firefox. https://bugzilla.mozilla.org/show_bug.cgi?id=1734359 https://hg.mozilla.org/integration/autoland/rev/b94153cca1f7

EDIT: The title bar bug happens even without MFE, or any other program messing with Firefox's immersive dark mode attributes. So, it's definitely a Firefox bug.

EDIT 2: Firefox uses a function within the LookAndFeel class in order to determine whether it should use dark mode for the title bars. In the LookAndFeel.h file, the function returns the value of a field. Haven't managed to find out where the field is set though, nor the source file of the LookAndFeel class (commonly it would be LookAndFeel.cpp, but the file is missing).

EDIT 3: Looks like this function is to blame: https://github.com/mozilla/gecko-dev/blob/master/widget/LookAndFeel.h#L391.

Guerra24 commented 2 years ago

Btw are you all sure Titlebar color is set to System in MFE? I can replicate the issue when set to Default but with System it does work just fine.

https://user-images.githubusercontent.com/9023392/174470587-967a970b-c4eb-4915-aed2-3badf6a49144.mp4

dongle-the-gadget commented 2 years ago

Btw are you all sure Titlebar color is set to System in MFE? I can replicate the issue when set to Default but with System it does work just fine.

Yes. And as I said before, it does not matter whether MFE is used or not. This is a bug within Firefox, not MFE or this theme.

dongle-the-gadget commented 2 years ago

Whether MFE works or not in this case is pretty much a hit or miss. Some systems have Firefox applying dark theme before MFE and doesn't cause this bug; while others have MFE applying dark theme first, leading to this bug.

dongle-the-gadget commented 2 years ago

On my system, Firefox takes like 3 seconds to initialize, while MFE only needs like 1 for applying the title bar color to Firefox. Yours looks pretty much instant.

Guerra24 commented 2 years ago

Okay, so this is the issue. Firefox theme detection is somehow off by one and since it's a bug in Firefox it can be reported through bugzilla and it should be valid since the issue is visible when the titlebar is enabled. I can do it but I'm not sure when, if you want to do it just let me know otherwise some time next week I will.

dongle-the-gadget commented 2 years ago

You can go ahead.