cargo fmt

This commit is contained in:
Victor Berger 2017-04-09 16:43:10 +02:00
parent f5bee06b7b
commit a7117369a2
No known key found for this signature in database
GPG Key ID: 3638519DDEAAD525
4 changed files with 42 additions and 24 deletions

View File

@ -218,7 +218,9 @@ impl InputBackend for GlutinInputBackend {
} }
fn get_handler(&mut self) -> Option<&mut InputHandler<Self>> { fn get_handler(&mut self) -> Option<&mut InputHandler<Self>> {
self.handler.as_mut().map(|handler| handler as &mut InputHandler<Self>) self.handler
.as_mut()
.map(|handler| handler as &mut InputHandler<Self>)
} }
fn clear_handler(&mut self) { fn clear_handler(&mut self) {
@ -233,7 +235,8 @@ impl InputBackend for GlutinInputBackend {
fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()> { fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()> {
if let Some((win_x, win_y)) = self.window.get_position() { if let Some((win_x, win_y)) = self.window.get_position() {
self.window.set_cursor_position(win_x + x as i32, win_y + y as i32) self.window
.set_cursor_position(win_x + x as i32, win_y + y as i32)
} else { } else {
Err(()) Err(())
} }
@ -304,7 +307,11 @@ impl InputBackend for GlutinInputBackend {
Event::MouseInput(state, button) => { Event::MouseInput(state, button) => {
handler.on_pointer_button(&self.seat, self.time_counter, button.into(), state.into()) handler.on_pointer_button(&self.seat, self.time_counter, button.into(), state.into())
} }
Event::Touch(Touch { phase: TouchPhase::Started, location: (x, y), id }) => { Event::Touch(Touch {
phase: TouchPhase::Started,
location: (x, y),
id,
}) => {
handler.on_touch(&self.seat, handler.on_touch(&self.seat,
self.time_counter, self.time_counter,
TouchEvent::Down { TouchEvent::Down {
@ -313,7 +320,11 @@ impl InputBackend for GlutinInputBackend {
y: y, y: y,
}) })
} }
Event::Touch(Touch { phase: TouchPhase::Moved, location: (x, y), id }) => { Event::Touch(Touch {
phase: TouchPhase::Moved,
location: (x, y),
id,
}) => {
handler.on_touch(&self.seat, handler.on_touch(&self.seat,
self.time_counter, self.time_counter,
TouchEvent::Motion { TouchEvent::Motion {
@ -322,7 +333,11 @@ impl InputBackend for GlutinInputBackend {
y: y, y: y,
}) })
} }
Event::Touch(Touch { phase: TouchPhase::Ended, location: (x, y), id }) => { Event::Touch(Touch {
phase: TouchPhase::Ended,
location: (x, y),
id,
}) => {
handler.on_touch(&self.seat, handler.on_touch(&self.seat,
self.time_counter, self.time_counter,
TouchEvent::Motion { TouchEvent::Motion {
@ -334,7 +349,11 @@ impl InputBackend for GlutinInputBackend {
self.time_counter, self.time_counter,
TouchEvent::Up { slot: Some(TouchSlot::new(id as u32)) }); TouchEvent::Up { slot: Some(TouchSlot::new(id as u32)) });
} }
Event::Touch(Touch { phase: TouchPhase::Cancelled, id, .. }) => { Event::Touch(Touch {
phase: TouchPhase::Cancelled,
id,
..
}) => {
handler.on_touch(&self.seat, handler.on_touch(&self.seat,
self.time_counter, self.time_counter,
TouchEvent::Cancel { slot: Some(TouchSlot::new(id as u32)) }) TouchEvent::Cancel { slot: Some(TouchSlot::new(id as u32)) })

View File

@ -90,7 +90,8 @@ impl KbdInternal {
fn new() -> Result<KbdInternal, ()> { fn new() -> Result<KbdInternal, ()> {
let context = xkb::Context::new(xkb::CONTEXT_NO_FLAGS); let context = xkb::Context::new(xkb::CONTEXT_NO_FLAGS);
// TODO: api to choose the keymap to load // TODO: api to choose the keymap to load
let keymap = xkb::Keymap::new_from_names(&context, &"", &"", &"fr", &"oss", None, 0).ok_or(())?; let keymap = xkb::Keymap::new_from_names(&context, &"", &"", &"fr", &"oss", None, 0)
.ok_or(())?;
let state = xkb::State::new(&keymap); let state = xkb::State::new(&keymap);
Ok(KbdInternal { Ok(KbdInternal {
focus: None, focus: None,
@ -186,10 +187,7 @@ impl KbdHandle {
pub fn input<F>(&self, keycode: u32, state: KeyState, serial: u32, filter: F) pub fn input<F>(&self, keycode: u32, state: KeyState, serial: u32, filter: F)
where F: FnOnce(&ModifiersState, Keysym) -> bool where F: FnOnce(&ModifiersState, Keysym) -> bool
{ {
let mut guard = self.internal let mut guard = self.internal.0.lock().unwrap();
.0
.lock()
.unwrap();
let mods_changed = guard.key_input(keycode, state); let mods_changed = guard.key_input(keycode, state);
if !filter(&guard.mods_state, guard.state.key_get_one_sym(keycode)) { if !filter(&guard.mods_state, guard.state.key_get_one_sym(keycode)) {
@ -218,10 +216,7 @@ impl KbdHandle {
pub fn set_focus(&self, focus: Option<(wl_surface::WlSurface, wl_keyboard::WlKeyboard)>, serial: u32) { pub fn set_focus(&self, focus: Option<(wl_surface::WlSurface, wl_keyboard::WlKeyboard)>, serial: u32) {
// TODO: check surface and keyboard are from the same client // TODO: check surface and keyboard are from the same client
let mut guard = self.internal let mut guard = self.internal.0.lock().unwrap();
.0
.lock()
.unwrap();
// remove current focus // remove current focus
let old_kbd = if let Some((old_surface, old_kbd)) = guard.focus.take() { let old_kbd = if let Some((old_surface, old_kbd)) = guard.focus.take() {

View File

@ -94,7 +94,9 @@ impl ShmGlobal {
where L: Into<Option<::slog::Logger>> where L: Into<Option<::slog::Logger>>
{ {
use slog::DrainExt; use slog::DrainExt;
let log = logger.into().unwrap_or_else(|| ::slog::Logger::root(::slog_stdlog::StdLog.fuse(), o!())); let log = logger
.into()
.unwrap_or_else(|| ::slog::Logger::root(::slog_stdlog::StdLog.fuse(), o!()));
// always add the mandatory formats // always add the mandatory formats
formats.push(wl_shm::Format::Argb8888); formats.push(wl_shm::Format::Argb8888);
@ -157,7 +159,9 @@ impl ShmGlobalToken {
} }
let data = unsafe { &*(buffer.get_user_data() as *mut InternalBufferData) }; let data = unsafe { &*(buffer.get_user_data() as *mut InternalBufferData) };
if data.pool.with_data_slice(|slice| f(slice, data.data)).is_err() { if data.pool
.with_data_slice(|slice| f(slice, data.data))
.is_err() {
// SIGBUS error occured // SIGBUS error occured
buffer.post_error(wl_shm::Error::InvalidFd as u32, "Bad pool size.".into()); buffer.post_error(wl_shm::Error::InvalidFd as u32, "Bad pool size.".into());
return Err(BufferAccessError::BadMap); return Err(BufferAccessError::BadMap);