Browse Source

Do not crash if all X11 fails

pull/316/head
falkTX 4 years ago
parent
commit
3370cdb78d
5 changed files with 47 additions and 10 deletions
  1. +1
    -0
      dgl/src/ApplicationPrivateData.cpp
  2. +17
    -1
      dgl/src/Window.cpp
  3. +22
    -8
      dgl/src/WindowPrivateData.cpp
  4. +1
    -1
      dgl/src/pugl-upstream
  5. +6
    -0
      distrho/src/DistrhoUIPrivateData.hpp

+ 1
- 0
dgl/src/ApplicationPrivateData.cpp View File

@@ -151,6 +151,7 @@ void Application::PrivateData::quit()

void Application::PrivateData::setClassName(const char* const name)
{
DISTRHO_SAFE_ASSERT_RETURN(world != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);

puglSetClassName(world, name);


+ 17
- 1
dgl/src/Window.cpp View File

@@ -132,6 +132,8 @@ void Window::setResizable(const bool resizable)

uint Window::getWidth() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0);

const double width = puglGetFrame(pData->view).width;
DISTRHO_SAFE_ASSERT_RETURN(width >= 0.0, 0);
return static_cast<uint>(width + 0.5);
@@ -139,6 +141,8 @@ uint Window::getWidth() const noexcept

uint Window::getHeight() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0);

const double height = puglGetFrame(pData->view).height;
DISTRHO_SAFE_ASSERT_RETURN(height >= 0.0, 0);
return static_cast<uint>(height + 0.5);
@@ -146,6 +150,8 @@ uint Window::getHeight() const noexcept

Size<uint> Window::getSize() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, Size<uint>());

const PuglRect rect = puglGetFrame(pData->view);
DISTRHO_SAFE_ASSERT_RETURN(rect.width >= 0.0, Size<uint>());
DISTRHO_SAFE_ASSERT_RETURN(rect.height >= 0.0, Size<uint>());
@@ -214,7 +220,8 @@ const char* Window::getTitle() const noexcept

void Window::setTitle(const char* const title)
{
puglSetWindowTitle(pData->view, title);
if (pData->view != nullptr)
puglSetWindowTitle(pData->view, title);
}

bool Window::isIgnoringKeyRepeat() const noexcept
@@ -277,11 +284,17 @@ bool Window::openFileBrowser(const FileBrowserOptions& options)

void Window::repaint() noexcept
{
if (pData->view == nullptr)
return;

puglPostRedisplay(pData->view);
}

void Window::repaint(const Rectangle<uint>& rect) noexcept
{
if (pData->view == nullptr)
return;

PuglRect prect = {
static_cast<double>(rect.getX()),
static_cast<double>(rect.getY()),
@@ -318,6 +331,9 @@ void Window::setGeometryConstraints(const uint minimumWidth,
pData->autoScaling = automaticallyScale;
pData->keepAspectRatio = keepAspectRatio;

if (pData->view == nullptr)
return;

const double scaleFactor = pData->scaleFactor;

puglSetGeometryConstraints(pData->view,


+ 22
- 8
dgl/src/WindowPrivateData.cpp View File

@@ -70,7 +70,10 @@ static double getDesktopScaleFactor(const PuglView* const view)
if (const char* const scale = getenv("DPF_SCALE_FACTOR"))
return std::max(1.0, std::atof(scale));

return puglGetDesktopScaleFactor(view);
if (view != nullptr)
return puglGetDesktopScaleFactor(view);

return 1.0;
}

// -----------------------------------------------------------------------
@@ -162,11 +165,11 @@ Window::PrivateData::PrivateData(Application& a, Window* const s,
: app(a),
appData(a.pData),
self(s),
view(puglNewView(appData->world)),
view(appData->world != nullptr ? puglNewView(appData->world) : nullptr),
transientParentView(nullptr),
topLevelWidgets(),
isClosed(parentWindowHandle == 0),
isVisible(parentWindowHandle != 0),
isVisible(parentWindowHandle != 0 && view != nullptr),
isEmbed(parentWindowHandle != 0),
scaleFactor(scale != 0.0 ? scale : getDesktopScaleFactor(view)),
autoScaling(false),
@@ -187,6 +190,12 @@ Window::PrivateData::PrivateData(Application& a, Window* const s,

Window::PrivateData::~PrivateData()
{
appData->idleCallbacks.remove(this);
appData->windows.remove(self);

if (view == nullptr)
return;

if (isEmbed)
{
#ifdef HAVE_X11
@@ -198,16 +207,12 @@ Window::PrivateData::~PrivateData()
isVisible = false;
}

appData->idleCallbacks.remove(this);
appData->windows.remove(self);

#ifdef DISTRHO_OS_WINDOWS
if (win32SelectedFile != nullptr && win32SelectedFile != kWin32SelectedFileCancelled)
std::free(const_cast<char*>(win32SelectedFile));
#endif

if (view != nullptr)
puglFreeView(view);
puglFreeView(view);
}

// -----------------------------------------------------------------------
@@ -244,6 +249,9 @@ void Window::PrivateData::initPre(const uint width, const uint height, const boo

void Window::PrivateData::initPost()
{
if (view == nullptr)
return;

// create view now, as a few methods we allow devs to use require it
puglRealize(view);

@@ -290,6 +298,9 @@ void Window::PrivateData::show()

DGL_DBG("Window show called\n");

if (view == nullptr)
return;

if (isClosed)
{
isClosed = false;
@@ -347,6 +358,9 @@ void Window::PrivateData::hide()

void Window::PrivateData::focus()
{
if (view == nullptr)
return;

if (! isEmbed)
puglRaiseWindow(view);



+ 1
- 1
dgl/src/pugl-upstream

@@ -1 +1 @@
Subproject commit 4e2888aaafa315936941eccc38dab695beacaa0d
Subproject commit fe76102568733092b232c253138ac913862e4f1b

+ 6
- 0
distrho/src/DistrhoUIPrivateData.hpp View File

@@ -168,12 +168,18 @@ public:
initializing(true),
receivedReshapeDuringInit(false)
{
if (pData->view == nullptr)
return;

pData->initPost();
puglBackendEnter(pData->view);
}

void leaveContext()
{
if (pData->view == nullptr)
return;

if (receivedReshapeDuringInit)
ui->uiReshape(getWidth(), getHeight());



Loading…
Cancel
Save