From 3f598086b74df57ba33dd9886b6e44a9b7f4cb53 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Sun, 30 Jan 2022 12:43:17 +0000 Subject: [PATCH] Store preferred output --- src/state.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/state.rs b/src/state.rs index f9bdcd8c..9119f4db 100644 --- a/src/state.rs +++ b/src/state.rs @@ -140,6 +140,12 @@ pub struct Application { pub im: InputMethod, pub visibility_override: visibility::State, pub physical_keyboard: Presence, + /// 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. + /// It should probably follow the focused input, + /// but not sure about being allowed on non-touch displays. + pub preferred_output: Option, pub outputs: HashMap, } @@ -155,6 +161,7 @@ impl Application { im: InputMethod::InactiveSince(now), visibility_override: visibility::State::NotForced, physical_keyboard: Presence::Missing, + preferred_output: None, outputs: Default::default(), } } @@ -181,9 +188,15 @@ impl Application { match change { outputs::ChangeType::Altered(state) => { app.outputs.insert(output, state); + app.preferred_output = app.preferred_output.or(Some(output)); }, outputs::ChangeType::Removed => { app.outputs.remove(&output); + if app.preferred_output == Some(output) { + // There's currently no policy to choose one output over another, + // so just take whichever comes first. + app.preferred_output = app.outputs.keys().next().map(|output| *output); + } }, }; app