Commit de8aaa1a authored by Dorota Czaplejewicz's avatar Dorota Czaplejewicz
Browse files

Merge remote-tracking branch 'upstream/master' into text_input_enable

parents 585ed5e9 ac360b61
......@@ -45,6 +45,7 @@ build_deb:
paths:
- "*.deb"
script:
- rm -f ../*.deb
- apt-get -y build-dep .
- apt-get -y install devscripts
- debuild -i -us -uc -b
......@@ -59,6 +60,7 @@ build_deb:arm64:
paths:
- "*.deb"
script:
- rm -f ../*.deb
- apt-get -y build-dep .
- apt-get -y install devscripts
- debuild -i -us -uc -b
......
This diff is collapsed.
squeekboard (1.6.0) UNRELEASED; urgency=medium
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
-- Dorota Czaplejewicz <dorota.czaplejewicz@puri.sm> Wed, 08 Jan 2020 11:53:07 +0000
squeekboard (1.6.0) amber-phone; urgency=medium
[ Dorota Czaplejewicz ]
* tools: Move entry.py
......
......@@ -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),
......
project(
'squeekboard',
'c', 'rust',
version: '1.6.0',
version: '1.8.0',
license: 'GPLv3',
meson_version: '>=0.51.0',
default_options: [
......
......@@ -22,7 +22,7 @@ use ::keyboard::{
};
use ::layout;
use ::layout::ArrangementKind;
use ::logging::PrintWarnings;
use ::logging;
use ::resources;
use ::util::c::as_str;
use ::util::hash_map_map;
......@@ -32,7 +32,7 @@ use ::xdg;
use serde::Deserialize;
use std::io::BufReader;
use std::iter::FromIterator;
use ::logging::WarningHandler;
use ::logging::Warn;
/// Gathers stuff defined in C or called by C
pub mod c {
......@@ -158,7 +158,7 @@ fn list_layout_sources(
fn load_layout_data(source: DataSource)
-> Result<::layout::LayoutData, LoadError>
{
let handler = PrintWarnings{};
let handler = logging::Print {};
match source {
DataSource::File(path) => {
Layout::from_file(path.clone())
......@@ -191,11 +191,13 @@ fn load_layout_data_with_fallback(
(
LoadError::BadData(Error::Missing(e)),
DataSource::File(file)
) => eprintln!( // TODO: print in debug logging level
) => log_print!(
logging::Level::Debug,
"Tried file {:?}, but it's missing: {}",
file, e
),
(e, source) => eprintln!(
(e, source) => log_print!(
logging::Level::Warning,
"Failed to load layout from {}: {}, skipping",
source, e
),
......@@ -334,7 +336,7 @@ impl Layout {
serde_yaml::from_reader(infile).map_err(Error::Yaml)
}
pub fn build<H: WarningHandler>(self, mut warning_handler: H)
pub fn build<H: logging::Handler>(self, mut warning_handler: H)
-> (Result<::layout::LayoutData, FormattingError>, H)
{
let button_names = self.views.values()
......@@ -472,7 +474,7 @@ impl Layout {
}
}
fn create_action<H: WarningHandler>(
fn create_action<H: logging::Handler>(
button_info: &HashMap<String, ButtonMeta>,
name: &str,
view_names: Vec<&String>,
......@@ -502,15 +504,18 @@ fn create_action<H: WarningHandler>(
(None, None, Some(text)) => SubmitData::Text(text.clone()),
(None, None, None) => SubmitData::Text(name.into()),
_ => {
warning_handler.handle(&format!(
"Button {} has more than one of (action, keysym, text)",
name
));
warning_handler.handle(
logging::Level::Warning,
&format!(
"Button {} has more than one of (action, keysym, text)",
name,
),
);
SubmitData::Text("".into())
},
};
fn filter_view_name<H: WarningHandler>(
fn filter_view_name<H: logging::Handler>(
button_name: &str,
view_name: String,
view_names: &Vec<&String>,
......@@ -519,10 +524,13 @@ fn create_action<H: WarningHandler>(
if view_names.contains(&&view_name) {
view_name
} else {
warning_handler.handle(&format!("Button {} switches to missing view {}",
button_name,
view_name,
));
warning_handler.handle(
logging::Level::Warning,
&format!("Button {} switches to missing view {}",
button_name,
view_name,
),
);
"base".into()
}
}
......@@ -562,27 +570,24 @@ fn create_action<H: WarningHandler>(
match keysym_valid(keysym.as_str()) {
true => keysym.clone(),
false => {
warning_handler.handle(&format!(
"Keysym name invalid: {}",
keysym,
));
warning_handler.handle(
logging::Level::Warning,
&format!(
"Keysym name invalid: {}",
keysym,
),
);
"space".into() // placeholder
},
}
)),
},
SubmitData::Text(text) => ::action::Action::Submit {
text: {
CString::new(text.clone())
.map_err(|e| {
warning_handler.handle(&format!(
"Text {} contains problems: {:?}",
text,
e
));
e
}).ok()
},
text: CString::new(text.clone()).or_warn(
warning_handler,
logging::Problem::Warning,
&format!("Text {} contains problems", text),
),
keys: text.chars().map(|codepoint| {
let codepoint_string = codepoint.to_string();
::action::KeySym(match keysym_valid(codepoint_string.as_str()) {
......@@ -596,7 +601,7 @@ fn create_action<H: WarningHandler>(
/// TODO: Since this will receive user-provided data,
/// all .expect() on them should be turned into soft fails
fn create_button<H: WarningHandler>(
fn create_button<H: logging::Handler>(
button_info: &HashMap<String, ButtonMeta>,
outlines: &HashMap<String, Outline>,
name: &str,
......@@ -620,14 +625,11 @@ fn create_button<H: WarningHandler>(
} else if let Some(text) = &button_meta.text {
::layout::Label::Text(
CString::new(text.as_str())
.unwrap_or_else(|e| {
warning_handler.handle(&format!(
"Text {} is invalid: {}",
text,
e,
));
CString::new("").unwrap()
})
.or_warn(
warning_handler,
logging::Problem::Warning,
&format!("Text {} is invalid", text),
).unwrap_or_else(|| CString::new("").unwrap())
)
} else {
::layout::Label::Text(cname.clone())
......@@ -638,7 +640,10 @@ fn create_button<H: WarningHandler>(
if outlines.contains_key(outline) {
outline.clone()
} else {
warning_handler.handle(&format!("Outline named {} does not exist! Using default for button {}", outline, name));
warning_handler.handle(
logging::Level::Warning,
&format!("Outline named {} does not exist! Using default for button {}", outline, name)
);
"default".into()
}
}
......@@ -647,12 +652,11 @@ fn create_button<H: WarningHandler>(
let outline = outlines.get(&outline_name)
.map(|outline| (*outline).clone())
.unwrap_or_else(|| {
warning_handler.handle(
&format!("No default outline defined! Using 1x1!")
);
Outline { width: 1f64, height: 1f64 }
});
.or_warn(
warning_handler,
logging::Problem::Warning,
"No default outline defined! Using 1x1!",
).unwrap_or(Outline { width: 1f64, height: 1f64 });
layout::Button {
name: cname,
......@@ -672,7 +676,7 @@ mod tests {
use super::*;
use std::error::Error as ErrorTrait;
use ::logging::PanicWarn;
use ::logging::ProblemPanic;
#[test]
fn test_parse_path() {
......@@ -742,7 +746,7 @@ mod tests {
fn test_layout_punctuation() {
let out = Layout::from_file(PathBuf::from("tests/layout_key1.yaml"))
.unwrap()
.build(PanicWarn).0
.build(ProblemPanic).0
.unwrap();
assert_eq!(
out.views["base"]
......@@ -757,7 +761,7 @@ mod tests {
fn test_layout_unicode() {
let out = Layout::from_file(PathBuf::from("tests/layout_key2.yaml"))
.unwrap()
.build(PanicWarn).0
.build(ProblemPanic).0
.unwrap();
assert_eq!(
out.views["base"]
......@@ -773,7 +777,7 @@ mod tests {
fn test_layout_unicode_multi() {
let out = Layout::from_file(PathBuf::from("tests/layout_key3.yaml"))
.unwrap()
.build(PanicWarn).0
.build(ProblemPanic).0
.unwrap();
assert_eq!(
out.views["base"]
......@@ -788,7 +792,7 @@ mod tests {
#[test]
fn parsing_fallback() {
assert!(Layout::from_resource(FALLBACK_LAYOUT_NAME)
.map(|layout| layout.build(PanicWarn).0.unwrap())
.map(|layout| layout.build(ProblemPanic).0.unwrap())
.is_ok()
);
}
......@@ -836,7 +840,7 @@ mod tests {
},
".",
Vec::new(),
&mut PanicWarn,
&mut ProblemPanic,
),
::action::Action::Submit {
text: Some(CString::new(".").unwrap()),
......@@ -849,7 +853,7 @@ mod tests {
fn test_layout_margins() {
let out = Layout::from_file(PathBuf::from("tests/layout_margins.yaml"))
.unwrap()
.build(PanicWarn).0
.build(ProblemPanic).0
.unwrap();
assert_eq!(
out.margins,
......
......@@ -5,13 +5,16 @@
use std::boxed::Box;
use std::ffi::CString;
use std::fmt;
use std::num::Wrapping;
use std::string::String;
use ::logging;
use ::util::c::into_cstring;
// Traits
use std::convert::TryFrom;
use ::logging::Warn;
/// Gathers stuff defined in C or called by C
......@@ -95,16 +98,20 @@ pub mod c {
let imservice = check_imservice(imservice, im).unwrap();
imservice.pending = IMProtocolState {
content_hint: {
ContentHint::from_bits(hint).unwrap_or_else(|| {
eprintln!("Warning: received invalid hint flags");
ContentHint::NONE
})
ContentHint::from_bits(hint)
.or_print(
logging::Problem::Warning,
"Received invalid hint flags",
)
.unwrap_or(ContentHint::NONE)
},
content_purpose: {
ContentPurpose::try_from(purpose).unwrap_or_else(|_e| {
eprintln!("Warning: Received invalid purpose value");
ContentPurpose::Normal
})
ContentPurpose::try_from(purpose)
.or_print(
logging::Problem::Warning,
"Received invalid purpose value",
)
.unwrap_or(ContentPurpose::Normal)
},
..imservice.pending.clone()
};
......@@ -119,10 +126,12 @@ pub mod c {
let imservice = check_imservice(imservice, im).unwrap();
imservice.pending = IMProtocolState {
text_change_cause: {
ChangeCause::try_from(cause).unwrap_or_else(|_e| {
eprintln!("Warning: received invalid cause value");
ChangeCause::InputMethod
})
ChangeCause::try_from(cause)
.or_print(
logging::Problem::Warning,
"Received invalid cause value",
)
.unwrap_or(ChangeCause::InputMethod)
},
..imservice.pending.clone()
};
......@@ -250,10 +259,17 @@ pub enum ContentPurpose {
Terminal = 13,
}
// Utilities from ::logging need a printable error type
pub struct UnrecognizedValue;
impl fmt::Display for UnrecognizedValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Unrecognized value")
}
}
impl TryFrom<u32> for ContentPurpose {
// There's only one way to fail: number not in protocol,
// so no special error type is needed
type Error = ();
type Error = UnrecognizedValue;
fn try_from(num: u32) -> Result<Self, Self::Error> {
use self::ContentPurpose::*;
match num {
......@@ -271,7 +287,7 @@ impl TryFrom<u32> for ContentPurpose {
11 => Ok(Time),
12 => Ok(Datetime),
13 => Ok(Terminal),
_ => Err(()),
_ => Err(UnrecognizedValue),
}
}
}
......@@ -284,14 +300,12 @@ pub enum ChangeCause {
}
impl TryFrom<u32> for ChangeCause {
// There's only one way to fail: number not in protocol,
// so no special error type is needed
type Error = ();
type Error = UnrecognizedValue;
fn try_from(num: u32) -> Result<Self, Self::Error> {
match num {
0 => Ok(ChangeCause::InputMethod),
1 => Ok(ChangeCause::Other),
_ => Err(())
_ => Err(UnrecognizedValue)
}
}
}
......
......@@ -9,6 +9,7 @@ use std::rc::Rc;
use std::string::FromUtf8Error;
use ::action::Action;
use ::logging;
// Traits
use std::io::Write;
......@@ -129,7 +130,12 @@ pub fn generate_keymap(
for (name, state) in keystates.iter() {
match &state.action {
Action::Submit { text: _, keys } => {
if let 0 = keys.len() { eprintln!("Key {} has no keysyms", name); };
if let 0 = keys.len() {
log_print!(
logging::Level::Warning,
"Key {} has no keysyms", name,
);
};
for (named_keysym, keycode) in keys.iter().zip(&state.keycodes) {
write!(
buf,
......
......@@ -20,17 +20,21 @@
use std::cell::RefCell;
use std::collections::{ HashMap, HashSet };
use std::ffi::CString;
use std::fmt;
use std::rc::Rc;
use std::vec::Vec;
use ::action::Action;
use ::drawing;
use ::keyboard::{ KeyState, PressType };
use ::logging;
use ::manager;
use ::submission::{ Submission, Timestamp };
use ::util::find_max_double;
// Traits
use std::borrow::Borrow;
use ::logging::Warn;
/// Gathers stuff defined in C or called by C
pub mod c {
......@@ -628,6 +632,12 @@ pub struct LayoutData {
#[derive(Debug)]
struct NoSuchView;
impl fmt::Display for NoSuchView {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "No such view")
}
}
// Unfortunately, changes are not atomic due to mutability :(
// An error will not be recoverable
// The usage of &mut on Rc<RefCell<KeyState>> doesn't mean anything special.
......@@ -793,9 +803,10 @@ mod seat {
fn try_set_view(layout: &mut Layout, view_name: String) {
layout.set_view(view_name.clone())
.map_err(|e|
eprintln!("Bad view {} ({:?}), ignoring", view_name, e)
).ok();
.or_print(
logging::Problem::Bug,
&format!("Bad view {}, ignoring", view_name),
);
}
/// A vessel holding an obligation to switch view.
......@@ -837,9 +848,10 @@ mod seat {
Action::LockView { lock: _, unlock: view } => {
new_view = Some(view.clone());
},
a => eprintln!(
"BUG: action {:?} was found inside locked keys",
a
a => log_print!(
logging::Level::Bug,
"Non-locking action {:?} was found inside locked keys",
a,
),
};
key.locked = false;
......@@ -858,7 +870,10 @@ mod seat {
rckey: &Rc<RefCell<KeyState>>,
) {
if !layout.pressed_keys.insert(::util::Pointer(rckey.clone())) {
eprintln!("Warning: key {:?} was already pressed", rckey);
log_print!(
logging::Level::Bug,
"Key {:?} was already pressed", rckey,
);
}
let mut key = rckey.borrow_mut();
submission.handle_press(&key, KeyState::get_id(rckey), time);
......@@ -936,7 +951,10 @@ mod seat {
}
}
},
Action::SetModifier(_) => eprintln!("Modifiers unsupported"),
Action::SetModifier(_) => log_print!(
logging::Level::Bug,
"Modifiers unsupported",
),
};
let pointer = ::util::Pointer(rckey.clone());
......
......@@ -15,6 +15,9 @@ extern crate regex;
extern crate serde;
extern crate xkbcommon;
#[macro_use]
mod logging;
mod action;
pub mod data;
mod drawing;
......@@ -24,7 +27,6 @@ mod keyboard;
mod layout;
mod locale;
mod locale_config;
mod logging;
mod manager;
mod outputs;
mod popover;
......
/*! 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::fmt;
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,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self, f)
}
}
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() {