| 
									
										
										
										
											2023-09-11 06:51:54 -06:00
										 |  |  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | 
					
						
							|  |  |  | From: clavin <clavin@electronjs.org> | 
					
						
							| 
									
										
										
										
											2024-01-02 15:59:47 -03:00
										 |  |  | Date: Mon, 11 Dec 2023 20:43:34 -0300 | 
					
						
							| 
									
										
										
										
											2023-09-11 06:51:54 -06:00
										 |  |  | Subject: fix: activate background material on windows | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This patch adds a condition to the HWND message handler to allow windows | 
					
						
							|  |  |  | with translucent background materials to become activated. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 15:59:47 -03:00
										 |  |  | It also ensures the lParam of WM_NCACTIVATE is set to -1 so as to not repaint | 
					
						
							|  |  |  | the client area, which can lead to a title bar incorrectly being displayed in | 
					
						
							|  |  |  | frameless windows. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-11 06:51:54 -06:00
										 |  |  | This patch likely can't be upstreamed as-is, as Chromium doesn't have | 
					
						
							|  |  |  | this use case in mind currently. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
 | 
					
						
							| 
									
										
										
										
											2025-02-07 11:14:12 -05:00
										 |  |  | index 3d1397ff82803c9ba45bdcee0b2c61ab5c8049a4..1e6a6715691e07c22202d865dce89c94b3e02d76 100644
 | 
					
						
							| 
									
										
										
										
											2023-09-11 06:51:54 -06:00
										 |  |  | --- a/ui/views/win/hwnd_message_handler.cc
 | 
					
						
							|  |  |  | +++ b/ui/views/win/hwnd_message_handler.cc
 | 
					
						
							| 
									
										
										
										
											2025-02-03 15:10:57 -05:00
										 |  |  | @@ -932,13 +932,13 @@ void HWNDMessageHandler::FrameTypeChanged() {
 | 
					
						
							| 
									
										
										
										
											2023-09-11 06:51:54 -06:00
										 |  |  |   | 
					
						
							|  |  |  |  void HWNDMessageHandler::PaintAsActiveChanged() { | 
					
						
							|  |  |  |    if (!delegate_->HasNonClientView() || !delegate_->CanActivate() || | 
					
						
							|  |  |  | -      !delegate_->HasFrame() ||
 | 
					
						
							|  |  |  | +      (!delegate_->HasFrame() && !is_translucent_) ||
 | 
					
						
							|  |  |  |        (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN)) { | 
					
						
							|  |  |  |      return; | 
					
						
							|  |  |  |    } | 
					
						
							| 
									
										
										
										
											2024-01-02 15:59:47 -03:00
										 |  |  |   | 
					
						
							|  |  |  |    DefWindowProcWithRedrawLock(WM_NCACTIVATE, delegate_->ShouldPaintAsActive(), | 
					
						
							|  |  |  | -                              0);
 | 
					
						
							|  |  |  | +                              delegate_->HasFrame() ? 0 : -1);
 | 
					
						
							|  |  |  |  } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |  void HWNDMessageHandler::SetWindowIcons(const gfx::ImageSkia& window_icon, | 
					
						
							| 
									
										
										
										
											2025-02-03 15:10:57 -05:00
										 |  |  | @@ -2327,17 +2327,18 @@ LRESULT HWNDMessageHandler::OnNCActivate(UINT message,
 | 
					
						
							| 
									
										
										
										
											2024-01-02 15:59:47 -03:00
										 |  |  |      delegate_->SchedulePaint(); | 
					
						
							| 
									
										
										
										
											2025-01-10 10:52:34 -06:00
										 |  |  |    } | 
					
						
							| 
									
										
										
										
											2024-01-02 15:59:47 -03:00
										 |  |  |   | 
					
						
							|  |  |  | -  // Calling DefWindowProc is only necessary if there's a system frame being
 | 
					
						
							|  |  |  | -  // drawn. Otherwise it can draw an incorrect title bar and cause visual
 | 
					
						
							|  |  |  | -  // corruption.
 | 
					
						
							|  |  |  | -  if (!delegate_->HasFrame() ||
 | 
					
						
							|  |  |  | +  // If the window is translucent, it may have the Mica background.
 | 
					
						
							|  |  |  | +  // In that case, it's necessary to call |DefWindowProc|, but we can
 | 
					
						
							|  |  |  | +  // pass -1 in the lParam to prevent any non-client area elements from
 | 
					
						
							|  |  |  | +  // being displayed.
 | 
					
						
							|  |  |  | +  if ((!delegate_->HasFrame() && !is_translucent_) ||
 | 
					
						
							|  |  |  |        delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { | 
					
						
							|  |  |  |      SetMsgHandled(TRUE); | 
					
						
							|  |  |  |      return TRUE; | 
					
						
							|  |  |  |    } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |    return DefWindowProcWithRedrawLock(WM_NCACTIVATE, paint_as_active || active, | 
					
						
							|  |  |  | -                                     0);
 | 
					
						
							|  |  |  | +                                     delegate_->HasFrame() ? 0 : -1);
 | 
					
						
							|  |  |  |  } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |  LRESULT HWNDMessageHandler::OnNCCalcSize(BOOL mode, LPARAM l_param) { |