Merge branch 'debug' into 'master'

Enable debugging at runtime

See merge request World/Phosh/squeekboard!526
This commit is contained in:
dcz
2022-04-13 16:40:36 +00:00
6 changed files with 123 additions and 9 deletions

View File

@ -6,6 +6,7 @@
* It's driven by the loop defined in the loop module. */
use crate::animation;
use crate::debug;
use crate::imservice::{ ContentHint, ContentPurpose };
use crate::main::{ Commands, PanelCommand, PixelSize };
use crate::outputs;
@ -15,19 +16,20 @@ use std::cmp;
use std::collections::HashMap;
use std::time::Instant;
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub enum Presence {
Present,
Missing,
}
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct InputMethodDetails {
pub hint: ContentHint,
pub purpose: ContentPurpose,
}
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum InputMethod {
Active(InputMethodDetails),
InactiveSince(Instant),
@ -35,12 +37,13 @@ pub enum InputMethod {
/// Incoming events.
/// This contains events that cause a change to the internal state.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum Event {
InputMethod(InputMethod),
Visibility(visibility::Event),
PhysicalKeyboard(Presence),
Output(outputs::Event),
Debug(debug::Event),
/// Event triggered because a moment in time passed.
/// Use to animate state transitions.
/// The value is the ideal arrival time.
@ -60,7 +63,7 @@ impl From<outputs::Event> for Event {
}
pub mod visibility {
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum Event {
/// User requested the panel to show
ForceVisible,
@ -80,7 +83,7 @@ pub mod visibility {
}
/// The outwardly visible state.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Outcome {
pub visibility: animation::Outcome,
pub im: InputMethod,
@ -138,11 +141,12 @@ impl Outcome {
/// All state changes return the next state and the optimal time for the next check.
///
/// This state tracker can be driven by any event loop.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Application {
pub im: InputMethod,
pub visibility_override: visibility::State,
pub physical_keyboard: Presence,
pub debug_mode_enabled: bool,
/// The output on which the panel should appear.
/// This is stored as part of the state
/// because it's not clear how to derive the output from the rest of the state.
@ -164,13 +168,29 @@ impl Application {
im: InputMethod::InactiveSince(now),
visibility_override: visibility::State::NotForced,
physical_keyboard: Presence::Missing,
debug_mode_enabled: false,
preferred_output: None,
outputs: Default::default(),
}
}
pub fn apply_event(self, event: Event, _now: Instant) -> Self {
match event {
pub fn apply_event(self, event: Event, now: Instant) -> Self {
if self.debug_mode_enabled {
println!(
"Received event:
{:#?}",
event,
);
}
let state = match event {
Event::Debug(dbg) => Self {
debug_mode_enabled: match dbg {
debug::Event::Enable => true,
debug::Event::Disable => false,
},
..self
},
Event::TimeoutReached(_) => self,
Event::Visibility(visibility) => Self {
@ -236,7 +256,19 @@ impl Application {
..self
},
}
};
if state.debug_mode_enabled {
println!(
"State is now:
{:#?}
Outcome:
{:#?}",
state,
state.get_outcome(now),
);
}
state
}
fn get_preferred_height(output: &OutputState) -> Option<PixelSize> {