Skip to content

Commit

Permalink
Fix browser not always initially showing
Browse files Browse the repository at this point in the history
Fixes a bug where the browser would initially start up as blank/white.
This is likely a bug internally with chromium (at least this version of
chromium) or CEF on high-DPI displays.  Posting a WM_SIZE message tells
Chromium/CEF that the window position/size has changed, and it adjusts
it back in to the right position.
  • Loading branch information
jp9000 committed Feb 26, 2019
1 parent 7d06995 commit d5b6812
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions panel/browser-panel-internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class QCefWidgetInternal : public QCefWidget {
virtual void setURL(const std::string &url) override;
virtual void setStartupScript(const std::string &script) override;

void Resize();

public slots:
void Init();
};
9 changes: 9 additions & 0 deletions panel/browser-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ void QCefWidgetInternal::Init()
url,
cefBrowserSettings,
rqc);
#ifdef _WIN32
Resize();
#endif
});

if (success)
Expand All @@ -219,7 +222,11 @@ void QCefWidgetInternal::Init()
void QCefWidgetInternal::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
Resize();
}

void QCefWidgetInternal::Resize()
{
QSize size = this->size() * devicePixelRatio();

QueueCEFTask([this, size] ()
Expand All @@ -230,6 +237,8 @@ void QCefWidgetInternal::resizeEvent(QResizeEvent *event)
HWND hwnd = cefBrowser->GetHost()->GetWindowHandle();
SetWindowPos(hwnd, nullptr, 0, 0, size.width(), size.height(),
SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
SendMessage(hwnd, WM_SIZE, 0,
MAKELPARAM(size.width(), size.height()));
#endif
});
}
Expand Down

0 comments on commit d5b6812

Please sign in to comment.