Skip to content

Commit

Permalink
Reset locale to "C" on Unix systems
Browse files Browse the repository at this point in the history
After Qt messes it up when you initialze a QCoreApplication or similar.
  • Loading branch information
askmeaboutlo0m committed Nov 12, 2024
1 parent bd6c061 commit f22bc3f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Unreleased Version 2.2.2-pre
* Fix: Make temporary tool switches by holding a key down work again. Thanks 3rd_EFNO and bunnie for reporting.
* Fix: Disregard hidden layers when layer picking in frame view.
* Feature: Add a search bar to the key frame properties dialog.
* Fix: Reset locale to "C" after Qt messes it up on startup. Thanks Meru for reporting.

2024-11-06 Version 2.2.2-beta.4
* Fix: Solve rendering glitches with selection outlines that happen on some systems. Thanks xxxx for reporting.
Expand Down
2 changes: 2 additions & 0 deletions src/desktop/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "desktop/utils/globalkeyeventfilter.h"
#include "desktop/utils/qtguicompat.h"
#include "desktop/utils/recents.h"
#include "dpcommon/platform_qt.h"
#include "libclient/brushes/brushpresetmodel.h"
#include "libclient/drawdance/global.h"
#include "libclient/utils/colorscheme.h"
Expand Down Expand Up @@ -1125,6 +1126,7 @@ extern "C" void drawpileMain(int argc, char **argv)
DrawpileApp appInstance(argc, argv);
DrawpileApp *app = &appInstance;
#endif
DP_QT_LOCALE_RESET();

compat::disableImageReaderAllocationLimit();
startApplication(app);
Expand Down
14 changes: 14 additions & 0 deletions src/drawdance/libcommon/dpcommon/platform_qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
#define DPCOMMON_PLATFORM_H
#include <QIODevice>

// On Unix systems, Qt messes up the locale on startup.
#ifdef Q_OS_UNIX
# include <locale.h>
# define DP_QT_LOCALE_RESET() \
do { \
setlocale(LC_ALL, "C"); \
} while (0)
#else
# define DP_QT_LOCALE_RESET() \
do { \
/* nothing */ \
} while (0)
#endif

// On Android, files don't get truncated when writing without the truncate flag.
static constexpr QIODevice::OpenMode DP_QT_WRITE_FLAGS =
#ifdef Q_OS_ANDROID
Expand Down
3 changes: 2 additions & 1 deletion src/thinsrv/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "cmake-config/config.h"
#include "dpcommon/platform_qt.h"
#include "libserver/jsonapi.h" // for datatype registration
#include "thinsrv/headless/headless.h"
#include "thinsrv/initsys.h"
Expand Down Expand Up @@ -56,7 +57,7 @@ int main(int argc, char *argv[])
#else
app.reset(new QCoreApplication(argc, argv));
#endif

DP_QT_LOCALE_RESET();

// Set common settings
QCoreApplication::setOrganizationName("drawpile");
Expand Down
1 change: 1 addition & 0 deletions src/tools/drawpile-timelapse/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static QString writeDefaultLogo()
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
DP_QT_LOCALE_RESET();
app.setOrganizationName("drawpile");
app.setOrganizationDomain("drawpile.net");
app.setApplicationName("drawpile-timelapse");
Expand Down

0 comments on commit f22bc3f

Please sign in to comment.