From 3eda26a2ac05ce6158bffb9fdc0353386af3d4e8 Mon Sep 17 00:00:00 2001 From: Ricardo Silva Veloso Date: Tue, 31 Jul 2018 22:23:16 -0300 Subject: [PATCH 1/3] Fix alpha component of color picker in some locales --- src/gstyle/gstyle-color.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gstyle/gstyle-color.c b/src/gstyle/gstyle-color.c index 41710dfdc..596d8d46a 100644 --- a/src/gstyle/gstyle-color.c +++ b/src/gstyle/gstyle-color.c @@ -116,8 +116,15 @@ gstyle_color_to_hsla (GstyleColor *self, static gchar * truncate_trailing_zeros (gdouble number) { + /* Switch to "C" locale to avoid problems with decimal separators */ + gchar *locale_backup = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); + gint c = g_snprintf(TRUNCATE_BUF, 6, "%.2f", number); + /* Restore locale */ + setlocale(LC_NUMERIC, locale_backup); + --c; while(TRUNCATE_BUF[c] == '0') c--; -- GitLab From 0b16cd657354d8872f63f7c8888917f8c03cf675 Mon Sep 17 00:00:00 2001 From: Ricardo Silva Veloso Date: Wed, 1 Aug 2018 01:43:02 -0300 Subject: [PATCH 2/3] Improve JS import snippets --- data/snippets/js.snippets | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/data/snippets/js.snippets b/data/snippets/js.snippets index ffe9ac2ef..f9a0885fe 100644 --- a/data/snippets/js.snippets +++ b/data/snippets/js.snippets @@ -2,19 +2,22 @@ snippet import import "${1:./module.js}"; $0 snippet from - import ${1:Module} from "${2:./}${3:$1|lower}"; +- desc import … from + import ${1:{ Module }} from "${2:./module.js}"; $0 -snippet require - const ${1:Module} = require("${2:./}${3:$1|lower}"); +snippet imports + const ${1:Module} = imports.${2:path}.${$1|decapitalize}; $0 snippet gi - const ${1:Gtk} = imports.gi.$1; +- desc imports.gi + const ${1:{ GObject, Gtk }} = imports.gi; $0 snippet lang +- desc imports.lang const ${1:Lang} = imports.${$1|decapitalize}; $0 -snippet imports - const ${1:Module} = imports.${2:path}.${$1|decapitalize}; +snippet require + const ${1:Module} = require("${2:./}${3:$1|lower}"); $0 snippet class class ${1:ClassName} { -- GitLab From 08d5cb0cc7124c6c59730c7de44c0297bebdaaae Mon Sep 17 00:00:00 2001 From: Ricardo Silva Veloso Date: Thu, 2 Aug 2018 21:19:18 -0300 Subject: [PATCH 3/3] Use uselocale() because setlocale() is not thread-safe --- src/gstyle/gstyle-color.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/gstyle/gstyle-color.c b/src/gstyle/gstyle-color.c index 596d8d46a..ffc63b565 100644 --- a/src/gstyle/gstyle-color.c +++ b/src/gstyle/gstyle-color.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "gstyle-private.h" #include "gstyle-colorlexer.h" @@ -117,16 +118,26 @@ static gchar * truncate_trailing_zeros (gdouble number) { /* Switch to "C" locale to avoid problems with decimal separators */ - gchar *locale_backup = setlocale(LC_NUMERIC, NULL); - setlocale(LC_NUMERIC, "C"); + locale_t bk_locale = uselocale (NULL); + locale_t base_locale = duplocale (bk_locale); + locale_t new_locale = newlocale (LC_ALL, "C", base_locale); /* Just LC_NUMERIC doesn't work */ - gint c = g_snprintf(TRUNCATE_BUF, 6, "%.2f", number); + if (new_locale != NULL) + uselocale (new_locale); + + gint c = g_snprintf (TRUNCATE_BUF, 6, "%.2f", number); /* Restore locale */ - setlocale(LC_NUMERIC, locale_backup); + uselocale (bk_locale); + + if (new_locale != NULL) + freelocale (new_locale); + else + freelocale (base_locale); + /* Format the number string, e.g. "0.50" => "0.5"; "1.0" => "1" */ --c; - while(TRUNCATE_BUF[c] == '0') + while (TRUNCATE_BUF[c] == '0') c--; if (TRUNCATE_BUF[c] == '.') -- GitLab