Improve code quality
This commit is contained in:
parent
952fd89c42
commit
796b08b430
|
@ -180,7 +180,7 @@ void event_callback(XPointer p, XRecordInterceptData *hook)
|
|||
|
||||
switch (event_type) {
|
||||
case KeyRelease:
|
||||
printf ("%d %d KeyPress: \t%s\t%s\n", key_code, res, XKeysymToString(XkbKeycodeToKeysym(ctrl_disp, key_code, 0, 0)), buffer.data());
|
||||
//printf ("%d %d KeyPress: \t%s\t%s\n", key_code, res, XKeysymToString(XkbKeycodeToKeysym(ctrl_disp, key_code, 0, 0)), buffer.data());
|
||||
if (res > 0) { // Send only printable chars, todo: change
|
||||
keypress_callback(interceptor_instance, buffer.data(), buffer.size());
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ use crate::matcher::{Match, MatchReceiver};
|
|||
use crate::keyboard::KeyboardSender;
|
||||
|
||||
pub struct Engine<'a>{
|
||||
sender: &'a KeyboardSender
|
||||
sender: &'a dyn KeyboardSender
|
||||
}
|
||||
|
||||
impl <'a> Engine<'a> {
|
||||
pub fn new(sender: &'a KeyboardSender) -> Engine<'a> {
|
||||
pub fn new(sender: &'a dyn KeyboardSender) -> Engine<'a> {
|
||||
Engine{sender}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,12 @@ impl super::KeyboardInterceptor for LinuxKeyboardInterceptor {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for LinuxKeyboardInterceptor {
|
||||
fn drop(&mut self) {
|
||||
unsafe { cleanup(); }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LinuxKeyboardSender {
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,9 @@ fn main() {
|
|||
let engine = Engine::new(&sender);
|
||||
|
||||
let matches = vec![Match{trigger:"e'".to_owned(), result: "è".to_owned()},
|
||||
Match{trigger:"e/".to_owned(), result: "é".to_owned()},
|
||||
Match{trigger:":lol".to_owned(), result: "😂".to_owned()},
|
||||
Match{trigger:":lll".to_owned(), result: "hello".to_owned()},
|
||||
Match{trigger:":llol".to_owned(), result: "😂😂😂😂😂".to_owned()},
|
||||
];
|
||||
|
||||
let mut matcher = ScrollingMatcher::new(&matches, &engine);
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::matcher::{Match, MatchReceiver};
|
|||
|
||||
pub struct ScrollingMatcher<'a>{
|
||||
matches: &'a Vec<Match>,
|
||||
receiver: &'a MatchReceiver,
|
||||
receiver: &'a dyn MatchReceiver,
|
||||
current_set: Vec<MatchEntry<'a>>
|
||||
}
|
||||
|
||||
|
@ -27,16 +27,16 @@ impl <'a> super::Matcher for ScrollingMatcher<'a> {
|
|||
self.current_set = old_matches;
|
||||
self.current_set.append(&mut new_matches);
|
||||
|
||||
let mut foundMatch = None;
|
||||
let mut found_match = None;
|
||||
|
||||
for entry in self.current_set.iter_mut() {
|
||||
if entry.remaining.len() == 0 {
|
||||
foundMatch = Some(entry._match);
|
||||
found_match = Some(entry._match);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(_match) = foundMatch {
|
||||
if let Some(_match) = found_match {
|
||||
self.current_set.clear();
|
||||
self.receiver.on_match(_match);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ impl <'a> super::Matcher for ScrollingMatcher<'a> {
|
|||
}
|
||||
|
||||
impl <'a> ScrollingMatcher<'a> {
|
||||
pub fn new(matches:&'a Vec<Match>, receiver: &'a MatchReceiver) -> ScrollingMatcher<'a> {
|
||||
pub fn new(matches:&'a Vec<Match>, receiver: &'a dyn MatchReceiver) -> ScrollingMatcher<'a> {
|
||||
let current_set = Vec::new();
|
||||
ScrollingMatcher{ matches, receiver, current_set }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user