Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add key repetition #16

Merged
merged 34 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
46d75d2
Add key repetition
trimental Jul 15, 2018
1d8161d
Use AsciiExt for older rust versions and fix warnings
trimental Jul 15, 2018
d45b354
Derive default for ModifiersState
trimental Jul 15, 2018
aadf70c
Control key repetition delay with control statements
trimental Jul 16, 2018
1d84980
Use chan crate to control key repetition
trimental Jul 17, 2018
c2fdb05
Add parameter in keyboard mapping for controlling key repetition
trimental Jul 17, 2018
0872611
Fix KeyRepeatKind documentation and idenitify repeated key events
trimental Jul 17, 2018
a07ee1b
Add bitflag controls for key repetition
trimental Jul 17, 2018
0400e97
Fix boolean logic to calculate if a character is repeatable
trimental Jul 17, 2018
96be173
Reflow the checking for repeatable keys and fix shifted characters
trimental Jul 18, 2018
f038261
Fix name of repeat timing variable
trimental Jul 18, 2018
4d50ad6
Hardcode values instead of is_ascii_punctuation for compatibility
trimental Jul 18, 2018
c451333
Downgrade chan for compatibility, fix doc for RepeatedKeyTypes, remov…
trimental Jul 18, 2018
a584591
Update kbd_input and selection to use key repetition
trimental Jul 18, 2018
7e9f5dd
Remove unused import from selection example
trimental Jul 18, 2018
dce3dc4
Send release key events
trimental Jul 18, 2018
60f8aba
Revert chan to latest version
trimental Jul 18, 2018
4c12c47
Replace chan crate with std::sync::mpsc
trimental Jul 19, 2018
6e0096e
Calculate time dynamically when repeating key events
trimental Jul 21, 2018
49c302a
Seperate keyboard functions with repeat and without
trimental Jul 22, 2018
37896f8
Use subsec_nanos over subsec_millis for compatibility
trimental Jul 22, 2018
2da5074
Fix examples and fix the sending of key press as key repeat
trimental Jul 22, 2018
ca4c3e3
Use xkb to decide what keys are repeatable
trimental Jul 22, 2018
434e927
Fix the keycode values sent to xkb_keymap_key_repeats
trimental Jul 22, 2018
2191c8d
Cleanup of key repetition
trimental Jul 22, 2018
8b68dcd
Use Implement instead of Fn, Fix docs, Remove redundant code, Fix key…
trimental Jul 22, 2018
4ba2f11
Fix key repeat logic
trimental Jul 23, 2018
bf3056e
Reflow key repetition logic
trimental Jul 23, 2018
7e76f54
Combine kbd_implement and kbd_implement_with_repeat
trimental Jul 23, 2018
2ba3dde
Dynamic state while repeating keys
trimental Jul 23, 2018
68e325c
Remove unnecessary mut binding
trimental Jul 23, 2018
c345d18
Directly pass state instead of through channel
trimental Jul 23, 2018
48a43c8
Key repetition cleanup
trimental Jul 24, 2018
2287bc2
Use generics for RepeatImpl, cargo fmt
trimental Jul 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 43 additions & 34 deletions examples/kbd_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::{Arc, Mutex};

use byteorder::{NativeEndian, WriteBytesExt};

use sctk::keyboard::{map_keyboard_auto, Event as KbEvent};
use sctk::keyboard::{map_keyboard_auto_with_repeat, Event as KbEvent, KeyRepeatKind, KeyRepeatEvent};
use sctk::reexports::client::protocol::wl_buffer::RequestsTrait as BufferRequests;
use sctk::reexports::client::protocol::wl_compositor::RequestsTrait as CompositorRequests;
use sctk::reexports::client::protocol::wl_display::RequestsTrait as DisplayRequests;
Expand Down Expand Up @@ -80,41 +80,50 @@ fn main() {

window.new_seat(&seat);

let _keyboard = map_keyboard_auto(seat.get_keyboard().unwrap(), move |event: KbEvent, _| {
match event {
KbEvent::Enter {
modifiers, keysyms, ..
} => {
println!(
"Gained focus while {} keys pressed and modifiers are {:?}.",
keysyms.len(),
modifiers
);
}
KbEvent::Leave { .. } => {
println!("Lost focus.");
}
KbEvent::Key {
keysym,
state,
utf8,
modifiers,
..
} => {
println!("Key {:?}: {:x}.", state, keysym);
println!(" -> Modifers are {:?}", modifiers);
if let Some(txt) = utf8 {
println!(" -> Received text \"{}\".", txt,);
let _keyboard = map_keyboard_auto_with_repeat(seat.get_keyboard().unwrap(), KeyRepeatKind::System,
move |event: KbEvent, _| {
match event {
KbEvent::Enter {
modifiers, keysyms, ..
} => {
println!(
"Gained focus while {} keys pressed and modifiers are {:?}.",
keysyms.len(),
modifiers
);
}
KbEvent::Leave { .. } => {
println!("Lost focus.");
}
KbEvent::Key {
keysym,
state,
utf8,
modifiers,
..
} => {
println!("Key {:?}: {:x}.", state, keysym);
println!(" -> Modifers are {:?}", modifiers);
if let Some(txt) = utf8 {
println!(" -> Received text \"{}\".", txt);
}
}
KbEvent::RepeatInfo { rate, delay } => {
println!(
"Received repeat info: start repeating every {}ms after an initial delay of {}ms",
rate, delay
);
}
}
},
move |repeat_event: KeyRepeatEvent, _| {
println!("Repeated key {:x}.", repeat_event.keysym);
println!(" -> Modifers are {:?}", repeat_event.modifiers);
if let Some(txt) = repeat_event.utf8 {
println!(" -> Received text \"{}\".", txt);
}
}
KbEvent::RepeatInfo { rate, delay } => {
println!(
"Received repeat info: start repeating every {}ms after an initial delay of {}ms",
rate, delay
);
}
}
});
);

if !env.shell.needs_configure() {
// initial draw to bootstrap on wl_shell
Expand Down
11 changes: 6 additions & 5 deletions examples/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::{Arc, Mutex};
use byteorder::{NativeEndian, WriteBytesExt};

use sctk::data_device::{DataDevice, DndEvent, ReadPipe};
use sctk::keyboard::{map_keyboard_auto, Event as KbEvent};
use sctk::keyboard::{map_keyboard_auto, Event as KbEvent, KeyState};
use sctk::utils::{DoubleMemPool, MemPool};
use sctk::window::{BasicFrame, Event as WEvent, Window};
use sctk::Environment;
Expand Down Expand Up @@ -87,9 +87,10 @@ fn main() {
let _keyboard = map_keyboard_auto(seat.get_keyboard().unwrap(), move |event: KbEvent, _| {
match event {
KbEvent::Key {
state,
utf8: Some(text), ..
} => {
if text == "p" {
if text == "p" && state == KeyState::Pressed {
// pressed the 'p' key, try to read contents !
device.with_selection(|offer| {
if let Some(offer) = offer {
Expand Down Expand Up @@ -133,8 +134,8 @@ fn main() {
Some(WEvent::Refresh) => {
window.refresh();
window.surface().commit();
},
Some(WEvent::Configure { new_size, states }) => {
}
Some(WEvent::Configure { new_size, .. }) => {
if let Some((w, h)) = new_size {
window.resize(w, h);
dimensions = (w, h)
Expand Down Expand Up @@ -176,7 +177,7 @@ fn redraw(
let _ = pool.seek(SeekFrom::Start(0));
{
let mut writer = BufWriter::new(&mut *pool);
for i in 0..(buf_x * buf_y) {
for _ in 0..(buf_x * buf_y) {
let _ = writer.write_u32::<NativeEndian>(0xFF000000);
}
let _ = writer.flush();
Expand Down
1 change: 1 addition & 0 deletions src/keyboard/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ functions:
fn xkb_keymap_ref(*mut xkb_keymap) -> *mut xkb_keymap,
fn xkb_keymap_unref(*mut xkb_keymap) -> (),
fn xkb_keymap_get_as_string(*mut xkb_keymap, xkb_keymap_format) -> *const c_char,
fn xkb_keymap_key_repeats(*mut xkb_keymap, xkb_keycode_t) -> c_int,

fn xkb_state_new(*mut xkb_keymap) -> *mut xkb_state,
fn xkb_state_ref(*mut xkb_state) -> *mut xkb_state,
Expand Down
Loading