Fallback to X11 message box implementation when SDL fails
This commit is contained in:
@@ -370,8 +370,6 @@ static int X11_MessageBoxInitPositions(MessageBoxData* data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !PLATFORM_SDL
|
||||
|
||||
// Create and set up X11 dialog box window
|
||||
static int X11_MessageBoxCreateWindow(MessageBoxData* data)
|
||||
{
|
||||
@@ -659,7 +657,11 @@ static int X11_MessageBoxLoop(MessageBoxData* data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !PLATFORM_SDL
|
||||
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.IsTrue())
|
||||
return DialogResult::None;
|
||||
@@ -846,6 +848,8 @@ DialogResult MessageBox::Show(Window* parent, const StringView& text, const Stri
|
||||
return data.resultButtonIndex == -1 ? DialogResult::None : data.buttons[data.resultButtonIndex].result;
|
||||
}
|
||||
|
||||
#if !PLATFORM_SDL
|
||||
|
||||
int X11ErrorHandler(X11::Display* display, X11::XErrorEvent* event)
|
||||
{
|
||||
if (event->error_code == 5)
|
||||
@@ -855,6 +859,7 @@ int X11ErrorHandler(X11::Display* display, X11::XErrorEvent* event)
|
||||
LOG(Error, "X11 Error: {0}", String(buffer));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
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>
|
||||
/// <returns>The message box dialog result.</returns>
|
||||
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;
|
||||
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;
|
||||
}
|
||||
if (result < 0)
|
||||
|
||||
Reference in New Issue
Block a user