Browse Source

Better handling of transient windows, using ScopedGraphicsContext

pull/327/head
falkTX 4 years ago
parent
commit
6f89fd3d21
4 changed files with 28 additions and 13 deletions
  1. +4
    -4
      dgl/StandaloneWindow.hpp
  2. +6
    -1
      dgl/Window.hpp
  3. +18
    -3
      dgl/src/Window.cpp
  4. +0
    -5
      dgl/src/WindowPrivateData.cpp

+ 4
- 4
dgl/StandaloneWindow.hpp View File

@@ -37,12 +37,12 @@ public:
sgc((Window&)*this) {} sgc((Window&)*this) {}


/** /**
Constructor with parent window, typically used to run as modal.
Constructor with a transient parent window, typically used to run as modal.
*/ */
StandaloneWindow(Application& app, Window& parentWindow)
: Window(app, parentWindow),
StandaloneWindow(Application& app, Window& transientParentWindow)
: Window(app, transientParentWindow),
TopLevelWidget((Window&)*this), TopLevelWidget((Window&)*this),
sgc((Window&)*this) {}
sgc((Window&)*this, transientParentWindow) {}


/** /**
Clear current graphics context. Clear current graphics context.


+ 6
- 1
dgl/Window.hpp View File

@@ -49,6 +49,8 @@ class TopLevelWidget;
*/ */
class Window class Window
{ {
struct PrivateData;

public: public:
#ifndef DGL_FILE_BROWSER_DISABLED #ifndef DGL_FILE_BROWSER_DISABLED
/** /**
@@ -131,6 +133,9 @@ public:
/** Constructor that will make the @a window graphics context the current one */ /** Constructor that will make the @a window graphics context the current one */
explicit ScopedGraphicsContext(Window& window); explicit ScopedGraphicsContext(Window& window);


/** Overloaded constructor, gives back context to its transient parent when done */
explicit ScopedGraphicsContext(Window& window, Window& transientParentWindow);

/** Desstructor for clearing current context, if not done yet */ /** Desstructor for clearing current context, if not done yet */
~ScopedGraphicsContext(); ~ScopedGraphicsContext();


@@ -142,6 +147,7 @@ public:


private: private:
Window& window; Window& window;
Window::PrivateData* ppData;
bool active; bool active;
}; };


@@ -451,7 +457,6 @@ protected:
#endif #endif


private: private:
struct PrivateData;
PrivateData* const pData; PrivateData* const pData;
friend class Application; friend class Application;
friend class PluginWindow; friend class PluginWindow;


+ 18
- 3
dgl/src/Window.cpp View File

@@ -25,20 +25,35 @@ START_NAMESPACE_DGL


Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win) Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win)
: window(win), : window(win),
ppData(nullptr),
active(puglBackendEnter(window.pData->view)) {} active(puglBackendEnter(window.pData->view)) {}


Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win, Window& transientWin)
: window(win),
ppData(transientWin.pData),
active(false)
{
puglBackendLeave(ppData->view);
active = puglBackendEnter(window.pData->view);
}

Window::ScopedGraphicsContext::~ScopedGraphicsContext() Window::ScopedGraphicsContext::~ScopedGraphicsContext()
{ {
if (active)
puglBackendLeave(window.pData->view);
done();
} }


void Window::ScopedGraphicsContext::done() void Window::ScopedGraphicsContext::done()
{ {
if (active) if (active)
{ {
active = false;
puglBackendLeave(window.pData->view); puglBackendLeave(window.pData->view);
active = false;
}

if (ppData != nullptr)
{
puglBackendEnter(ppData->view);
ppData = nullptr;
} }
} }




+ 0
- 5
dgl/src/WindowPrivateData.cpp View File

@@ -123,7 +123,6 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, PrivateData* c
#endif #endif
modal(ppData) modal(ppData)
{ {
puglBackendLeave(transientParentView);
puglSetTransientFor(view, puglGetNativeWindow(transientParentView)); puglSetTransientFor(view, puglGetNativeWindow(transientParentView));


initPre(DEFAULT_WIDTH, DEFAULT_HEIGHT, false); initPre(DEFAULT_WIDTH, DEFAULT_HEIGHT, false);
@@ -266,10 +265,6 @@ bool Window::PrivateData::initPost()
puglShow(view); puglShow(view);
} }


// give context back to transient parent window
if (transientParentView != nullptr)
puglBackendEnter(transientParentView);

return true; return true;
} }




Loading…
Cancel
Save