Commit 1fc5ebd7 authored by Jeremy Soller's avatar Jeremy Soller

Make vesad handle events per handle

parent 0a9b1593
......@@ -91,20 +91,22 @@ fn main() {
}
}
for (screen_id, screen) in scheme.screens.iter() {
if let Some(count) = screen.can_read() {
let event_packet = Packet {
id: 0,
pid: 0,
uid: 0,
gid: 0,
a: syscall::number::SYS_FEVENT,
b: *screen_id,
c: EVENT_READ,
d: count
};
socket.write(&event_packet).expect("vesad: failed to write display event");
for (handle_id, handle) in scheme.handles.iter() {
if handle.flags & EVENT_READ != 0 {
if let Some(count) = scheme.can_read(*handle_id) {
let event_packet = Packet {
id: 0,
pid: 0,
uid: 0,
gid: 0,
a: syscall::number::SYS_FEVENT,
b: *handle_id,
c: EVENT_READ,
d: count
};
socket.write(&event_packet).expect("vesad: failed to write display event");
}
}
}
}
......
......@@ -8,15 +8,16 @@ use display::Display;
use screen::{Screen, GraphicScreen, TextScreen};
#[derive(Clone)]
enum HandleKind {
pub enum HandleKind {
Input,
Screen(usize),
}
#[derive(Clone)]
struct Handle {
kind: HandleKind,
flags: usize,
pub struct Handle {
pub kind: HandleKind,
pub flags: usize,
pub events: usize,
}
pub struct DisplayScheme {
......@@ -25,7 +26,7 @@ pub struct DisplayScheme {
active: usize,
pub screens: BTreeMap<usize, Box<Screen>>,
next_id: usize,
handles: BTreeMap<usize, Handle>,
pub handles: BTreeMap<usize, Handle>,
}
impl DisplayScheme {
......@@ -81,7 +82,8 @@ impl SchemeMut for DisplayScheme {
self.handles.insert(id, Handle {
kind: HandleKind::Input,
flags: flags
flags: flags,
events: 0,
});
Ok(id)
......@@ -104,7 +106,8 @@ impl SchemeMut for DisplayScheme {
self.handles.insert(id, Handle {
kind: HandleKind::Screen(screen_i),
flags: flags
flags: flags,
events: 0,
});
Ok(id)
......@@ -130,15 +133,14 @@ impl SchemeMut for DisplayScheme {
}
fn fevent(&mut self, id: usize, flags: usize) -> Result<usize> {
let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?;
if let HandleKind::Screen(screen_i) = handle.kind {
if let Some(screen) = self.screens.get_mut(&screen_i) {
return screen.event(flags).and(Ok(screen_i));
}
if let HandleKind::Screen(_screen_i) = handle.kind {
handle.events = flags;
Ok(id)
} else {
Err(Error::new(EBADF))
}
Err(Error::new(EBADF))
}
fn fmap(&mut self, id: usize, offset: usize, size: usize) -> Result<usize> {
......
......@@ -13,7 +13,6 @@ pub struct GraphicScreen {
pub display: Display,
pub seek: usize,
pub input: VecDeque<Event>,
pub requested: usize
}
impl GraphicScreen {
......@@ -22,7 +21,6 @@ impl GraphicScreen {
display: display,
seek: 0,
input: VecDeque::new(),
requested: 0
}
}
}
......@@ -45,11 +43,6 @@ impl Screen for GraphicScreen {
}.to_event());
}
fn event(&mut self, flags: usize) -> Result<usize> {
self.requested = flags;
Ok(0)
}
fn map(&self, offset: usize, size: usize) -> Result<usize> {
if offset + size <= self.display.offscreen.len() * 4 {
Ok(self.display.offscreen.as_ptr() as usize + offset)
......
......@@ -14,8 +14,6 @@ pub trait Screen {
fn resize(&mut self, width: usize, height: usize);
fn event(&mut self, flags: usize) -> Result<usize>;
fn map(&self, offset: usize, size: usize) -> Result<usize>;
fn input(&mut self, event: &Event);
......
......@@ -15,7 +15,6 @@ pub struct TextScreen {
pub changed: BTreeSet<usize>,
pub ctrl: bool,
pub input: VecDeque<u8>,
pub requested: usize
}
impl TextScreen {
......@@ -26,7 +25,6 @@ impl TextScreen {
changed: BTreeSet::new(),
ctrl: false,
input: VecDeque::new(),
requested: 0
}
}
}
......@@ -46,11 +44,6 @@ impl Screen for TextScreen {
self.console.state.h = height / 16;
}
fn event(&mut self, flags: usize) -> Result<usize> {
self.requested = flags;
Ok(0)
}
fn map(&self, _offset: usize, _size: usize) -> Result<usize> {
Err(Error::new(EBADF))
}
......
Markdown is supported
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