summaryrefslogtreecommitdiff
path: root/pugl/pugl_x11.c
diff options
context:
space:
mode:
Diffstat (limited to 'pugl/pugl_x11.c')
-rw-r--r--pugl/pugl_x11.c65
1 files changed, 49 insertions, 16 deletions
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index da33063..35cca8c 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -1,5 +1,5 @@
/*
- Copyright 2012-2014 David Robillard <http://drobilla.net>
+ Copyright 2012-2015 David Robillard <http://drobilla.net>
Copyright 2013 Robin Gareus <robin@gareus.org>
Copyright 2011-2012 Ben Loftis, Harrison Consoles
@@ -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");
}
}
@@ -137,7 +138,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
}
@@ -212,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);
}
@@ -482,9 +494,18 @@ puglGrabFocus(PuglView* view)
}
PuglStatus
+puglWaitForEvent(PuglView* view)
+{
+ XEvent xevent;
+ XPeekEvent(view->impl->display, &xevent);
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
puglProcessEvents(PuglView* view)
{
XEvent xevent;
+ bool resized = false;
while (XPending(view->impl->display) > 0) {
XNextEvent(view->impl->display, &xevent);
bool ignore = false;
@@ -515,6 +536,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) {
@@ -524,6 +547,16 @@ 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);
+ view->redisplay = true;
+ }
+#endif
+ }
+
if (view->redisplay) {
const PuglEventExpose expose = {
PUGL_EXPOSE, view, true, 0, 0, view->width, view->height, 0