keycodes: Moved submission to Rust

This commit is contained in:
Dorota Czaplejewicz
2019-10-09 08:52:10 +00:00
parent 10bad4ebe3
commit 31fdde4da9
5 changed files with 58 additions and 32 deletions

View File

@ -1,15 +1,21 @@
#ifndef __KEYBOARD_H
#define __KEYBOARD_H
#include "stdbool.h"
#include "inttypes.h"
#include "stdbool.h"
#include "virtual-keyboard-unstable-v1-client-protocol.h"
struct squeek_key;
uint32_t squeek_key_is_pressed(struct squeek_key *key);
void squeek_key_set_pressed(struct squeek_key *key, uint32_t pressed);
uint32_t squeek_key_is_locked(struct squeek_key *key);
void squeek_key_set_locked(struct squeek_key *key, uint32_t pressed);
uint32_t squeek_key_get_keycode(struct squeek_key *key);
uint32_t squeek_key_equal(struct squeek_key* key, struct squeek_key* key1);
enum key_press {
KEY_RELEASE = 0,
KEY_PRESS = 1,
};
void squeek_key_press(struct squeek_key *key, struct zwp_virtual_keyboard_v1*, enum key_press press, uint32_t timestamp);
#endif

View File

@ -17,8 +17,25 @@ pub mod c {
use super::*;
use ::util::c;
use std::os::raw::c_void;
pub type CKeyState = c::Wrapped<KeyState>;
#[repr(transparent)]
pub struct ZwpVirtualKeyboardV1(*const c_void);
#[no_mangle]
extern "C" {
/// Checks if point falls within bounds,
/// which are relative to origin and rotated by angle (I think)
pub fn eek_virtual_keyboard_v1_key(
virtual_keyboard: *mut ZwpVirtualKeyboardV1,
timestamp: u32,
keycode: u32,
press: u32,
);
}
// The following defined in Rust. TODO: wrap naked pointers to Rust data inside RefCells to prevent multiple writers
/// Compares pointers to the data
@ -34,15 +51,7 @@ pub mod c {
//let key = unsafe { Rc::from_raw(key.0) };
return key.to_owned().pressed as u32;
}
#[no_mangle]
pub extern "C"
fn squeek_key_set_pressed(key: CKeyState, pressed: u32) {
let key = key.clone_ref();
let mut key = key.borrow_mut();
key.pressed = pressed != 0;
}
#[no_mangle]
pub extern "C"
fn squeek_key_is_locked(key: CKeyState) -> u32 {
@ -56,11 +65,27 @@ pub mod c {
let mut key = key.borrow_mut();
key.locked = locked != 0;
}
#[no_mangle]
pub extern "C"
fn squeek_key_get_keycode(key: CKeyState) -> u32 {
return key.to_owned().keycode.unwrap_or(0u32);
fn squeek_key_press(
key: CKeyState,
virtual_keyboard: *mut ZwpVirtualKeyboardV1,
press: u32,
timestamp: u32,
) {
let key = key.clone_ref();
let mut key = key.borrow_mut();
key.pressed = press != 0;
if let Some(keycode) = key.keycode {
let keycode = keycode - 8;
unsafe {
eek_virtual_keyboard_v1_key(
virtual_keyboard, timestamp, keycode, press
);
}
}
}
}

View File

@ -1,3 +1,12 @@
#include "wayland.h"
struct squeek_wayland *squeek_wayland = NULL;
// The following functions only exist
// to create linkable symbols out of inline functions,
// because those are not directly callable from Rust
void
eek_virtual_keyboard_v1_key(struct zwp_virtual_keyboard_v1 *zwp_virtual_keyboard_v1, uint32_t time, uint32_t key, uint32_t state) {
zwp_virtual_keyboard_v1_key(zwp_virtual_keyboard_v1, time, key, state);
}