From 3d27fe91f5c25405df0d332f17a7c6fc97d7da27 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 1 Nov 2014 00:48:15 +0100 Subject: Add support for transient child windows. No Windows support currently. Conflicts: pugl/pugl.h pugl/pugl_osx.m pugl/pugl_win.cpp pugl/pugl_x11.c --- pugl/pugl.h | 9 +++++++++ pugl/pugl_internal.h | 7 +++++++ pugl/pugl_osx.m | 30 ++++++++++++++++++------------ pugl/pugl_x11.c | 5 +++++ 4 files changed, 39 insertions(+), 12 deletions(-) (limited to 'pugl') diff --git a/pugl/pugl.h b/pugl/pugl.h index 54b4c78..53115ff 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -176,6 +176,15 @@ puglInitWindowMinSize(PuglView* view, int width, int height); PUGL_API void puglInitResizable(PuglView* view, bool resizable); +/** + Set transient parent before creating a window. + + On X11, parent_id must be a Window. + On OSX, parent_id must be an NSView*. +*/ +PUGL_API void +puglInitTransientFor(PuglView* view, uintptr_t parent); + /** Set the context type before creating a window. */ diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h index 8a193d6..5b2b1c7 100644 --- a/pugl/pugl_internal.h +++ b/pugl/pugl_internal.h @@ -49,6 +49,7 @@ struct PuglViewImpl { PuglNativeWindow parent; PuglContextType ctx_type; + uintptr_t transient_parent; int width; int height; @@ -110,6 +111,12 @@ puglInitResizable(PuglView* view, bool resizable) view->resizable = resizable; } +void +puglInitTransientFor(PuglView* view, uintptr_t parent) +{ + view->transient_parent = parent; +} + void puglInitContextType(PuglView* view, PuglContextType type) { diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index 6139837..8735a6d 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -59,7 +59,6 @@ } [self setAcceptsMouseMovedEvents:YES]; - [self setLevel: CGShieldingWindowLevel() + 1]; return (PuglWindow*)self; } @@ -445,17 +444,24 @@ puglCreateWindow(PuglView* view, const char* title) [NSAutoreleasePool new]; impl->app = [NSApplication sharedApplication]; - NSString* titleString = [[NSString alloc] - initWithBytes:title - length:strlen(title) - encoding:NSUTF8StringEncoding]; - - id window = [[PuglWindow new] retain]; - - [window setPuglview:view]; - [window setTitle:titleString]; - if (view->min_width || view->min_height) { - [window setContentMinSize:NSMakeSize(view->min_width, view->min_height)]; + if (view->transient_parent) { + NSView* pview = (NSView*)view->transient_parent; + [pview addSubview:impl->glview]; + [impl->glview setHidden:NO]; + [impl->glview setLevel: CGShieldingWindowLevel() + 1]; + } else { + NSString* titleString = [[NSString alloc] + initWithBytes:title + length:strlen(title) + encoding:NSUTF8StringEncoding]; + + id window = [[RobTKPuglWindow new] retain]; + [window setPuglview:view]; + [window setTitle:titleString]; + if (view->min_width || view->min_height) { + [window setContentMinSize:NSMakeSize(min_width, min_height)]; + } + impl->window = window; } impl->glview = [PuglOpenGLView new]; diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index e3325cd..4bf1f65 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -226,6 +226,11 @@ puglCreateWindow(PuglView* view, const char* title) XSetWMProtocols(impl->display, impl->win, &wmDelete, 1); } + if (view->transient_parent) { + XSetTransientForHint(impl->display, impl->win, + (Window)(view->transient_parent)); + } + XFree(vi); return 0; -- cgit v1.2.1