It's already been thought of, apart from there's a bug. It works like this:
install_allegro sets the default title (I hope no-one is expecting it to work if called before install_allegro?)
The implementation of set_window_title copies the supplied title into the variable osx_window_title, and does the OS call to actually set the title if the window exists.
|2|| * Sets the title for both the application menu and the window if present.|
|4||static void osx_sys_set_window_title(AL_CONST char *title)|
|6|| char tmp[ALLEGRO_MESSAGE_SIZE];|
|8|| _al_sane_strncpy(osx_window_title, title, ALLEGRO_MESSAGE_SIZE);|
|9|| do_uconvert(title, U_CURRENT, tmp, U_UTF8, ALLEGRO_MESSAGE_SIZE);|
|11|| NSString *ns_title = [NSString stringWithUTF8String: tmp];|
|13|| if (osx_window)|
|14|| [osx_window setTitle: ns_title];|
In set_gfx_mode, when the window is created, the call
is made. This should set the title to whatever has been set previously (which is the default if set_window_title has never been called by the user). This is the desired behaviour. Unfortunately, _al_sane_strcpy fails if source == destination, which it is, in this case. It leaves osx_window_title as an empty string, which is probably what you are seeing.
Still following me?
So I propose an explicit check for this case,
--- src/macosx/system.m (revision 7527)
+++ src/macosx/system.m (working copy)
@@ -563,7 +563,8 @@
- _al_sane_strncpy(osx_window_title, title, ALLEGRO_MESSAGE_SIZE);
+ if (osx_window_title != title)
+ _al_sane_strncpy(osx_window_title, title, ALLEGRO_MESSAGE_SIZE);
do_uconvert(title, U_CURRENT, tmp, U_UTF8, ALLEGRO_MESSAGE_SIZE);
NSString *ns_title = [NSString stringWithUTF8String: tmp];
This is IMO the lowest impact solution, though probably not the neatest one.
ps. AFAIK, the behaviour of strncpy is supposed to be undefined if source and destination overlap (link) so the behaviour of _al_sane_strncpy seems quite reasonable in this case.