Add key up/down C API

This commit is contained in:
Paul Rouget 2020-06-29 10:22:14 +02:00
parent 7653c6c9fc
commit 71bd7a4199
3 changed files with 31 additions and 0 deletions

1
Cargo.lock generated
View file

@ -5224,6 +5224,7 @@ dependencies = [
"backtrace", "backtrace",
"cbindgen", "cbindgen",
"env_logger", "env_logger",
"keyboard-types",
"lazy_static", "lazy_static",
"libc", "libc",
"log", "log",

View file

@ -19,6 +19,7 @@ lazy_static = "1"
log = "0.4" log = "0.4"
simpleservo = { path = "../api" } simpleservo = { path = "../api" }
surfman = "0.3" surfman = "0.3"
keyboard-types = "0.5"
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
libc = "0.2" libc = "0.2"

View file

@ -16,6 +16,7 @@ mod vslogger;
use backtrace::Backtrace; use backtrace::Backtrace;
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
use env_logger; use env_logger;
use keyboard_types::Key;
use log::LevelFilter; use log::LevelFilter;
use simpleservo::{self, gl_glue, ServoGlue, SERVO}; use simpleservo::{self, gl_glue, ServoGlue, SERVO};
use simpleservo::{ use simpleservo::{
@ -717,6 +718,34 @@ pub extern "C" fn click(x: f32, y: f32) {
}); });
} }
#[no_mangle]
pub extern "C" fn key_down(name: *const c_char) {
catch_any_panic(|| {
debug!("key_down");
let name = unsafe { CStr::from_ptr(name) };
let key = Key::from_str(&name.to_str().expect("Can't read string"));
if let Ok(key) = key {
call(|s| s.key_down(key));
} else {
warn!("Received unknown keys");
}
})
}
#[no_mangle]
pub extern "C" fn key_up(name: *const c_char) {
catch_any_panic(|| {
debug!("key_up");
let name = unsafe { CStr::from_ptr(name) };
let key = Key::from_str(&name.to_str().expect("Can't read string"));
if let Ok(key) = key {
call(|s| s.key_up(key));
} else {
warn!("Received unknown keys");
}
})
}
#[no_mangle] #[no_mangle]
pub extern "C" fn media_session_action(action: CMediaSessionActionType) { pub extern "C" fn media_session_action(action: CMediaSessionActionType) {
catch_any_panic(|| { catch_any_panic(|| {