Simplify the EditWindow singleton using an instance wrapper.

This commit is contained in:
Adam Reichold 2015-11-28 12:48:06 +01:00
parent 9ec0557edf
commit ebe85388a3

View File

@ -24,8 +24,6 @@
#include "rtimage.h" #include "rtimage.h"
#include "threadutils.h" #include "threadutils.h"
static EditWindow* editWnd = NULL;
// Check if the system has more than one display and option is set // Check if the system has more than one display and option is set
bool EditWindow::isMultiDisplayEnabled() bool EditWindow::isMultiDisplayEnabled()
{ {
@ -35,29 +33,26 @@ bool EditWindow::isMultiDisplayEnabled()
// Should only be created once, auto-creates window on correct display // Should only be created once, auto-creates window on correct display
EditWindow* EditWindow::getInstance(RTWindow* p) EditWindow* EditWindow::getInstance(RTWindow* p)
{ {
struct EditWindowInstance
{
EditWindow editWnd;
if (editWnd == NULL) { EditWindowInstance(RTWindow* p) : editWnd(p)
static MyMutex smutex_; {
MyMutex::MyLock lock(smutex_);
if ( editWnd == 0 ) {
editWnd = new EditWindow(p);
// Determine the other display and maximize the window on that // Determine the other display and maximize the window on that
const Glib::RefPtr< Gdk::Window >& wnd = p->get_window(); const Glib::RefPtr< Gdk::Window >& wnd = p->get_window();
int monNo = p->get_screen()->get_monitor_at_window (wnd); int monNo = p->get_screen()->get_monitor_at_window (wnd);
Gdk::Rectangle lMonitorRect; Gdk::Rectangle lMonitorRect;
editWnd->get_screen()->get_monitor_geometry(isMultiDisplayEnabled() ? (monNo == 0 ? 1 : 0) : monNo, lMonitorRect); editWnd.get_screen()->get_monitor_geometry(isMultiDisplayEnabled() ? (monNo == 0 ? 1 : 0) : monNo, lMonitorRect);
editWnd->move(lMonitorRect.get_x(), lMonitorRect.get_y()); editWnd.move(lMonitorRect.get_x(), lMonitorRect.get_y());
editWnd->maximize(); editWnd.maximize();
editWnd->show();
} else {
editWnd->show_all();
} }
} };
return editWnd; static EditWindowInstance instance_(p);
instance_.editWnd.show_all();
return &instance_.editWnd;
} }
EditWindow::EditWindow (RTWindow* p) : parent(p) , isFullscreen(false) EditWindow::EditWindow (RTWindow* p) : parent(p) , isFullscreen(false)