Repository: electron/electron
File: shell/browser/native_window_views.cc (C++)

Code before:

  auto* desktop_window_tree_host =
      static_cast<ElectronDesktopWindowTreeHostWin*>(
          GetNativeWindow()->GetHost());

  // Synchronize the internal state; otherwise, the background material may not
  // work properly.
  if (desktop_window_tree_host) {
    desktop_window_tree_host->SetIsTranslucent(is_translucent);
  }

  auto* desktop_native_widget_aura =
      static_cast<ElectronDesktopNativeWidgetAura*>(widget()->native_widget());
  desktop_native_widget_aura->UpdateWindowTransparency();

  // For frameless windows with a background material set, we also need to
  // remove the caption color so it doesn't render a caption bar (since the
  // window is frameless)
  COLORREF caption_color =
      is_translucent ? DWMWA_COLOR_NONE : DWMWA_COLOR_DEFAULT;
  result = DwmSetWindowAttribute(hwnd, DWMWA_CAPTION_COLOR, &caption_color,
                                 sizeof(caption_color));
  if (FAILED(result))
    LOG(WARNING) << "Failed to set caption color to transparent";

  // Activate the translucent window
  DefWindowProc(hwnd, WM_NCACTIVATE, TRUE, has_frame() ? 0 : -1);
#endif
}

void NativeWindowViews::SetVisibleOnAllWorkspaces(
    bool visible,
    bool visibleOnFullScreen,
    bool skipTransformProcessType) {
  widget()->SetVisibleOnAllWorkspaces(visible);
}

bool NativeWindowViews::IsVisibleOnAllWorkspaces() const {
  // On Windows this always returns false.
  return widget()->IsVisibleOnAllWorkspaces();
}

content::DesktopMediaID NativeWindowViews::GetDesktopMediaID() const {
  const gfx::AcceleratedWidget accelerated_widget = GetAcceleratedWidget();
  content::DesktopMediaID::Id window_handle = content::DesktopMediaID::kNullId;
  content::DesktopMediaID::Id aura_id = content::DesktopMediaID::kNullId;
#if BUILDFLAG(IS_WIN)
  window_handle =
      reinterpret_cast<content::DesktopMediaID::Id>(accelerated_widget);
#elif BUILDFLAG(IS_LINUX)
  window_handle = static_cast<uint32_t>(accelerated_widget);

Review comment (suggestion):
```suggestion
  // Activate the non-client area of the window
```

Don't see the condition being specific to translucent windows.

Code after:
          GetNativeWindow()->GetHost());

  // Synchronize the internal state; otherwise, the background material may not
  // work properly.
  if (desktop_window_tree_host) {
    desktop_window_tree_host->SetIsTranslucent(is_translucent);
  }

  auto* desktop_native_widget_aura =
      static_cast<ElectronDesktopNativeWidgetAura*>(widget()->native_widget());
  desktop_native_widget_aura->UpdateWindowTransparency();

  // For frameless windows with a background material set, we also need to
  // remove the caption color so it doesn't render a caption bar (since the
  // window is frameless)
  COLORREF caption_color =
      is_translucent ? DWMWA_COLOR_NONE : DWMWA_COLOR_DEFAULT;
  result = DwmSetWindowAttribute(hwnd, DWMWA_CAPTION_COLOR, &caption_color,
                                 sizeof(caption_color));
  if (FAILED(result))
    LOG(WARNING) << "Failed to set caption color to transparent";

  // Activate the non-client area of the window
  DefWindowProc(hwnd, WM_NCACTIVATE, TRUE, has_frame() ? 0 : -1);
#endif
}

void NativeWindowViews::SetVisibleOnAllWorkspaces(
    bool visible,
    bool visibleOnFullScreen,
    bool skipTransformProcessType) {
  widget()->SetVisibleOnAllWorkspaces(visible);
}

bool NativeWindowViews::IsVisibleOnAllWorkspaces() const {
  // On Windows this always returns false.
  return widget()->IsVisibleOnAllWorkspaces();
}

content::DesktopMediaID NativeWindowViews::GetDesktopMediaID() const {
  const gfx::AcceleratedWidget accelerated_widget = GetAcceleratedWidget();
  content::DesktopMediaID::Id window_handle = content::DesktopMediaID::kNullId;
  content::DesktopMediaID::Id aura_id = content::DesktopMediaID::kNullId;
#if BUILDFLAG(IS_WIN)
  window_handle =
      reinterpret_cast<content::DesktopMediaID::Id>(accelerated_widget);
#elif BUILDFLAG(IS_LINUX)
  window_handle = static_cast<uint32_t>(accelerated_widget);
#endif
  aura::WindowTreeHost* const host =
      aura::WindowTreeHost::GetForAcceleratedWidget(accelerated_widget);