From 6fe7556b2fb835d591ce1f49ea150e9f8ef6e902 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sun, 12 Jan 2025 16:42:55 +0100 Subject: [PATCH] sokol_app.h html5: new init flag sapp_desc.html5_update_document_title (#1186) When sapp_desc.html5_update_document_title is true, sokol_app.h will set the HTML document.title to sapp_desc.window_title. Fixes #1132 --- CHANGELOG.md | 9 +++++++++ sokol_app.h | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9d5dbbff..622598c01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ ## Updates +### 12-Jan-2025 + +- The Jai and D language bindings now also have integrated comments + (see https://github.com/floooh/sokol/pull/1182 and https://github.com/floooh/sokol/pull/1183). +- sokol_app.h html5: a new init flag `sapp_desc.html5_update_document_title` has been + added. When this is set to true, sokol-app will overwrite the HTML `document.title` property with + the `sapp_desc.window_title` string (also see issue https://github.com/floooh/sokol/issues/1132 + and PR https://github.com/floooh/sokol/pull/1182). + ### 11-Jan-2025 The language bindings code-generation can now extract comments from the C headers diff --git a/sokol_app.h b/sokol_app.h index 19c6c9d9a..e1e1bed90 100644 --- a/sokol_app.h +++ b/sokol_app.h @@ -1766,6 +1766,10 @@ typedef struct sapp_logger { void* user_data; } sapp_logger; +/* + sokol-app initialization options, used as return value of sokol_main() + or sapp_run() argument. +*/ typedef struct sapp_desc { void (*init_cb)(void); // these are the user-provided callbacks without user data void (*frame_cb)(void); @@ -1806,6 +1810,7 @@ typedef struct sapp_desc { bool html5_preserve_drawing_buffer; // HTML5 only: whether to preserve default framebuffer content between frames bool html5_premultiplied_alpha; // HTML5 only: whether the rendered pixels use premultiplied alpha convention bool html5_ask_leave_site; // initial state of the internal html5_ask_leave_site flag (see sapp_html5_ask_leave_site()) + bool html5_update_document_title; // if true, update the HTML document.title with sapp_desc.window_title bool html5_bubble_mouse_events; // if true, mouse events will bubble up to the web page bool html5_bubble_touch_events; // same for touch events bool html5_bubble_wheel_events; // same for wheel events @@ -3198,7 +3203,7 @@ _SOKOL_PRIVATE sapp_desc _sapp_desc_defaults(const sapp_desc* desc) { res.clipboard_size = _sapp_def(res.clipboard_size, 8192); res.max_dropped_files = _sapp_def(res.max_dropped_files, 1); res.max_dropped_file_path_length = _sapp_def(res.max_dropped_file_path_length, 2048); - res.window_title = _sapp_def(res.window_title, "sokol_app"); + res.window_title = _sapp_def(res.window_title, "sokol"); return res; } @@ -5092,7 +5097,10 @@ EM_JS(void, sapp_js_remove_dragndrop_listeners, (void), { canvas.removeEventListener('drop', Module.sokol_drop); }); -EM_JS(void, sapp_js_init, (const char* c_str_target_selector), { +EM_JS(void, sapp_js_init, (const char* c_str_target_selector, const char* c_str_document_title), { + if (c_str_document_title !== 0) { + document.title = UTF8ToString(c_str_document_title); + } const target_selector_str = UTF8ToString(c_str_target_selector); if (Module['canvas'] !== undefined) { if (typeof Module['canvas'] === 'object') { @@ -6015,7 +6023,8 @@ _SOKOL_PRIVATE void _sapp_emsc_frame_main_loop(void) { _SOKOL_PRIVATE void _sapp_emsc_run(const sapp_desc* desc) { _sapp_init_state(desc); - sapp_js_init(_sapp.html5_canvas_selector); + const char* document_title = desc->html5_update_document_title ? _sapp.window_title : 0; + sapp_js_init(_sapp.html5_canvas_selector, document_title); double w, h; if (_sapp.desc.html5_canvas_resize) { w = (double) _sapp_def(_sapp.desc.width, _SAPP_FALLBACK_DEFAULT_WINDOW_WIDTH);