aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-01-04 11:02:32 -0500
committerDavid Robillard <d@drobilla.net>2023-01-04 13:28:46 -0500
commit2e8e543725e7e3b375321b93c0f5a2e684b60911 (patch)
tree5ed8d077186df5a01c881d764a872f9daaa3060a /src
parent0da2b2695face3321e0e39c50b47f6156dfed4e2 (diff)
downloadpugl-2e8e543725e7e3b375321b93c0f5a2e684b60911.tar.gz
pugl-2e8e543725e7e3b375321b93c0f5a2e684b60911.tar.bz2
pugl-2e8e543725e7e3b375321b93c0f5a2e684b60911.zip
Add puglUnrealize()
Diffstat (limited to 'src')
-rw-r--r--src/common.c6
-rw-r--r--src/mac.m39
-rw-r--r--src/win.c26
-rw-r--r--src/x11.c66
4 files changed, 114 insertions, 23 deletions
diff --git a/src/common.c b/src/common.c
index 9ea3594..c3f0818 100644
--- a/src/common.c
+++ b/src/common.c
@@ -1,4 +1,4 @@
-// Copyright 2012-2022 David Robillard <d@drobilla.net>
+// Copyright 2012-2023 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
// Common implementations of public API functions in the core library
@@ -136,10 +136,6 @@ puglNewView(PuglWorld* const world)
void
puglFreeView(PuglView* view)
{
- if (view->eventFunc && view->backend) {
- puglDispatchSimpleEvent(view, PUGL_DESTROY);
- }
-
// Remove from world view list
PuglWorld* world = view->world;
for (size_t i = 0; i < world->numViews; ++i) {
diff --git a/src/mac.m b/src/mac.m
index 0ba95ca..658c807 100644
--- a/src/mac.m
+++ b/src/mac.m
@@ -1,4 +1,4 @@
-// Copyright 2012-2022 David Robillard <d@drobilla.net>
+// Copyright 2012-2023 David Robillard <d@drobilla.net>
// Copyright 2017 Hanspeter Portner <dev@open-music-kontrollers.ch>
// SPDX-License-Identifier: ISC
@@ -1171,6 +1171,43 @@ puglRealize(PuglView* view)
}
PuglStatus
+puglUnrealize(PuglView* const view)
+{
+ PuglInternals* const impl = view->impl;
+ if (!impl || !impl->wrapperView) {
+ return PUGL_FAILURE;
+ }
+
+ puglDispatchSimpleEvent(view, PUGL_DESTROY);
+
+ if (view->backend) {
+ view->backend->destroy(view);
+ }
+
+ if (impl->wrapperView) {
+ [impl->wrapperView removeFromSuperview];
+ impl->wrapperView->puglview = NULL;
+ }
+
+ if (impl->window) {
+ [impl->window close];
+ }
+
+ if (impl->wrapperView) {
+ [impl->wrapperView release];
+ impl->wrapperView = NULL;
+ }
+
+ if (impl->window) {
+ [impl->window release];
+ impl->window = NULL;
+ }
+
+ memset(&view->lastConfigure, 0, sizeof(PuglConfigureEvent));
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
puglShow(PuglView* view)
{
if (!view->impl->wrapperView) {
diff --git a/src/win.c b/src/win.c
index e41222b..13ad090 100644
--- a/src/win.c
+++ b/src/win.c
@@ -1,4 +1,4 @@
-// Copyright 2012-2022 David Robillard <d@drobilla.net>
+// Copyright 2012-2023 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
#include "win.h"
@@ -275,6 +275,30 @@ puglRealize(PuglView* view)
}
PuglStatus
+puglUnrealize(PuglView* const view)
+{
+ PuglInternals* const impl = view->impl;
+ if (!impl || !impl->hwnd) {
+ return PUGL_FAILURE;
+ }
+
+ puglDispatchSimpleEvent(view, PUGL_DESTROY);
+
+ if (view->backend) {
+ view->backend->destroy(view);
+ }
+
+ ReleaseDC(view->impl->hwnd, view->impl->hdc);
+ view->impl->hdc = NULL;
+
+ DestroyWindow(view->impl->hwnd);
+ view->impl->hwnd = NULL;
+
+ memset(&view->lastConfigure, 0, sizeof(PuglConfigureEvent));
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
puglShow(PuglView* view)
{
PuglInternals* impl = view->impl;
diff --git a/src/x11.c b/src/x11.c
index 271a0fb..1dc4f9d 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -1,4 +1,4 @@
-// Copyright 2012-2022 David Robillard <d@drobilla.net>
+// Copyright 2012-2023 David Robillard <d@drobilla.net>
// Copyright 2013 Robin Gareus <robin@gareus.org>
// Copyright 2011-2012 Ben Loftis, Harrison Consoles
// SPDX-License-Identifier: ISC
@@ -344,6 +344,21 @@ defineCursorName(PuglView* const view, const char* const name)
}
#endif
+static void
+clearX11Clipboard(PuglX11Clipboard* const board)
+{
+ for (unsigned long i = 0; i < board->numFormats; ++i) {
+ free(board->formatStrings[i]);
+ board->formatStrings[i] = NULL;
+ }
+
+ board->source = None;
+ board->numFormats = 0;
+ board->acceptedFormatIndex = UINT32_MAX;
+ board->acceptedFormat = None;
+ board->data.len = 0;
+}
+
PuglStatus
puglRealize(PuglView* const view)
{
@@ -474,6 +489,40 @@ puglRealize(PuglView* const view)
}
PuglStatus
+puglUnrealize(PuglView* const view)
+{
+ PuglInternals* const impl = view->impl;
+ if (!impl || !impl->win) {
+ return PUGL_FAILURE;
+ }
+
+ puglDispatchSimpleEvent(view, PUGL_DESTROY);
+ clearX11Clipboard(&impl->clipboard);
+
+ if (impl->xic) {
+ XDestroyIC(impl->xic);
+ impl->xic = None;
+ }
+
+ if (view->backend) {
+ view->backend->destroy(view);
+ }
+
+ if (view->world->impl->display && impl->win) {
+ XDestroyWindow(view->world->impl->display, impl->win);
+ impl->win = None;
+ }
+
+ XFree(impl->vi);
+ impl->vi = NULL;
+
+ memset(&view->lastConfigure, 0, sizeof(PuglConfigureEvent));
+ memset(&view->impl->pendingConfigure, 0, sizeof(PuglEvent));
+ memset(&view->impl->pendingExpose, 0, sizeof(PuglEvent));
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
puglShow(PuglView* const view)
{
PuglStatus st = view->impl->win ? PUGL_SUCCESS : puglRealize(view);
@@ -493,21 +542,6 @@ puglHide(PuglView* const view)
return PUGL_SUCCESS;
}
-static void
-clearX11Clipboard(PuglX11Clipboard* const board)
-{
- for (unsigned long i = 0; i < board->numFormats; ++i) {
- free(board->formatStrings[i]);
- board->formatStrings[i] = NULL;
- }
-
- board->source = None;
- board->numFormats = 0;
- board->acceptedFormatIndex = UINT32_MAX;
- board->acceptedFormat = None;
- board->data.len = 0;
-}
-
void
puglFreeViewInternals(PuglView* const view)
{