Wholesale cargo fmt to get CI back to green
This commit is contained in:
+115
-100
@@ -1,19 +1,25 @@
|
||||
use log::{debug, error, info, trace};
|
||||
use common::io::{Io, Pio, ReadOnly, WriteOnly};
|
||||
use log::{debug, error, info, trace};
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
#[inline(always)]
|
||||
pub(crate) unsafe fn pause() { std::arch::aarch64::__yield(); }
|
||||
pub(crate) unsafe fn pause() {
|
||||
std::arch::aarch64::__yield();
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
#[inline(always)]
|
||||
pub(crate) unsafe fn pause() { std::arch::x86::_mm_pause(); }
|
||||
pub(crate) unsafe fn pause() {
|
||||
std::arch::x86::_mm_pause();
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[inline(always)]
|
||||
pub(crate) unsafe fn pause() { std::arch::x86_64::_mm_pause(); }
|
||||
pub(crate) unsafe fn pause() {
|
||||
std::arch::x86_64::_mm_pause();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
@@ -67,7 +73,7 @@ enum Command {
|
||||
Diagnostic = 0xAC,
|
||||
DisableFirst = 0xAD,
|
||||
EnableFirst = 0xAE,
|
||||
WriteSecond = 0xD4
|
||||
WriteSecond = 0xD4,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -77,13 +83,13 @@ enum KeyboardCommand {
|
||||
EnableReporting = 0xF4,
|
||||
SetDefaultsDisable = 0xF5,
|
||||
SetDefaults = 0xF6,
|
||||
Reset = 0xFF
|
||||
Reset = 0xFF,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[repr(u8)]
|
||||
enum KeyboardCommandData {
|
||||
ScancodeSet = 0xF0
|
||||
ScancodeSet = 0xF0,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -97,7 +103,7 @@ enum MouseCommand {
|
||||
EnableReporting = 0xF4,
|
||||
SetDefaultsDisable = 0xF5,
|
||||
SetDefaults = 0xF6,
|
||||
Reset = 0xFF
|
||||
Reset = 0xFF,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -132,7 +138,9 @@ impl Ps2 {
|
||||
if self.status().contains(StatusFlags::OUTPUT_FULL) {
|
||||
return Ok(());
|
||||
}
|
||||
unsafe { pause(); }
|
||||
unsafe {
|
||||
pause();
|
||||
}
|
||||
timeout -= 1;
|
||||
}
|
||||
Err(Error::ReadTimeout)
|
||||
@@ -141,10 +149,12 @@ impl Ps2 {
|
||||
fn wait_write(&mut self) -> Result<(), Error> {
|
||||
let mut timeout = 100_000;
|
||||
while timeout > 0 {
|
||||
if ! self.status().contains(StatusFlags::INPUT_FULL) {
|
||||
if !self.status().contains(StatusFlags::INPUT_FULL) {
|
||||
return Ok(());
|
||||
}
|
||||
unsafe { pause(); }
|
||||
unsafe {
|
||||
pause();
|
||||
}
|
||||
timeout -= 1;
|
||||
}
|
||||
Err(Error::WriteTimeout)
|
||||
@@ -157,7 +167,9 @@ impl Ps2 {
|
||||
let val = self.data.read();
|
||||
trace!("ps2d: flush {}: {:X}", message, val);
|
||||
}
|
||||
unsafe { pause(); }
|
||||
unsafe {
|
||||
pause();
|
||||
}
|
||||
timeout -= 1;
|
||||
}
|
||||
}
|
||||
@@ -179,7 +191,12 @@ impl Ps2 {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn retry<F: Fn(&mut Self) -> Result<u8, Error>>(&mut self, name: fmt::Arguments, retries: usize, f: F) -> Result<u8, Error> {
|
||||
fn retry<F: Fn(&mut Self) -> Result<u8, Error>>(
|
||||
&mut self,
|
||||
name: fmt::Arguments,
|
||||
retries: usize,
|
||||
f: F,
|
||||
) -> Result<u8, Error> {
|
||||
trace!("ps2d: {}", name);
|
||||
let mut res = Err(Error::NoMoreTries);
|
||||
for retry in 0..retries {
|
||||
@@ -187,7 +204,7 @@ impl Ps2 {
|
||||
match res {
|
||||
Ok(ok) => {
|
||||
return Ok(ok);
|
||||
},
|
||||
}
|
||||
Err(ref err) => {
|
||||
info!("ps2d: {}: retry {}/{}: {:?}", name, retry + 1, retries, err);
|
||||
}
|
||||
@@ -197,26 +214,19 @@ impl Ps2 {
|
||||
}
|
||||
|
||||
fn config(&mut self) -> Result<ConfigFlags, Error> {
|
||||
self.retry(
|
||||
format_args!("read config"),
|
||||
4,
|
||||
|x| {
|
||||
x.command(Command::ReadConfig)?;
|
||||
x.read()
|
||||
}
|
||||
).map(ConfigFlags::from_bits_truncate)
|
||||
self.retry(format_args!("read config"), 4, |x| {
|
||||
x.command(Command::ReadConfig)?;
|
||||
x.read()
|
||||
})
|
||||
.map(ConfigFlags::from_bits_truncate)
|
||||
}
|
||||
|
||||
fn set_config(&mut self, config: ConfigFlags) -> Result<(), Error> {
|
||||
self.retry(
|
||||
format_args!("write config"),
|
||||
4,
|
||||
|x| {
|
||||
x.command(Command::WriteConfig)?;
|
||||
x.write(config.bits())?;
|
||||
Ok(0)
|
||||
}
|
||||
)?;
|
||||
self.retry(format_args!("write config"), 4, |x| {
|
||||
x.command(Command::WriteConfig)?;
|
||||
x.write(config.bits())?;
|
||||
Ok(0)
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -229,14 +239,16 @@ impl Ps2 {
|
||||
}
|
||||
|
||||
fn keyboard_command(&mut self, command: KeyboardCommand) -> Result<u8, Error> {
|
||||
self.retry(
|
||||
format_args!("keyboard command {:?}", command),
|
||||
4,
|
||||
|x| x.keyboard_command_inner(command as u8)
|
||||
)
|
||||
self.retry(format_args!("keyboard command {:?}", command), 4, |x| {
|
||||
x.keyboard_command_inner(command as u8)
|
||||
})
|
||||
}
|
||||
|
||||
fn keyboard_command_data(&mut self, command: KeyboardCommandData, data: u8) -> Result<u8, Error> {
|
||||
fn keyboard_command_data(
|
||||
&mut self,
|
||||
command: KeyboardCommandData,
|
||||
data: u8,
|
||||
) -> Result<u8, Error> {
|
||||
self.retry(
|
||||
format_args!("keyboard command {:?} {:#x}", command, data),
|
||||
4,
|
||||
@@ -248,7 +260,7 @@ impl Ps2 {
|
||||
}
|
||||
x.write(data);
|
||||
x.read()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -262,11 +274,9 @@ impl Ps2 {
|
||||
}
|
||||
|
||||
fn mouse_command(&mut self, command: MouseCommand) -> Result<u8, Error> {
|
||||
self.retry(
|
||||
format_args!("mouse command {:?}", command),
|
||||
4,
|
||||
|x| x.mouse_command_inner(command as u8)
|
||||
)
|
||||
self.retry(format_args!("mouse command {:?}", command), 4, |x| {
|
||||
x.mouse_command_inner(command as u8)
|
||||
})
|
||||
}
|
||||
|
||||
fn mouse_command_data(&mut self, command: MouseCommandData, data: u8) -> Result<u8, Error> {
|
||||
@@ -282,7 +292,7 @@ impl Ps2 {
|
||||
x.command(Command::WriteSecond)?;
|
||||
x.write(data as u8)?;
|
||||
x.read()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -290,7 +300,7 @@ impl Ps2 {
|
||||
let status = self.status();
|
||||
if status.contains(StatusFlags::OUTPUT_FULL) {
|
||||
let data = self.data.read();
|
||||
Some((! status.contains(StatusFlags::SECOND_OUTPUT_FULL), data))
|
||||
Some((!status.contains(StatusFlags::SECOND_OUTPUT_FULL), data))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -323,32 +333,31 @@ impl Ps2 {
|
||||
self.flush_read("keyboard reset");
|
||||
}
|
||||
|
||||
self.retry(
|
||||
format_args!("keyboard defaults"),
|
||||
4,
|
||||
|x| {
|
||||
x.flush_read("keyboard before defaults");
|
||||
self.retry(format_args!("keyboard defaults"), 4, |x| {
|
||||
x.flush_read("keyboard before defaults");
|
||||
|
||||
// Set defaults and disable scanning
|
||||
let b = x.keyboard_command(KeyboardCommand::SetDefaultsDisable)?;
|
||||
if b != 0xFA {
|
||||
error!("ps2d: keyboard failed to set defaults: {:02X}", b);
|
||||
return Err(Error::CommandRetry);
|
||||
}
|
||||
|
||||
// Clear remaining data
|
||||
x.flush_read("keyboard after defaults");
|
||||
|
||||
Ok(b)
|
||||
// Set defaults and disable scanning
|
||||
let b = x.keyboard_command(KeyboardCommand::SetDefaultsDisable)?;
|
||||
if b != 0xFA {
|
||||
error!("ps2d: keyboard failed to set defaults: {:02X}", b);
|
||||
return Err(Error::CommandRetry);
|
||||
}
|
||||
)?;
|
||||
|
||||
// Clear remaining data
|
||||
x.flush_read("keyboard after defaults");
|
||||
|
||||
Ok(b)
|
||||
})?;
|
||||
|
||||
{
|
||||
// Set scancode set to 2
|
||||
let scancode_set = 2;
|
||||
b = self.keyboard_command_data(KeyboardCommandData::ScancodeSet, scancode_set)?;
|
||||
if b != 0xFA {
|
||||
error!("ps2d: keyboard failed to set scancode set {}: {:02X}", scancode_set, b);
|
||||
error!(
|
||||
"ps2d: keyboard failed to set scancode set {}: {:02X}",
|
||||
scancode_set, b
|
||||
);
|
||||
}
|
||||
|
||||
// Clear remaining data
|
||||
@@ -369,38 +378,34 @@ impl Ps2 {
|
||||
self.flush_read("enable second");
|
||||
}
|
||||
|
||||
self.retry(
|
||||
format_args!("mouse reset"),
|
||||
4,
|
||||
|x| {
|
||||
// Clear remaining data
|
||||
x.flush_read("mouse before reset");
|
||||
self.retry(format_args!("mouse reset"), 4, |x| {
|
||||
// Clear remaining data
|
||||
x.flush_read("mouse before reset");
|
||||
|
||||
// Reset mouse
|
||||
let mut b = x.mouse_command(MouseCommand::Reset)?;
|
||||
if b == 0xFA {
|
||||
b = x.read()?;
|
||||
if b != 0xAA {
|
||||
error!("ps2d: mouse failed self test 1: {:02X}", b);
|
||||
return Err(Error::CommandRetry);
|
||||
}
|
||||
|
||||
b = x.read()?;
|
||||
if b != 0x00 {
|
||||
error!("ps2d: mouse failed self test 2: {:02X}", b);
|
||||
return Err(Error::CommandRetry);
|
||||
}
|
||||
} else {
|
||||
error!("ps2d: mouse failed to reset: {:02X}", b);
|
||||
// Reset mouse
|
||||
let mut b = x.mouse_command(MouseCommand::Reset)?;
|
||||
if b == 0xFA {
|
||||
b = x.read()?;
|
||||
if b != 0xAA {
|
||||
error!("ps2d: mouse failed self test 1: {:02X}", b);
|
||||
return Err(Error::CommandRetry);
|
||||
}
|
||||
|
||||
// Clear remaining data
|
||||
x.flush_read("mouse after reset");
|
||||
|
||||
Ok(b)
|
||||
b = x.read()?;
|
||||
if b != 0x00 {
|
||||
error!("ps2d: mouse failed self test 2: {:02X}", b);
|
||||
return Err(Error::CommandRetry);
|
||||
}
|
||||
} else {
|
||||
error!("ps2d: mouse failed to reset: {:02X}", b);
|
||||
return Err(Error::CommandRetry);
|
||||
}
|
||||
)?;
|
||||
|
||||
// Clear remaining data
|
||||
x.flush_read("mouse after reset");
|
||||
|
||||
Ok(b)
|
||||
})?;
|
||||
|
||||
{
|
||||
// Set defaults
|
||||
@@ -417,8 +422,9 @@ impl Ps2 {
|
||||
// Enable extra packet on mouse
|
||||
//TODO: show error return values
|
||||
if self.mouse_command_data(MouseCommandData::SetSampleRate, 200)? != 0xFA
|
||||
|| self.mouse_command_data(MouseCommandData::SetSampleRate, 100)? != 0xFA
|
||||
|| self.mouse_command_data(MouseCommandData::SetSampleRate, 80)? != 0xFA {
|
||||
|| self.mouse_command_data(MouseCommandData::SetSampleRate, 100)? != 0xFA
|
||||
|| self.mouse_command_data(MouseCommandData::SetSampleRate, 80)? != 0xFA
|
||||
{
|
||||
error!("ps2d: mouse failed to enable extra packet");
|
||||
}
|
||||
|
||||
@@ -442,7 +448,10 @@ impl Ps2 {
|
||||
let resolution = 3;
|
||||
b = self.mouse_command_data(MouseCommandData::SetResolution, resolution)?;
|
||||
if b != 0xFA {
|
||||
error!("ps2d: mouse failed to set resolution to {}: {:02X}", resolution, b);
|
||||
error!(
|
||||
"ps2d: mouse failed to set resolution to {}: {:02X}",
|
||||
resolution, b
|
||||
);
|
||||
}
|
||||
|
||||
// Clear remaining data
|
||||
@@ -453,7 +462,7 @@ impl Ps2 {
|
||||
// Set scaling to 1:1
|
||||
b = self.mouse_command(MouseCommand::SetScaling1To1)?;
|
||||
if b != 0xFA {
|
||||
error!("ps2d: mouse failed to set scaling: {:02X}", b);
|
||||
error!("ps2d: mouse failed to set scaling: {:02X}", b);
|
||||
}
|
||||
|
||||
// Clear remaining data
|
||||
@@ -465,7 +474,10 @@ impl Ps2 {
|
||||
let sample_rate = 200;
|
||||
b = self.mouse_command_data(MouseCommandData::SetSampleRate, sample_rate)?;
|
||||
if b != 0xFA {
|
||||
error!("ps2d: mouse failed to set sample rate to {}: {:02X}", sample_rate, b);
|
||||
error!(
|
||||
"ps2d: mouse failed to set sample rate to {}: {:02X}",
|
||||
sample_rate, b
|
||||
);
|
||||
}
|
||||
|
||||
// Clear remaining data
|
||||
@@ -475,13 +487,16 @@ impl Ps2 {
|
||||
{
|
||||
b = self.mouse_command(MouseCommand::StatusRequest)?;
|
||||
if b != 0xFA {
|
||||
error!("ps2d: mouse failed to request status: {:02X}", b);
|
||||
error!("ps2d: mouse failed to request status: {:02X}", b);
|
||||
} else {
|
||||
let a = self.read()?;
|
||||
let b = self.read()?;
|
||||
let c = self.read()?;
|
||||
|
||||
debug!("ps2d: mouse status {:#x} resolution {:#x} sample rate {:#x}", a, b, c);
|
||||
debug!(
|
||||
"ps2d: mouse status {:#x} resolution {:#x} sample rate {:#x}",
|
||||
a, b, c
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,9 +521,9 @@ impl Ps2 {
|
||||
{
|
||||
// Since the default config may have interrupts enabled, and the kernel may eat up
|
||||
// our data in that case, we will write a config without reading the current one
|
||||
config = ConfigFlags::POST_PASSED |
|
||||
ConfigFlags::FIRST_DISABLED |
|
||||
ConfigFlags::SECOND_DISABLED;
|
||||
config = ConfigFlags::POST_PASSED
|
||||
| ConfigFlags::FIRST_DISABLED
|
||||
| ConfigFlags::SECOND_DISABLED;
|
||||
trace!("ps2d: config set {:?}", config);
|
||||
self.set_config(config)?;
|
||||
|
||||
|
||||
+5
-5
@@ -57,7 +57,7 @@ pub mod us {
|
||||
['\0', '\0'],
|
||||
['\0', '\0'],
|
||||
['\0', '\0'],
|
||||
[' ', ' ']
|
||||
[' ', ' '],
|
||||
];
|
||||
|
||||
pub fn get_char(scancode: u8, shift: bool) -> char {
|
||||
@@ -236,7 +236,7 @@ pub mod dvorak {
|
||||
['\0', '\0'],
|
||||
['\0', '\0'],
|
||||
['\0', '\0'],
|
||||
[' ', ' ']
|
||||
[' ', ' '],
|
||||
];
|
||||
|
||||
pub fn get_char(scancode: u8, shift: bool) -> char {
|
||||
@@ -311,7 +311,7 @@ pub mod azerty {
|
||||
['\0', '\0'],
|
||||
['\0', '\0'],
|
||||
['\0', '\0'],
|
||||
[' ', ' ']
|
||||
[' ', ' '],
|
||||
];
|
||||
|
||||
pub fn get_char(scancode: u8, shift: bool) -> char {
|
||||
@@ -386,7 +386,7 @@ pub mod bepo {
|
||||
['\0', '\0'],
|
||||
['\0', '\0'],
|
||||
['\0', '\0'],
|
||||
[' ', ' ']
|
||||
[' ', ' '],
|
||||
];
|
||||
|
||||
pub fn get_char(scancode: u8, shift: bool) -> char {
|
||||
@@ -461,7 +461,7 @@ pub mod it {
|
||||
['\0', '\0'],
|
||||
['\0', '\0'],
|
||||
['\0', '\0'],
|
||||
[' ', ' ']
|
||||
[' ', ' '],
|
||||
];
|
||||
|
||||
pub fn get_char(scancode: u8, shift: bool) -> char {
|
||||
|
||||
+24
-18
@@ -5,11 +5,11 @@ extern crate bitflags;
|
||||
extern crate orbclient;
|
||||
extern crate syscall;
|
||||
|
||||
use std::{env, process};
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::{Read, Write};
|
||||
use std::os::unix::fs::OpenOptionsExt;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::{env, process};
|
||||
|
||||
use log::info;
|
||||
use syscall::call::iopl;
|
||||
@@ -21,7 +21,6 @@ mod keymap;
|
||||
mod state;
|
||||
mod vm;
|
||||
|
||||
|
||||
fn daemon(daemon: redox_daemon::Daemon) -> ! {
|
||||
common::setup_logging(
|
||||
"misc",
|
||||
@@ -35,10 +34,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
|
||||
iopl(3).expect("ps2d: failed to get I/O permission");
|
||||
}
|
||||
|
||||
let (keymap, keymap_name): (
|
||||
fn(u8, bool) -> char,
|
||||
&str
|
||||
) = match env::args().skip(1).next() {
|
||||
let (keymap, keymap_name): (fn(u8, bool) -> char, &str) = match env::args().skip(1).next() {
|
||||
Some(k) => match k.to_lowercase().as_ref() {
|
||||
"dvorak" => (keymap::dvorak::get_char, "dvorak"),
|
||||
"us" => (keymap::us::get_char, "us"),
|
||||
@@ -71,11 +67,13 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
|
||||
.open("/scheme/serio/0")
|
||||
.expect("ps2d: failed to open /scheme/serio/0");
|
||||
|
||||
event_file.write(&syscall::Event {
|
||||
id: key_file.as_raw_fd() as usize,
|
||||
flags: syscall::EVENT_READ,
|
||||
data: 0
|
||||
}).expect("ps2d: failed to event /scheme/serio/0");
|
||||
event_file
|
||||
.write(&syscall::Event {
|
||||
id: key_file.as_raw_fd() as usize,
|
||||
flags: syscall::EVENT_READ,
|
||||
data: 0,
|
||||
})
|
||||
.expect("ps2d: failed to event /scheme/serio/0");
|
||||
|
||||
let mut mouse_file = OpenOptions::new()
|
||||
.read(true)
|
||||
@@ -84,15 +82,19 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
|
||||
.open("/scheme/serio/1")
|
||||
.expect("ps2d: failed to open /scheme/serio/1");
|
||||
|
||||
event_file.write(&syscall::Event {
|
||||
id: mouse_file.as_raw_fd() as usize,
|
||||
flags: syscall::EVENT_READ,
|
||||
data: 1
|
||||
}).expect("ps2d: failed to event /scheme/serio/1");
|
||||
event_file
|
||||
.write(&syscall::Event {
|
||||
id: mouse_file.as_raw_fd() as usize,
|
||||
flags: syscall::EVENT_READ,
|
||||
data: 1,
|
||||
})
|
||||
.expect("ps2d: failed to event /scheme/serio/1");
|
||||
|
||||
libredox::call::setrens(0, 0).expect("ps2d: failed to enter null namespace");
|
||||
|
||||
daemon.ready().expect("ps2d: failed to mark daemon as ready");
|
||||
daemon
|
||||
.ready()
|
||||
.expect("ps2d: failed to mark daemon as ready");
|
||||
|
||||
let mut ps2d = Ps2d::new(input, keymap);
|
||||
|
||||
@@ -108,7 +110,11 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
|
||||
// to grab bytes and sort them based on the source
|
||||
|
||||
let mut event = syscall::Event::default();
|
||||
if event_file.read(&mut event).expect("ps2d: failed to read event file") == 0 {
|
||||
if event_file
|
||||
.read(&mut event)
|
||||
.expect("ps2d: failed to read event file")
|
||||
== 0
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+81
-42
@@ -4,7 +4,7 @@ use std::os::unix::io::AsRawFd;
|
||||
use std::str;
|
||||
|
||||
use log::{error, warn};
|
||||
use orbclient::{KeyEvent, MouseEvent, MouseRelativeEvent, ButtonEvent, ScrollEvent};
|
||||
use orbclient::{ButtonEvent, KeyEvent, MouseEvent, MouseRelativeEvent, ScrollEvent};
|
||||
|
||||
use crate::controller::Ps2;
|
||||
use crate::vm;
|
||||
@@ -22,7 +22,7 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Ps2d<F: Fn(u8,bool) -> char> {
|
||||
pub struct Ps2d<F: Fn(u8, bool) -> char> {
|
||||
ps2: Ps2,
|
||||
vmmouse: bool,
|
||||
vmmouse_relative: bool,
|
||||
@@ -39,10 +39,10 @@ pub struct Ps2d<F: Fn(u8,bool) -> char> {
|
||||
packet_i: usize,
|
||||
extra_packet: bool,
|
||||
//Keymap function
|
||||
get_char: F
|
||||
get_char: F,
|
||||
}
|
||||
|
||||
impl<F: Fn(u8,bool) -> char> Ps2d<F> {
|
||||
impl<F: Fn(u8, bool) -> char> Ps2d<F> {
|
||||
pub fn new(input: File, keymap: F) -> Self {
|
||||
let mut ps2 = Ps2::new();
|
||||
let extra_packet = ps2.init().expect("ps2d: failed to initialize");
|
||||
@@ -67,7 +67,7 @@ impl<F: Fn(u8,bool) -> char> Ps2d<F> {
|
||||
packets: [0; 4],
|
||||
packet_i: 0,
|
||||
extra_packet,
|
||||
get_char: keymap
|
||||
get_char: keymap,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,11 +228,19 @@ impl<F: Fn(u8,bool) -> char> Ps2d<F> {
|
||||
}
|
||||
|
||||
if scancode != 0 {
|
||||
self.input.write(&KeyEvent {
|
||||
character: (self.get_char)(ps2_scancode, self.lshift || self.rshift),
|
||||
scancode,
|
||||
pressed
|
||||
}.to_event()).expect("ps2d: failed to write key event");
|
||||
self.input
|
||||
.write(
|
||||
&KeyEvent {
|
||||
character: (self.get_char)(
|
||||
ps2_scancode,
|
||||
self.lshift || self.rshift,
|
||||
),
|
||||
scancode,
|
||||
pressed,
|
||||
}
|
||||
.to_event(),
|
||||
)
|
||||
.expect("ps2d: failed to write key event");
|
||||
}
|
||||
}
|
||||
} else if self.vmmouse {
|
||||
@@ -254,10 +262,15 @@ impl<F: Fn(u8,bool) -> char> Ps2d<F> {
|
||||
|
||||
if self.vmmouse_relative {
|
||||
if dx != 0 || dy != 0 {
|
||||
self.input.write(&MouseRelativeEvent {
|
||||
dx: dx as i32,
|
||||
dy: dy as i32,
|
||||
}.to_event()).expect("ps2d: failed to write mouse event");
|
||||
self.input
|
||||
.write(
|
||||
&MouseRelativeEvent {
|
||||
dx: dx as i32,
|
||||
dy: dy as i32,
|
||||
}
|
||||
.to_event(),
|
||||
)
|
||||
.expect("ps2d: failed to write mouse event");
|
||||
}
|
||||
} else {
|
||||
let x = dx as i32;
|
||||
@@ -272,24 +285,37 @@ impl<F: Fn(u8,bool) -> char> Ps2d<F> {
|
||||
};
|
||||
|
||||
if dz != 0 {
|
||||
self.input.write(&ScrollEvent {
|
||||
x: 0,
|
||||
y: -(dz as i32),
|
||||
}.to_event()).expect("ps2d: failed to write scroll event");
|
||||
self.input
|
||||
.write(
|
||||
&ScrollEvent {
|
||||
x: 0,
|
||||
y: -(dz as i32),
|
||||
}
|
||||
.to_event(),
|
||||
)
|
||||
.expect("ps2d: failed to write scroll event");
|
||||
}
|
||||
|
||||
let left = status & vm::LEFT_BUTTON == vm::LEFT_BUTTON;
|
||||
let middle = status & vm::MIDDLE_BUTTON == vm::MIDDLE_BUTTON;
|
||||
let right = status & vm::RIGHT_BUTTON == vm::RIGHT_BUTTON;
|
||||
if left != self.mouse_left || middle != self.mouse_middle || right != self.mouse_right {
|
||||
if left != self.mouse_left
|
||||
|| middle != self.mouse_middle
|
||||
|| right != self.mouse_right
|
||||
{
|
||||
self.mouse_left = left;
|
||||
self.mouse_middle = middle;
|
||||
self.mouse_right = right;
|
||||
self.input.write(&ButtonEvent {
|
||||
left: left,
|
||||
middle: middle,
|
||||
right: right,
|
||||
}.to_event()).expect("ps2d: failed to write button event");
|
||||
self.input
|
||||
.write(
|
||||
&ButtonEvent {
|
||||
left: left,
|
||||
middle: middle,
|
||||
right: right,
|
||||
}
|
||||
.to_event(),
|
||||
)
|
||||
.expect("ps2d: failed to write button event");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -297,13 +323,17 @@ impl<F: Fn(u8,bool) -> char> Ps2d<F> {
|
||||
self.packet_i += 1;
|
||||
|
||||
let flags = MousePacketFlags::from_bits_truncate(self.packets[0]);
|
||||
if ! flags.contains(MousePacketFlags::ALWAYS_ON) {
|
||||
if !flags.contains(MousePacketFlags::ALWAYS_ON) {
|
||||
error!("ps2d: mouse misalign {:X}", self.packets[0]);
|
||||
|
||||
self.packets = [0; 4];
|
||||
self.packet_i = 0;
|
||||
} else if self.packet_i >= self.packets.len() || (!self.extra_packet && self.packet_i >= 3) {
|
||||
if ! flags.contains(MousePacketFlags::X_OVERFLOW) && ! flags.contains(MousePacketFlags::Y_OVERFLOW) {
|
||||
} else if self.packet_i >= self.packets.len()
|
||||
|| (!self.extra_packet && self.packet_i >= 3)
|
||||
{
|
||||
if !flags.contains(MousePacketFlags::X_OVERFLOW)
|
||||
&& !flags.contains(MousePacketFlags::Y_OVERFLOW)
|
||||
{
|
||||
let mut dx = self.packets[1] as i32;
|
||||
if flags.contains(MousePacketFlags::X_SIGN) {
|
||||
dx -= 0x100;
|
||||
@@ -324,34 +354,43 @@ impl<F: Fn(u8,bool) -> char> Ps2d<F> {
|
||||
}
|
||||
|
||||
if dx != 0 || dy != 0 {
|
||||
self.input.write(&MouseRelativeEvent {
|
||||
dx: dx,
|
||||
dy: dy,
|
||||
}.to_event()).expect("ps2d: failed to write mouse event");
|
||||
self.input
|
||||
.write(&MouseRelativeEvent { dx: dx, dy: dy }.to_event())
|
||||
.expect("ps2d: failed to write mouse event");
|
||||
}
|
||||
|
||||
if dz != 0 {
|
||||
self.input.write(&ScrollEvent {
|
||||
x: 0,
|
||||
y: dz,
|
||||
}.to_event()).expect("ps2d: failed to write scroll event");
|
||||
self.input
|
||||
.write(&ScrollEvent { x: 0, y: dz }.to_event())
|
||||
.expect("ps2d: failed to write scroll event");
|
||||
}
|
||||
|
||||
let left = flags.contains(MousePacketFlags::LEFT_BUTTON);
|
||||
let middle = flags.contains(MousePacketFlags::MIDDLE_BUTTON);
|
||||
let right = flags.contains(MousePacketFlags::RIGHT_BUTTON);
|
||||
if left != self.mouse_left || middle != self.mouse_middle || right != self.mouse_right {
|
||||
if left != self.mouse_left
|
||||
|| middle != self.mouse_middle
|
||||
|| right != self.mouse_right
|
||||
{
|
||||
self.mouse_left = left;
|
||||
self.mouse_middle = middle;
|
||||
self.mouse_right = right;
|
||||
self.input.write(&ButtonEvent {
|
||||
left: left,
|
||||
middle: middle,
|
||||
right: right,
|
||||
}.to_event()).expect("ps2d: failed to write button event");
|
||||
self.input
|
||||
.write(
|
||||
&ButtonEvent {
|
||||
left: left,
|
||||
middle: middle,
|
||||
right: right,
|
||||
}
|
||||
.to_event(),
|
||||
)
|
||||
.expect("ps2d: failed to write button event");
|
||||
}
|
||||
} else {
|
||||
warn!("ps2d: overflow {:X} {:X} {:X} {:X}", self.packets[0], self.packets[1], self.packets[2], self.packets[3]);
|
||||
warn!(
|
||||
"ps2d: overflow {:X} {:X} {:X} {:X}",
|
||||
self.packets[0], self.packets[1], self.packets[2], self.packets[3]
|
||||
);
|
||||
}
|
||||
|
||||
self.packets = [0; 4];
|
||||
|
||||
Reference in New Issue
Block a user