-
Notifications
You must be signed in to change notification settings - Fork 244
panel: Propagate "focus-in" event to browser host #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The CEF instance is wrapped in another QWindow instance for Windows and Linux and thus consumes any focus events that are propagated through the application. To ensure that a wrapped CEF instance regains focus after its wrapping window receives focus, the event needs to be explicitly sent to the browser host instance it wraps.
c97e002 to
1fc0b7d
Compare
WizardCM
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some testing, I thought this had provided an improvement, however with or without this change, the Auth window for Twitch correctly focuses the Username input on initial open, and then does not if the window is unfocused and tabbed back in.
I tested with CEF 136, so it's likely this fix works fine for 127 (I will have to test again later) but has no effect with the Chrome runtime on modern Chromium versions.
| CefRefPtr<CefBrowserHost> host{cefBrowser->GetHost()}; | ||
|
|
||
| if (host) { | ||
| host->SetFocus(hasFocus); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| host->SetFocus(hasFocus); | |
| host->SetFocus(hasFocus()); |
Most checks in Qt are functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should actually simply be true, hasFocus used to be a boolean passed into an explicit setFocus method I moved this code from. So I guess this resolves to a non-zero function pointer and thus implicitly a "truthy" value in this form.
Implicit type conversions are evil like that..
| return true; | ||
| #else | ||
| // Return early event does not target the window wrapper or no browser instance is present | ||
| if (object != window_ || !cefBrowser) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (object != window_ || !cefBrowser) { | |
| if (object != window || !cefBrowser) { |
You may have uncommitted code where you've renamed it, but currently it's called window.
Description
Fixes the issue of a browser window not regaining keyboard input focus when a user switched away from and back to OBS Studio as their active application.
Motivation and Context
The CEF instance is wrapped in another QWindow instance for Windows and Linux and thus consumes any focus events that are propagated through the application.
To ensure that a wrapped CEF instance regains focus after its wrapping window receives focus, the event needs to be explicitly sent to the browser host instance it wraps.
The least-intrusive way to achieve this within the current code architecture is to install the instance of
QCefWidgetInternalowning theQWindowto handle all events sent to the window. If the window itself is the target of the event and it's of typeFocusIn, the focus state of the browser host window is set explicitly.In tests this has shown that it allows keyboard input fields on a loaded website to regain input focus.
How Has This Been Tested?
Tested on macOS 26 (which did not require the fix) and Windows 11 (which did).
Types of changes
Checklist: