Index: FL/Fl_Sys_Menu_Bar.H
===================================================================
--- FL/Fl_Sys_Menu_Bar.H	(revision 12582)
+++ FL/Fl_Sys_Menu_Bar.H	(working copy)
@@ -24,33 +24,49 @@
 class Fl_Sys_Menu_Bar_Driver;
 
 /**
-  A class to create, modify and delete menus that appear on Mac OS X in the menu bar at the top of the screen.
+ A class to create and modify menus that appear on Mac OS X in the menu bar at the top of the screen.
+ To use this class, just replace Fl_Menu_Bar by Fl_Sys_Menu_Bar, and, on the Mac platform,
+ a system menu at the top of the screen will be available. This menu will match an array
+ of Fl_Menu_Item's exactly as in all other FLTK menus.
  
   On other than Mac OS X platforms, Fl_Sys_Menu_Bar is a synonym of class Fl_Menu_Bar.
- \n To use this class, just replace Fl_Menu_Bar by Fl_Sys_Menu_Bar, and, on the Mac platform,
- a system menu at the top of the screen will be available. This menu will match an array
- of Fl_Menu_Item's exactly as with standard FLTK menus.
  
+  On the MacOS platform, the system menu bar of any FLTK app begins with the Application
+  menu which the FLTK library automatically constructs. Functions
+  Fl_Mac_App_Menu::custom_application_menu_items() and fl_mac_set_about() can be used to further customize
+  the Application menu. The FLTK library also automatically constructs and handles a Window menu which can be
+  further customized (or even removed) calling
+  Fl_Sys_Menu_Bar::window_menu_style(window_menu_style_enum style).
+  Other member functions of this class allow the app to generate the rest of the system menu bar.
+  It is recommended to localize the system menu bar using the standard Mac OS X localization procedure
+  (see \ref osissues_localize).
+ 
  Changes to the menu state are immediately visible in the menubar when they are made
  using member functions of the Fl_Sys_Menu_Bar class. Other changes (e.g., by a call to
  Fl_Menu_Item::set()) should be followed by a call to update() to be
  visible in the menubar across all platforms.
  
-  A few FLTK features are not supported by the Mac System menu:
+ A few FLTK menu features are not supported by the Mac System menu:
   \li no symbolic labels
   \li no embossed labels
   \li no font sizes
- 
- You can configure a callback for the 'About' menu item to invoke your own code with Fl_Sys_Menu_Bar::about().
- */
+  */
 class FL_EXPORT Fl_Sys_Menu_Bar : public Fl_Menu_Bar {
 protected:
   virtual void draw();
 public:
+  /** Possible styles of the Window menu in the system menu bar */
+  typedef enum {
+    no_window_menu = 0,     ///< No Window menu in the system menu bar
+    tabbing_mode_none,      ///< No tabbed windows, but the system menu bar contains a Window menu
+    tabbing_mode_automatic, ///< Windows are created by themselves but can be tabbed later
+    tabbing_mode_preferred, ///< Windows are tabbed when created
+    tabbing_mode_by_class   ///< The Window menu contains a "Merge Windows by Class" item
+  } window_menu_style_enum;
   Fl_Sys_Menu_Bar(int x,int y,int w,int h,const char *l=0);
   virtual ~Fl_Sys_Menu_Bar();
   static Fl_Sys_Menu_Bar_Driver *driver();
-  /** Return the system menu's array of Fl_Menu_Item's 
+  /** Return the system menu's array of Fl_Menu_Item's
    */
   const Fl_Menu_Item *menu() const {return Fl_Menu_::menu();}
   void menu(const Fl_Menu_Item *m);
@@ -81,6 +97,10 @@
   void shortcut (int i, int s);
   void setonly (Fl_Menu_Item *item);
   static void about(Fl_Callback *cb, void *data);
+  
+  static window_menu_style_enum window_menu_style();
+  static void window_menu_style(window_menu_style_enum style);
+  static void create_window_menu();
 };
 
 extern Fl_Sys_Menu_Bar *fl_sys_menu_bar;
Index: FL/Fl_Sys_Menu_Bar_Driver.H
===================================================================
--- FL/Fl_Sys_Menu_Bar_Driver.H	(revision 12582)
+++ FL/Fl_Sys_Menu_Bar_Driver.H	(working copy)
@@ -19,11 +19,15 @@
 #ifndef Fl_Sys_Menu_Bar_Driver_H
 #define Fl_Sys_Menu_Bar_Driver_H
 
+#if !defined(FL_DOXYGEN)
+
 #include <FL/Fl_Sys_Menu_Bar.H>
 
 class Fl_Sys_Menu_Bar_Driver {
   friend class Fl_Sys_Menu_Bar;
 public:
+  static Fl_Sys_Menu_Bar::window_menu_style_enum window_menu_style_;
+  static Fl_Sys_Menu_Bar_Driver *driver_; // to be assigned with a unique object of this class or of a derived class
   Fl_Sys_Menu_Bar *bar;
   Fl_Sys_Menu_Bar_Driver();
   virtual ~Fl_Sys_Menu_Bar_Driver();
@@ -45,11 +49,13 @@
   virtual void remove(int index) { bar->Fl_Menu_Bar::remove(index); }
   virtual void replace(int index, const char *name) { bar->Fl_Menu_Bar::replace(index, name); }
   virtual void mode(int i, int fl) { bar->Fl_Menu_Bar::mode(i, fl); }
-  
-  static Fl_Sys_Menu_Bar_Driver *driver_; // to be assigned with a unique object of this class or of a derived class
-  static Fl_Sys_Menu_Bar_Driver* new_driver();
+  virtual void create_window_menu() {}
+
+  static Fl_Sys_Menu_Bar::window_menu_style_enum window_menu_style() { return window_menu_style_; }
+  static void window_menu_style(Fl_Sys_Menu_Bar::window_menu_style_enum style) { window_menu_style_ = style; }
 };
 
+#endif // !defined(FL_DOXYGEN)
 
 #endif // Fl_Sys_Menu_Bar_Driver_H
 
Index: src/Fl_MacOS_Sys_Menu_Bar.mm
===================================================================
--- src/Fl_MacOS_Sys_Menu_Bar.mm	(revision 12582)
+++ src/Fl_MacOS_Sys_Menu_Bar.mm	(working copy)
@@ -17,10 +17,15 @@
 //
 
 #if defined(__APPLE__)
+#import <Cocoa/Cocoa.h>
 
 #include <FL/Fl_Sys_Menu_Bar_Driver.H>
 #include <FL/x.H>
 #include "drivers/Cocoa/Fl_MacOS_Sys_Menu_Bar_Driver.H"
+#include "flstring.h"
+#include <stdio.h>
+#include <ctype.h>
+#include <stdarg.h>
 
 
 Fl_MacOS_Sys_Menu_Bar_Driver* Fl_MacOS_Sys_Menu_Bar_Driver::new_driver() {
@@ -31,7 +36,6 @@
       delete driver_;
     }
     driver_ = once;
-    if (driver_->bar) driver_->update();
   }
   return once;
 }
@@ -40,14 +44,6 @@
 // static variable Fl_Sys_Menu_Bar_Driver::driver_ with an object of class Fl_MacOS_Sys_Menu_Bar_Driver
 static Fl_MacOS_Sys_Menu_Bar_Driver *unused = Fl_MacOS_Sys_Menu_Bar_Driver::new_driver();
 
-
-#import <Cocoa/Cocoa.h>
-
-#include "flstring.h"
-#include <stdio.h>
-#include <ctype.h>
-#include <stdarg.h>
-
 typedef const Fl_Menu_Item *pFl_Menu_Item;
 
 static Fl_Menu_Bar *custom_menu;
@@ -110,6 +106,7 @@
 {
   const Fl_Menu_Item *item = [self getFlItem];
   menu->picked(item);
+  Fl::flush();
   if ( item->flags & FL_MENU_TOGGLE ) {	// update the menu toggle symbol
     [self setState:(item->value() ? NSOnState : NSOffState)];
   }
@@ -486,6 +483,220 @@
     [item release];
   }
 }
+
+
+static void minimize_win_cb(Fl_Widget *, void *data)
+ {
+     [[NSApp mainWindow] miniaturize:nil];
+   }
+
+static void window_menu_cb(Fl_Widget *, void *data)
+ {
+     if (data) ((Fl_Window*)data)->show();
+     }
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
+
+static void previous_tab_cb(Fl_Widget *, void *data)
+ {
+     [[NSApp mainWindow] selectPreviousTab:nil];
+   }
+
+static void next_tab_cb(Fl_Widget *, void *data)
+ {
+     [[NSApp mainWindow] selectNextTab:nil];
+   }
+
+static void move_tab_cb(Fl_Widget *, void *data)
+ {
+     [[NSApp mainWindow] moveTabToNewWindow:nil];
+   Fl_MacOS_Sys_Menu_Bar_Driver::compute_window_menu_state();
+   }
+
+static void merge_all_windows_cb(Fl_Widget *, void *)
+{
+    Fl_Window *first = Fl::first_window();
+    if (first) {
+        [(NSWindow*)fl_xid(first) mergeAllWindows:nil];
+        Fl_MacOS_Sys_Menu_Bar_Driver::compute_window_menu_state();
+      }
+  }
+
+static bool merge_windows_for_class(Fl_Window *first)
+{
+    bool retval = false;
+    Fl_Window *win = first;
+    NSWindow *nsw = (NSWindow*)fl_xid(first), *nsw2;
+    while ((win = Fl::next_window(win)) != NULL) {
+        int diff = strcmp(win->xclass(), first->xclass());
+        if (win->parent() || diff) continue;
+        nsw2 = (NSWindow*)fl_xid(win);
+        [nsw2 addTabbedWindow:nsw ordered:NSWindowAbove];
+        retval = true;
+      }
+    return retval;
+  }
+
+static void merge_windows_by_class_cb(Fl_Widget *, void *)
+{
+  more:
+    Fl_Window *win = Fl::first_window();
+    NSWindow *nsw;
+    while (win) {
+        nsw = (NSWindow*)fl_xid(win);
+        if (!win->parent() && ![nsw tabbedWindows] && strcmp(win->xclass(), Fl_Window::default_xclass())) {
+            if (merge_windows_for_class(win)) goto more;
+          }
+        win = Fl::next_window(win);
+      }
+    Fl_MacOS_Sys_Menu_Bar_Driver::compute_window_menu_state();
+  }
+#endif
+
+static bool window_menu_installed = false;
+
+void Fl_MacOS_Sys_Menu_Bar_Driver::create_window_menu(void)
+{
+  if (window_menu_style() == Fl_Sys_Menu_Bar::no_window_menu) return;
+  if (window_menu_installed) return;
+  window_menu_installed = true;
+  int rank = 0;
+  if (fl_sys_menu_bar && fl_sys_menu_bar->menu()) {
+    if (fl_sys_menu_bar->find_index("Window") >= 0) { // there's already a "Window" menu -> don't create another
+      window_menu_style_ = Fl_Sys_Menu_Bar::no_window_menu;
+      return;
+    }
+    // put the Window menu last in menu bar or before Help if it's present
+    const Fl_Menu_Item *item = fl_sys_menu_bar->menu();
+    while (item->label() && strcmp(item->label(), "Help") != 0) {
+      item = item->next();
+    }
+    rank = fl_sys_menu_bar->find_index(item);
+  } else if (!fl_sys_menu_bar) {
+    fl_open_display();
+    new Fl_Sys_Menu_Bar(0,0,0,0);
+  }
+  rank = fl_sys_menu_bar->Fl_Menu_::insert(rank, "Window", 0, NULL, 0, FL_SUBMENU);
+  fl_sys_menu_bar->Fl_Menu_::insert(++rank, "Minimize", FL_COMMAND+'m', minimize_win_cb, 0, FL_MENU_DIVIDER);
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
+  if (fl_mac_os_version >= 101200 && window_menu_style() != Fl_Sys_Menu_Bar::tabbing_mode_none) {
+    fl_sys_menu_bar->Fl_Menu_::insert(++rank, "Show Previous Tab", FL_SHIFT+FL_CTRL+0x9, previous_tab_cb, 0, FL_MENU_INACTIVE);
+    fl_sys_menu_bar->Fl_Menu_::insert(++rank, "Show Next Tab", FL_CTRL+0x9, next_tab_cb, 0, FL_MENU_INACTIVE);
+    fl_sys_menu_bar->Fl_Menu_::insert(++rank, "Move Tab To New Window", 0, move_tab_cb, 0, FL_MENU_INACTIVE);
+    if (window_menu_style() == Fl_Sys_Menu_Bar::tabbing_mode_by_class)
+      fl_sys_menu_bar->Fl_Menu_::insert(++rank, "Merge Windows by Class", 0, merge_windows_by_class_cb, 0, FL_MENU_INACTIVE | FL_MENU_DIVIDER);
+    else
+      fl_sys_menu_bar->Fl_Menu_::insert(++rank, "Merge All Windows", 0, merge_all_windows_cb, 0, FL_MENU_INACTIVE | FL_MENU_DIVIDER);
+  }
+#endif
+  ((Fl_Menu_Item*)fl_sys_menu_bar->menu()+rank)->user_data(&window_menu_style_);
+  fl_sys_menu_bar->update();
+}
+
+int Fl_MacOS_Sys_Menu_Bar_Driver::find_first_window()
+{
+  int count = bar->size(), i;
+  for (i = 0; i < count; i++) {
+    if (bar->menu()[i].user_data() == &window_menu_style_) break;
+  }
+  return i < count ? i : -1;
+}
+
+void Fl_MacOS_Sys_Menu_Bar_Driver::new_window(Fl_Window *win)
+{
+  if (!window_menu_style() || !win->label()) return;
+  int index = find_first_window();
+  if (index < 0) return;
+  while ((bar->menu()+index+1)->label()) index++;
+  const char *p = win->iconlabel() ? win->iconlabel() : win->label();
+  int index2 = bar->Fl_Menu_::insert(index+1, p, 0, window_menu_cb, win, FL_MENU_RADIO);
+  setonly((Fl_Menu_Item*)bar->menu()+index2);
+  compute_window_menu_state();
+}
+
+void Fl_MacOS_Sys_Menu_Bar_Driver::remove_window(Fl_Window *win)
+{
+  if (!window_menu_style()) return;
+  int index = find_first_window() + 1;
+  if (index < 1) return;
+  while (true) {
+    Fl_Menu_Item *item = (Fl_Menu_Item*)bar->menu() + index;
+    if (!item->label()) return;
+    if (item->user_data() == win) {
+      bool doit = item->value();
+      remove(index);
+      if (doit) {
+        item = (Fl_Menu_Item*)bar->menu() + find_first_window() + 1;
+        if (item->label()) {
+          ((Fl_Window*)item->user_data())->show();
+          setonly(item);
+        }
+      }
+      break;
+    }
+    index++;
+  }
+  compute_window_menu_state();
+}
+
+void Fl_MacOS_Sys_Menu_Bar_Driver::rename_window(Fl_Window *win)
+{
+  if (!window_menu_style()) return;
+  int index = find_first_window() + 1;
+  if (index < 1) return;
+  while (true) {
+    Fl_Menu_Item *item = (Fl_Menu_Item*)bar->menu() + index;
+    if (!item->label()) return;
+    if (item->user_data() == win) {
+      replace(index, win->iconlabel() ? win->iconlabel() : win->label());
+      return;
+    }
+    index++;
+  }
+}
+
+void Fl_MacOS_Sys_Menu_Bar_Driver::compute_window_menu_state() {
+  if (!window_menu_installed || fl_mac_os_version < 101200 || !fl_sys_menu_bar || !window_menu_style() ||
+      window_menu_style() == Fl_Sys_Menu_Bar::tabbing_mode_none) return;
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
+  // computes active/inactive state of the Window menu items
+  // according to presence/absence of tabbed and tabbable windows
+  const int index = ((Fl_MacOS_Sys_Menu_Bar_Driver*)Fl_Sys_Menu_Bar::driver())->find_first_window(); // The "Merge All Windows" item
+  if (index < 0) return;
+  
+  // is the current window tabbed?
+  Fl_Window *win = Fl::first_window();
+  NSWindow *main = win ? (NSWindow*)fl_xid(win) : nil;
+  if ([main tabbedWindows]) {
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-1))->activate();
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-2))->activate();
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-3))->activate();
+  }
+  else {
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-1))->deactivate();
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-2))->deactivate();
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index-3))->deactivate();
+  }
+  // is there any untabbed, tabbable window?
+  const Fl_Menu_Item *item = fl_sys_menu_bar->menu() + index + 1;
+  int total = 0, untabbed = 0;
+  while (item->label()) {
+    total++;
+    NSWindow *nsw = (NSWindow*)fl_xid( (Fl_Window*)item->user_data() );
+    if (![nsw tabbedWindows] && [nsw tabbingMode] != NSWindowTabbingModeDisallowed) {
+      untabbed++;
+    }
+    item++;
+  }
+  if (untabbed > 0 && total >= 2)
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index))->activate();
+  else
+    ((Fl_Menu_Item*)(fl_sys_menu_bar->menu() + index))->deactivate();
+  
+  fl_sys_menu_bar->update();
+#endif
+}
+
 #endif /* __APPLE__ */
 
 //
Index: src/Fl_Sys_Menu_Bar.cxx
===================================================================
--- src/Fl_Sys_Menu_Bar.cxx	(revision 12582)
+++ src/Fl_Sys_Menu_Bar.cxx	(working copy)
@@ -166,7 +166,7 @@
  * \param data   a pointer transmitted as 2nd argument to the callback.
  */
 void Fl_Sys_Menu_Bar::about(Fl_Callback *cb, void *data) {
-  if (fl_sys_menu_bar) fl_sys_menu_bar->driver()->about(cb, data);
+  driver()->about(cb, data);
 }
 
 void Fl_Sys_Menu_Bar::draw() {
@@ -173,6 +173,53 @@
   driver()->draw();
 }
 
+
+
+/** Get the style of the Window menu in the system menu bar */
+Fl_Sys_Menu_Bar::window_menu_style_enum Fl_Sys_Menu_Bar::window_menu_style() {
+  return Fl_Sys_Menu_Bar_Driver::window_menu_style();
+}
+
+/** Set the desired style of the Window menu in the system menu bar.
+ This function, to be called before the first call to Fl_Window::show(), allows to
+ control whether the system menu bar should contain a Window menu,
+ and if yes, whether new windows should be displayed in tabbed form. These are
+ the effects of various values for \p style :
+ \li \c  no_window_menu : don't add a Window menu to the system menu bar
+ \li \c tabbing_mode_none :   add a simple Window menu to the system menu bar
+ \li \c  tabbing_mode_automatic : the window menu also contains "Merge All Windows" to group
+ all windows in a single tabbed display mode. This is the \b default Window menu style
+ for FLTK apps.
+ \li \c tabbing_mode_preferred : new windows are displayed in tabbed mode when first created
+ \li \c  tabbing_mode_by_class : the "Merge All Windows" Window menu item is replaced by "Merge Windows by Class".
+ This is useful if the app handles windows of distinct nature: windows
+ of the same class according to Fl_Window::xclass() are merged and displayed in tabbed form.
+ 
+ The Window menu, if present, is entirely created and controlled by the FLTK library.
+ Mac OS version 10.12 or later must be running for windows to be displayed in tabbed form.
+ Under non MacOS platforms, this function does nothing.
+ \version 1.4
+ */
+void Fl_Sys_Menu_Bar::window_menu_style(Fl_Sys_Menu_Bar::window_menu_style_enum style) {
+  Fl_Sys_Menu_Bar_Driver::window_menu_style(style);
+}
+
+/** Adds a Window menu, to the end of the system menu bar.
+ FLTK apps typically don't need to call this function which is automatically
+ called by the library the first time a window is shown. The default system menu bar
+ contains a Window menu with a "Merge All Windows" item.
+ Other Window menu styles can be obtained calling
+ Fl_Sys_Menu_Bar::window_menu_style(window_menu_style_enum) before the first Fl_Window::show().
+ Alternatively, an app can call create_window_menu() after having populated the system menu bar,
+ for example with menu(const Fl_Menu_Item *), and before the first Fl_Window::show().
+ 
+ This function does nothing on non MacOS platforms.
+ \version 1.4
+ */
+void Fl_Sys_Menu_Bar::create_window_menu() {
+  driver()->create_window_menu();
+}
+
 #if !defined(FL_DOXYGEN)
 Fl_Sys_Menu_Bar_Driver *Fl_Sys_Menu_Bar::driver() {
   if (!Fl_Sys_Menu_Bar_Driver::driver_) { // initialize this static variable if it was not initialized previously
@@ -186,6 +233,8 @@
 Fl_Sys_Menu_Bar_Driver::Fl_Sys_Menu_Bar_Driver() {bar = NULL;}
 
 Fl_Sys_Menu_Bar_Driver::~Fl_Sys_Menu_Bar_Driver() {}
+
+Fl_Sys_Menu_Bar::window_menu_style_enum Fl_Sys_Menu_Bar_Driver::window_menu_style_ = Fl_Sys_Menu_Bar::tabbing_mode_automatic;
 #endif // !defined(FL_DOXYGEN)
 
 //
Index: src/Fl_cocoa.mm
===================================================================
--- src/Fl_cocoa.mm	(revision 12582)
+++ src/Fl_cocoa.mm	(working copy)
@@ -1303,9 +1303,14 @@
 }
 - (void)windowDidMove:(NSNotification *)notif
 {
-  fl_lock_function();
   FLWindow *nsw = (FLWindow*)[notif object];
   Fl_Window *window = [nsw getFl_Window];
+  if ([[nsw contentView] frame].size.height != window->h()) {
+    // the contentView, but not the window frame, is resized. This happens with tabbed windows.
+    [self windowDidResize:notif];
+    return;
+  }
+  fl_lock_function();
   resize_from_system = window;
   NSPoint pt2;
   pt2 = [nsw convertBaseToScreen:NSMakePoint(0, [[nsw contentView] frame].size.height)];
@@ -1391,6 +1396,20 @@
   Fl_Window *window = [nsw getFl_Window];
   Fl::first_window(window);
   update_e_xy_and_e_xy_root(nsw);
+  if (fl_sys_menu_bar && Fl_MacOS_Sys_Menu_Bar_Driver::window_menu_style()) {
+    // select the corresponding Window menu item
+    int index = Fl_MacOS_Sys_Menu_Bar_Driver::driver()->find_first_window() + 1;
+    while (index > 0) {
+      Fl_Menu_Item *item = (Fl_Menu_Item*)fl_sys_menu_bar->menu() + index;
+      if (!item->label()) break;
+      if (item->user_data() == window) {
+        fl_sys_menu_bar->setonly(item);
+        Fl_MacOS_Sys_Menu_Bar_Driver::compute_window_menu_state();
+        break;
+      }
+      index++;
+    }
+  }
   fl_unlock_function();
 }
 - (void)windowDidDeminiaturize:(NSNotification *)notif
@@ -1857,7 +1876,13 @@
 
 
 // Gets the border sizes and the titlebar size
-static void get_window_frame_sizes(int &bx, int &by, int &bt) {
+static void get_window_frame_sizes(int &bx, int &by, int &bt, Fl_Window *win) {
+  FLWindow *flw = fl_xid(win);
+  if (flw) {
+    bt = [flw frame].size.height - [[flw contentView] frame].size.height;
+    bx = by = 0;
+    return;
+  }
   static int top = 0, left, bottom;
   if (!top) {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -1941,7 +1966,7 @@
     } else {
       ret = 1;
     }
-    get_window_frame_sizes(bx, by, bt);
+    get_window_frame_sizes(bx, by, bt, w);
   }
   // The coordinates of the whole window, including non-client area
   xoff = bx;
@@ -2267,6 +2292,11 @@
   fl_lock_function();
   FLWindow *cw = (FLWindow*)[self window];
   Fl_Window *window = [cw getFl_Window];
+  if (!window->parent() && rect.size.height != window->h() ) { // this happens with tabbed window
+        window->resize([cw frame].origin.x,
+                       main_screen_height - ([cw frame].origin.y + rect.size.height),
+                       rect.size.width, rect.size.height);
+  }
   through_drawRect = YES;
   Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window);
   if (fl_mac_os_version >= 100700) { // determine whether window is mapped to a retina display
@@ -2908,7 +2938,7 @@
   fl_open_display();
   NSInteger winlevel = NSNormalWindowLevel;
   NSUInteger winstyle;
-  Fl_MacOS_Sys_Menu_Bar_Driver::new_driver(); // useful if run in a static initializer
+  Fl_MacOS_Sys_Menu_Bar_Driver::new_driver()->create_window_menu();
   Fl_Window* w = pWindow;
   if (w->parent()) {
     w->border(0);
@@ -3018,6 +3048,18 @@
                                     contentRect:crect
                                       styleMask:winstyle];
   [cw setFrameOrigin:crect.origin];
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
+  if (fl_mac_os_version >= 101200) {
+    if (!w->parent() && (winstyle & NSTitledWindowMask) && (winstyle & NSResizableWindowMask)
+        && !w->modal() && !w->non_modal() && Fl_MacOS_Sys_Menu_Bar_Driver::window_menu_style() > Fl_Sys_Menu_Bar::tabbing_mode_none) {
+      if (Fl_MacOS_Sys_Menu_Bar_Driver::window_menu_style() == Fl_Sys_Menu_Bar::tabbing_mode_preferred)
+        [cw setTabbingMode:NSWindowTabbingModePreferred];
+      else [cw setTabbingMode:NSWindowTabbingModeAutomatic];
+    } else {
+      [cw setTabbingMode:NSWindowTabbingModeDisallowed];
+    }
+  }
+#endif
   if (!w->parent()) {
     [cw setHasShadow:YES];
     [cw setAcceptsMouseMovedEvents:YES];
@@ -3094,7 +3136,10 @@
   } else { // a top-level window
     [cw makeKeyAndOrderFront:nil];
   }
-  
+  if (fl_sys_menu_bar && Fl_MacOS_Sys_Menu_Bar_Driver::window_menu_style() && !w->parent() && w->border() &&
+      !w->modal() && !w->non_modal()) {
+    Fl_MacOS_Sys_Menu_Bar_Driver::driver()->new_window(w);
+  }
   int old_event = Fl::e_number;
   w->handle(Fl::e_number = FL_SHOW);
   Fl::e_number = old_event;
@@ -3110,7 +3155,7 @@
  */
 void Fl_Cocoa_Window_Driver::size_range() {
   int bx, by, bt;
-  get_window_frame_sizes(bx, by, bt);
+  get_window_frame_sizes(bx, by, bt, pWindow);
   Fl_Window_Driver::size_range();
   NSSize minSize = NSMakeSize(minw(), minh() + bt);
   NSSize maxSize = NSMakeSize(maxw() ? maxw():32000, maxh() ? maxh() + bt:32000);
@@ -3161,6 +3206,8 @@
 void Fl_Cocoa_Window_Driver::label(const char *name, const char *mininame) {
   if (shown() || Fl_X::i(pWindow)) {
     q_set_window_title(fl_xid(pWindow), name, mininame);
+    if (fl_sys_menu_bar && Fl_Sys_Menu_Bar_Driver::window_menu_style())
+      Fl_MacOS_Sys_Menu_Bar_Driver::driver()->rename_window(pWindow);
   }
 }
 
@@ -3219,7 +3266,7 @@
       }
       pWindow->Fl_Group::resize(X,Y,W,H);
       // transmit changes in FLTK coords to cocoa
-      get_window_frame_sizes(bx, by, bt);
+      get_window_frame_sizes(bx, by, bt, pWindow);
       bx = X; by = Y;
       parent = pWindow->window();
       while (parent) {
@@ -3537,6 +3584,8 @@
 }
 
 void Fl_Cocoa_Window_Driver::destroy(FLWindow *xid) {
+  if (fl_sys_menu_bar && Fl_Sys_Menu_Bar_Driver::window_menu_style())
+    Fl_MacOS_Sys_Menu_Bar_Driver::driver()->remove_window([xid getFl_Window]);
   [xid close];
 }
 
@@ -4275,7 +4324,7 @@
   if (!shown() || parent() || !border() || !visible())
     return w();
   int bx, by, bt;
-  get_window_frame_sizes(bx, by, bt);
+  get_window_frame_sizes(bx, by, bt, pWindow);
   return w() + 2 * bx;
 }
 
@@ -4284,7 +4333,7 @@
   if (!shown() || parent() || !border() || !visible())
     return h();
   int bx, by, bt;
-  get_window_frame_sizes(bx, by, bt);
+  get_window_frame_sizes(bx, by, bt, pWindow);
   return h() + bt + by;
 }
 
Index: src/drivers/Cocoa/Fl_MacOS_Sys_Menu_Bar_Driver.H
===================================================================
--- src/drivers/Cocoa/Fl_MacOS_Sys_Menu_Bar_Driver.H	(revision 12582)
+++ src/drivers/Cocoa/Fl_MacOS_Sys_Menu_Bar_Driver.H	(working copy)
@@ -1,7 +1,7 @@
 //
 // "$Id$"
 //
-// system menu bar widget for the Fast Light Tool Kit (FLTK).
+// Definition of class Fl_MacOS_Sys_Menu_Bar_Driver for the Fast Light Tool Kit (FLTK).
 //
 // Copyright 2017 by Bill Spitzak and others.
 //
@@ -39,7 +39,15 @@
   virtual void remove(int index);
   virtual void replace(int index, const char *name);
   virtual void mode(int i, int fl);
+  virtual void create_window_menu();
+
+  int find_first_window();
+  void new_window(Fl_Window *win);
+  void remove_window(Fl_Window *win);
+  void rename_window(Fl_Window *win);
+  static void compute_window_menu_state();
   static Fl_MacOS_Sys_Menu_Bar_Driver* new_driver();
+  static inline Fl_MacOS_Sys_Menu_Bar_Driver *driver() {return new_driver();}
 };
 
 
Index: test/menubar.cxx
===================================================================
--- test/menubar.cxx	(revision 12582)
+++ test/menubar.cxx	(working copy)
@@ -257,6 +257,7 @@
     {0}
   };
   Fl_Mac_App_Menu::custom_application_menu_items(custom);
+  Fl_Sys_Menu_Bar::window_menu_style(Fl_Sys_Menu_Bar::no_window_menu);
 #endif
   window.show(argc, argv);
   return Fl::run();
