Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from rust-mmap to memmap-rs #9

Merged
merged 1 commit into from Jan 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -10,7 +10,7 @@ description = "Keyboard mapping utility for wayland-client using libxkbcommon."
[dependencies]
bitflags = "0.3"
lazy_static = "0.1"
mmap = "0.1"
memmap = "0.2"
wayland-client = "0.5"
dlib = "0.2"

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -17,7 +17,7 @@
#[macro_use] extern crate bitflags;
#[macro_use] extern crate dlib;
#[macro_use] extern crate lazy_static;
extern crate mmap;
extern crate memmap;
extern crate wayland_client;

mod ffi;
Expand Down
16 changes: 8 additions & 8 deletions src/mapped_keyboard.rs
@@ -1,12 +1,13 @@
use wayland_client::{Event, EventIterator, Proxy};
use wayland_client::wayland::seat::{WlSeat, WlKeyboard, WlKeyboardEvent, WlKeyboardKeyState};

use std::fs::File;
use std::iter::Iterator;
use std::ptr;
use std::os::unix::io::RawFd;
use std::os::unix::io::{FromRawFd, RawFd};
use std::sync::{Arc, Mutex};

use mmap::{MemoryMap, MapOption};
use memmap::{Mmap, Protection};

use ffi;
use ffi::XKBCOMMON_HANDLE as XKBH;
Expand All @@ -26,7 +27,7 @@ impl KbState {
}

pub fn get_one_sym(&self, keycode: u32) -> u32 {
unsafe {
unsafe {
(XKBH.xkb_state_key_get_one_sym)(
self.xkb_state, keycode + 8)
}
Expand Down Expand Up @@ -152,16 +153,15 @@ impl MappedKeyboard {
fn init(&mut self, fd: RawFd, size: usize) {
let mut state = self.state.lock().unwrap();

let map = MemoryMap::new(
size as usize,
&[MapOption::MapReadable, MapOption::MapFd(fd)]
).unwrap();
let map = unsafe {
Mmap::open_with_offset(&File::from_raw_fd(fd), Protection::Read, 0, size).unwrap()
};

let xkb_keymap = {
unsafe {
(XKBH.xkb_keymap_new_from_string)(
state.xkb_context,
map.data() as *const _,
map.ptr() as *const _,
ffi::xkb_keymap_format::XKB_KEYMAP_FORMAT_TEXT_V1,
ffi::xkb_keymap_compile_flags::XKB_KEYMAP_COMPILE_NO_FLAGS
)
Expand Down