Skip to content

win-capture: Add WPF's HwndWrapper to list of generic classes - #14294

Open
beheh wants to merge 1 commit into
obsproject:masterfrom
beheh:wpf-window-type-match
Open

beheh wants to merge 1 commit into
obsproject:masterfrom
beheh:wpf-window-type-match

Conversation

@beheh

@beheh beheh commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Description

Apps using Windows Presentation Foundation (WPF) get a semi-random class name for each time window that is created (concretely, WPF generates a random GUID, that differs across closing and reoping windows and differs across app restarts). This means that is the window class is basically never stable for such apps.

When a user sets "Winow Match Priority" in OBS to "Match title, otherwise find window of same type", it will never find a window of the same type, and despite the name, OBS will actually reject an identical title if the window class does not match.

This PR adds the WPF-specific prefix to the list of generic_class_substrings, so that OBS ignores the class for such WPF windows and always goes only by title.

Motivation and Context

My team maintains the app Hearthstone Deck Tracker, which is a companion app to the game Hearthstone. It works by rendering an overlay in a separate window, which streamers capture and overlay on their stream. I've previously made changes to OBS in support of it in #13590. It uses Windows Presentation Foundation (WPF) as it's GUI framework.

I've recently had a streamer reach out to my about OBS losing track of a capturable window whenever they restart my overlay. Concretely they encountered this issue in Streamlabs, but I could reproduce the issue myself in OBS. It is as follows: In a Window Capture, the Window Match Priority "Match title, otherwise find window of same type" scans for the window class. After investigating, I realized that WPF Windows are created with a semi-random Window class:

https://github.com/dotnet/wpf/blob/997187874fe5d89cc66f9fbba8ededf14c556a30/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/HwndWrapper.cs#L91

Specifically, they are of the shape HwndWrapper[{appName};{threadName};{randomName}], where random name is a random GUID chosen each time the window is created. This means a windows class capture will never match across app restarts, as the class will have changed.

This so far is not a problem yet. However, window_rating with WINDOW_PRIORITY_CLASS actually goes by the window class first and only checks the title if it matches. This is appropriate for basically every over app, but in the WPF case here it bricks capturing these apps until the user reselects the app (which will memorize the temporary class again, until it's closed and reopened).

Clearly WPF is doing something very unusual here, and we are already recommending to our users to explicitly switch to Window Title matching. However, as WPF is used by many apps, I'm hoping a fix in OBS can improve this for more users.

How Has This Been Tested?

I've compiled this branch locally and confirmed with HDT that with the commit, it indeed works when the match priority is set to title/type and I restart the app.

Types of changes

  • Tweak (non-breaking change to improve existing functionality)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@WizardCM WizardCM added kind/bug Categorizes issue or PR as related to a bug. platform/windows Categorizes issue or PR as affecting Windows specifically labels Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. platform/windows Categorizes issue or PR as affecting Windows specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants