Verified Commit 78c6f9ed authored by Jeremy Soller's avatar Jeremy Soller
Browse files

WIP: Add mouse cursor visibility, mouse grabbing, and mouse relative mode

parent 1762355c
......@@ -124,6 +124,12 @@ pub trait Handler {
flags: &str, title: String) -> syscall::Result<usize>;
/// Called when the scheme is read for events
fn handle_window_read(&mut self, orb: &mut Orbital, id: usize, buf: &mut [Event]) -> syscall::Result<usize>;
/// Called when the window asks to set mouse cursor visibility
fn handle_window_mouse_cursor(&mut self, orb: &mut Orbital, id: usize, visible: bool) -> syscall::Result<()>;
/// Called when the window asks to set mouse grabbing
fn handle_window_mouse_grab(&mut self, orb: &mut Orbital, id: usize, grab: bool) -> syscall::Result<()>;
/// Called when the window asks to set mouse relative mode
fn handle_window_mouse_relative(&mut self, orb: &mut Orbital, id: usize, relative: bool) -> syscall::Result<()>;
/// Called when the window asks to be repositioned
fn handle_window_position(&mut self, orb: &mut Orbital, id: usize, x: Option<i32>, y: Option<i32>) -> syscall::Result<()>;
/// Called when the window asks to be resized
......@@ -397,6 +403,33 @@ impl<H: Handler> SchemeMut for OrbitalHandler<H> {
(kind, data)
};
match kind {
"M" => match data {
"C,0" => {
self.handler.handle_window_mouse_cursor(&mut self.orb, id, false)?;
Ok(buf.len())
},
"C,1" => {
self.handler.handle_window_mouse_cursor(&mut self.orb, id, true)?;
Ok(buf.len())
},
"G,0" => {
self.handler.handle_window_mouse_grab(&mut self.orb, id, false)?;
Ok(buf.len())
}
"G,1" => {
self.handler.handle_window_mouse_grab(&mut self.orb, id, true)?;
Ok(buf.len())
},
"R,0" => {
self.handler.handle_window_mouse_relative(&mut self.orb, id, false)?;
Ok(buf.len())
},
"R,1" => {
self.handler.handle_window_mouse_relative(&mut self.orb, id, true)?;
Ok(buf.len())
},
_ => Err(syscall::Error::new(EINVAL)),
},
"P" => {
let mut parts = data.split(',');
let x = parts.next().unwrap_or("").parse::<i32>().ok();
......
......@@ -193,6 +193,30 @@ impl Handler for OrbitalScheme {
Err(Error::new(EBADF))
}
}
fn handle_window_mouse_cursor(&mut self, _orb: &mut Orbital, id: usize, visible: bool) -> syscall::Result<()> {
if let Some(window) = self.windows.get_mut(&id) {
window.mouse_cursor = visible;
Ok(())
} else {
Err(Error::new(EBADF))
}
}
fn handle_window_mouse_grab(&mut self, _orb: &mut Orbital, id: usize, grab: bool) -> syscall::Result<()> {
if let Some(window) = self.windows.get_mut(&id) {
window.mouse_grab = grab;
Ok(())
} else {
Err(Error::new(EBADF))
}
}
fn handle_window_mouse_relative(&mut self, _orb: &mut Orbital, id: usize, relative: bool) -> syscall::Result<()> {
if let Some(window) = self.windows.get_mut(&id) {
window.mouse_relative = relative;
Ok(())
} else {
Err(Error::new(EBADF))
}
}
fn handle_window_position(&mut self, _orb: &mut Orbital, id: usize, x: Option<i32>, y: Option<i32>) -> syscall::Result<()> {
if let Some(window) = self.windows.get_mut(&id) {
window.x = x.unwrap_or(window.x);
......
......@@ -36,6 +36,9 @@ pub struct Window {
pub notified_read: bool,
//TODO: implement better clipboard mechanism
pub clipboard_seek: usize,
pub mouse_cursor: bool,
pub mouse_grab: bool,
pub mouse_relative: bool,
}
impl Window {
......@@ -58,6 +61,9 @@ impl Window {
notified_read: false,
//TODO: implement better clipboard mechanism
clipboard_seek: 0,
mouse_cursor: true,
mouse_grab: false,
mouse_relative: false,
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment