Format everything and add rustfmt to travis (#951)

* Format everything and add rustfmt to travis

* Remove extern crate winit from examples and add force_multiline_blocks

* Format the code properly

* Fix inconsistent period in PULL_REQUEST_TEMPLATE.md

* Only run rustfmt on nightly

* Travis fixings
This commit is contained in:
Osspial 2019-06-21 11:33:15 -04:00 committed by GitHub
parent b1b5aefc4b
commit e2c84725de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
109 changed files with 4787 additions and 3679 deletions

View file

@ -1,13 +1,12 @@
use std::ptr;
use std::sync::Arc;
use std::collections::HashMap;
use std::os::raw::c_char;
use std::{collections::HashMap, os::raw::c_char, ptr, sync::Arc};
use super::{ffi, XConnection, XError};
use super::inner::{close_im, ImeInner};
use super::input_method::PotentialInputMethods;
use super::context::{ImeContextCreationError, ImeContext};
use super::{
context::{ImeContext, ImeContextCreationError},
inner::{close_im, ImeInner},
input_method::PotentialInputMethods,
};
pub unsafe fn xim_set_callback(
xconn: &Arc<XConnection>,
@ -17,12 +16,7 @@ pub unsafe fn xim_set_callback(
) -> Result<(), XError> {
// It's advisable to wrap variadic FFI functions in our own functions, as we want to minimize
// access that isn't type-checked.
(xconn.xlib.XSetIMValues)(
xim,
field,
callback,
ptr::null_mut::<()>(),
);
(xconn.xlib.XSetIMValues)(xim, field, callback, ptr::null_mut::<()>());
xconn.check_errors()
}
@ -107,18 +101,14 @@ unsafe fn replace_im(inner: *mut ImeInner) -> Result<(), ReplaceImError> {
let _ = close_im(xconn, new_im.im);
}
result
}.map_err(ReplaceImError::SetDestroyCallbackFailed)?;
}
.map_err(ReplaceImError::SetDestroyCallbackFailed)?;
let mut new_contexts = HashMap::new();
for (window, old_context) in (*inner).contexts.iter() {
let spot = old_context.as_ref().map(|old_context| old_context.ic_spot);
let new_context = {
let result = ImeContext::new(
xconn,
new_im.im,
*window,
spot,
);
let result = ImeContext::new(xconn, new_im.im, *window, spot);
if result.is_err() {
let _ = close_im(xconn, new_im.im);
}
@ -137,7 +127,7 @@ unsafe fn replace_im(inner: *mut ImeInner) -> Result<(), ReplaceImError> {
Ok(())
}
pub unsafe extern fn xim_instantiate_callback(
pub unsafe extern "C" fn xim_instantiate_callback(
_display: *mut ffi::Display,
client_data: ffi::XPointer,
// This field is unsupplied.
@ -160,7 +150,7 @@ pub unsafe extern fn xim_instantiate_callback(
// This callback is triggered when the input method is closed on the server end. When this
// happens, XCloseIM/XDestroyIC doesn't need to be called, as the resources have already been
// free'd (attempting to do so causes our connection to freeze).
pub unsafe extern fn xim_destroy_callback(
pub unsafe extern "C" fn xim_destroy_callback(
_xim: ffi::XIM,
client_data: ffi::XPointer,
// This field is unsupplied.

View file

@ -1,6 +1,8 @@
use std::ptr;
use std::sync::Arc;
use std::os::raw::{c_short, c_void};
use std::{
os::raw::{c_short, c_void},
ptr,
sync::Arc,
};
use super::{ffi, util, XConnection, XError};
@ -22,7 +24,8 @@ unsafe fn create_pre_edit_attr<'a>(
ic_spot,
ptr::null_mut::<()>(),
),
).expect("XVaCreateNestedList returned NULL")
)
.expect("XVaCreateNestedList returned NULL")
}
// WARNING: this struct doesn't destroy its XIC resource when dropped.
@ -49,7 +52,9 @@ impl ImeContext {
};
let ic = ic.ok_or(ImeContextCreationError::Null)?;
xconn.check_errors().map_err(ImeContextCreationError::XError)?;
xconn
.check_errors()
.map_err(ImeContextCreationError::XError)?;
Ok(ImeContext {
ic,

View file

@ -1,12 +1,8 @@
use std::mem;
use std::ptr;
use std::sync::Arc;
use std::collections::HashMap;
use std::{collections::HashMap, mem, ptr, sync::Arc};
use super::{ffi, XConnection, XError};
use super::input_method::PotentialInputMethods;
use super::context::ImeContext;
use super::{context::ImeContext, input_method::PotentialInputMethods};
pub unsafe fn close_im(xconn: &Arc<XConnection>, im: ffi::XIM) -> Result<(), XError> {
(xconn.xlib.XCloseIM)(im);
@ -33,10 +29,7 @@ pub struct ImeInner {
}
impl ImeInner {
pub fn new(
xconn: Arc<XConnection>,
potential_input_methods: PotentialInputMethods,
) -> Self {
pub fn new(xconn: Arc<XConnection>, potential_input_methods: PotentialInputMethods) -> Self {
ImeInner {
xconn,
im: ptr::null_mut(),

View file

@ -1,9 +1,11 @@
use std::env;
use std::fmt;
use std::ptr;
use std::sync::Arc;
use std::os::raw::c_char;
use std::ffi::{CStr, CString, IntoStringError};
use std::{
env,
ffi::{CStr, CString, IntoStringError},
fmt,
os::raw::c_char,
ptr,
sync::Arc,
};
use parking_lot::Mutex;
@ -13,10 +15,7 @@ lazy_static! {
static ref GLOBAL_LOCK: Mutex<()> = Default::default();
}
unsafe fn open_im(
xconn: &Arc<XConnection>,
locale_modifiers: &CStr,
) -> Option<ffi::XIM> {
unsafe fn open_im(xconn: &Arc<XConnection>, locale_modifiers: &CStr) -> Option<ffi::XIM> {
let _lock = GLOBAL_LOCK.lock();
// XSetLocaleModifiers returns...
@ -97,11 +96,9 @@ unsafe fn get_xim_servers(xconn: &Arc<XConnection>) -> Result<Vec<String>, GetXi
let root = (xconn.xlib.XDefaultRootWindow)(xconn.display);
let mut atoms: Vec<ffi::Atom> = xconn.get_property(
root,
servers_atom,
ffi::XA_ATOM,
).map_err(GetXimServersError::GetPropertyError)?;
let mut atoms: Vec<ffi::Atom> = xconn
.get_property(root, servers_atom, ffi::XA_ATOM)
.map_err(GetXimServersError::GetPropertyError)?;
let mut names: Vec<*const c_char> = Vec::with_capacity(atoms.len());
(xconn.xlib.XGetAtomNames)(
@ -135,15 +132,12 @@ impl InputMethodName {
pub fn from_string(string: String) -> Self {
let c_string = CString::new(string.clone())
.expect("String used to construct CString contained null byte");
InputMethodName {
c_string,
string,
}
InputMethodName { c_string, string }
}
pub fn from_str(string: &str) -> Self {
let c_string = CString::new(string)
.expect("String used to construct CString contained null byte");
let c_string =
CString::new(string).expect("String used to construct CString contained null byte");
InputMethodName {
c_string,
string: string.to_owned(),

View file

@ -1,20 +1,24 @@
// Important: all XIM calls need to happen from the same thread!
mod callbacks;
mod context;
mod inner;
mod input_method;
mod context;
mod callbacks;
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender};
use std::sync::{
mpsc::{Receiver, Sender},
Arc,
};
use super::{ffi, util, XConnection, XError};
use self::inner::{close_im, ImeInner};
use self::input_method::PotentialInputMethods;
use self::context::ImeContext;
use self::callbacks::*;
pub use self::context::ImeContextCreationError;
use self::{
callbacks::*,
context::ImeContext,
inner::{close_im, ImeInner},
input_method::PotentialInputMethods,
};
pub type ImeReceiver = Receiver<(ffi::Window, i16, i16)>;
pub type ImeSender = Sender<(ffi::Window, i16, i16)>;
@ -37,10 +41,7 @@ impl Ime {
let potential_input_methods = PotentialInputMethods::new(&xconn);
let (mut inner, client_data) = {
let mut inner = Box::new(ImeInner::new(
xconn,
potential_input_methods,
));
let mut inner = Box::new(ImeInner::new(xconn, potential_input_methods));
let inner_ptr = Box::into_raw(inner);
let client_data = inner_ptr as _;
let destroy_callback = ffi::XIMCallback {
@ -54,9 +55,12 @@ impl Ime {
let xconn = Arc::clone(&inner.xconn);
let input_method = inner.potential_input_methods.open_im(&xconn, Some(&|| {
let _ = unsafe { set_instantiate_callback(&xconn, client_data) };
}));
let input_method = inner.potential_input_methods.open_im(
&xconn,
Some(&|| {
let _ = unsafe { set_instantiate_callback(&xconn, client_data) };
}),
);
let is_fallback = input_method.is_fallback();
if let Some(input_method) = input_method.ok() {
@ -84,19 +88,12 @@ impl Ime {
// Ok(_) indicates that nothing went wrong internally
// Ok(true) indicates that the action was actually performed
// Ok(false) indicates that the action is not presently applicable
pub fn create_context(&mut self, window: ffi::Window)
-> Result<bool, ImeContextCreationError>
{
pub fn create_context(&mut self, window: ffi::Window) -> Result<bool, ImeContextCreationError> {
let context = if self.is_destroyed() {
// Create empty entry in map, so that when IME is rebuilt, this window has a context.
None
} else {
Some(unsafe { ImeContext::new(
&self.inner.xconn,
self.inner.im,
window,
None,
) }?)
Some(unsafe { ImeContext::new(&self.inner.xconn, self.inner.im, window, None) }?)
};
self.inner.contexts.insert(window, context);
Ok(!self.is_destroyed())