From b0fa21017b387ed4fa1cb245a0d677034ef76843 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 18 Nov 2017 13:24:17 +0200 Subject: [PATCH] Implemented setting of window title in Cocoa backend --- src/posix/cocoa/i_video.mm | 44 +++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index c89a6601d..a1bc96403 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,10 +1552,5 @@ 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]; - else - TITLE_STRING = [NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()]; - [m_window setTitle:TITLE_STRING]; -} \ No newline at end of file + CocoaVideo::SetWindowTitle(title); +}