Fallback to X11 message box implementation when SDL fails
This commit is contained in:
@@ -366,8 +366,6 @@ static int X11_MessageBoxInitPositions(MessageBoxData* data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !PLATFORM_SDL
|
|
||||||
|
|
||||||
// Create and set up X11 dialog box window
|
// Create and set up X11 dialog box window
|
||||||
static int X11_MessageBoxCreateWindow(MessageBoxData* data)
|
static int X11_MessageBoxCreateWindow(MessageBoxData* data)
|
||||||
{
|
{
|
||||||
@@ -655,7 +653,11 @@ static int X11_MessageBoxLoop(MessageBoxData* data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !PLATFORM_SDL
|
||||||
DialogResult MessageBox::Show(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon)
|
DialogResult MessageBox::Show(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon)
|
||||||
|
#else
|
||||||
|
DialogResult MessageBox::ShowFallback(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
if (CommandLine::Options.Headless)
|
if (CommandLine::Options.Headless)
|
||||||
return DialogResult::None;
|
return DialogResult::None;
|
||||||
@@ -842,6 +844,8 @@ DialogResult MessageBox::Show(Window* parent, const StringView& text, const Stri
|
|||||||
return data.resultButtonIndex == -1 ? DialogResult::None : data.buttons[data.resultButtonIndex].result;
|
return data.resultButtonIndex == -1 ? DialogResult::None : data.buttons[data.resultButtonIndex].result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !PLATFORM_SDL
|
||||||
|
|
||||||
int X11ErrorHandler(X11::Display* display, X11::XErrorEvent* event)
|
int X11ErrorHandler(X11::Display* display, X11::XErrorEvent* event)
|
||||||
{
|
{
|
||||||
if (event->error_code == 5)
|
if (event->error_code == 5)
|
||||||
@@ -851,6 +855,7 @@ int X11ErrorHandler(X11::Display* display, X11::XErrorEvent* event)
|
|||||||
LOG(Error, "X11 Error: {0}", String(buffer));
|
LOG(Error, "X11 Error: {0}", String(buffer));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32 CalculateDpi()
|
int32 CalculateDpi()
|
||||||
|
|||||||
@@ -237,4 +237,9 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(MessageBox);
|
|||||||
/// <param name="icon">One of the MessageBoxIcon values that specifies which icon to display in the message box.</param>
|
/// <param name="icon">One of the MessageBoxIcon values that specifies which icon to display in the message box.</param>
|
||||||
/// <returns>The message box dialog result.</returns>
|
/// <returns>The message box dialog result.</returns>
|
||||||
API_FUNCTION() static DialogResult Show(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon);
|
API_FUNCTION() static DialogResult Show(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon);
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if PLATFORM_SDL && PLATFORM_LINUX
|
||||||
|
static DialogResult ShowFallback(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -475,7 +475,15 @@ DialogResult MessageBox::Show(Window* parent, const StringView& text, const Stri
|
|||||||
int result = -1;
|
int result = -1;
|
||||||
if (SDL_ShowMessageBox(&data, &result) != 0)
|
if (SDL_ShowMessageBox(&data, &result) != 0)
|
||||||
{
|
{
|
||||||
LOG(Error, "Failed to show message box: {0}", String(SDL_GetError()));
|
#if PLATFORM_LINUX
|
||||||
|
// Fallback to native messagebox implementation in case some system fonts are missing
|
||||||
|
if (SDLPlatform::UsesX11())
|
||||||
|
{
|
||||||
|
LOG(Warning, "Failed to show SDL message box: {0}", String(SDL_GetError()));
|
||||||
|
return ShowFallback(parent, text, caption, buttons, icon);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
LOG(Error, "Failed to show SDL message box: {0}", String(SDL_GetError()));
|
||||||
return DialogResult::Abort;
|
return DialogResult::Abort;
|
||||||
}
|
}
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user