Skip to content

Commit

Permalink
Add key up/down C API
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Jun 29, 2020
1 parent 7653c6c commit 71bd7a4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ports/libsimpleservo/capi/Cargo.toml
Expand Up @@ -19,6 +19,7 @@ lazy_static = "1"
log = "0.4"
simpleservo = { path = "../api" }
surfman = "0.3"
keyboard-types = "0.5"

[target.'cfg(target_os = "windows")'.dependencies]
libc = "0.2"
Expand Down
29 changes: 29 additions & 0 deletions ports/libsimpleservo/capi/src/lib.rs
Expand Up @@ -16,6 +16,7 @@ mod vslogger;
use backtrace::Backtrace;
#[cfg(not(target_os = "windows"))]
use env_logger;
use keyboard_types::Key;
use log::LevelFilter;
use simpleservo::{self, gl_glue, ServoGlue, SERVO};
use simpleservo::{
Expand Down Expand Up @@ -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]
pub extern "C" fn media_session_action(action: CMediaSessionActionType) {
catch_any_panic(|| {
Expand Down

0 comments on commit 71bd7a4

Please sign in to comment.