From e43dee9d8a74fda6325054fc95e99992b8ba5a16 Mon Sep 17 00:00:00 2001
From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
Date: Wed, 10 Jun 2020 17:22:29 +0200
Subject: [PATCH] Fix for "Fullscreen_off removing the icon from the titlebar
 on MacOS" in fltk.coredev

---
 src/Fl_cocoa.mm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index d7d7ec151..31f5bd08e 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -3188,6 +3188,19 @@ static NSUInteger calc_win_style(Fl_Window *win) {
   } else winstyle = NSBorderlessWindowMask;
   return winstyle;
 }
+
+static void restore_window_title_and_icon(Fl_Window *pWindow, NSImage *icon) {
+  FLWindow *nswin = fl_xid(pWindow);
+  q_set_window_title(nswin, pWindow->label(), pWindow->iconlabel());
+  if (!icon) icon = ((Fl_Cocoa_Screen_Driver*)Fl::screen_driver())->default_icon;
+  if (icon && ([nswin styleMask] & NSTitledWindowMask) && pWindow->label() && strlen(pWindow->label())>0) {
+    NSButton *icon_button = [nswin standardWindowButton:NSWindowDocumentIconButton];
+    if (icon_button) {
+      [icon setSize:[icon_button frame].size];
+      [icon_button setImage:icon];
+    }
+  }
+}
 #endif
 
 void Fl_Cocoa_Window_Driver::fullscreen_off(int X, int Y, int W, int H) {
@@ -3200,6 +3213,7 @@ void Fl_Cocoa_Window_Driver::fullscreen_off(int X, int Y, int W, int H) {
     else if (pWindow->non_modal()) level = non_modal_window_level();
     [nswin setLevel:level];
     [nswin setStyleMask:calc_win_style(pWindow)]; //10.6
+    restore_window_title_and_icon(pWindow, icon_image);
     pWindow->resize(X, Y, W, H);
   } else
 #endif
@@ -3216,6 +3230,7 @@ void Fl_Cocoa_Window_Driver::use_border() {
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
   if (fl_mac_os_version >= 100600) {
     [fl_xid(pWindow) setStyleMask:calc_win_style(pWindow)]; // 10.6
+    if (border()) restore_window_title_and_icon(pWindow, icon_image);
     pWindow->redraw();
   }
   else
-- 
GitLab