From e83c2b421d140244a6b9edb051b3e0d4aacda332 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 22 Jul 2019 16:30:53 +0200 Subject: Add PuglWorld The old API was broken for programs that manage multiple views, since it was impossible to wait for events on any view. There are also several functions in the API which are not actually associated with views at all, so those can now be moved to the more appropriate PuglWorld to make this more clear. The old puglInit() and puglDestroy() functions are preserved for compatibility, but marked as deprecated. --- pugl/detail/mac.m | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'pugl/detail/mac.m') diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m index 385070d..23344ed 100644 --- a/pugl/detail/mac.m +++ b/pugl/detail/mac.m @@ -566,7 +566,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type) - (void) urgentTick { - [NSApp requestUserAttention:NSInformationalRequest]; + [puglview->world->impl->app requestUserAttention:NSInformationalRequest]; } - (void) viewDidEndLiveResize @@ -636,8 +636,27 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type) @end +PuglWorldInternals* +puglInitWorldInternals(void) +{ + PuglWorldInternals* impl = (PuglWorldInternals*)calloc( + 1, sizeof(PuglWorldInternals)); + + impl->app = [NSApplication sharedApplication]; + impl->autoreleasePool = [NSAutoreleasePool new]; + + return impl; +} + +void +puglFreeWorldInternals(PuglWorld* world) +{ + [world->impl->autoreleasePool drain]; + free(world->impl); +} + PuglInternals* -puglInitInternals(void) +puglInitViewInternals(void) { return (PuglInternals*)calloc(1, sizeof(PuglInternals)); } @@ -660,9 +679,6 @@ puglCreateWindow(PuglView* view, const char* title) { PuglInternals* impl = view->impl; - [NSAutoreleasePool new]; - impl->app = [NSApplication sharedApplication]; - // Create wrapper view to handle input impl->wrapperView = [PuglWrapperView alloc]; impl->wrapperView->puglview = view; @@ -727,7 +743,7 @@ puglCreateWindow(PuglView* view, const char* title) } [window setContentView:impl->wrapperView]; - [impl->app activateIgnoringOtherApps:YES]; + [view->world->impl->app activateIgnoringOtherApps:YES]; [window makeFirstResponder:impl->wrapperView]; [window makeKeyAndOrderFront:window]; } @@ -752,7 +768,7 @@ puglHideWindow(PuglView* view) } void -puglDestroy(PuglView* view) +puglFreeViewInternals(PuglView* view) { view->backend->destroy(view); [view->impl->wrapperView removeFromSuperview]; @@ -764,9 +780,7 @@ puglDestroy(PuglView* view) if (view->impl->window) { [view->impl->window release]; } - free(view->windowClass); free(view->impl); - free(view); } void @@ -791,7 +805,7 @@ void puglRequestAttention(PuglView* view) { if (![view->impl->window isKeyWindow]) { - [NSApp requestUserAttention:NSInformationalRequest]; + [view->world->impl->app requestUserAttention:NSInformationalRequest]; view->impl->wrapperView->urgentTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:view->impl->wrapperView @@ -820,7 +834,7 @@ puglProcessEvents(PuglView* view) { if (view->impl->nextEvent) { // Process event that was dequeued earier by puglWaitForEvent - [view->impl->app sendEvent: view->impl->nextEvent]; + [view->world->impl->app sendEvent: view->impl->nextEvent]; view->impl->nextEvent = NULL; } @@ -830,7 +844,7 @@ puglProcessEvents(PuglView* view) untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]);) { - [view->impl->app sendEvent: ev]; + [view->world->impl->app sendEvent: ev]; } return PUGL_SUCCESS; -- cgit v1.2.1