fix_activate_background_material_on_windows.patch 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: clavin <[email protected]>
  3. Date: Mon, 11 Dec 2023 20:43:34 -0300
  4. Subject: fix: activate background material on windows
  5. This patch adds a condition to the HWND message handler to allow windows
  6. with translucent background materials to become activated.
  7. It also ensures the lParam of WM_NCACTIVATE is set to -1 so as to not repaint
  8. the client area, which can lead to a title bar incorrectly being displayed in
  9. frameless windows.
  10. This patch likely can't be upstreamed as-is, as Chromium doesn't have
  11. this use case in mind currently.
  12. diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
  13. index 64aa90f0fcd7fb2a66b8ea98ab355c4f4f6ffa08..740f92ec4e355032d02138c87d6c4473c8abd3a1 100644
  14. --- a/ui/views/win/hwnd_message_handler.cc
  15. +++ b/ui/views/win/hwnd_message_handler.cc
  16. @@ -901,13 +901,13 @@ void HWNDMessageHandler::FrameTypeChanged() {
  17. void HWNDMessageHandler::PaintAsActiveChanged() {
  18. if (!delegate_->HasNonClientView() || !delegate_->CanActivate() ||
  19. - !delegate_->HasFrame() ||
  20. + (!delegate_->HasFrame() && !is_translucent_) ||
  21. (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN)) {
  22. return;
  23. }
  24. DefWindowProcWithRedrawLock(WM_NCACTIVATE, delegate_->ShouldPaintAsActive(),
  25. - 0);
  26. + delegate_->HasFrame() ? 0 : -1);
  27. }
  28. void HWNDMessageHandler::SetWindowIcons(const gfx::ImageSkia& window_icon,
  29. @@ -2254,17 +2254,18 @@ LRESULT HWNDMessageHandler::OnNCActivate(UINT message,
  30. if (IsVisible())
  31. delegate_->SchedulePaint();
  32. - // Calling DefWindowProc is only necessary if there's a system frame being
  33. - // drawn. Otherwise it can draw an incorrect title bar and cause visual
  34. - // corruption.
  35. - if (!delegate_->HasFrame() ||
  36. + // If the window is translucent, it may have the Mica background.
  37. + // In that case, it's necessary to call |DefWindowProc|, but we can
  38. + // pass -1 in the lParam to prevent any non-client area elements from
  39. + // being displayed.
  40. + if ((!delegate_->HasFrame() && !is_translucent_) ||
  41. delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) {
  42. SetMsgHandled(TRUE);
  43. return TRUE;
  44. }
  45. return DefWindowProcWithRedrawLock(WM_NCACTIVATE, paint_as_active || active,
  46. - 0);
  47. + delegate_->HasFrame() ? 0 : -1);
  48. }
  49. LRESULT HWNDMessageHandler::OnNCCalcSize(BOOL mode, LPARAM l_param) {