[master] 5830226 - Change procedure to capture window titlebar for macOS ≥ 10.15

GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 5830226 - Change procedure to capture window titlebar for macOS ≥ 10.15 "ManoloFLTK" 01:47 Oct 11 top right image
 
commit 5830226aab4428e77e7aa4078e0f544aef92f326
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Sun Oct 11 10:42:51 2020 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Sun Oct 11 10:43:01 2020 +0200

    Change procedure to capture window titlebar for macOS â?¥ 10.15
    
    That is necessary to support macOS Big Sur because previous procedure
    did not work for tabbed windows. The new procedure is potentially
    usable from macOS 10.5, but tested at this stage for macOS â?¥ 10.15.

 src/Fl_cocoa.mm                                      | 17 ++++++++++++++++-
 src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm         |  2 +-
 src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H           |  2 +-
 src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx         |  4 ++--
 src/drivers/Quartz/Fl_Quartz_Copy_Surface_Driver.cxx |  2 +-
 5 files changed, 21 insertions(+), 6 deletions(-)

diff --git src/Fl_cocoa.mm src/Fl_cocoa.mm
index c7f4e41..f70cc62 100644
--- src/Fl_cocoa.mm
+++ src/Fl_cocoa.mm
@@ -4382,7 +4382,22 @@ void Fl_Cocoa_Window_Driver::draw_layer_to_context(CALayer *layer, CGContextRef
     CGContextFillRect(gc, CGRectMake(0, 0, w, h));
   }
   CGContextSetShouldAntialias(gc, true);
-  [layer renderInContext:gc]; // 10.5
+  if (fl_mac_os_version >= 101500) {
+    FLWindow *flwin = fl_xid(pWindow);
+    [flwin makeMainWindow];
+    [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];
+    NSInteger win_id = [flwin windowNumber];
+    CFArrayRef array = CFArrayCreate(NULL, (const void**)&win_id, 1, NULL);
+    NSRect rr = [flwin frame];
+    rr.origin.y += rr.size.height - h;
+    rr.size.height = h;
+    rr.origin.y = CGDisplayBounds(CGMainDisplayID()).size.height - (rr.origin.y + rr.size.height);
+    CGImageRef img = CGWindowListCreateImageFromArray(rr, array, kCGWindowImageBoundsIgnoreFraming); // 10.5
+    CFRelease(array);
+    CGContextDrawImage(gc, CGRectMake(0, 0, w, h), img);
+    CGImageRelease(img);
+  } else
+    [layer renderInContext:gc]; // 10.5
   CGContextRestoreGState(gc);
 #endif
 }
diff --git src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
index 2a09556..9cf95a2 100644
--- src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
+++ src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
@@ -405,7 +405,7 @@ void Fl_Cocoa_Printer_Driver::draw_decorated_window(Fl_Window *win, int x_offset
     CGContextSaveGState(gc);
     CGContextTranslateCTM(gc, x_offset - 0.5, y_offset + bt - 0.5);
     CGContextScaleCTM(gc, 1/s, -1/s);
-    Fl_Cocoa_Window_Driver::draw_layer_to_context(layer, gc, win->w() * s, bt);
+    Fl_Cocoa_Window_Driver::driver(win)->draw_layer_to_context(layer, gc, win->w() * s, bt);
     CGContextRestoreGState(gc);
     bool clip_corners = fl_mac_os_version >= 100600 && !win->parent();
     if (clip_corners) {
diff --git src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
index dedc7bb..2b48549 100644
--- src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
+++ src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
@@ -140,7 +140,7 @@ public:
   virtual void capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl_RGB_Image*& left, Fl_RGB_Image*& bottom, Fl_RGB_Image*& right);
   virtual void wait_for_expose();
   CALayer *get_titlebar_layer();
-  static void draw_layer_to_context(CALayer *layer, CGContextRef gc, int w, int h);
+  void draw_layer_to_context(CALayer *layer, CGContextRef gc, int w, int h);
   virtual int scroll(int src_x, int src_y, int src_w, int src_h, int dest_x, int dest_y, void (*draw_area)(void*, int,int,int,int), void* data);
 
   // these functions are OpenGL-related and use objective-c
diff --git src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
index 6525855..cec8e0b 100644
--- src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
+++ src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
@@ -328,8 +328,8 @@ void Fl_Cocoa_Window_Driver::capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl
   CGContextClearRect(auxgc, CGRectMake(0,0,data_w,data_h));
   CGContextScaleCTM(auxgc, factor, factor);
   if (layer) {
-    Fl_Cocoa_Window_Driver::draw_layer_to_context(layer, auxgc, scaled_w, htop);
-    if (fl_mac_os_version >= 101300) {
+    draw_layer_to_context(layer, auxgc, scaled_w, htop);
+    if (fl_mac_os_version >= 101300 && fl_mac_os_version < 101500) {
       // drawn layer is left transparent and alpha-premultiplied: demultiply it and set it opaque.
       uchar *p = rgba;
       uchar *last = rgba + data_w * data_h * 4;
diff --git src/drivers/Quartz/Fl_Quartz_Copy_Surface_Driver.cxx src/drivers/Quartz/Fl_Quartz_Copy_Surface_Driver.cxx
index a1377a5..5f37355 100644
--- src/drivers/Quartz/Fl_Quartz_Copy_Surface_Driver.cxx
+++ src/drivers/Quartz/Fl_Quartz_Copy_Surface_Driver.cxx
@@ -97,7 +97,7 @@ void Fl_Quartz_Copy_Surface_Driver::draw_decorated_window(Fl_Window *win, int x_
   CGContextTranslateCTM(gc, x_offset - 0.5, y_offset + bt - 0.5);
   float s = Fl::screen_scale(win->screen_num());
   CGContextScaleCTM(gc, 1/s, s >= 1 ? -1/s : -1);
-  Fl_Cocoa_Window_Driver::draw_layer_to_context(layer, gc, win->w() * s, bt*s);
+  Fl_Cocoa_Window_Driver::driver(win)->draw_layer_to_context(layer, gc, win->w() * s, bt*s);
   CGContextRestoreGState(gc);
   draw(win, x_offset, y_offset + bt); // print the window inner part
 }
Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2020 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.