mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Add basic keyboard support for magicleap
This commit is contained in:
parent
9ca6768a56
commit
3af2f9afea
5 changed files with 129 additions and 4 deletions
|
@ -13,6 +13,7 @@ test = false
|
|||
bench = false
|
||||
|
||||
[dependencies]
|
||||
keyboard-types = "0.4"
|
||||
libservo = { path = "../../components/servo" }
|
||||
log = "0.4"
|
||||
servo-egl = "0.2"
|
||||
|
|
|
@ -8,6 +8,9 @@ use egl::egl::EGLSurface;
|
|||
use egl::egl::MakeCurrent;
|
||||
use egl::egl::SwapBuffers;
|
||||
use egl::eglext::eglGetProcAddress;
|
||||
use keyboard_types::Key;
|
||||
use keyboard_types::KeyState;
|
||||
use keyboard_types::KeyboardEvent;
|
||||
use log::info;
|
||||
use log::warn;
|
||||
use servo::compositing::windowing::AnimationState;
|
||||
|
@ -58,12 +61,40 @@ pub enum MLLogLevel {
|
|||
Verbose = 5,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum MLKeyType {
|
||||
kNone,
|
||||
kCharacter,
|
||||
kBackspace,
|
||||
kShift,
|
||||
kSpeechToText,
|
||||
kPageEmoji,
|
||||
kPageLowerLetters,
|
||||
kPageNumericSymbols,
|
||||
kCancel,
|
||||
kSubmit,
|
||||
kPrevious,
|
||||
kNext,
|
||||
kClear,
|
||||
kClose,
|
||||
kEnter,
|
||||
kCustom1,
|
||||
kCustom2,
|
||||
kCustom3,
|
||||
kCustom4,
|
||||
kCustom5,
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct MLLogger(extern "C" fn(MLLogLevel, *const c_char));
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct MLHistoryUpdate(extern "C" fn(MLApp, bool, *const c_char, bool));
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct MLKeyboard(extern "C" fn(MLApp, bool));
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct MLApp(*mut c_void);
|
||||
|
@ -78,6 +109,7 @@ pub unsafe extern "C" fn init_servo(
|
|||
app: MLApp,
|
||||
logger: MLLogger,
|
||||
history_update: MLHistoryUpdate,
|
||||
keyboard: MLKeyboard,
|
||||
url: *const c_char,
|
||||
width: u32,
|
||||
height: u32,
|
||||
|
@ -116,6 +148,7 @@ pub unsafe extern "C" fn init_servo(
|
|||
app: app,
|
||||
browser_id: browser_id,
|
||||
history_update: history_update,
|
||||
keyboard: keyboard,
|
||||
scroll_state: ScrollState::TriggerUp,
|
||||
scroll_scale: TypedScale::new(SCROLL_SCALE / hidpi),
|
||||
servo: servo,
|
||||
|
@ -162,6 +195,8 @@ pub unsafe extern "C" fn heartbeat_servo(servo: *mut ServoInstance) {
|
|||
}
|
||||
}
|
||||
},
|
||||
EmbedderMsg::ShowIME(..) => (servo.keyboard.0)(servo.app, true),
|
||||
EmbedderMsg::HideIME => (servo.keyboard.0)(servo.app, false),
|
||||
// Ignore most messages for now
|
||||
EmbedderMsg::ChangePageTitle(..) |
|
||||
EmbedderMsg::BrowserCreated(..) |
|
||||
|
@ -177,8 +212,6 @@ pub unsafe extern "C" fn heartbeat_servo(servo: *mut ServoInstance) {
|
|||
EmbedderMsg::NewFavicon(..) |
|
||||
EmbedderMsg::HeadParsed |
|
||||
EmbedderMsg::SetFullscreenState(..) |
|
||||
EmbedderMsg::ShowIME(..) |
|
||||
EmbedderMsg::HideIME |
|
||||
EmbedderMsg::Shutdown |
|
||||
EmbedderMsg::Panic(..) => {},
|
||||
}
|
||||
|
@ -186,6 +219,39 @@ pub unsafe extern "C" fn heartbeat_servo(servo: *mut ServoInstance) {
|
|||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn keyboard_servo(
|
||||
servo: *mut ServoInstance,
|
||||
key_code: char,
|
||||
key_type: MLKeyType,
|
||||
) {
|
||||
if let Some(servo) = servo.as_mut() {
|
||||
let key = match key_type {
|
||||
MLKeyType::kCharacter => Key::Character([key_code].iter().collect()),
|
||||
MLKeyType::kBackspace => Key::Backspace,
|
||||
MLKeyType::kEnter => Key::Enter,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
let key_down = KeyboardEvent {
|
||||
state: KeyState::Down,
|
||||
key: key,
|
||||
..KeyboardEvent::default()
|
||||
};
|
||||
|
||||
let key_up = KeyboardEvent {
|
||||
state: KeyState::Up,
|
||||
..key_down.clone()
|
||||
};
|
||||
|
||||
// TODO: can the ML1 generate separate press and release events?
|
||||
servo.servo.handle_events(vec![
|
||||
WindowEvent::Keyboard(key_down),
|
||||
WindowEvent::Keyboard(key_up),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Some magic numbers.
|
||||
|
||||
// How far does the cursor have to move for it to count as a drag rather than a click?
|
||||
|
@ -353,6 +419,7 @@ pub struct ServoInstance {
|
|||
app: MLApp,
|
||||
browser_id: BrowserId,
|
||||
history_update: MLHistoryUpdate,
|
||||
keyboard: MLKeyboard,
|
||||
servo: Servo<WindowInstance>,
|
||||
scroll_state: ScrollState,
|
||||
scroll_scale: TypedScale<f32, DevicePixel, LayoutPixel>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue