Skip to content

Commit

Permalink
X11 webview reload
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Mar 15, 2024
1 parent 64900a8 commit 025bcf6
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/plugin/WebViewX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
#include <clocale>
#include <cstdio>
#include <dlfcn.h>
#include <functional>
#include <linux/limits.h>
#include <X11/Xlib.h>

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------------------------------------------

struct WebViewIPC {
struct WebViewX11 {
ChildProcess p;
::Display* display;
::Window childWindow;
Expand Down Expand Up @@ -66,20 +67,20 @@ void* addWebView(const uintptr_t parentWinId, const double scaleFactor, const ui
while (environ[envsize] != nullptr)
++envsize;

char** const envp = new char*[envsize + 32];
char** const envp = new char*[envsize + 5];

for (uint i = 0; i < envsize; ++i)
envp[i] = strdup(environ[i]);

for (uint i = 0; i < 32; ++i)
for (uint i = 0; i < 5; ++i)
envp[envsize + i] = nullptr;

set_envp_value(envp, "LANG=en_US.UTF-8");
set_envp_value(envp, "DPF_WEBVIEW_PORT", String(port));
set_envp_value(envp, "DPF_WEBVIEW_SCALE_FACTOR", String(scaleFactor));
set_envp_value(envp, "DPF_WEBVIEW_WIN_ID", String(parentWinId));

WebViewIPC* const ipc = new WebViewIPC();
WebViewX11* const ipc = new WebViewX11();
ipc->display = display;
ipc->childWindow = 0;
ipc->ourWindow = parentWinId;
Expand All @@ -96,22 +97,22 @@ void* addWebView(const uintptr_t parentWinId, const double scaleFactor, const ui

void destroyWebView(void* const webviewptr)
{
WebViewIPC* const ipc = static_cast<WebViewIPC*>(webviewptr);
WebViewX11* const ipc = static_cast<WebViewX11*>(webviewptr);

XCloseDisplay(ipc->display);
delete ipc;
}

void reloadWebView(void* const webviewptr)
{
WebViewIPC* const ipc = static_cast<WebViewIPC*>(webviewptr);
WebViewX11* const ipc = static_cast<WebViewX11*>(webviewptr);

ipc->p.signal(SIGUSR1);
}

void resizeWebView(void* const webviewptr, const uint offset, const uint width, const uint height)
{
WebViewIPC* const ipc = static_cast<WebViewIPC*>(webviewptr);
WebViewX11* const ipc = static_cast<WebViewX11*>(webviewptr);

if (ipc->childWindow == 0)
{
Expand All @@ -135,6 +136,10 @@ void resizeWebView(void* const webviewptr, const uint offset, const uint width,

// -----------------------------------------------------------------------------------------------------------

static std::function<void()> reloadFn;

// -----------------------------------------------------------------------------------------------------------

struct GtkContainer;
struct GtkPlug;
struct GtkWidget;
Expand Down Expand Up @@ -253,7 +258,7 @@ static bool gtk3(Display* const display, const Window winId, double scaleFactor,
GtkWidget* const webview = webkit_web_view_new_with_settings(settings);
DISTRHO_SAFE_ASSERT_RETURN(webview != nullptr, false);

webkit_web_view_load_uri (WEBKIT_WEB_VIEW (webview), url);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW (webview), url);

gtk_container_add(GTK_CONTAINER(window), webview);

Expand All @@ -263,6 +268,10 @@ static bool gtk3(Display* const display, const Window winId, double scaleFactor,
XMapWindow(display, wid);
XFlush(display);

reloadFn = [=](){
webkit_web_view_load_uri(WEBKIT_WEB_VIEW (webview), url);
};

gtk_main();

dlclose(lib);
Expand Down Expand Up @@ -359,6 +368,10 @@ static bool qt5webengine(const Window winId, const double scaleFactor, const cha
QWebEngineView_setUrl(webview, *qurl);
QWebEngineView_show(webview);

reloadFn = [=](){
QWebEngineView_setUrl(webview, *qurl);
};

QApplication_exec();

dlclose(lib);
Expand Down Expand Up @@ -455,6 +468,11 @@ static bool qt6webengine(const Window winId, const double scaleFactor, const cha
QWebEngineView_setUrl(webview, *qurl);
QWebEngineView_show(webview);

reloadFn = [=](){
QWebEngineView_setUrl(webview, *qurl);
};


QApplication_exec();

dlclose(lib);
Expand All @@ -470,7 +488,7 @@ static void signalHandler(const int sig)
{
DISTRHO_SAFE_ASSERT_RETURN(sig == SIGUSR1,);

d_stdout("TODO: refresh web view");
reloadFn();
}

DISTRHO_PLUGIN_EXPORT
Expand Down

0 comments on commit 025bcf6

Please sign in to comment.