From d16ad3dcb54b1cc5d53af134ac55a05f6f6453e4 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 31 Oct 2017 19:47:56 -0400 Subject: [PATCH] - added I_FriendlyWindowTitle cvar, which takes the current game/mod name and uses it as a default window title. --- src/d_main.cpp | 14 ++++++++++++++ src/posix/cocoa/i_video.mm | 11 +++++++++++ src/posix/sdl/sdlvideo.cpp | 13 +++++++++++++ src/win32/i_main.cpp | 13 +++++++++++++ 4 files changed, 51 insertions(+) diff --git a/src/d_main.cpp b/src/d_main.cpp index 06a772066..df34f0b6d 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -127,6 +127,7 @@ void DrawHUD(); // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- +extern void I_SetWindowTitle(const char* caption); extern void ReadStatistics(); extern void M_RestoreMode (); extern void M_SetDefaultMode (); @@ -163,6 +164,7 @@ EXTERN_CVAR (Bool, lookstrafe) EXTERN_CVAR (Int, screenblocks) EXTERN_CVAR (Bool, sv_cheats) EXTERN_CVAR (Bool, sv_unlimited_pickup) +EXTERN_CVAR (Bool, I_FriendlyWindowTitle) extern int testingmode; extern bool setmodeneeded; @@ -2737,6 +2739,9 @@ void D_DoomMain (void) setmodeneeded = false; // This may be set to true here, but isn't needed for a restart } + if (I_FriendlyWindowTitle) + I_SetWindowTitle(DoomStartupInfo.Name.GetChars()); + D_DoomLoop (); // this only returns if a 'restart' CCMD is given. // // Clean up after a restart @@ -2891,3 +2896,12 @@ DEFINE_FIELD_X(InputEventData, event_t, data2) DEFINE_FIELD_X(InputEventData, event_t, data3) DEFINE_FIELD_X(InputEventData, event_t, x) DEFINE_FIELD_X(InputEventData, event_t, y) + + +CUSTOM_CVAR(Bool, I_FriendlyWindowTitle, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE|CVAR_NOINITCALL) +{ + if (self) + I_SetWindowTitle(DoomStartupInfo.Name.GetChars()); + else + I_SetWindowTitle(NULL); +} \ No newline at end of file diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index b8765c1a6..c89a6601d 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -1519,3 +1519,14 @@ void I_SetMainWindowVisible(bool visible) { CocoaVideo::SetWindowVisible(visible); } + +// each platform has its own specific version of this function. +void I_SetWindowTitle(const char* title) +{ + static NSString* const TITLE_STRING; + if (title) + TITLE_STRING = [NSString stringWithFormat:@"%s", title]; + else + TITLE_STRING = [NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()]; + [m_window setTitle:TITLE_STRING]; +} \ No newline at end of file diff --git a/src/posix/sdl/sdlvideo.cpp b/src/posix/sdl/sdlvideo.cpp index c1d830659..318a91e6e 100644 --- a/src/posix/sdl/sdlvideo.cpp +++ b/src/posix/sdl/sdlvideo.cpp @@ -551,3 +551,16 @@ ADD_STAT (blit) BlitCycles.TimeMS(), SDLFlipCycles.TimeMS()); return out; } + +// each platform has its own specific version of this function. +void I_SetWindowTitle(const char* caption) +{ + if (caption) + SDL_SetWindowTitle(Screen, caption); + else + { + FString default_caption; + default_caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime()); + SDL_SetWindowTitle(Screen, default_caption); + } +} diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index d6d246185..019b01e7e 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -1360,3 +1360,16 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int n MainThread = INVALID_HANDLE_VALUE; return 0; } + +// each platform has its own specific version of this function. +void I_SetWindowTitle(const char* caption) +{ + if (caption) + SetWindowText(Window, (LPCTSTR)caption); + else + { + char default_caption[100]; + mysnprintf(default_caption, countof(default_caption), "" GAMESIG " %s " X64 " (%s)", GetVersionString(), GetGitTime()); + SetWindowText(Window, default_caption); + } +}