Skip to content

Commit

Permalink
wayland: register callbacks for keyboard events
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxxxxxxxxxxx committed Jul 18, 2023
1 parent 5902ede commit 415ea96
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 3 deletions.
83 changes: 80 additions & 3 deletions src/native/linux_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,86 @@ static mut SEAT_LISTENER: wl_seat_listener = wl_seat_listener {
};

unsafe extern "C" fn seat_handle_capabilities(
_data: *mut std::ffi::c_void,
_seat: *mut wl_seat,
_caps: wl_seat_capability,
data: *mut std::ffi::c_void,
seat: *mut wl_seat,
caps: wl_seat_capability,
) {
let display: &mut WaylandDisplay = &mut *(data as *mut _);

if caps & wl_seat_capability_WL_SEAT_CAPABILITY_KEYBOARD != 0 {
// struct wl_keyboard *keyboard = wl_seat_get_keyboard(seat);
let id: *mut wl_proxy = wl_request_constructor!(
display.client,
seat,
WL_SEAT_GET_KEYBOARD,
display.client.wl_keyboard_interface
);
assert!(!id.is_null());
// wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL);
(display.client.wl_proxy_add_listener)(
id,
&KEYBOARD_LISTENER as *const _ as _,
data,
);
}
}

static mut KEYBOARD_LISTENER: wl_keyboard_listener = wl_keyboard_listener {
keymap: Some(keyboard_handle_keymap),
enter: Some(keyboard_handle_enter),
leave: Some(keyboard_handle_leave),
key: Some(keyboard_handle_key),
modifiers: Some(keyboard_handle_modifiers),
repeat_info: Some(keyboard_handle_repeat_info),
};

unsafe extern "C" fn keyboard_handle_keymap(
_data: *mut ::std::os::raw::c_void,
_wl_keyboard: *mut wl_keyboard,
_format: u32,
_fd: i32,
_size: u32,
) {
}
unsafe extern "C" fn keyboard_handle_enter(
_data: *mut ::std::os::raw::c_void,
_wl_keyboard: *mut wl_keyboard,
_serial: u32,
_surface: *mut wl_surface,
_keys: *mut wl_array,
) {
}
unsafe extern "C" fn keyboard_handle_leave(
_data: *mut ::std::os::raw::c_void,
_wl_keyboard: *mut wl_keyboard,
_serial: u32,
_surface: *mut wl_surface,
) {
}
unsafe extern "C" fn keyboard_handle_key(
_data: *mut ::std::os::raw::c_void,
_wl_keyboard: *mut wl_keyboard,
_serial: u32,
_time: u32,
_key: u32,
_state: u32,
) {
}
unsafe extern "C" fn keyboard_handle_modifiers(
_data: *mut ::std::os::raw::c_void,
_wl_keyboard: *mut wl_keyboard,
_serial: u32,
_mods_depressed: u32,
_mods_latched: u32,
_mods_locked: u32,
_group: u32,
) {
}
unsafe extern "C" fn keyboard_handle_repeat_info(
_data: *mut ::std::os::raw::c_void,
_wl_keyboard: *mut wl_keyboard,
_rate: i32,
_delay: i32,
) {
}

Expand Down
62 changes: 62 additions & 0 deletions src/native/linux_wayland/libwayland_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,66 @@ pub struct wl_seat_listener {
>,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct wl_keyboard_listener {
pub keymap: ::std::option::Option<
unsafe extern "C" fn(
data: *mut ::std::os::raw::c_void,
wl_keyboard: *mut wl_keyboard,
format: u32,
fd: i32,
size: u32,
),
>,
pub enter: ::std::option::Option<
unsafe extern "C" fn(
data: *mut ::std::os::raw::c_void,
wl_keyboard: *mut wl_keyboard,
serial: u32,
surface: *mut wl_surface,
keys: *mut wl_array,
),
>,
pub leave: ::std::option::Option<
unsafe extern "C" fn(
data: *mut ::std::os::raw::c_void,
wl_keyboard: *mut wl_keyboard,
serial: u32,
surface: *mut wl_surface,
),
>,
pub key: ::std::option::Option<
unsafe extern "C" fn(
data: *mut ::std::os::raw::c_void,
wl_keyboard: *mut wl_keyboard,
serial: u32,
time: u32,
key: u32,
state: u32,
),
>,
pub modifiers: ::std::option::Option<
unsafe extern "C" fn(
data: *mut ::std::os::raw::c_void,
wl_keyboard: *mut wl_keyboard,
serial: u32,
mods_depressed: u32,
mods_latched: u32,
mods_locked: u32,
group: u32,
),
>,
pub repeat_info: ::std::option::Option<
unsafe extern "C" fn(
data: *mut ::std::os::raw::c_void,
wl_keyboard: *mut wl_keyboard,
rate: i32,
delay: i32,
),
>,
}

pub type wl_display_connect =
unsafe extern "C" fn(name: *const ::std::os::raw::c_char) -> *mut wl_display;
pub type wl_proxy_destroy = unsafe extern "C" fn(proxy: *mut wl_proxy);
Expand Down Expand Up @@ -460,6 +520,7 @@ pub struct LibWaylandClient {
pub wl_seat_interface: *mut wl_interface,
pub wl_shm_interface: *mut wl_interface,
pub wl_shm_pool_interface: *mut wl_interface,
pub wl_keyboard_interface: *mut wl_interface,
}

impl LibWaylandClient {
Expand Down Expand Up @@ -494,6 +555,7 @@ impl LibWaylandClient {
wl_seat_interface: module.get_symbol("wl_seat_interface").unwrap(),
wl_shm_interface: module.get_symbol("wl_shm_interface").unwrap(),
wl_shm_pool_interface: module.get_symbol("wl_shm_pool_interface").unwrap(),
wl_keyboard_interface: module.get_symbol("wl_keyboard_interface").unwrap(),

_module: std::rc::Rc::new(module),
})
Expand Down

0 comments on commit 415ea96

Please sign in to comment.