Save outputs state
This commit is contained in:
@ -170,6 +170,7 @@ mod test {
|
|||||||
im: InputMethod::Active(imdetails_new()),
|
im: InputMethod::Active(imdetails_new()),
|
||||||
physical_keyboard: Presence::Missing,
|
physical_keyboard: Presence::Missing,
|
||||||
visibility_override: visibility::State::NotForced,
|
visibility_override: visibility::State::NotForced,
|
||||||
|
..Application::new(start)
|
||||||
};
|
};
|
||||||
|
|
||||||
let l = State::new(state, now);
|
let l = State::new(state, now);
|
||||||
|
|||||||
@ -23,7 +23,7 @@ pub mod c {
|
|||||||
// Defined in C
|
// Defined in C
|
||||||
|
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Clone, PartialEq, Copy, Debug)]
|
#[derive(Clone, PartialEq, Copy, Debug, Eq, Hash)]
|
||||||
pub struct WlOutput(*const c_void);
|
pub struct WlOutput(*const c_void);
|
||||||
|
|
||||||
impl WlOutput {
|
impl WlOutput {
|
||||||
@ -382,7 +382,7 @@ impl OutputState {
|
|||||||
|
|
||||||
/// Not guaranteed to exist,
|
/// Not guaranteed to exist,
|
||||||
/// but can be used to look up state.
|
/// but can be used to look up state.
|
||||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Debug, Eq, Hash)]
|
||||||
pub struct OutputId(c::WlOutput);
|
pub struct OutputId(c::WlOutput);
|
||||||
|
|
||||||
// WlOutput is a pointer,
|
// WlOutput is a pointer,
|
||||||
@ -399,8 +399,10 @@ struct Output {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct NotFound;
|
struct NotFound;
|
||||||
|
|
||||||
|
/// Wayland global ID type
|
||||||
type GlobalId = u32;
|
type GlobalId = u32;
|
||||||
|
|
||||||
|
/// The outputs manager
|
||||||
pub struct Outputs {
|
pub struct Outputs {
|
||||||
outputs: Vec<(Output, GlobalId)>,
|
outputs: Vec<(Output, GlobalId)>,
|
||||||
sender: event_loop::driver::Threaded,
|
sender: event_loop::driver::Threaded,
|
||||||
@ -463,6 +465,6 @@ pub enum ChangeType {
|
|||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
output: OutputId,
|
pub output: OutputId,
|
||||||
change: ChangeType,
|
pub change: ChangeType,
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/state.rs
24
src/state.rs
@ -9,9 +9,10 @@ use crate::animation;
|
|||||||
use crate::imservice::{ ContentHint, ContentPurpose };
|
use crate::imservice::{ ContentHint, ContentPurpose };
|
||||||
use crate::main::{ Commands, PanelCommand };
|
use crate::main::{ Commands, PanelCommand };
|
||||||
use crate::outputs;
|
use crate::outputs;
|
||||||
|
use crate::outputs::{OutputId, OutputState};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum Presence {
|
pub enum Presence {
|
||||||
Present,
|
Present,
|
||||||
@ -139,6 +140,7 @@ pub struct Application {
|
|||||||
pub im: InputMethod,
|
pub im: InputMethod,
|
||||||
pub visibility_override: visibility::State,
|
pub visibility_override: visibility::State,
|
||||||
pub physical_keyboard: Presence,
|
pub physical_keyboard: Presence,
|
||||||
|
pub outputs: HashMap<OutputId, OutputState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application {
|
impl Application {
|
||||||
@ -153,6 +155,7 @@ impl Application {
|
|||||||
im: InputMethod::InactiveSince(now),
|
im: InputMethod::InactiveSince(now),
|
||||||
visibility_override: visibility::State::NotForced,
|
visibility_override: visibility::State::NotForced,
|
||||||
physical_keyboard: Presence::Missing,
|
physical_keyboard: Presence::Missing,
|
||||||
|
outputs: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,9 +176,17 @@ impl Application {
|
|||||||
..self
|
..self
|
||||||
},
|
},
|
||||||
|
|
||||||
Event::Output(output) => {
|
Event::Output(outputs::Event { output, change }) => {
|
||||||
println!("Stub: output event {:?}", output);
|
let mut app = self;
|
||||||
self
|
match change {
|
||||||
|
outputs::ChangeType::Altered(state) => {
|
||||||
|
app.outputs.insert(output, state);
|
||||||
|
},
|
||||||
|
outputs::ChangeType::Removed => {
|
||||||
|
app.outputs.remove(&output);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
app
|
||||||
},
|
},
|
||||||
|
|
||||||
Event::InputMethod(new_im) => match (self.im.clone(), new_im) {
|
Event::InputMethod(new_im) => match (self.im.clone(), new_im) {
|
||||||
@ -271,6 +282,7 @@ mod test {
|
|||||||
im: InputMethod::Active(imdetails_new()),
|
im: InputMethod::Active(imdetails_new()),
|
||||||
physical_keyboard: Presence::Missing,
|
physical_keyboard: Presence::Missing,
|
||||||
visibility_override: visibility::State::NotForced,
|
visibility_override: visibility::State::NotForced,
|
||||||
|
..Application::new(start)
|
||||||
};
|
};
|
||||||
|
|
||||||
let state = state.apply_event(Event::InputMethod(InputMethod::InactiveSince(now)), now);
|
let state = state.apply_event(Event::InputMethod(InputMethod::InactiveSince(now)), now);
|
||||||
@ -299,6 +311,7 @@ mod test {
|
|||||||
im: InputMethod::Active(imdetails_new()),
|
im: InputMethod::Active(imdetails_new()),
|
||||||
physical_keyboard: Presence::Missing,
|
physical_keyboard: Presence::Missing,
|
||||||
visibility_override: visibility::State::NotForced,
|
visibility_override: visibility::State::NotForced,
|
||||||
|
..Application::new(start)
|
||||||
};
|
};
|
||||||
|
|
||||||
let state = state.apply_event(Event::InputMethod(InputMethod::InactiveSince(now)), now);
|
let state = state.apply_event(Event::InputMethod(InputMethod::InactiveSince(now)), now);
|
||||||
@ -323,6 +336,7 @@ mod test {
|
|||||||
im: InputMethod::Active(imdetails_new()),
|
im: InputMethod::Active(imdetails_new()),
|
||||||
physical_keyboard: Presence::Missing,
|
physical_keyboard: Presence::Missing,
|
||||||
visibility_override: visibility::State::NotForced,
|
visibility_override: visibility::State::NotForced,
|
||||||
|
..Application::new(start)
|
||||||
};
|
};
|
||||||
// This reflects the sequence from Wayland:
|
// This reflects the sequence from Wayland:
|
||||||
// disable, disable, enable, disable
|
// disable, disable, enable, disable
|
||||||
@ -361,6 +375,7 @@ mod test {
|
|||||||
im: InputMethod::InactiveSince(now),
|
im: InputMethod::InactiveSince(now),
|
||||||
physical_keyboard: Presence::Missing,
|
physical_keyboard: Presence::Missing,
|
||||||
visibility_override: visibility::State::NotForced,
|
visibility_override: visibility::State::NotForced,
|
||||||
|
..Application::new(start)
|
||||||
};
|
};
|
||||||
now += Duration::from_secs(1);
|
now += Duration::from_secs(1);
|
||||||
|
|
||||||
@ -394,6 +409,7 @@ mod test {
|
|||||||
im: InputMethod::Active(imdetails_new()),
|
im: InputMethod::Active(imdetails_new()),
|
||||||
physical_keyboard: Presence::Missing,
|
physical_keyboard: Presence::Missing,
|
||||||
visibility_override: visibility::State::NotForced,
|
visibility_override: visibility::State::NotForced,
|
||||||
|
..Application::new(start)
|
||||||
};
|
};
|
||||||
now += Duration::from_secs(1);
|
now += Duration::from_secs(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user