Skip to content

Commit c97e002

Browse files
committed
panel: Propagate "focus-in" event to browser host
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.
1 parent a776dd6 commit c97e002

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

panel/browser-panel-internal.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ extern std::vector<PopupWhitelistInfo> forced_popups;
2424
class QCefWidgetInternal : public QCefWidget {
2525
Q_OBJECT
2626

27+
private:
28+
virtual bool eventFilter(QObject *object, QEvent *event) override;
29+
2730
public:
2831
QCefWidgetInternal(QWidget *parent, const std::string &url, CefRefPtr<CefRequestContext> rqc);
2932
~QCefWidgetInternal();

panel/browser-panel.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ QCefWidgetInternal::QCefWidgetInternal(QWidget *parent, const std::string &url_,
178178
#ifndef __APPLE__
179179
window = new QWindow();
180180
window->setFlags(Qt::FramelessWindowHint);
181+
window->setObjectName("QCefWidgetInternalWindow");
182+
window->installEventFilter(this);
181183
#endif
182184
}
183185

@@ -186,6 +188,28 @@ QCefWidgetInternal::~QCefWidgetInternal()
186188
closeBrowser();
187189
}
188190

191+
bool QCefWidgetInternal::eventFilter(QObject *object, QEvent *event)
192+
{
193+
#ifdef __APPLE__
194+
UNUSED_PARAMETER(object);
195+
UNUSED_PARAMETER(event);
196+
197+
return true;
198+
#else
199+
if (object != window || event->type() != QEvent::FocusIn || !cefBrowser) {
200+
return true;
201+
}
202+
203+
CefRefPtr<CefBrowserHost> host{cefBrowser->GetHost()};
204+
205+
if (host) {
206+
host->SetFocus(hasFocus);
207+
}
208+
209+
return true;
210+
#endif
211+
}
212+
189213
void QCefWidgetInternal::closeBrowser()
190214
{
191215
if (!cefBrowser) {

panel/browser-panel.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class QCefWidget : public QWidget {
3636
protected:
3737
inline QCefWidget(QWidget *parent) : QWidget(parent) {}
3838

39+
private:
40+
virtual bool eventFilter(QObject *object, QEvent *event) = 0;
41+
3942
public:
4043
virtual void setURL(const std::string &url) = 0;
4144
virtual void setStartupScript(const std::string &script) = 0;

0 commit comments

Comments
 (0)