Compare commits

...

24 Commits
v1.3.0 ... lang

Author SHA1 Message Date
06849fe668 language: Use dbus to find out current language before env 2019-11-20 21:48:23 +00:00
317d8a58dc Merge branch 'translations' into 'master'
translations: Updated pl and en with new layouts

See merge request Librem5/squeekboard!261
2019-11-20 12:26:39 +00:00
89b3ab9a81 translations: Updated pl and en with new layouts 2019-11-20 12:12:07 +00:00
8690808a29 layouts: Correct xkb symbols usage 2019-11-20 11:18:02 +00:00
be4ac32477 Merge branch '153-fix-German-layout-xkb-buttons-without-keycode-property' into 'master'
German layout: Correct xkb symbols usage

See merge request Librem5/squeekboard!251
2019-11-20 11:15:18 +00:00
5068f36d9d German layout: Correct xkb symbols usage 2019-11-20 11:15:18 +00:00
8c48e96f50 Merge branch 'codes' into 'master'
Language code fixes

See merge request Librem5/squeekboard!258
2019-11-20 11:12:47 +00:00
f15619287a Merge branch 'de' into 'master'
DE fixes

See merge request Librem5/squeekboard!259
2019-11-20 10:47:34 +00:00
eb5c28e77f translation: Use right codes in German 2019-11-20 10:25:56 +00:00
7fb34feaf8 translations: Use the correct code for Norwegian 2019-11-20 10:24:31 +00:00
20a6cf52ac layouts: Rename ja+kana to jp+kana 2019-11-20 10:23:05 +00:00
c566d8853e translations: Register Spanish 2019-11-20 10:21:41 +00:00
0beddc6856 Merge branch 'patch-8' into 'master'
translations: Spanish

See merge request Librem5/squeekboard!246
2019-11-20 10:11:48 +00:00
3170a0b615 Merge branch 'renderer' into 'master'
Renderer reworks

See merge request Librem5/squeekboard!238
2019-11-19 10:34:47 +00:00
4f28e3413a langs: add de-DE for switcher 2019-11-19 00:10:35 +01:00
291be9fa79 Update de-DE.txt 2019-11-18 22:58:27 +00:00
fd5d060eee langs: add de-DE for switcher 2019-11-18 22:56:47 +01:00
cffe07521e Merge branch 'prebuild_tests' into 'master'
Prebuild tests

See merge request Librem5/squeekboard!250
2019-11-17 15:14:50 +00:00
36af546362 tests: Bump timeout for the execution of all unit tests 2019-11-17 15:06:07 +00:00
0da848a5a0 tests: Use correct test compilation command 2019-11-17 14:56:25 +00:00
8c9ae98bda Merge branch 'release' into 'master'
Release 1.3.0

See merge request Librem5/squeekboard!247
2019-11-16 15:49:58 +00:00
ef025509ba translations: Spanish 2019-11-15 20:57:24 +00:00
c096698ec1 renderer: Remove unused ascii_font 2019-11-07 14:13:27 +00:00
3aaaed3bae renderer: Clean up EekColor & label 2019-11-07 14:10:20 +00:00
19 changed files with 174 additions and 186 deletions

20
Cargo.lock generated
View File

@ -54,6 +54,15 @@ name = "cc"
version = "1.0.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "dbus"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"libdbus-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.4"
@ -232,6 +241,14 @@ name = "libc"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libdbus-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "linked-hash-map"
version = "0.5.2"
@ -324,6 +341,7 @@ name = "rs"
version = "0.1.0"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"dbus 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glib 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -436,6 +454,7 @@ dependencies = [
"checksum cairo-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd940f0d609699e343ef71c4af5f66423afbf30d666f796dabd8fd15229cf5b6"
"checksum cairo-sys-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d25596627380be4381247dba06c69ad05ca21b3b065bd9827e416882ac41dcd2"
"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be"
"checksum dbus 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "48b5f0f36f1eebe901b0e6bee369a77ed3396334bf3f09abd46454a576f71819"
"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e"
"checksum fragile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f8140122fa0d5dcb9fc8627cfce2b37cc1500f752636d46ea28bc26785c2f9"
"checksum gdk 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc52c7244046df9d959df87289f1fc5cca23f9f850bab0c967963e2ecb83a96"
@ -451,6 +470,7 @@ dependencies = [
"checksum gtk-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d487d333a4b87072e6bf9f2e55befa0ebef01b9496c2e263c0f4a1ff3d6c04b1"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba"
"checksum libdbus-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc12a3bc971424edbbf7edaf6e5740483444db63aa8e23d3751ff12a30f306f0"
"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
"checksum maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"

View File

@ -4,6 +4,7 @@ version = "0.1.0"
[dependencies]
bitflags = "1.0.*"
dbus = "0.6.*"
maplit = "1.0.*"
regex = "1.1.*"
serde = { version = "1.0.*", features = ["derive"] }

View File

@ -1,7 +1,7 @@
# German layout by Mark Müller
# Version 2019101900
# Version 2019111700
---
bounds: { x: 0, y: 1, width: 360, height: 210 }
bounds: { x: 0, y: 1, width: 360, height: 208 }
outlines:
default:
@ -20,27 +20,27 @@ views:
- "q w e r t z u i o p"
- "a s d f g h j k l"
- "Shift_L y x c v b n m BackSpace"
- "show_numbers show_dechars preferences space , period Return"
- "show_numbers show_eschars preferences space , . Return"
upper:
- "Q W E R T Z U I O P"
- "A S D F G H J K L"
- "Shift_L Y X C V B N M BackSpace"
- "show_numbers show_dechars preferences space ! ? Return"
- "show_numbers show_eschars preferences space ! ? Return"
numbers:
- "1 2 3 4 5 6 7 8 9 0"
- "@ # € % & - _ + ( )"
- "show_symbols , \" ' colon = < > BackSpace"
- "show_letters show_dechars preferences space , period Return"
- "show_symbols , \" ' : = < > BackSpace"
- "show_letters show_eschars preferences space , . Return"
symbols:
- "~ ` ´ | · √ µ ÷ × ¶"
- "© ® £ $ ¥ ^ ° * { }"
- "show_numbers \\ / § π τ [ ] BackSpace"
- "show_letters show_dechars preferences space , period Return"
dechars:
- "show_letters show_eschars preferences space , . Return"
eschars:
- "ä è é ö ü Ä È É Ö Ü"
- "à â ê î ô À Â È Î Ô"
- "show_numbers « » ç Ç æ œ ß BackSpace"
- "show_letters show_dechars preferences space „ “ Return"
- "show_letters show_eschars preferences space „ “ Return"
buttons:
Shift_L:
@ -53,6 +53,7 @@ buttons:
BackSpace:
outline: "altline"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
preferences:
action: "show_prefs"
outline: "special"
@ -72,24 +73,18 @@ buttons:
set_view: "symbols"
outline: "altline"
label: "*/="
show_dechars:
show_eschars:
action:
locking:
lock_view: "dechars"
lock_view: "eschars"
unlock_view: "base"
outline: "altline"
label: "äÄ"
period:
outline: "default"
label: "."
space:
outline: "spaceline"
label: " "
keysym: "space"
Return:
outline: "altline"
icon: "key-enter"
colon:
label: ":"
"\"":
keysym: "quotedbl"
keysym: "Return"

View File

@ -1,7 +1,7 @@
# Japanese Kana layout by Mark Müller
# Version 2019101900
# Version 2019111800
---
bounds: { x: 0, y: 1, width: 360, height: 210 }
bounds: { x: 0, y: 1, width: 360, height: 208 }
outlines:
default:
@ -199,25 +199,29 @@ views:
- "\\ ´ ` · ¶"
buttons:
# following 4 buttons are keysyms from libxkbcommon
# following 4 buttons use the corresponding xkb name as keysym
BackSpace:
outline: "wide"
icon: "edit-clear-symbolic"
keysym: "BackSpace"
Return:
outline: "wide"
icon: "key-enter"
keysym: "Return"
Left:
outline: "wide"
label: "←"
keysym: "Left"
Right:
outline: "wide"
label: "→"
keysym: "Right"
# special button "preferences" is handled in the code
preferences:
action: "show_prefs"
outline: "special"
icon: "keyboard-mode-symbolic"
# space button (unicode)
# space button with unicode keysym for ideographic space
space:
outline: "default-wide"
label: "␣"

8
data/langs/de-DE.txt Normal file
View File

@ -0,0 +1,8 @@
us Englisch (US)
de Deutsch
el Griechisch
es Spanisch
it Italienisch
jp+kana Japanisch (Kana)
no Norwegisch

View File

@ -2,7 +2,9 @@ us English (US)
de German
el Greek
es Spanish
fi Finnish
it Italian
jp+kana Japanese (kana)
nb Norwegian
no Norwegian
se Swedish

7
data/langs/es-ES.txt Normal file
View File

@ -0,0 +1,7 @@
us Inglés (EE.UU.)
de Alemán
el Griego
es Español
it Italiano
jp+kana Japonés (Kana)
no Noruego

View File

@ -2,7 +2,8 @@ us angielski (USA)
de niemiecki
el grecki
es hiszpański
fi fiński
it włoski
jp+kana japoński (kana)
nb norweski
no norweski
se szwedzki

1
debian/control vendored
View File

@ -12,6 +12,7 @@ Build-Depends:
libgtk-3-dev,
libcroco3-dev,
librust-bitflags-1-dev (>= 1.0),
librust-dbus-0.6-dev (>= 0.6),
librust-gio+v2-44-dev,
librust-glib+v2-44-dev,
librust-glib-sys-dev,

View File

@ -50,8 +50,7 @@ typedef struct _EekRendererPrivate
gint origin_x;
gint origin_y;
PangoFontDescription *ascii_font;
PangoFontDescription *font;
PangoFontDescription *font; // owned reference
cairo_surface_t *keyboard_surface;
} EekRendererPrivate;
@ -59,8 +58,7 @@ typedef struct _EekRendererPrivate
G_DEFINE_TYPE_WITH_PRIVATE (EekRenderer, eek_renderer, G_TYPE_OBJECT)
/* eek-keyboard-drawing.c */
static void eek_renderer_real_render_button_label (EekRenderer *self,
PangoLayout *layout,
static void eek_renderer_render_button_label (EekRenderer *self, cairo_t *cr, GtkStyleContext *ctx,
const struct squeek_button *button);
static void invalidate (EekRenderer *renderer);
@ -125,9 +123,9 @@ static void
render_keyboard_surface (EekRenderer *renderer, struct squeek_view *view)
{
EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer);
EekColor foreground;
eek_renderer_get_foreground_color (priv->view_context, &foreground);
GdkRGBA color = {0};
gtk_style_context_get_color (priv->view_context, GTK_STATE_FLAG_NORMAL, &color);
EekBounds bounds = squeek_view_get_bounds (level_keyboard_current(priv->keyboard));
@ -152,15 +150,16 @@ render_keyboard_surface (EekRenderer *renderer, struct squeek_view *view)
cairo_translate (data.cr, bounds.x, bounds.y);
cairo_set_source_rgba (data.cr,
foreground.red,
foreground.green,
foreground.blue,
foreground.alpha);
color.red,
color.green,
color.blue,
color.alpha);
/* draw rows */
squeek_view_foreach(level_keyboard_current(priv->keyboard),
create_keyboard_surface_row_callback,
&data);
cairo_restore (data.cr);
cairo_destroy (data.cr);
@ -198,9 +197,6 @@ static void render_button_in_context(EekRenderer *self,
struct button_place *place,
gboolean active) {
cairo_surface_t *outline_surface = NULL;
PangoLayout *layout;
PangoRectangle extents = { 0, };
EekColor foreground;
/* render outline */
EekBounds bounds = squeek_button_get_bounds(place->button);
@ -231,7 +227,6 @@ static void render_button_in_context(EekRenderer *self,
cairo_surface_destroy(outline_surface);
cairo_paint (cr);
eek_renderer_get_foreground_color (ctx, &foreground);
/* render icon (if any) */
const char *icon_name = squeek_button_get_icon_name(place->button);
@ -249,10 +244,13 @@ static void render_button_in_context(EekRenderer *self,
cairo_rectangle (cr, 0, 0, width, height);
cairo_clip (cr);
/* Draw the shape of the icon using the foreground color */
cairo_set_source_rgba (cr, foreground.red,
foreground.green,
foreground.blue,
foreground.alpha);
GdkRGBA color = {0};
gtk_style_context_get_color (ctx, GTK_STATE_FLAG_NORMAL, &color);
cairo_set_source_rgba (cr, color.red,
color.green,
color.blue,
color.alpha);
cairo_mask_surface (cr, icon_surface, 0.0, 0.0);
cairo_surface_destroy(icon_surface);
cairo_fill (cr);
@ -260,25 +258,7 @@ static void render_button_in_context(EekRenderer *self,
return;
}
}
/* render label */
layout = pango_cairo_create_layout (cr);
eek_renderer_real_render_button_label (self, layout, place->button);
pango_layout_get_extents (layout, NULL, &extents);
cairo_save (cr);
cairo_move_to
(cr,
(bounds.width - (double)extents.width / PANGO_SCALE) / 2,
(bounds.height - (double)extents.height / PANGO_SCALE) / 2);
cairo_set_source_rgba (cr,
foreground.red,
foreground.green,
foreground.blue,
foreground.alpha);
pango_cairo_show_layout (cr, layout);
cairo_restore (cr);
g_object_unref (layout);
eek_renderer_render_button_label (self, cr, ctx, place->button);
}
static void
@ -363,9 +343,10 @@ eek_renderer_apply_transformation_for_button (cairo_t *cr,
}
static void
eek_renderer_real_render_button_label (EekRenderer *self,
PangoLayout *layout,
const struct squeek_button *button)
eek_renderer_render_button_label (EekRenderer *self,
cairo_t *cr,
GtkStyleContext *ctx,
const struct squeek_button *button)
{
EekRendererPrivate *priv = eek_renderer_get_instance_private (self);
@ -381,16 +362,11 @@ eek_renderer_real_render_button_label (EekRenderer *self,
if (!priv->font) {
const PangoFontDescription *base_font;
gdouble ascii_size, size;
gdouble size;
base_font = pango_context_get_font_description (priv->pcontext);
// FIXME: Base font size on the same size unit used for button sizing,
// and make the default about 1/3 of the current row height
ascii_size = 30000.0;
priv->ascii_font = pango_font_description_copy (base_font);
pango_font_description_set_size (priv->ascii_font,
(gint)round(ascii_size));
size = 30000.0;
priv->font = pango_font_description_copy (base_font);
pango_font_description_set_size (priv->font, (gint)round(size * 0.6));
@ -403,6 +379,8 @@ eek_renderer_real_render_button_label (EekRenderer *self,
font = pango_font_description_copy (priv->font);
pango_font_description_set_size (font,
(gint)round(pango_font_description_get_size (font) * scale));
PangoLayout *layout = pango_cairo_create_layout (cr);
pango_layout_set_font_description (layout, font);
pango_font_description_free (font);
@ -413,6 +391,27 @@ eek_renderer_real_render_button_label (EekRenderer *self,
}
pango_layout_set_width (layout,
PANGO_SCALE * bounds.width * scale);
PangoRectangle extents = { 0, };
pango_layout_get_extents (layout, NULL, &extents);
cairo_save (cr);
cairo_move_to
(cr,
(bounds.width - (double)extents.width / PANGO_SCALE) / 2,
(bounds.height - (double)extents.height / PANGO_SCALE) / 2);
GdkRGBA color = {0};
gtk_style_context_get_color (ctx, GTK_STATE_FLAG_NORMAL, &color);
cairo_set_source_rgba (cr,
color.red,
color.green,
color.blue,
color.alpha);
pango_cairo_show_layout (cr, layout);
cairo_restore (cr);
g_object_unref (layout);
}
/*
@ -550,7 +549,6 @@ eek_renderer_finalize (GObject *object)
g_object_unref(priv->css_provider);
g_object_unref(priv->view_context);
g_object_unref(priv->button_context);
pango_font_description_free (priv->ascii_font);
pango_font_description_free (priv->font);
G_OBJECT_CLASS (eek_renderer_parent_class)->finalize (object);
}
@ -850,22 +848,6 @@ eek_renderer_render_keyboard (EekRenderer *renderer,
EEK_RENDERER_GET_CLASS(renderer)->render_keyboard (renderer, cr);
}
void
eek_renderer_get_foreground_color (GtkStyleContext *context,
EekColor *color)
{
g_return_if_fail (color);
GtkStateFlags flags = GTK_STATE_FLAG_NORMAL;
GdkRGBA gcolor;
gtk_style_context_get_color (context, flags, &gcolor);
color->red = gcolor.red;
color->green = gcolor.green;
color->blue = gcolor.blue;
color->alpha = gcolor.alpha;
}
static gboolean
sign (EekPoint *p1, EekPoint *p2, EekPoint *p3)
{

View File

@ -86,16 +86,6 @@ cairo_surface_t *eek_renderer_get_icon_surface(const gchar *icon_name,
void eek_renderer_render_keyboard (EekRenderer *renderer,
cairo_t *cr);
void eek_renderer_set_default_foreground_color
(EekRenderer *renderer,
const EekColor *color);
void eek_renderer_set_default_background_color
(EekRenderer *renderer,
const EekColor *color);
void eek_renderer_get_foreground_color
(GtkStyleContext *context,
EekColor *color);
void eek_renderer_set_border_width (EekRenderer *renderer,
gdouble border_width);
void eek_renderer_apply_transformation_for_button

View File

@ -72,35 +72,3 @@ eek_bounds_free (EekBounds *bounds)
{
g_slice_free (EekBounds, bounds);
}
/* EekColor */
G_DEFINE_BOXED_TYPE(EekColor, eek_color, eek_color_copy, eek_color_free);
EekColor *
eek_color_copy (const EekColor *color)
{
return g_slice_dup (EekColor, color);
}
void
eek_color_free (EekColor *color)
{
g_slice_free (EekColor, color);
}
EekColor *
eek_color_new (gdouble red,
gdouble green,
gdouble blue,
gdouble alpha)
{
EekColor *color;
color = g_slice_new (EekColor);
color->red = red;
color->green = green;
color->blue = blue;
color->alpha = alpha;
return color;
}

View File

@ -34,10 +34,8 @@ G_BEGIN_DECLS
#define EEK_TYPE_POINT (eek_point_get_type ())
#define EEK_TYPE_BOUNDS (eek_bounds_get_type ())
#define EEK_TYPE_COLOR (eek_color_get_type ())
typedef struct _EekBounds EekBounds;
typedef struct _EekColor EekColor;
typedef struct _EekboardContextService EekboardContextService;
typedef struct _LevelKeyboard LevelKeyboard;
@ -85,33 +83,6 @@ GType eek_bounds_get_type (void) G_GNUC_CONST;
EekBounds *eek_bounds_copy (const EekBounds *bounds);
void eek_bounds_free (EekBounds *bounds);
/**
* EekColor:
* @red: red component of color, between 0.0 and 1.0
* @green: green component of color, between 0.0 and 1.0
* @blue: blue component of color, between 0.0 and 1.0
* @alpha: alpha component of color, between 0.0 and 1.0
*
* Color used for drawing.
*/
struct _EekColor
{
/*< public >*/
gdouble red;
gdouble green;
gdouble blue;
gdouble alpha;
};
GType eek_color_get_type (void) G_GNUC_CONST;
EekColor *eek_color_new (gdouble red,
gdouble green,
gdouble blue,
gdouble alpha);
EekColor *eek_color_copy (const EekColor *color);
void eek_color_free (EekColor *color);
struct transformation {
gdouble origin_x;
gdouble origin_y;

View File

@ -1,5 +1,6 @@
#[macro_use]
extern crate bitflags;
extern crate dbus;
extern crate gio;
extern crate glib;
extern crate glib_sys;

View File

@ -1,8 +1,8 @@
/*! Locale detection and management.
* Based on https://github.com/rust-locale/locale_config
*
* Ready for deletion/replacement once Debian starts packaging this,
* although this version doesn't need lazy_static.
* Modified for dbus querying.
* This version doesn't need lazy_static.
*
* Copyright (c) 20162019 Jan Hudec <bulb@ucw.cz>
Copyright (c) 2016 A.J. Gardner <aaron.j.gardner@gmail.com>
@ -11,10 +11,13 @@
Copyright (c) 2019, Sophie Tauchert <999eagle@999eagle.moe>
*/
use dbus::Connection;
use regex::Regex;
use std::borrow::Cow;
use std::env;
use dbus::stdintf::org_freedesktop_dbus::Properties;
/// Errors that may be returned by `locale_config`.
#[derive(Copy,Clone,Debug,PartialEq,Eq)]
pub enum Error {
@ -463,19 +466,23 @@ fn tag(s: &str) -> Result<LanguageRange> {
// TODO: Read /etc/locale.alias
fn tag_inv(s: &str) -> LanguageRange {
tag(s).unwrap_or(LanguageRange::invariant())
tag(s).unwrap_or_else(|_e| LanguageRange::invariant())
}
pub fn system_locale() -> Option<Locale> {
/// Returns the locale using Unix roles and the given lookup method.
// TODO: maybe don't drop all errors on the floor like that
fn unix_locale<'a, 'b, F, E>(get: F) -> Locale
where F: Fn(&'a str) -> ::std::result::Result<String, E>
{
// LC_ALL overrides everything
if let Ok(all) = env::var("LC_ALL") {
if let Ok(all) = get("LC_ALL") {
if let Ok(t) = tag(all.as_ref()) {
return Some(Locale::from(t));
return Locale::from(t);
}
}
// LANG is default
let mut loc =
if let Ok(lang) = env::var("LANG") {
if let Ok(lang) = get("LANG") {
Locale::from(tag_inv(lang.as_ref()))
} else {
Locale::invariant()
@ -494,7 +501,7 @@ pub fn system_locale() -> Option<Locale> {
("telephone", "LC_TELEPHONE"),
("measurement", "LC_MEASUREMENT"),
].iter() {
if let Ok(val) = env::var(var) {
if let Ok(val) = get(var) {
if let Ok(tag) = tag(val.as_ref())
{
loc.add_category(cat, &tag);
@ -502,7 +509,7 @@ pub fn system_locale() -> Option<Locale> {
}
}
// LANGUAGE defines fallbacks
if let Ok(langs) = env::var("LANGUAGE") {
if let Ok(langs) = get("LANGUAGE") {
for i in langs.split(':') {
if i != "" {
if let Ok(tag) = tag(i) {
@ -511,16 +518,44 @@ pub fn system_locale() -> Option<Locale> {
}
}
}
if loc.as_ref() != "" {
return Some(loc);
} else {
return None;
}
loc
}
fn env_locale() -> Locale {
unix_locale(env::var)
}
fn dbus_locale()
-> std::result::Result<Locale, Box<dyn std::error::Error>>
{
let connection = Connection::get_private(dbus::BusType::Session)?;
let property = connection.with_path(
"org.freedesktop.locale1", "/org/freedesktop/locale1", 100
);
let locales: Vec<String>
= property.get("org.freedesktop.locale1", "Locale")?;
let val_pairs: Vec<(String, String)> = locales.into_iter().map(|s| {
let mut splits = s.splitn(2, "=");
(splits.next().unwrap().into(), splits.next().unwrap_or("").into())
}).collect();
Ok(unix_locale(|var| {
match val_pairs.iter().find(|(name, _val)| name == &var) {
Some((_name, val)) => Ok(val.clone()),
None => Err(()),
}
}))
}
pub fn system_locale() -> Locale {
dbus_locale().unwrap_or_else(|_e| env_locale())
}
#[cfg(test)]
mod test {
use super::LanguageRange;
use super::*;
#[test]
fn unix_tags() {

View File

@ -39,6 +39,7 @@ cc = meson.get_compiler('c')
deps = [
# dependency('glib-2.0', version: '>=2.26.0'),
dependency('dbus-1', version: '>=1.3'),
dependency('gio-2.0', version: '>=2.26.0'),
dependency('gtk+-3.0', version: '>=3.0'),
dependency('libcroco-0.6'),
@ -72,7 +73,7 @@ build_rstests = custom_target(
output: ['src'],
install: false,
console: true,
command: [cargo_script, '', 'build', '--tests'],
command: [cargo_script, '', 'test', '--no-run'],
depends: rslibs, # no point building tests if the code itself fails
)
@ -80,6 +81,8 @@ test(
'rstest',
cargo_script,
args: ['', 'test'],
# this is a whole Carg-based test suite, let it run for a while
timeout: 900,
depends: build_rstests,
)

View File

@ -110,14 +110,11 @@ pub fn show(window: EekGtkKeyboard, position: ::layout::c::Bounds) {
.map(|(_kind, name)| name.as_str())
.collect();
let translations = system_locale()
.map(|locale|
locale.tags_for("messages")
.next().unwrap() // guaranteed to exist
.as_ref()
.to_owned()
)
.and_then(|lang| resources::get_layout_names(lang.as_str()));
let translations = resources::get_layout_names(system_locale()
.tags_for("messages")
.next().unwrap() // guaranteed to exist by locale_config
.as_ref()
);
// sorted collection of human and machine names
let mut human_names: Vec<(&str, &str)> = match translations {

View File

@ -17,7 +17,7 @@ const KEYBOARDS: &[(*const str, *const str)] = &[
("es", include_str!("../data/keyboards/es.yaml")),
("fi", include_str!("../data/keyboards/fi.yaml")),
("it", include_str!("../data/keyboards/it.yaml")),
("ja+kana", include_str!("../data/keyboards/ja+kana.yaml")),
("jp+kana", include_str!("../data/keyboards/jp+kana.yaml")),
("no", include_str!("../data/keyboards/no.yaml")),
("number", include_str!("../data/keyboards/number.yaml")),
("se", include_str!("../data/keyboards/se.yaml")),
@ -39,7 +39,9 @@ pub fn get_keyboard(needle: &str) -> Option<&'static str> {
/// Translations of the layout identifier strings
const LAYOUT_NAMES: &[(*const str, *const str)] = &[
("de-DE", include_str!("../data/langs/de-DE.txt")),
("en-US", include_str!("../data/langs/en-US.txt")),
("es-ES", include_str!("../data/langs/es-ES.txt")),
("pl-PL", include_str!("../data/langs/pl-PL.txt")),
];

View File

@ -54,7 +54,7 @@ foreach layout : [
'es',
'fi',
'it',
'ja+kana',
'jp+kana',
'no',
'number',
'se',