Skip to content

Commit

Permalink
obs-browser: Add Linux browser panel support
Browse files Browse the repository at this point in the history
This adds browser panel support for Linux.
  • Loading branch information
cg2121 committed Dec 8, 2020
1 parent ce8f6f8 commit 214af24
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ set(obs-browser_HEADERS

# only allow browser panels on win32 for now -- other operating systems
# need more testing
if(WIN32 AND BROWSER_PANEL_SUPPORT_ENABLED)
if(BROWSER_PANEL_SUPPORT_ENABLED)
list(APPEND obs-browser_SOURCES
panel/browser-panel.cpp
panel/browser-panel-client.cpp
Expand Down
2 changes: 2 additions & 0 deletions panel/browser-panel-internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class QCefWidgetInternal : public QCefWidget {
std::string script;
CefRefPtr<CefRequestContext> rqc;
QTimer timer;
QWindow *window = nullptr;
QWidget *container = nullptr;
bool allowAllPopups_ = false;

virtual void resizeEvent(QResizeEvent *event) override;
Expand Down
38 changes: 28 additions & 10 deletions panel/browser-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <util/base.h>
#include <thread>

#if !defined(_WIN32) && !defined(__APPLE__)
#include <X11/Xlib.h>
#endif

extern bool QueueCEFTask(std::function<void()> task);
extern "C" void obs_browser_initialize(void);
extern os_event_t *cef_started_event;
Expand Down Expand Up @@ -220,8 +224,6 @@ void QCefWidgetInternal::closeBrowser()

void QCefWidgetInternal::Init()
{
WId id = winId();

bool success = QueueCEFTask([this, id]() {
CefWindowInfo windowInfo;

Expand All @@ -237,10 +239,11 @@ void QCefWidgetInternal::Init()
size *= devicePixelRatio();
#endif
RECT rc = {0, 0, size.width(), size.height()};
windowInfo.SetAsChild((HWND)id, rc);
#elif __APPLE__
windowInfo.SetAsChild((CefWindowHandle)id, 0, 0, size.width(),
size.height());
windowInfo.SetAsChild((HWND)this->window->winId(), rc);
#else
CefRect rc = {0, 0, size.width(), size.height()};
windowInfo.SetAsChild((CefWindowHandle)this->window->winId(),
rc);
#endif

CefRefPtr<QCefBrowserClient> browserClient =
Expand All @@ -253,9 +256,7 @@ void QCefWidgetInternal::Init()
CefRefPtr<CefDictionaryValue>(),
#endif
rqc);
#ifdef _WIN32
Resize();
#endif
});

if (success)
Expand All @@ -270,7 +271,6 @@ void QCefWidgetInternal::resizeEvent(QResizeEvent *event)

void QCefWidgetInternal::Resize()
{
#ifdef _WIN32
#ifdef SUPPORTS_FRACTIONAL_SCALING
QSize size = this->size() * devicePixelRatioF();
#elif
Expand All @@ -280,24 +280,42 @@ void QCefWidgetInternal::Resize()
QueueCEFTask([this, size]() {
if (!cefBrowser)
return;

#ifdef _WIN32
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()));
});
#elif __APPLE__
#else
auto id = cefBrowser->GetHost()->GetWindowHandle();
auto xDisplay = cef_get_xdisplay();
XWindowChanges changes = {};
changes.x = 0;
changes.y = 0;
changes.width = size.width();
changes.height = size.height();
XConfigureWindow(xDisplay, id, CWX | CWY | CWHeight | CWWidth,
&changes);
#endif

this->container->resize(size.width(), size.height());
});
}

void QCefWidgetInternal::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);

if (!cefBrowser) {
window = new QWindow();
obs_browser_initialize();
connect(&timer, SIGNAL(timeout()), this, SLOT(Init()));
timer.start(500);
Init();
container = QWidget::createWindowContainer(window, this);
container->show();
}
}

Expand Down
5 changes: 3 additions & 2 deletions panel/browser-panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ static inline QCef *obs_browser_init_panel(void)
#ifdef _WIN32
void *lib = os_dlopen("obs-browser");
#else
void *lib = os_dlopen("../obs-plugins/obs-browser");
// Need to un-hardcode this, as I couldn't get it to work otherwise
void *lib = os_dlopen("/usr/lib/obs-plugins/obs-browser.so");
#endif
QCef *(*create_qcef)(void) = nullptr;

Expand All @@ -93,7 +94,7 @@ static inline int obs_browser_qcef_version(void)
#ifdef _WIN32
void *lib = os_dlopen("obs-browser");
#else
void *lib = os_dlopen("../obs-plugins/obs-browser");
void *lib = os_dlopen("/usr/lib/obs-plugins/obs-browser.so");
#endif
int (*qcef_version)(void) = nullptr;

Expand Down

0 comments on commit 214af24

Please sign in to comment.