aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11.c
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/x11.c
parent0da2b2695face3321e0e39c50b47f6156dfed4e2 (diff)
downloadpugl-2e8e543725e7e3b375321b93c0f5a2e684b60911.tar.gz
pugl-2e8e543725e7e3b375321b93c0f5a2e684b60911.tar.bz2
pugl-2e8e543725e7e3b375321b93c0f5a2e684b60911.zip
Add puglUnrealize()
Diffstat (limited to 'src/x11.c')
-rw-r--r--src/x11.c66
1 files changed, 50 insertions, 16 deletions
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)
{