Skip to content

Commit

Permalink
- Implement Fl_Window::wait_for_expose() for Mac OS:
Browse files Browse the repository at this point in the history
The -[NSWindow makeKeyAndOrderFront:] message used to make the window appear on the screen,
but, starting with 10.10 (approximately), this changed, and it became necessary to query for events
for a new window to appear on the screen. With 10.11 two event messages are needed.
The solution is therefore to implement Fl_Window::wait_for_expose().

- Calling NSDisableScreenUpdates()()/NSEnableScreenUpdates() before and after window updates
greatly accelerates multi-window update operations.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10826 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Aug 7, 2015
1 parent 9a38c24 commit cc36ab5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions FL/mac.H
Expand Up @@ -208,6 +208,7 @@ public:
static Fl_Fontdesc* calc_fl_fonts(void); // computes the fl_fonts global variable
static int dnd(int use_selection); // call Fl_X::dnd(1) to support text dragging
static int calc_mac_os_version(void); // computes the fl_mac_os_version global variable
static void do_wait_for_expose();
private:
#if FLTK_ABI_VERSION >= 10304
CGRect* subRect_; // makes sure subwindow remains inside its parent window
Expand Down
4 changes: 4 additions & 0 deletions src/Fl_Window.cxx
Expand Up @@ -462,9 +462,13 @@ void Fl_Window::free_icons() {

void Fl_Window::wait_for_expose() {
if (!shown()) return;
#ifdef __APPLE__
Fl_X::do_wait_for_expose();
#else
while (!i || i->wait_for_expose) {
Fl::wait();
}
#endif
}

//
Expand Down
15 changes: 10 additions & 5 deletions src/Fl_cocoa.mm
Expand Up @@ -779,7 +779,9 @@ int fl_wait( double time )
// the idle function may turn off idle, we can then wait:
if (Fl::idle) time_to_wait = 0.0;
}
NSDisableScreenUpdates(); // 10.3 Makes updates to all windows appear as a single event
Fl::flush();
NSEnableScreenUpdates(); // 10.3
if (Fl::idle && !in_idle) // 'idle' may have been set within flush()
time_to_wait = 0.0;
double retval = fl_wait(time_to_wait);
Expand Down Expand Up @@ -3047,10 +3049,6 @@ static void set_subwindow_frame(Fl_Window *w) { // maps a subwindow at its corre
x->changed_resolution(false);
#endif
[cw makeKeyAndOrderFront:nil];
if (fl_mac_os_version >= 101100) { // these two messages seem necessary to make the window appear on screen
[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];
[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];
}
}

if (!w->parent()) {
Expand Down Expand Up @@ -3087,6 +3085,13 @@ static void set_subwindow_frame(Fl_Window *w) { // maps a subwindow at its corre
}
}

void Fl_X::do_wait_for_expose()
{ // this will make freshly created windows appear on the screen
[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];
if (fl_mac_os_version >= 101100) { // this extra message seems necessary with 10.11
[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];
}
}

/*
* returns pointer to the filename, or null if name ends with ':'
Expand Down Expand Up @@ -3340,7 +3345,7 @@ to YES and calls handleUpdateEvent() that calls Fl_X::flush(). Fl_X::flush() set
void Fl_X::q_release_context(Fl_X *x) {
if (x && x->gc!=fl_gc) return;
if (!fl_gc) return;
CGContextRestoreGState(fl_gc); // KEEP IT: matches the CGContextSaveGState of make_current
CGContextRestoreGState(fl_gc); // match the CGContextSaveGState's of make_current
CGContextRestoreGState(fl_gc);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
Fl_X::set_high_resolution(false);
Expand Down

0 comments on commit cc36ab5

Please sign in to comment.