Merge branch 'bad-locale'

This commit is contained in:
Daniel Eklöf 2022-01-13 11:48:03 +01:00
commit 69ec74a605
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 54 additions and 3 deletions

View file

@ -47,6 +47,7 @@
* [SGR-Pixels (1016) mouse extended coordinates](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Extended-coordinates) is now supported * [SGR-Pixels (1016) mouse extended coordinates](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Extended-coordinates) is now supported
(https://codeberg.org/dnkl/foot/issues/762). (https://codeberg.org/dnkl/foot/issues/762).
### Changed ### Changed
* PaperColorDark and PaperColorLight themes renamed to * PaperColorDark and PaperColorLight themes renamed to
@ -58,6 +59,10 @@
* The width of the block cursors outline in an unfocused window is * The width of the block cursors outline in an unfocused window is
now scaled by the output scaling factor (“desktop now scaled by the output scaling factor (“desktop
scaling”). Previously, it was always 1px. scaling”). Previously, it was always 1px.
* Foot will now try to change the locale to either “C.UTF-8” or
“en_US.UTF-8” if started with a non-UTF8 locale. If this fails, foot
will start, but only to display a window with an error (users shell
is not executed).
### Deprecated ### Deprecated

52
main.c
View file

@ -424,10 +424,48 @@ main(int argc, char *const *argv)
LOG_ERR("setlocale() failed"); LOG_ERR("setlocale() failed");
return ret; return ret;
} }
LOG_INFO("locale: %s", locale); LOG_INFO("locale: %s", locale);
if (!locale_is_utf8()) {
LOG_ERR("locale is not UTF-8"); bool bad_locale = !locale_is_utf8();
return ret; if (bad_locale) {
static const char fallback_locales[][12] = {
"C.UTF-8",
"en_US.UTF-8",
};
/*
* Try to force an UTF-8 locale. If we succeed, launch the
* users shell as usual, but add a user-notification saying
* the locale has been changed.
*/
for (size_t i = 0; i < ALEN(fallback_locales); i++) {
const char *const fallback_locale = fallback_locales[i];
if (setlocale(LC_CTYPE, fallback_locale) != NULL) {
LOG_WARN("locale '%s' is not UTF-8, using '%s' instead",
locale, fallback_locale);
user_notification_add_fmt(
&user_notifications, USER_NOTIFICATION_WARNING,
"locale '%s' is not UTF-8, using '%s' instead",
locale, fallback_locale);
bad_locale = false;
break;
}
}
if (bad_locale) {
LOG_ERR("locale '%s' is not UTF-8, "
"and failed to enable a fallback locale", locale);
user_notification_add_fmt(
&user_notifications, USER_NOTIFICATION_ERROR,
"locale '%s' is not UTF-8, "
"and failed to enable a fallback locale",
locale);
}
} }
struct config conf = {NULL}; struct config conf = {NULL};
@ -502,6 +540,14 @@ main(int argc, char *const *argv)
conf.fonts[0].arr[0].pattern, &conf.notifications); conf.fonts[0].arr[0].pattern, &conf.notifications);
} }
if (bad_locale) {
static char *const bad_locale_fake_argv[] = {"/bin/sh", "-c", "", NULL};
argc = 1;
argv = bad_locale_fake_argv;
conf.hold_at_exit = true;
}
struct fdm *fdm = NULL; struct fdm *fdm = NULL;
struct reaper *reaper = NULL; struct reaper *reaper = NULL;
struct wayland *wayl = NULL; struct wayland *wayl = NULL;