Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
01acf31
Feature - [Android] Webview support
Namaneo Oct 31, 2024
812f8d7
Feature - [Linux] Webview support
Namaneo Nov 1, 2024
9fe89b7
Feature - [WASM] Webview support
Namaneo Nov 5, 2024
c4b052e
Merge remote-tracking branch 'origin/android-webview' into other-webv…
Namaneo Nov 5, 2024
f6fa65d
Merge remote-tracking branch 'origin/linux-webview' into other-webviews
Namaneo Nov 5, 2024
d58b0ff
Merge remote-tracking branch 'origin/wasm-webview' into other-webviews
Namaneo Nov 5, 2024
9057e41
Custom script moved to `parsec-ui`
Namaneo Nov 5, 2024
0dab25f
Mostly remove duplicated code
Namaneo Nov 5, 2024
f290db5
Woops
Namaneo Nov 5, 2024
1d44419
Remove duplicate flags
Namaneo Nov 5, 2024
5851a6c
Fix include
Namaneo Nov 5, 2024
8ac93e5
Fix makefile
Namaneo Nov 5, 2024
f5b8cf7
Steam webview cleanup (I guess)
Namaneo Nov 6, 2024
124462f
`native` instead of `parent`
Namaneo Nov 6, 2024
1281d70
Woops
Namaneo Nov 6, 2024
ae748cd
Fix Android
Namaneo Nov 6, 2024
bce2f25
Fix macOS
Namaneo Nov 6, 2024
bf1675d
Fix double-free corruption
Namaneo Nov 7, 2024
72f1a26
More performant mty_webview_send_text on some platforms
Namaneo Nov 7, 2024
f199a00
Runtime linking with GTK on Linux
Namaneo Dec 2, 2024
3627ca3
Merge remote-tracking branch 'origin/stable' into other-webviews
Namaneo Dec 16, 2024
5a067fd
Typo
Namaneo Dec 16, 2024
33fa477
Merge remote-tracking branch 'origin/stable' into other-webviews
Namaneo Jan 6, 2025
5b43cc3
Update webkitgtk version
Namaneo Jan 24, 2025
8a10ebb
Merge remote-tracking branch 'origin/stable' into other-webviews
Namaneo Jan 24, 2025
1fcaa92
Merge remote-tracking branch 'origin/stable' into other-webviews
Namaneo Jan 28, 2025
d00f3ba
Relaxed webkit version on linux
Namaneo Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ LOCAL_SRC_FILES := \
src/thread.c \
src/tlocal.c \
src/version.c \
src/webview.c \
src/gfx/gl/gl.c \
src/gfx/gl/gl-ui.c \
src/gfx/vk/vk.c \
Expand Down
1 change: 1 addition & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ OBJS = \
src/thread.o \
src/tlocal.o \
src/version.o \
src/webview.o \
src/hid/utils.o \
src/unix/compress.o \
src/unix/file.o \
Expand Down
3 changes: 2 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NAME = matoya
!IFDEF STEAM
WEBVIEW_OBJ = src\swebview.obj
!ELSE
WEBVIEW_OBJ = src\windows\webview.obj
WEBVIEW_OBJ = src\windows\webview-win.obj
!ENDIF

OBJS = \
Expand All @@ -41,6 +41,7 @@ OBJS = \
src\thread.obj \
src\tlocal.obj \
src\version.obj \
src\webview.obj \
src\gfx\vk\vk.obj \
src\gfx\vk\vk-ctx.obj \
src\gfx\vk\vk-ui.obj \
Expand Down
1 change: 1 addition & 0 deletions src/gfx/vk/vkproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
((e) == VK_ERROR_OUT_OF_DATE_KHR || (e) == VK_SUBOPTIMAL_KHR)

#elif defined(MTY_VK_XLIB)
#define LIBX11_NO_SYMBOLS
#include "dl/libx11.h"
#include "vulkan/vulkan_xlib.h"

Expand Down
117 changes: 27 additions & 90 deletions src/swebview.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,14 @@ struct sbase {
};

struct webview {
MTY_App *app;
MTY_Window window;
WEBVIEW_READY ready_func;
WEBVIEW_TEXT text_func;
WEBVIEW_KEY key_func;
MTY_Queue *pushq;
struct webview_base base;

MTY_Mutex *mutex;
ISteamHTMLSurface *surface;
EHTMLKeyModifiers smods;
HHTMLBrowser browser;
char *source;
bool debug;
bool ready;
bool visible;
bool passthrough;

void *bgra;
bool bgra_dirty;
Expand All @@ -68,7 +61,7 @@ struct webview {

static void webview_update_size(struct webview *ctx)
{
MTY_Size size = MTY_WindowGetSize(ctx->app, ctx->window);
MTY_Size size = MTY_WindowGetSize(ctx->base.app, ctx->base.window);

SteamAPI_ISteamHTMLSurface_SetSize(ctx->surface, ctx->browser, size.w, size.h);
}
Expand All @@ -87,7 +80,7 @@ static void webview_on_browser_ready(struct webview *ctx, HTML_BrowserReady_t *p
if (ctx->source)
SteamAPI_ISteamHTMLSurface_LoadURL(ctx->surface, ctx->browser, ctx->source, NULL);

if (ctx->debug)
if (ctx->base.debug)
SteamAPI_ISteamHTMLSurface_OpenDeveloperTools(ctx->surface, ctx->browser);
}

Expand Down Expand Up @@ -180,30 +173,10 @@ static void finished_request_run0(void *This, void *pvParam)
struct webview *ctx = base->ctx;
HTML_FinishedRequest_t *params = pvParam;

const char *script =
"const __MTY_MSGS = [];"

"let __MTY_WEBVIEW = b64 => {"
"__MTY_MSGS.push(b64);"
"};"

"window.MTY_NativeSendText = text => {"
"alert('T' + text);"
"};"

"alert('R');"

"const __MTY_INTERVAL = setInterval(() => {"
"if (window.MTY_NativeListener) {"
"__MTY_WEBVIEW = b64 => {window.MTY_NativeListener(atob(b64));};"

"for (let msg = __MTY_MSGS.shift(); msg; msg = __MTY_MSGS.shift())"
"__MTY_WEBVIEW(msg);"

"clearInterval(__MTY_INTERVAL);"
"}"
"}, 100);";

const char *script = "window.native = {"
"postMessage: (message) => alert(message),"
"addEventListener: (listener) => window.addEventListener('message', listener),"
"}";
SteamAPI_ISteamHTMLSurface_ExecuteJavascript(ctx->surface, params->unBrowserHandle, script);
}

Expand Down Expand Up @@ -235,26 +208,7 @@ static void js_alert_run0(void *This, void *pvParam)
SteamAPI_ISteamHTMLSurface_JSDialogResponse(ctx->surface, ctx->browser, true);

const char *str = params->pchMessage;

switch (str[0]) {
// MTY_EVENT_WEBVIEW_READY
case 'R':
ctx->ready = true;

// Send any queued messages before the WebView became ready
for (char *msg = NULL; MTY_QueuePopPtr(ctx->pushq, 0, (void **) &msg, NULL);) {
mty_webview_send_text(ctx, msg);
MTY_Free(msg);
}

ctx->ready_func(ctx->app, ctx->window);
break;

// MTY_EVENT_WEBVIEW_TEXT
case 'T':
ctx->text_func(ctx->app, ctx->window, str + 1);
break;
}
mty_webview_base_handle_event(&ctx->base, str);
}

static void js_alert_run1(void *This, void *pvParam, bool _dummy0, SteamAPICall_t _dummy1)
Expand Down Expand Up @@ -283,10 +237,10 @@ static void set_cursor_run0(void *This, void *pvParam)
HTML_SetCursor_t *params = pvParam;

switch (params->eMouseCursor) {
case dc_hand: MTY_AppSetCursor(ctx->app, MTY_CURSOR_HAND); break;
case dc_ibeam: MTY_AppSetCursor(ctx->app, MTY_CURSOR_IBEAM); break;
case dc_hand: MTY_AppSetCursor(ctx->base.app, MTY_CURSOR_HAND); break;
case dc_ibeam: MTY_AppSetCursor(ctx->base.app, MTY_CURSOR_IBEAM); break;
default:
MTY_AppSetCursor(ctx->app, MTY_CURSOR_ARROW);
MTY_AppSetCursor(ctx->base.app, MTY_CURSOR_ARROW);
break;
}
}
Expand Down Expand Up @@ -330,17 +284,12 @@ struct webview *mty_webview_create(MTY_App *app, MTY_Window window, const char *
bool debug, WEBVIEW_READY ready_func, WEBVIEW_TEXT text_func, WEBVIEW_KEY key_func)
{
struct webview *ctx = MTY_Alloc(1, sizeof(struct webview));
ctx->app = app;
ctx->window = window;
ctx->mutex = MTY_MutexCreate();
ctx->ready_func = ready_func;
ctx->text_func = text_func;
ctx->key_func = key_func;
ctx->debug = debug;

mty_webview_base_create(&ctx->base, app, window, dir, debug, ready_func, text_func, key_func);

steam_global_init(dir ? dir : ".");

ctx->pushq = MTY_QueueCreate(50, 0);
ctx->mutex = MTY_MutexCreate();

bool r = SteamAPI_InitSafe();
if (!r) {
Expand Down Expand Up @@ -393,16 +342,14 @@ void mty_webview_destroy(struct webview **webview)

SteamAPI_Shutdown();

if (ctx->pushq)
MTY_QueueFlush(ctx->pushq, MTY_Free);

MTY_QueueDestroy(&ctx->pushq);
MTY_MutexDestroy(&ctx->mutex);
MTY_Free(ctx->source);
MTY_Free(ctx->bgra);

steam_global_destroy();

mty_webview_base_destroy(&ctx->base);

MTY_Free(ctx);
*webview = NULL;
}
Expand All @@ -426,10 +373,10 @@ void mty_webview_show(struct webview *ctx, bool show)
ctx->visible = show;

if (show) {
MTY_AppShowCursor(ctx->app, true);
MTY_AppShowCursor(ctx->base.app, true);

} else {
MTY_AppSetCursor(ctx->app, MTY_CURSOR_NONE);
MTY_AppSetCursor(ctx->base.app, MTY_CURSOR_NONE);
}

SteamAPI_ISteamHTMLSurface_SetKeyFocus(ctx->surface, ctx->browser, show);
Expand All @@ -443,24 +390,14 @@ bool mty_webview_is_visible(struct webview *ctx)

void mty_webview_send_text(struct webview *ctx, const char *msg)
{
if (!ctx->ready) {
MTY_QueuePushPtr(ctx->pushq, MTY_Strdup(msg), 0);
if (!ctx->base.ready) {
MTY_QueuePushPtr(ctx->base.pushq, MTY_Strdup(msg), 0);

} else {
if (ctx->browser == 0)
return;

size_t msg_size = strlen(msg);
size_t size = msg_size * 4 + 64;
char *script = MTY_Alloc(size, 1);

memcpy(script, "__MTY_WEBVIEW('", 15);

MTY_BytesToBase64(msg, msg_size, script + 15, size - 15);

size_t end = strlen(script);
memcpy(script + end, "');", 3);

char *script = mty_webview_base_format_text(msg);
SteamAPI_ISteamHTMLSurface_ExecuteJavascript(ctx->surface, ctx->browser, script);
MTY_Free(script);
}
Expand All @@ -476,7 +413,7 @@ void mty_webview_reload(struct webview *ctx)

void mty_webview_set_input_passthrough(struct webview *ctx, bool passthrough)
{
ctx->passthrough = passthrough;
ctx->base.passthrough = passthrough;
}

static EHTMLKeyModifiers webview_mods(MTY_Mod mods)
Expand Down Expand Up @@ -547,10 +484,10 @@ bool mty_webview_event(struct webview *ctx, MTY_Event *evt)
evt->key.vkey, ctx->smods);
}

if (ctx->passthrough)
if (ctx->base.passthrough)
evt->type = MTY_EVENT_WEBVIEW_KEY;

return !ctx->passthrough;
return !ctx->base.passthrough;
}
case MTY_EVENT_TEXT: {
wchar_t codepoint[8] = {0};
Expand All @@ -568,7 +505,7 @@ bool mty_webview_event(struct webview *ctx, MTY_Event *evt)

void mty_webview_run(struct webview *ctx)
{
if (!ctx->ready || ctx->visible)
if (!ctx->base.ready || ctx->visible)
SteamAPI_RunCallbacks();
}

Expand All @@ -585,7 +522,7 @@ void mty_webview_render(struct webview *ctx)
ctx->desc.format = MTY_COLOR_FORMAT_UNKNOWN;
}

MTY_WindowDrawQuad(ctx->app, ctx->window, ctx->bgra, &ctx->desc);
MTY_WindowDrawQuad(ctx->base.app, ctx->base.window, ctx->bgra, &ctx->desc);

MTY_MutexUnlock(ctx->mutex);
}
Expand Down
Loading