Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dca0e55557 | |||
| a78f8e246b | |||
| 9d027426b7 | |||
| fdcc4f5aab | |||
| 4e4f8e1932 | |||
| 357a46ced3 | |||
| ed31e40991 | |||
| e06e23dd4c | |||
| 0bfd846139 | |||
| a93f3c55e7 |
20
Cargo.lock
generated
20
Cargo.lock
generated
@ -5,7 +5,7 @@ name = "aho-corasick"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -69,7 +69,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.49"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@ -221,7 +221,7 @@ dependencies = [
|
||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cairo-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cairo-sys-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.49 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gdk 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gdk-pixbuf 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gdk-pixbuf-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -284,7 +284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.2.1"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@ -348,15 +348,15 @@ version = "1.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utf8-ranges 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.12"
|
||||
version = "0.6.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@ -504,7 +504,7 @@ dependencies = [
|
||||
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
|
||||
"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.49 (registry+https://github.com/rust-lang/crates.io-index)" = "e450b8da92aa6f274e7c6437692f9f2ce6d701fb73bacfcf87897b3f89a4c20e"
|
||||
"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
|
||||
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
|
||||
"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"
|
||||
@ -524,7 +524,7 @@ dependencies = [
|
||||
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
|
||||
"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"
|
||||
"checksum memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3197e20c7edb283f87c071ddfc7a2cca8f8e0b888c242959846a6fce03c72223"
|
||||
"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
|
||||
"checksum pango 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4c2cb169402a3eb1ba034a7cc7d95b8b1c106e9be5ba4be79a5a93dc1a2795f4"
|
||||
"checksum pango-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6eb49268e69dd0c1da5d3001a61aac08e2e9d2bfbe4ae4b19b9963c998f6453"
|
||||
@ -532,7 +532,7 @@ dependencies = [
|
||||
"checksum proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0319972dcae462681daf4da1adeeaa066e3ebd29c69be96c6abb1259d2ee2bcc"
|
||||
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
|
||||
"checksum regex 1.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d9d8297cc20bbb6184f8b45ff61c8ee6a9ac56c156cec8e38c3e5084773c44ad"
|
||||
"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
|
||||
"checksum regex-syntax 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e734e891f5b408a29efbf8309e656876276f49ab6a6ac208600b4419bd893d90"
|
||||
"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
|
||||
"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64"
|
||||
"checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35"
|
||||
|
||||
17
debian/changelog
vendored
17
debian/changelog
vendored
@ -1,3 +1,20 @@
|
||||
squeekboard (1.8.0) amber-phone; urgency=medium
|
||||
|
||||
[ Dorota Czaplejewicz ]
|
||||
* translations: Use gnome-desktop's xkb info database for layout names
|
||||
* translations: Make the code cleaner
|
||||
* overlay: Add terminal
|
||||
* eek-layout: Remove unused
|
||||
* pre-release: Update deps
|
||||
|
||||
-- Dorota Czaplejewicz <dorota.czaplejewicz@puri.sm> Tue, 14 Jan 2020 13:55:00 +0000
|
||||
|
||||
squeekboard (1.7.0) amber-phone; urgency=medium
|
||||
|
||||
* New terminal layout appearing on terminal input hint
|
||||
|
||||
-- Dorota Czaplejewicz <dorota.czaplejewicz@puri.sm> Wed, 08 Jan 2020 11:53:07 +0000
|
||||
|
||||
squeekboard (1.7.0) amber-phone; urgency=medium
|
||||
|
||||
* New terminal layout appearing on terminal input hint
|
||||
|
||||
1
debian/control
vendored
1
debian/control
vendored
@ -9,6 +9,7 @@ Build-Depends:
|
||||
ninja-build,
|
||||
pkg-config,
|
||||
libglib2.0-dev,
|
||||
libgnome-desktop-3-dev,
|
||||
libgtk-3-dev,
|
||||
libcroco3-dev,
|
||||
librust-bitflags-1-dev (>= 1.0),
|
||||
|
||||
@ -28,7 +28,6 @@
|
||||
#include <glib-object.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include "eek-types.h"
|
||||
#include "eek-layout.h"
|
||||
#include "src/layout.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:eek-layout
|
||||
* @short_description: Base class of a layout engine
|
||||
*
|
||||
* The #EekLayout class is a base class of layout engine which
|
||||
* arranges keyboard elements.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "eek-layout.h"
|
||||
#include "eek-keyboard.h"
|
||||
#include "eekboard/eekboard-context-service.h"
|
||||
#include "eek-xml-layout.h"
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (EekLayout, eek_layout, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
eek_layout_class_init (EekLayoutClass *klass)
|
||||
{
|
||||
klass->create_keyboard = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
eek_layout_init (EekLayout *self)
|
||||
{
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined(__EEK_H_INSIDE__) && !defined(EEK_COMPILATION)
|
||||
#error "Only <eek/eek.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef EEK_LAYOUT_H
|
||||
#define EEK_LAYOUT_H 1
|
||||
|
||||
#include <glib-object.h>
|
||||
#include "eek-types.h"
|
||||
#include "src/layout.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define EEK_TYPE_LAYOUT (eek_layout_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE (EekLayout, eek_layout, EEK, LAYOUT, GObject)
|
||||
|
||||
/**
|
||||
* EekLayoutClass:
|
||||
* @create_keyboard: virtual function for creating a keyboard
|
||||
*/
|
||||
struct _EekLayoutClass
|
||||
{
|
||||
/*< private >*/
|
||||
GObjectClass parent_class;
|
||||
|
||||
/*< public >*/
|
||||
LevelKeyboard* (* create_keyboard) (EekboardContextService *manager,
|
||||
EekLayout *self,
|
||||
gdouble initial_width,
|
||||
gdouble initial_height);
|
||||
|
||||
/*< private >*/
|
||||
/* padding */
|
||||
gpointer pdummy[24];
|
||||
};
|
||||
|
||||
GType eek_layout_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* EEK_LAYOUT_H */
|
||||
@ -23,7 +23,6 @@
|
||||
#define __EEK_H_INSIDE__ 1
|
||||
|
||||
#include "eek-keyboard.h"
|
||||
#include "eek-layout.h"
|
||||
|
||||
void eek_init (void);
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
project(
|
||||
'squeekboard',
|
||||
'c', 'rust',
|
||||
version: '1.7.0',
|
||||
version: '1.8.0',
|
||||
license: 'GPLv3',
|
||||
meson_version: '>=0.51.0',
|
||||
default_options: [
|
||||
|
||||
@ -1,24 +1,99 @@
|
||||
/*! Locale-specific functions */
|
||||
/*! Locale-specific functions.
|
||||
*
|
||||
* This file is intended as a library:
|
||||
* it must pass errors upwards
|
||||
* and panicking is allowed only when
|
||||
* this code encounters an internal inconsistency.
|
||||
*/
|
||||
|
||||
use std::cmp;
|
||||
use std::ffi::CString;
|
||||
use std::ffi::{ CStr, CString };
|
||||
use std::os::raw::c_char;
|
||||
use std::ptr;
|
||||
use std::str::Utf8Error;
|
||||
|
||||
mod c {
|
||||
use std::os::raw::c_char;
|
||||
use super::*;
|
||||
use std::os::raw::c_void;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type c_int = i32;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct GnomeXkbInfo(*const c_void);
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" {
|
||||
// from libc
|
||||
pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
|
||||
// from gnome-desktop3
|
||||
pub fn gnome_xkb_info_new() -> GnomeXkbInfo;
|
||||
pub fn gnome_xkb_info_get_layout_info (
|
||||
info: GnomeXkbInfo,
|
||||
id: *const c_char,
|
||||
display_name: *mut *const c_char,
|
||||
short_name: *const *const c_char,
|
||||
xkb_layout: *const *const c_char,
|
||||
xkb_variant: *const *const c_char
|
||||
) -> c_int;
|
||||
pub fn g_object_unref(o: GnomeXkbInfo);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
StringConversion(Utf8Error),
|
||||
NoInfo,
|
||||
}
|
||||
|
||||
pub struct XkbInfo(c::GnomeXkbInfo);
|
||||
|
||||
impl XkbInfo {
|
||||
pub fn new() -> XkbInfo {
|
||||
XkbInfo(unsafe { c::gnome_xkb_info_new() })
|
||||
}
|
||||
pub fn get_display_name(&self, id: &str) -> Result<String, Error> {
|
||||
let id = cstring_safe(id);
|
||||
let id_ref = id.as_ptr();
|
||||
let mut display_name: *const c_char = ptr::null();
|
||||
let found = unsafe {
|
||||
c::gnome_xkb_info_get_layout_info(
|
||||
self.0,
|
||||
id_ref,
|
||||
&mut display_name as *mut *const c_char,
|
||||
ptr::null(), ptr::null(), ptr::null(),
|
||||
)
|
||||
};
|
||||
if found != 0 && !display_name.is_null() {
|
||||
let display_name = unsafe { CStr::from_ptr(display_name) };
|
||||
display_name.to_str()
|
||||
.map(str::to_string)
|
||||
.map_err(Error::StringConversion)
|
||||
} else {
|
||||
Err(Error::NoInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for XkbInfo {
|
||||
fn drop(&mut self) {
|
||||
unsafe { c::g_object_unref(self.0) }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Translation<'a>(pub &'a str);
|
||||
|
||||
impl<'a> Translation<'a> {
|
||||
pub fn to_owned(&'a self) -> OwnedTranslation {
|
||||
OwnedTranslation(self.0.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct OwnedTranslation(pub String);
|
||||
|
||||
fn cstring_safe(s: &str) -> CString {
|
||||
CString::new(s)
|
||||
.unwrap_or(CString::new("").unwrap())
|
||||
|
||||
@ -70,12 +70,12 @@ pub enum Level {
|
||||
/// Approach 2.
|
||||
pub trait Warn {
|
||||
type Value;
|
||||
fn ok_warn(self, msg: &str) -> Option<Self::Value>;
|
||||
fn or_warn(self, msg: &str) -> Option<Self::Value>;
|
||||
}
|
||||
|
||||
impl<T, E: Error> Warn for Result<T, E> {
|
||||
type Value = T;
|
||||
fn ok_warn(self, msg: &str) -> Option<T> {
|
||||
fn or_warn(self, msg: &str) -> Option<T> {
|
||||
self.map_err(|e| {
|
||||
eprintln!("{}: {}", msg, e);
|
||||
e
|
||||
@ -83,6 +83,16 @@ impl<T, E: Error> Warn for Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Warn for Option<T> {
|
||||
type Value = T;
|
||||
fn or_warn(self, msg: &str) -> Option<T> {
|
||||
self.or_else(|| {
|
||||
eprintln!("{}", msg);
|
||||
None
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A mutable handler for text warnings.
|
||||
/// Approach 3.
|
||||
pub trait WarningHandler {
|
||||
|
||||
@ -19,7 +19,6 @@ sources = [
|
||||
'../eek/eek-element.c',
|
||||
'../eek/eek-gtk-keyboard.c',
|
||||
'../eek/eek-keyboard.c',
|
||||
'../eek/eek-layout.c',
|
||||
'../eek/eek-renderer.c',
|
||||
'../eek/eek-types.c',
|
||||
'../eek/eek-xml-layout.c',
|
||||
@ -39,6 +38,7 @@ cc = meson.get_compiler('c')
|
||||
deps = [
|
||||
# dependency('glib-2.0', version: '>=2.26.0'),
|
||||
dependency('gio-2.0', version: '>=2.26.0'),
|
||||
dependency('gnome-desktop-3.0', version: '>=3.0'),
|
||||
dependency('gtk+-3.0', version: '>=3.0'),
|
||||
dependency('libcroco-0.6'),
|
||||
dependency('wayland-client', version: '>=1.14'),
|
||||
|
||||
117
src/popover.rs
117
src/popover.rs
@ -4,7 +4,8 @@ use gio;
|
||||
use gtk;
|
||||
use std::ffi::CString;
|
||||
use ::layout::c::{ Bounds, EekGtkKeyboard };
|
||||
use ::locale::{ Translation, compare_current_locale };
|
||||
use ::locale;
|
||||
use ::locale::{ OwnedTranslation, Translation, compare_current_locale };
|
||||
use ::locale_config::system_locale;
|
||||
use ::manager;
|
||||
use ::resources;
|
||||
@ -17,6 +18,7 @@ use glib::variant::ToVariant;
|
||||
use gtk::PopoverExt;
|
||||
use gtk::WidgetExt;
|
||||
use std::io::Write;
|
||||
use ::logging::Warn;
|
||||
|
||||
mod variants {
|
||||
use glib;
|
||||
@ -94,7 +96,7 @@ mod variants {
|
||||
}
|
||||
}
|
||||
|
||||
fn make_menu_builder(inputs: Vec<(&str, Translation)>) -> gtk::Builder {
|
||||
fn make_menu_builder(inputs: Vec<(&str, OwnedTranslation)>) -> gtk::Builder {
|
||||
let mut xml: Vec<u8> = Vec::new();
|
||||
writeln!(
|
||||
xml,
|
||||
@ -194,6 +196,82 @@ fn get_current_layout(
|
||||
}
|
||||
}
|
||||
|
||||
/// Translates all provided layout names according to current locale,
|
||||
/// for the purpose of display (i.e. errors will be caught and reported)
|
||||
fn translate_layout_names(layouts: &Vec<LayoutId>) -> Vec<OwnedTranslation> {
|
||||
// This procedure is rather ugly...
|
||||
// Xkb lookup *must not* be applied to non-system layouts,
|
||||
// so both translators can't be merged into one lookup table,
|
||||
// therefore must be done in two steps.
|
||||
// `XkbInfo` being temporary also means
|
||||
// that its return values must be copied,
|
||||
// forcing the use of `OwnedTranslation`.
|
||||
enum Status {
|
||||
/// xkb names should get all translated here
|
||||
Translated(OwnedTranslation),
|
||||
/// Builtin names need builtin translations
|
||||
Remaining(String),
|
||||
}
|
||||
|
||||
// Attempt to take all xkb names from gnome-desktop's xkb info.
|
||||
let xkb_translator = locale::XkbInfo::new();
|
||||
|
||||
let translated_names = layouts.iter()
|
||||
.map(|id| match id {
|
||||
LayoutId::System { name, kind: _ } => {
|
||||
xkb_translator.get_display_name(name)
|
||||
.map(|s| Status::Translated(OwnedTranslation(s)))
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!(
|
||||
"No display name for xkb layout {}: {:?}",
|
||||
name,
|
||||
e,
|
||||
);
|
||||
Status::Remaining(name.clone())
|
||||
})
|
||||
},
|
||||
LayoutId::Local(name) => Status::Remaining(name.clone()),
|
||||
});
|
||||
|
||||
// Non-xkb layouts and weird xkb layouts
|
||||
// still need to be looked up in the internal database.
|
||||
let builtin_translations = system_locale()
|
||||
.map(|locale|
|
||||
locale.tags_for("messages")
|
||||
.next().unwrap() // guaranteed to exist
|
||||
.as_ref()
|
||||
.to_owned()
|
||||
)
|
||||
.or_warn("No locale detected")
|
||||
.and_then(|lang| {
|
||||
resources::get_layout_names(lang.as_str())
|
||||
.or_warn(&format!("No translations for locale {}", lang))
|
||||
});
|
||||
|
||||
match builtin_translations {
|
||||
Some(translations) => {
|
||||
translated_names
|
||||
.map(|status| match status {
|
||||
Status::Remaining(name) => {
|
||||
translations.get(name.as_str())
|
||||
.unwrap_or(&Translation(name.as_str()))
|
||||
.to_owned()
|
||||
},
|
||||
Status::Translated(t) => t,
|
||||
})
|
||||
.collect()
|
||||
},
|
||||
None => {
|
||||
translated_names
|
||||
.map(|status| match status {
|
||||
Status::Remaining(name) => OwnedTranslation(name),
|
||||
Status::Translated(t) => t,
|
||||
})
|
||||
.collect()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show(
|
||||
window: EekGtkKeyboard,
|
||||
position: Bounds,
|
||||
@ -218,46 +296,21 @@ pub fn show(
|
||||
.chain(overlay_layouts)
|
||||
.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 translated_names = all_layouts.iter()
|
||||
.map(LayoutId::get_name);
|
||||
let translated_names: Vec<Translation> = match translations {
|
||||
Some(translations) => {
|
||||
translated_names
|
||||
.map(move |name| {
|
||||
translations.get(name)
|
||||
.map(|translation| translation.clone())
|
||||
.unwrap_or(Translation(name))
|
||||
})
|
||||
.collect()
|
||||
},
|
||||
None => {
|
||||
translated_names.map(|name| Translation(name))
|
||||
.collect()
|
||||
},
|
||||
};
|
||||
let translated_names = translate_layout_names(&all_layouts);
|
||||
|
||||
// sorted collection of human and machine names
|
||||
let mut human_names: Vec<(Translation, LayoutId)> = translated_names
|
||||
let mut human_names: Vec<(OwnedTranslation, LayoutId)> = translated_names
|
||||
.into_iter()
|
||||
.zip(all_layouts.clone().into_iter())
|
||||
.collect();
|
||||
|
||||
human_names.sort_unstable_by(|(tr_a, _), (tr_b, _)| {
|
||||
compare_current_locale(tr_a.0, tr_b.0)
|
||||
compare_current_locale(&tr_a.0, &tr_b.0)
|
||||
});
|
||||
|
||||
// GVariant doesn't natively support `enum`s,
|
||||
// so the `choices` vector will serve as a lookup table.
|
||||
let choices_with_translations: Vec<(String, (Translation, LayoutId))>
|
||||
let choices_with_translations: Vec<(String, (OwnedTranslation, LayoutId))>
|
||||
= human_names.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, human_entry)| {(
|
||||
@ -268,7 +321,7 @@ pub fn show(
|
||||
|
||||
let builder = make_menu_builder(
|
||||
choices_with_translations.iter()
|
||||
.map(|(id, (translation, _))| (id.as_str(), translation.clone()))
|
||||
.map(|(id, (translation, _))| (id.as_str(), (*translation).clone()))
|
||||
.collect()
|
||||
);
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ use std::iter::FromIterator;
|
||||
// and what a convenience layout. "_wide" is not a layout,
|
||||
// neither is "number"
|
||||
const KEYBOARDS: &[(*const str, *const str)] = &[
|
||||
// layouts
|
||||
("us", include_str!("../data/keyboards/us.yaml")),
|
||||
("us_wide", include_str!("../data/keyboards/us_wide.yaml")),
|
||||
("de", include_str!("../data/keyboards/de.yaml")),
|
||||
@ -24,6 +25,7 @@ const KEYBOARDS: &[(*const str, *const str)] = &[
|
||||
("no", include_str!("../data/keyboards/no.yaml")),
|
||||
("number", include_str!("../data/keyboards/number.yaml")),
|
||||
("se", include_str!("../data/keyboards/se.yaml")),
|
||||
// layout+overlay
|
||||
("terminal", include_str!("../data/keyboards/terminal.yaml")),
|
||||
// Overlays
|
||||
("emoji", include_str!("../data/keyboards/emoji.yaml")),
|
||||
@ -44,7 +46,8 @@ pub fn get_keyboard(needle: &str) -> Option<&'static str> {
|
||||
}
|
||||
|
||||
const OVERLAY_NAMES: &[*const str] = &[
|
||||
"emoji"
|
||||
"emoji",
|
||||
"terminal",
|
||||
];
|
||||
|
||||
pub fn get_overlays() -> Vec<&'static str> {
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.Free
|
||||
*/
|
||||
|
||||
/*! CSS data loading */
|
||||
/*! CSS data loading. */
|
||||
|
||||
use std::env;
|
||||
|
||||
@ -83,6 +83,7 @@ fn get_theme_name(settings: >k::Settings) -> GtkTheme {
|
||||
.map_err(|e| {
|
||||
match &e {
|
||||
env::VarError::NotPresent => {},
|
||||
// maybe TODO: forward this warning?
|
||||
e => eprintln!("GTK_THEME variable invalid: {}", e),
|
||||
};
|
||||
e
|
||||
@ -93,13 +94,15 @@ fn get_theme_name(settings: >k::Settings) -> GtkTheme {
|
||||
None => GtkTheme {
|
||||
name: {
|
||||
settings.get_property("gtk-theme-name")
|
||||
.ok_warn("No theme name")
|
||||
// maybe TODO: is this worth a warning?
|
||||
.or_warn("No theme name")
|
||||
.and_then(|value| value.get::<String>())
|
||||
.unwrap_or(DEFAULT_THEME_NAME.into())
|
||||
},
|
||||
variant: {
|
||||
settings.get_property("gtk-application-prefer-dark-theme")
|
||||
.ok_warn("No settings key")
|
||||
// maybe TODO: is this worth a warning?
|
||||
.or_warn("No settings key")
|
||||
.and_then(|value| value.get::<bool>())
|
||||
.and_then(|dark_preferred| match dark_preferred {
|
||||
true => Some("dark".into()),
|
||||
|
||||
@ -190,6 +190,11 @@ impl<T> Borrow<Rc<T>> for Pointer<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WarningHandler {
|
||||
/// Handle a warning
|
||||
fn handle(&mut self, warning: &str);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user