diff --git a/src/outputs.rs b/src/outputs.rs index e4466457..a5cd517b 100644 --- a/src/outputs.rs +++ b/src/outputs.rs @@ -22,7 +22,7 @@ pub mod c { // Defined in C #[repr(transparent)] - #[derive(Clone, PartialEq, Copy)] + #[derive(Clone, PartialEq, Copy, Debug)] pub struct WlOutput(*const c_void); #[repr(C)] @@ -68,7 +68,7 @@ pub mod c { } /// Map to `wl_output.transform` values - #[derive(Clone)] + #[derive(Clone, Copy, Debug)] pub enum Transform { Normal = 0, Rotated90 = 1, @@ -206,13 +206,25 @@ pub mod c { let mut collection = outputs.borrow_mut(); let output = collection .find_output_mut(wl_output); - match output { - Some(output) => { output.current = output.pending.clone(); } - None => log_print!( - logging::Level::Warning, - "Got done on unknown output", - ), + let event = match output { + Some(output) => { + output.current = output.pending.clone(); + Some(Event { + output: OutputId(wl_output), + change: ChangeType::Altered(output.current), + }) + }, + None => { + log_print!( + logging::Level::Warning, + "Got done on unknown output", + ); + None + } }; + if let Some(event) = event { + collection.send_event(event); + } } extern fn outputs_handle_scale( @@ -288,13 +300,13 @@ pub struct Size { } /// wl_output mode -#[derive(Clone)] +#[derive(Clone, Copy, Debug)] struct Mode { width: i32, height: i32, } -#[derive(Clone)] +#[derive(Clone, Copy, Debug)] pub struct OutputState { current_mode: Option, transform: Option, @@ -345,7 +357,13 @@ impl OutputState { /// Not guaranteed to exist, /// but can be used to look up state. -pub type OutputId = c::WlOutput; +#[derive(Clone, Copy, PartialEq, Debug)] +pub struct OutputId(c::WlOutput); + +// WlOutput is a pointer, +// but in the public interface, +// we're only using it as a lookup key. +unsafe impl Send for OutputId {} struct Output { output: c::WlOutput, @@ -366,6 +384,10 @@ impl Outputs { } } + fn send_event(&self, event: Event) { + self.sender.send(event.into()).unwrap() + } + fn find_output(&self, wl_output: c::WlOutput) -> Option<&Output> { self.outputs .iter() @@ -384,3 +406,16 @@ impl Outputs { ) } } + +#[derive(Clone, Copy, Debug)] +pub enum ChangeType { + /// Added or changed + Altered(OutputState), + Removed, +} + +#[derive(Clone, Copy, Debug)] +pub struct Event { + output: OutputId, + change: ChangeType, +} diff --git a/src/state.rs b/src/state.rs index f3db005d..9009f1f4 100644 --- a/src/state.rs +++ b/src/state.rs @@ -8,6 +8,7 @@ use crate::animation; use crate::imservice::{ ContentHint, ContentPurpose }; use crate::main::{ Commands, PanelCommand }; +use crate::outputs; use std::time::Instant; @@ -36,7 +37,7 @@ pub enum Event { InputMethod(InputMethod), Visibility(visibility::Event), PhysicalKeyboard(Presence), - + Output(outputs::Event), /// Event triggered because a moment in time passed. /// Use to animate state transitions. /// The value is the ideal arrival time. @@ -49,6 +50,12 @@ impl From for Event { } } +impl From for Event { + fn from(ev: outputs::Event) -> Self { + Self::Output(ev) + } +} + pub mod visibility { #[derive(Clone)] pub enum Event { @@ -166,6 +173,11 @@ impl Application { ..self }, + Event::Output(output) => { + println!("Stub: output event {:?}", output); + self + }, + Event::InputMethod(new_im) => match (self.im.clone(), new_im) { (InputMethod::Active(_old), InputMethod::Active(new_im)) => Self {