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

Code before:
  if (backdrop_type != DWMSBT_NONE && backdrop_type != DWMSBT_AUTO &&
      !has_frame()) {
    caption_color = DWMWA_COLOR_NONE;
  }
  result = DwmSetWindowAttribute(GetAcceleratedWidget(), DWMWA_CAPTION_COLOR,
                                 &caption_color, sizeof(caption_color));

  if (FAILED(result))
    LOG(WARNING) << "Failed to set caption color to transparent";
#endif
}

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

bool NativeWindowViews::IsVisibleOnAllWorkspaces() const {
#if BUILDFLAG(IS_LINUX)
  if (IsX11()) {
    // Use the presence/absence of _NET_WM_STATE_STICKY in _NET_WM_STATE to
    // determine whether the current window is visible on all workspaces.
    x11::Atom sticky_atom = x11::GetAtom("_NET_WM_STATE_STICKY");
    std::vector<x11::Atom> wm_states;
    auto* connection = x11::Connection::Get();
    connection->GetArrayProperty(
        static_cast<x11::Window>(GetAcceleratedWidget()),
        x11::GetAtom("_NET_WM_STATE"), &wm_states);
    return base::Contains(wm_states, sticky_atom);
  }
#endif
  return false;
}

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);
  aura::Window* const aura_window = host ? host->window() : nullptr;
  if (aura_window) {
    aura_id = content::DesktopMediaID::RegisterNativeWindow(

Review comment (suggestion):
Electron 37 delegates this out to [Widget::IsVisibleOnAllWorkspaces()](https://chromium.googlesource.com/chromium/src/+/main/ui/views/widget/widget.cc#1114).

What this code does is copy the logic of that function -- returning `true` if `widget() && widget()->IsVisibleOnAllWorkspaces()` -- and then falls back to the old implementation otherwise. Keeping the old implementation should prevent the breaking change in 36.

Code after:
  if (backdrop_type != DWMSBT_NONE && backdrop_type != DWMSBT_AUTO &&
      !has_frame()) {
    caption_color = DWMWA_COLOR_NONE;
  }
  result = DwmSetWindowAttribute(GetAcceleratedWidget(), DWMWA_CAPTION_COLOR,
                                 &caption_color, sizeof(caption_color));

  if (FAILED(result))
    LOG(WARNING) << "Failed to set caption color to transparent";
#endif
}

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

bool NativeWindowViews::IsVisibleOnAllWorkspaces() const {
  // NB: Electron >= 37 has a better long-term fix, but it also has an edge
  // case which is a breaking change. The code here is dirtier (e.g. accessing
  // a method marked as private) to avoid that edge case. More info @
  // https://github.com/electron/electron/pull/46834#issuecomment-2836287699
  if (const auto* view_native_widget = widget()->native_widget_private())
    return view_native_widget->IsVisibleOnAllWorkspaces();

#if BUILDFLAG(IS_LINUX)
  if (IsX11()) {
    // Use the presence/absence of _NET_WM_STATE_STICKY in _NET_WM_STATE to
    // determine whether the current window is visible on all workspaces.
    x11::Atom sticky_atom = x11::GetAtom("_NET_WM_STATE_STICKY");
    std::vector<x11::Atom> wm_states;
    auto* connection = x11::Connection::Get();
    connection->GetArrayProperty(
        static_cast<x11::Window>(GetAcceleratedWidget()),
        x11::GetAtom("_NET_WM_STATE"), &wm_states);
    return base::Contains(wm_states, sticky_atom);
  }
#endif
  return false;
}

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)