outputs: Notify the state manager about changes
This commit is contained in:
		@ -22,7 +22,7 @@ pub mod c {
 | 
				
			|||||||
    // Defined in C
 | 
					    // Defined in C
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[repr(transparent)]
 | 
					    #[repr(transparent)]
 | 
				
			||||||
    #[derive(Clone, PartialEq, Copy)]
 | 
					    #[derive(Clone, PartialEq, Copy, Debug)]
 | 
				
			||||||
    pub struct WlOutput(*const c_void);
 | 
					    pub struct WlOutput(*const c_void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[repr(C)]
 | 
					    #[repr(C)]
 | 
				
			||||||
@ -68,7 +68,7 @@ pub mod c {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Map to `wl_output.transform` values
 | 
					    /// Map to `wl_output.transform` values
 | 
				
			||||||
    #[derive(Clone)]
 | 
					    #[derive(Clone, Copy, Debug)]
 | 
				
			||||||
    pub enum Transform {
 | 
					    pub enum Transform {
 | 
				
			||||||
        Normal = 0,
 | 
					        Normal = 0,
 | 
				
			||||||
        Rotated90 = 1,
 | 
					        Rotated90 = 1,
 | 
				
			||||||
@ -206,13 +206,25 @@ pub mod c {
 | 
				
			|||||||
        let mut collection = outputs.borrow_mut();
 | 
					        let mut collection = outputs.borrow_mut();
 | 
				
			||||||
        let output = collection
 | 
					        let output = collection
 | 
				
			||||||
            .find_output_mut(wl_output);
 | 
					            .find_output_mut(wl_output);
 | 
				
			||||||
        match output {
 | 
					        let event = match output {
 | 
				
			||||||
            Some(output) => { output.current = output.pending.clone(); }
 | 
					            Some(output) => {
 | 
				
			||||||
            None => log_print!(
 | 
					                output.current = output.pending.clone();
 | 
				
			||||||
                logging::Level::Warning,
 | 
					                Some(Event {
 | 
				
			||||||
                "Got done on unknown output",
 | 
					                    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(
 | 
					    extern fn outputs_handle_scale(
 | 
				
			||||||
@ -288,13 +300,13 @@ pub struct Size {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// wl_output mode
 | 
					/// wl_output mode
 | 
				
			||||||
#[derive(Clone)]
 | 
					#[derive(Clone, Copy, Debug)]
 | 
				
			||||||
struct Mode {
 | 
					struct Mode {
 | 
				
			||||||
    width: i32,
 | 
					    width: i32,
 | 
				
			||||||
    height: i32,
 | 
					    height: i32,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone)]
 | 
					#[derive(Clone, Copy, Debug)]
 | 
				
			||||||
pub struct OutputState {
 | 
					pub struct OutputState {
 | 
				
			||||||
    current_mode: Option<Mode>,
 | 
					    current_mode: Option<Mode>,
 | 
				
			||||||
    transform: Option<c::Transform>,
 | 
					    transform: Option<c::Transform>,
 | 
				
			||||||
@ -345,7 +357,13 @@ 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.
 | 
				
			||||||
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 {
 | 
					struct Output {
 | 
				
			||||||
    output: c::WlOutput,
 | 
					    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> {
 | 
					    fn find_output(&self, wl_output: c::WlOutput) -> Option<&Output> {
 | 
				
			||||||
        self.outputs
 | 
					        self.outputs
 | 
				
			||||||
            .iter()
 | 
					            .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,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										14
									
								
								src/state.rs
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/state.rs
									
									
									
									
									
								
							@ -8,6 +8,7 @@
 | 
				
			|||||||
use crate::animation;
 | 
					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 std::time::Instant;
 | 
					use std::time::Instant;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -36,7 +37,7 @@ pub enum Event {
 | 
				
			|||||||
    InputMethod(InputMethod),
 | 
					    InputMethod(InputMethod),
 | 
				
			||||||
    Visibility(visibility::Event),
 | 
					    Visibility(visibility::Event),
 | 
				
			||||||
    PhysicalKeyboard(Presence),
 | 
					    PhysicalKeyboard(Presence),
 | 
				
			||||||
    
 | 
					    Output(outputs::Event),
 | 
				
			||||||
    /// Event triggered because a moment in time passed.
 | 
					    /// Event triggered because a moment in time passed.
 | 
				
			||||||
    /// Use to animate state transitions.
 | 
					    /// Use to animate state transitions.
 | 
				
			||||||
    /// The value is the ideal arrival time.
 | 
					    /// The value is the ideal arrival time.
 | 
				
			||||||
@ -49,6 +50,12 @@ impl From<InputMethod> for Event {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl From<outputs::Event> for Event {
 | 
				
			||||||
 | 
					    fn from(ev: outputs::Event) -> Self {
 | 
				
			||||||
 | 
					        Self::Output(ev)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub mod visibility {
 | 
					pub mod visibility {
 | 
				
			||||||
    #[derive(Clone)]
 | 
					    #[derive(Clone)]
 | 
				
			||||||
    pub enum Event {
 | 
					    pub enum Event {
 | 
				
			||||||
@ -166,6 +173,11 @@ impl Application {
 | 
				
			|||||||
                ..self
 | 
					                ..self
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Event::Output(output) => {
 | 
				
			||||||
 | 
					                println!("Stub: output event {:?}", output);
 | 
				
			||||||
 | 
					                self
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Event::InputMethod(new_im) => match (self.im.clone(), new_im) {
 | 
					            Event::InputMethod(new_im) => match (self.im.clone(), new_im) {
 | 
				
			||||||
                (InputMethod::Active(_old), InputMethod::Active(new_im))
 | 
					                (InputMethod::Active(_old), InputMethod::Active(new_im))
 | 
				
			||||||
                => Self {
 | 
					                => Self {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user