forge
Explore
Log in

Don't you dare go Hollow

Print message when output was not found

Browse files at this commit

ea590918696709b0586eb1941b4829ffc5a46e94Ivan MolodetskikhParent: 2e4a2e1
niri-ipc/src/lib.rsmodified+11 -0
@@ -58,6 +58,8 @@ pub enum Response {
5858 Outputs(HashMap<String, Output>),
5959 /// Information about the focused window.
6060 FocusedWindow(Option<Window>),
61+ /// Output configuration change result.
62+ OutputConfigChanged(OutputConfigChanged),
6163 }
6264
6365 /// Actions that niri can perform.
@@ -456,6 +458,15 @@ pub struct Window {
456458 pub app_id: Option<String>,
457459 }
458460
461+/// Output configuration change result.
462+#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
463+pub enum OutputConfigChanged {
464+ /// The target output was connected and the change was applied.
465+ Applied,
466+ /// The target output was not found, the change will be applied when it is connected.
467+ OutputWasMissing,
468+}
469+
459470 impl FromStr for SizeChange {
460471 type Err = &'static str;
461472
src/ipc/client.rsmodified+11 -4
@@ -1,5 +1,7 @@
11 use anyhow::{anyhow, bail, Context};
2-use niri_ipc::{LogicalOutput, Mode, Output, Request, Response, Socket, Transform};
2+use niri_ipc::{
3+ LogicalOutput, Mode, Output, OutputConfigChanged, Request, Response, Socket, Transform,
4+};
35 use serde_json::json;
46
57 use crate::cli::Msg;
@@ -241,10 +243,15 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
241243 bail!("unexpected response: expected Handled, got {response:?}");
242244 };
243245 }
244- Msg::Output { .. } => {
245- let Response::Handled = response else {
246- bail!("unexpected response: expected Handled, got {response:?}");
246+ Msg::Output { output, .. } => {
247+ let Response::OutputConfigChanged(response) = response else {
248+ bail!("unexpected response: expected OutputConfigChanged, got {response:?}");
247249 };
250+
251+ if response == OutputConfigChanged::OutputWasMissing {
252+ println!("Output \"{output}\" is not connected.");
253+ println!("The change will apply when it is connected.");
254+ }
248255 }
249256 }
250257
src/ipc/server.rsmodified+11 -2
@@ -8,7 +8,7 @@ use calloop::io::Async;
88 use directories::BaseDirs;
99 use futures_util::io::{AsyncReadExt, BufReader};
1010 use futures_util::{AsyncBufReadExt, AsyncWriteExt};
11-use niri_ipc::{Reply, Request, Response};
11+use niri_ipc::{OutputConfigChanged, Reply, Request, Response};
1212 use smithay::desktop::Window;
1313 use smithay::reexports::calloop::generic::Generic;
1414 use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction};
@@ -170,10 +170,19 @@ fn process(ctx: &ClientCtx, request: Request) -> Reply {
170170 Response::Handled
171171 }
172172 Request::Output { output, action } => {
173+ let ipc_outputs = ctx.ipc_outputs.lock().unwrap();
174+ let response = if ipc_outputs.contains_key(&output) {
175+ OutputConfigChanged::Applied
176+ } else {
177+ OutputConfigChanged::OutputWasMissing
178+ };
179+ drop(ipc_outputs);
180+
173181 ctx.event_loop.insert_idle(move |state| {
174182 state.apply_transient_output_config(&output, action);
175183 });
176- Response::Handled
184+
185+ Response::OutputConfigChanged(response)
177186 }
178187 };
179188