Skip to content
This repository has been archived by the owner on Jan 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #54 from Immington-Industries/keyboard-fix
Browse files Browse the repository at this point in the history
Fix bindings for input::keyboard
  • Loading branch information
Timidger authored Aug 21, 2016
2 parents fe2696e + 9b79fe8 commit c58aef6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
16 changes: 7 additions & 9 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ lazy_static! {
}

fn start_interactive_action(view: WlcView, origin: Point) -> bool {
{
let mut comp = COMPOSITOR.write().unwrap();
if comp.view != None {
return false;
}
comp.grab = origin;
comp.view = Some(view);
let mut comp = COMPOSITOR.write().unwrap();
if comp.view != None {
return false
}
comp.grab = origin;
comp.view = Some(view);

view.bring_to_front();
return true;
return true
}

fn start_interactive_move(view: WlcView, origin: Point) {
Expand Down Expand Up @@ -154,7 +152,7 @@ extern fn on_view_request_resize(view: WlcView, edges: ResizeEdge, origin: &Poin

extern fn on_keyboard_key(view: WlcView, _time: u32, mods: &KeyboardModifiers, key: u32, state: KeyState) -> bool {
use std::process::Command;
let sym = input::keyboard::get_keysym_for_key(key, mods.mods);
let sym = input::keyboard::get_keysym_for_key(key, *mods);
if state == KeyState::Pressed {
if mods.mods == MOD_CTRL {
// Key Q
Expand Down
37 changes: 26 additions & 11 deletions src/input.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
//! Contains methods for interacting with the pointer
//! and keyboard of wlc.
use super::types::{KeyMod, Point};
use libc::{size_t, uint32_t};
use super::types::{KeyboardModifiers, Point};

#[link(name = "wlc")]
extern "C" {
//fn wlc_keyboard_get_current_keys(out_memb: *const size_t) -> *const u32;
fn wlc_keyboard_get_current_keys(out_memb: *const size_t) -> *const uint32_t;

fn wlc_keyboard_get_keysym_for_key(key: u32, modifiers: &KeyMod) -> u32;
fn wlc_keyboard_get_keysym_for_key(key: uint32_t,
modifiers: *const KeyboardModifiers) -> uint32_t;

fn wlc_keyboard_get_utf32_for_key(key: u32, modifiers: &KeyMod) -> u32;
fn wlc_keyboard_get_utf32_for_key(key: uint32_t,
modifiers: *const KeyboardModifiers) -> uint32_t;

// Pointer functions
fn wlc_pointer_get_position(out_position: *mut Point);
Expand Down Expand Up @@ -37,16 +40,28 @@ pub mod pointer {
}

pub mod keyboard {
//! Methods for interacting with the keyboard
use super::super::types::{KeyMod};
//! Methods for interacting with the keyboard
use std::slice;
use libc::size_t;
use super::super::types::KeyboardModifiers;
#[allow(deprecated)]
use super::super::xkb::Keysym;

/// Get currently held keys.
/// # Panics
/// All the time, this function hasn't been implemented yet
pub fn get_current_keys<'a>() -> &'a[u32] {
unimplemented!();
pub fn get_current_keys<'a>() -> Option<&'a[u32]> {
let mut size: size_t = 0;
unsafe {
let out_ptr = super::wlc_keyboard_get_current_keys(&mut size);
if size == 0 || out_ptr.is_null() {
None
}
else {
Some(slice::from_raw_parts(out_ptr, size as usize))
}
}
}

/// Gets a keysym given a key and modifiers.
Expand All @@ -55,14 +70,14 @@ pub mod keyboard {
/// deprecated. Please use `Keysym::raw` on the Keysym returned from this
/// function for now. **In version 0.6 this will return a u32**.
#[allow(deprecated)]
pub fn get_keysym_for_key(key: u32, modifiers: KeyMod) -> Keysym {
pub fn get_keysym_for_key(key: u32, modifiers: KeyboardModifiers) -> Keysym {
unsafe {
Keysym::from(super::wlc_keyboard_get_keysym_for_key(key, &modifiers))
Keysym::from(super::wlc_keyboard_get_keysym_for_key(key, &modifiers) as u32)
}
}

/// Gets a UTF32 value for a given key and modifiers.
pub fn get_utf32_for_key(key: u32, modifiers: KeyMod) -> u32 {
pub fn get_utf32_for_key(key: u32, modifiers: KeyboardModifiers) -> u32 {
unsafe { super::wlc_keyboard_get_utf32_for_key(key, &modifiers) }
}
}

0 comments on commit c58aef6

Please sign in to comment.