From 35bb9ba9d36e8dd474ea1c133fc055bb132d8c8c 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 # 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 2c305b49e..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,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); }