From dc90b4f5d902218b4e1ccfa5a2b3c1a0b24a7995 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Sep 2015 13:00:18 -0400 Subject: Fix destruction of cairo context. --- pugl/pugl_x11.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pugl/pugl_x11.c') diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index da33063..a48edde 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -137,7 +137,8 @@ destroyContext(PuglView* view) #endif #ifdef PUGL_HAVE_CAIRO if (view->ctx_type == PUGL_CAIRO) { - glXDestroyContext(view->impl->display, view->impl->ctx); + cairo_destroy(view->impl->cr); + cairo_surface_destroy(view->impl->surface); } #endif } -- cgit v1.2.3 From ae2153511097fc0cc34c0456ebbb13fd4f5c79ec Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Sep 2015 13:00:37 -0400 Subject: Fix resizing with cairo context. --- pugl/pugl_x11.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'pugl/pugl_x11.c') diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index a48edde..bd85b37 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -43,17 +43,18 @@ #include "pugl/pugl_internal.h" struct PuglInternalsImpl { - Display* display; - int screen; - Window win; - XIM xim; - XIC xic; + Display* display; + int screen; + Window win; + XIM xim; + XIC xic; #ifdef PUGL_HAVE_CAIRO - cairo_t* cr; + cairo_surface_t* surface; + cairo_t* cr; #endif #ifdef PUGL_HAVE_GL - GLXContext ctx; - Bool doubleBuffered; + GLXContext ctx; + Bool doubleBuffered; #endif }; @@ -118,9 +119,9 @@ createContext(PuglView* view, XVisualInfo* vi) #endif #ifdef PUGL_HAVE_CAIRO if (view->ctx_type == PUGL_CAIRO) { - cairo_surface_t* surface = cairo_xlib_surface_create( + view->impl->surface = cairo_xlib_surface_create( impl->display, impl->win, vi->visual, view->width, view->height); - if (!(impl->cr = cairo_create(surface))) { + if (!(impl->cr = cairo_create(view->impl->surface))) { fprintf(stderr, "failed to create cairo context\n"); } } @@ -486,6 +487,7 @@ PuglStatus puglProcessEvents(PuglView* view) { XEvent xevent; + bool resized = false; while (XPending(view->impl->display) > 0) { XNextEvent(view->impl->display, &xevent); bool ignore = false; @@ -516,6 +518,8 @@ puglProcessEvents(PuglView* view) XSetICFocus(view->impl->xic); } else if (xevent.type == FocusOut) { XUnsetICFocus(view->impl->xic); + } else if (xevent.type == ConfigureNotify) { + resized = true; } if (!ignore) { @@ -525,6 +529,15 @@ puglProcessEvents(PuglView* view) } } + if (resized) { +#ifdef PUGL_HAVE_CAIRO + if (view->ctx_type == PUGL_CAIRO) { + cairo_xlib_surface_set_size( + view->impl->surface, view->width, view->height); + } +#endif + } + if (view->redisplay) { const PuglEventExpose expose = { PUGL_EXPOSE, view, true, 0, 0, view->width, view->height, 0 -- cgit v1.2.3 From 6b4a5a128ef5d87374dfef017cd20e069c068a4b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Sep 2015 15:22:49 -0400 Subject: Add support for aspect ratio constraints. Currently only implemented on X11. --- pugl/pugl_x11.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'pugl/pugl_x11.c') diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index bd85b37..6375609 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -214,10 +214,20 @@ puglCreateWindow(PuglView* view, const char* title) sizeHints.max_width = view->width; sizeHints.max_height = view->height; XSetNormalHints(impl->display, impl->win, &sizeHints); - } else if (view->min_width || view->min_height) { - sizeHints.flags = PMinSize; - sizeHints.min_width = view->min_width; - sizeHints.min_height = view->min_height; + } else { + if (view->min_width || view->min_height) { + sizeHints.flags = PMinSize; + sizeHints.min_width = view->min_width; + sizeHints.min_height = view->min_height; + } + if (view->min_aspect_x) { + sizeHints.flags |= PAspect; + sizeHints.min_aspect.x = view->min_aspect_x; + sizeHints.min_aspect.y = view->min_aspect_y; + sizeHints.max_aspect.x = view->max_aspect_x; + sizeHints.max_aspect.y = view->max_aspect_y; + } + XSetNormalHints(impl->display, impl->win, &sizeHints); } -- cgit v1.2.3 From 809ead2220f5a9ed66f88b1ae84a93e334e2717f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Sep 2015 19:45:02 -0400 Subject: Add puglWaitForEvent for blocking main loops. --- pugl/pugl_x11.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'pugl/pugl_x11.c') diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index 6375609..32501da 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -493,6 +493,14 @@ puglGrabFocus(PuglView* view) view->impl->display, view->impl->win, RevertToPointerRoot, CurrentTime); } +PuglStatus +puglWaitForEvent(PuglView* view) +{ + XEvent xevent; + XPeekEvent(view->impl->display, &xevent); + return PUGL_SUCCESS; +} + PuglStatus puglProcessEvents(PuglView* view) { @@ -544,6 +552,7 @@ puglProcessEvents(PuglView* view) if (view->ctx_type == PUGL_CAIRO) { cairo_xlib_surface_set_size( view->impl->surface, view->width, view->height); + view->redisplay = true; } #endif } -- cgit v1.2.3 From 6abce4944cb49c65dd1d592be45b766110dbfeba Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Sep 2015 19:51:03 -0400 Subject: Update copyright dates. --- pugl/pugl_x11.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pugl/pugl_x11.c') diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index 32501da..35cca8c 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -1,5 +1,5 @@ /* - Copyright 2012-2014 David Robillard + Copyright 2012-2015 David Robillard Copyright 2013 Robin Gareus Copyright 2011-2012 Ben Loftis, Harrison Consoles -- cgit v1.2.3