Print message when output was not found

This commit is contained in:
Ivan Molodetskikh
2024-05-05 12:50:18 +04:00
parent 2e4a2e13b1
commit ea59091869
3 changed files with 33 additions and 6 deletions
+11
View File
@@ -58,6 +58,8 @@ pub enum Response {
Outputs(HashMap<String, Output>), Outputs(HashMap<String, Output>),
/// Information about the focused window. /// Information about the focused window.
FocusedWindow(Option<Window>), FocusedWindow(Option<Window>),
/// Output configuration change result.
OutputConfigChanged(OutputConfigChanged),
} }
/// Actions that niri can perform. /// Actions that niri can perform.
@@ -456,6 +458,15 @@ pub struct Window {
pub app_id: Option<String>, pub app_id: Option<String>,
} }
/// Output configuration change result.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
pub enum OutputConfigChanged {
/// The target output was connected and the change was applied.
Applied,
/// The target output was not found, the change will be applied when it is connected.
OutputWasMissing,
}
impl FromStr for SizeChange { impl FromStr for SizeChange {
type Err = &'static str; type Err = &'static str;
+11 -4
View File
@@ -1,5 +1,7 @@
use anyhow::{anyhow, bail, Context}; use anyhow::{anyhow, bail, Context};
use niri_ipc::{LogicalOutput, Mode, Output, Request, Response, Socket, Transform}; use niri_ipc::{
LogicalOutput, Mode, Output, OutputConfigChanged, Request, Response, Socket, Transform,
};
use serde_json::json; use serde_json::json;
use crate::cli::Msg; use crate::cli::Msg;
@@ -241,10 +243,15 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
bail!("unexpected response: expected Handled, got {response:?}"); bail!("unexpected response: expected Handled, got {response:?}");
}; };
} }
Msg::Output { .. } => { Msg::Output { output, .. } => {
let Response::Handled = response else { let Response::OutputConfigChanged(response) = response else {
bail!("unexpected response: expected Handled, got {response:?}"); bail!("unexpected response: expected OutputConfigChanged, got {response:?}");
}; };
if response == OutputConfigChanged::OutputWasMissing {
println!("Output \"{output}\" is not connected.");
println!("The change will apply when it is connected.");
}
} }
} }
+11 -2
View File
@@ -8,7 +8,7 @@ use calloop::io::Async;
use directories::BaseDirs; use directories::BaseDirs;
use futures_util::io::{AsyncReadExt, BufReader}; use futures_util::io::{AsyncReadExt, BufReader};
use futures_util::{AsyncBufReadExt, AsyncWriteExt}; use futures_util::{AsyncBufReadExt, AsyncWriteExt};
use niri_ipc::{Reply, Request, Response}; use niri_ipc::{OutputConfigChanged, Reply, Request, Response};
use smithay::desktop::Window; use smithay::desktop::Window;
use smithay::reexports::calloop::generic::Generic; use smithay::reexports::calloop::generic::Generic;
use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction}; use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction};
@@ -170,10 +170,19 @@ fn process(ctx: &ClientCtx, request: Request) -> Reply {
Response::Handled Response::Handled
} }
Request::Output { output, action } => { Request::Output { output, action } => {
let ipc_outputs = ctx.ipc_outputs.lock().unwrap();
let response = if ipc_outputs.contains_key(&output) {
OutputConfigChanged::Applied
} else {
OutputConfigChanged::OutputWasMissing
};
drop(ipc_outputs);
ctx.event_loop.insert_idle(move |state| { ctx.event_loop.insert_idle(move |state| {
state.apply_transient_output_config(&output, action); state.apply_transient_output_config(&output, action);
}); });
Response::Handled
Response::OutputConfigChanged(response)
} }
}; };