Skip to content

Commit 2369054

Browse files
committed
Minor changes
1 parent 9ad27c7 commit 2369054

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ categories = [
1515
license = "MIT/Apache-2.0"
1616
readme = "README.md"
1717
repository = "https://github.com/rust-osdev/ps2-mouse"
18-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1918

2019
[dependencies]
2120
bitflags = "1.2.1"

src/lib.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
#![no_std]
44
#![warn(missing_docs)]
5+
#![feature(const_fn)]
56

67
use bitflags::bitflags;
78
use x86_64::instructions::port::Port;
@@ -73,6 +74,15 @@ pub struct MouseState {
7374
}
7475

7576
impl MouseState {
77+
/// Returns a new `MouseState`.
78+
pub const fn new() -> MouseState {
79+
MouseState {
80+
flags: MouseFlags::empty(),
81+
x: 0,
82+
y: 0,
83+
}
84+
}
85+
7686
/// Returns true if the left mouse button is currently down.
7787
pub fn left_button_down(&self) -> bool {
7888
self.flags.contains(MouseFlags::LEFT_BUTTON)
@@ -107,17 +117,27 @@ impl MouseState {
107117
pub fn moved(&self) -> bool {
108118
self.x_moved() || self.y_moved()
109119
}
120+
121+
/// Returns the x delta of the mouse state.
122+
pub fn get_x(&self) -> i16 {
123+
self.x
124+
}
125+
126+
/// Returns the y delta of the mouse state.
127+
pub fn get_y(&self) -> i16 {
128+
self.y
129+
}
110130
}
111131

112132
impl Mouse {
113133
/// Creates a new `Mouse`.
114-
pub fn new() -> Mouse {
134+
pub const fn new() -> Mouse {
115135
Mouse {
116136
command_port: Port::new(ADDRESS_PORT_ADDRESS),
117137
data_port: Port::new(DATA_PORT_ADDRESS),
118138
current_packet: 0,
119-
current_state: MouseState::default(),
120-
completed_state: MouseState::default(),
139+
current_state: MouseState::new(),
140+
completed_state: MouseState::new(),
121141
on_complete: None,
122142
}
123143
}

0 commit comments

Comments
 (0)