aboutsummaryrefslogtreecommitdiffstats
path: root/pugl/detail/mac.m
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-07-22 16:30:53 +0200
committerDavid Robillard <d@drobilla.net>2019-09-03 08:32:16 +0200
commite83c2b421d140244a6b9edb051b3e0d4aacda332 (patch)
tree398e49f43c96f4602496874fa7b3680236138720 /pugl/detail/mac.m
parent5081d49f9f08596c07a8ed32430a4fa3e1baf352 (diff)
downloadpugl-e83c2b421d140244a6b9edb051b3e0d4aacda332.tar.gz
pugl-e83c2b421d140244a6b9edb051b3e0d4aacda332.tar.bz2
pugl-e83c2b421d140244a6b9edb051b3e0d4aacda332.zip
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.
Diffstat (limited to 'pugl/detail/mac.m')
-rw-r--r--pugl/detail/mac.m38
1 files changed, 26 insertions, 12 deletions
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;