From d16ad3dcb54b1cc5d53af134ac55a05f6f6453e4 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 31 Oct 2017 19:47:56 -0400 Subject: [PATCH 1/6] - 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 06a7720664..df34f0b6de 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 b8765c1a67..c89a6601d5 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 c1d8306590..318a91e6e5 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 d6d2461857..019b01e7e8 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); + } +} From d313ef4b615048ac92700ce27db6bb28e261bc15 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 31 Oct 2017 20:00:58 -0400 Subject: [PATCH 2/6] - de-init DoomStartupInfo on 'restart' ccmd so that the window title always contains the correct game information. --- src/d_main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/d_main.cpp b/src/d_main.cpp index df34f0b6de..130091d169 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2777,6 +2777,10 @@ void D_DoomMain (void) FS_Close(); // destroy the global FraggleScript. DeinitMenus(); + // delete DoomStartupInfo data + DoomStartupInfo.Name = (const char*)0; + DoomStartupInfo.BkColor = DoomStartupInfo.FgColor = DoomStartupInfo.Type = 0; + GC::FullGC(); // clean up before taking down the object list. // Delete the reference to the VM functions here which were deleted and will be recreated after the restart. From 7d4f8af2456fd3d357f7bb064cf5a7cd387c3ef1 Mon Sep 17 00:00:00 2001 From: raa-eruanna Date: Wed, 1 Nov 2017 04:13:10 -0400 Subject: [PATCH 3/6] - fixed compile on Linux and (maybe?) Mac --- src/posix/cocoa/i_video.mm | 16 +++++++++++----- src/posix/sdl/sdlvideo.cpp | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index c89a6601d5..2c305b49eb 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -1523,10 +1523,16 @@ void I_SetMainWindowVisible(bool 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]; + { + static NSString* const TITLE_STRING = + [NSString stringWithFormat:@"%s", title]; + [m_window setTitle:TITLE_STRING]; + } else - TITLE_STRING = [NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()]; - [m_window setTitle:TITLE_STRING]; -} \ No newline at end of file + { + static NSString* const TITLE_STRING = + [NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()]; + [m_window setTitle:TITLE_STRING]; + } +} diff --git a/src/posix/sdl/sdlvideo.cpp b/src/posix/sdl/sdlvideo.cpp index 318a91e6e5..6a0420ae81 100644 --- a/src/posix/sdl/sdlvideo.cpp +++ b/src/posix/sdl/sdlvideo.cpp @@ -556,11 +556,12 @@ ADD_STAT (blit) void I_SetWindowTitle(const char* caption) { if (caption) - SDL_SetWindowTitle(Screen, caption); + SDL_SetWindowTitle(static_cast(screen)->GetSDLWindow(), caption); else { FString default_caption; default_caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime()); - SDL_SetWindowTitle(Screen, default_caption); + SDL_SetWindowTitle(static_cast(screen)->GetSDLWindow(), default_caption); } } + From c3c637a0cc724d13985bcb4d4f82f9bd2a3f3332 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 18 Nov 2017 00:53:16 -0500 Subject: [PATCH 4/6] - set i_friendlywindowtitle to true by default --- src/d_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 130091d169..4ea71b3cdb 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2902,7 +2902,7 @@ 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) +CUSTOM_CVAR(Bool, I_FriendlyWindowTitle, true, CVAR_GLOBALCONFIG|CVAR_ARCHIVE|CVAR_NOINITCALL) { if (self) I_SetWindowTitle(DoomStartupInfo.Name.GetChars()); From 35bb9ba9d36e8dd474ea1c133fc055bb132d8c8c Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 18 Nov 2017 13:24:17 +0200 Subject: [PATCH 5/6] Implemented setting of window title in Cocoa backend # Conflicts: # src/posix/cocoa/i_video.mm --- src/posix/cocoa/i_video.mm | 48 ++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 2c305b49eb..a1bc96403c 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -197,9 +197,12 @@ namespace @interface CocoaWindow : NSWindow { + NSString* m_title; } - (BOOL)canBecomeKeyWindow; +- (void)setTitle:(NSString*)title; +- (void)updateTitle; @end @@ -211,6 +214,23 @@ namespace return true; } +- (void)setTitle:(NSString*)title +{ + m_title = title; + + [self updateTitle]; +} + +- (void)updateTitle +{ + if (nil == m_title) + { + m_title = [NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()]; + } + + [super setTitle:m_title]; +} + @end @@ -271,6 +291,7 @@ public: static void UseHiDPI(bool hiDPI); static void SetCursor(NSCursor* cursor); static void SetWindowVisible(bool visible); + static void SetWindowTitle(const char* title); private: struct ModeIterator @@ -717,6 +738,16 @@ void CocoaVideo::SetWindowVisible(bool visible) } } +void CocoaVideo::SetWindowTitle(const char* title) +{ + if (CocoaVideo* const video = GetInstance()) + { + NSString* const nsTitle = nullptr == title ? nil : + [NSString stringWithCString:title encoding:NSISOLatin1StringEncoding]; + [video->m_window setTitle:nsTitle]; + } +} + void CocoaVideo::SetFullscreenMode(const int width, const int height) { @@ -813,9 +844,7 @@ void CocoaVideo::SetMode(const int width, const int height, const bool fullscree [[NSOpenGLContext currentContext] flushBuffer]; - static NSString* const TITLE_STRING = - [NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()]; - [m_window setTitle:TITLE_STRING]; + [m_window updateTitle]; if (![m_window isKeyWindow]) { @@ -1523,16 +1552,5 @@ void I_SetMainWindowVisible(bool visible) // each platform has its own specific version of this function. void I_SetWindowTitle(const char* title) { - if (title) - { - static NSString* const TITLE_STRING = - [NSString stringWithFormat:@"%s", title]; - [m_window setTitle:TITLE_STRING]; - } - else - { - static NSString* const TITLE_STRING = - [NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()]; - [m_window setTitle:TITLE_STRING]; - } + CocoaVideo::SetWindowTitle(title); } From 28d47d463f95742e73daece1aea3c566871ece88 Mon Sep 17 00:00:00 2001 From: raa-eruanna Date: Sat, 18 Nov 2017 08:11:27 -0500 Subject: [PATCH 6/6] - fix linux compile # Conflicts: # src/posix/sdl/sdlvideo.cpp --- src/posix/sdl/sdlvideo.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/posix/sdl/sdlvideo.cpp b/src/posix/sdl/sdlvideo.cpp index 6a0420ae81..8cae687397 100644 --- a/src/posix/sdl/sdlvideo.cpp +++ b/src/posix/sdl/sdlvideo.cpp @@ -555,6 +555,7 @@ ADD_STAT (blit) // each platform has its own specific version of this function. void I_SetWindowTitle(const char* caption) { + auto Screen = static_cast(screen)->GetSDLWindow(); if (caption) SDL_SetWindowTitle(static_cast(screen)->GetSDLWindow(), caption); else