fix(window): the title a program passes to gl_open / gvk_open reaches the window

The runtime opens a game's window before main, titled with the program's name, and
gl_open attached to it without passing its title on (render3d's gvk_open called win_open,
which returns early on Windows and opened a second window on macOS). win_set_title in
cocoa.ll / win32.ll (setTitle: / SetWindowTextW, UTF-8 -> UTF-16; a no-op without a window,
stubbed headless) retitles it from gl_open, and win_open on an open window retitles it on
both platforms.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-17 14:02:23 +03:00
parent bb267ff3d5
commit 1256bbfec7
7 changed files with 93 additions and 3 deletions

View file

@ -229,7 +229,15 @@ entry:
store i32 %w, ptr @W_fbw
store i32 %h, ptr @W_fbh
store i32 %scale, ptr @W_scale
; a window already open (the runtime opens a game's before main) is retitled, not
; opened again - as win32.ll's win_open does
%have = load ptr, ptr @W_win
%again = icmp ne ptr %have, null
br i1 %again, label %retitle, label %make
retitle:
call void @win_set_title(ptr %title)
ret void
make:
%appcls = call ptr @objc_getClass(ptr @.c_app)
%sel_sh = call ptr @sel_registerName(ptr @.s_shared)
%app = call ptr @objc_msgSend(ptr %appcls, ptr %sel_sh)
@ -1700,6 +1708,31 @@ out:
ret void
}
; ---- win_set_title --------------------------------------------------------------------
; Retitle the window the runtime opened before main: gl_open / gvk_open attach to that window
; rather than opening one, and the title the program asked for would otherwise be dropped in
; favour of the program's name. A no-op without a window.
define void @win_set_title(ptr %title) {
entry:
%win = load ptr, ptr @W_win
%nowin = icmp eq ptr %win, null
%notitle = icmp eq ptr %title, null
%skip = or i1 %nowin, %notitle
br i1 %skip, label %out, label %go
go:
%strcls = call ptr @objc_getClass(ptr @.c_str)
%sel_utf8 = call ptr @sel_registerName(ptr @.s_utf8)
%ns = call ptr (ptr, ptr, ptr) @objc_msgSend(ptr %strcls, ptr %sel_utf8, ptr %title)
%none = icmp eq ptr %ns, null
br i1 %none, label %out, label %set
set:
%sel_title = call ptr @sel_registerName(ptr @.s_title)
%r = call ptr (ptr, ptr, ptr) @objc_msgSend(ptr %win, ptr %sel_title, ptr %ns)
br label %out
out:
ret void
}
; ---- App.window_hide / App.window_show ------------------------------------------------
; The game's window leaves the screen and comes back with its view, layer and GL context
; untouched: a launcher steps aside while the game it started runs. The run does not end