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 {
58 Outputs(HashMap<String, Output>),58 Outputs(HashMap<String, Output>),
59 /// Information about the focused window.59 /// Information about the focused window.
60 FocusedWindow(Option<Window>),60 FocusedWindow(Option<Window>),
61+ /// Output configuration change result.
62+ OutputConfigChanged(OutputConfigChanged),
61 }63 }
62 64
63 /// Actions that niri can perform.65 /// Actions that niri can perform.
@@ -456,6 +458,15 @@ pub struct Window {
456 pub app_id: Option<String>,458 pub app_id: Option<String>,
457 }459 }
458 460
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+
459 impl FromStr for SizeChange {470 impl FromStr for SizeChange {
460 type Err = &'static str;471 type Err = &'static str;
461 472
src/ipc/client.rsmodified+11 -4
@@ -1,5 +1,7 @@
1 use anyhow::{anyhow, bail, Context};1 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+};
3 use serde_json::json;5 use serde_json::json;
4 6
5 use crate::cli::Msg;7 use crate::cli::Msg;
@@ -241,10 +243,15 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
241 bail!("unexpected response: expected Handled, got {response:?}");243 bail!("unexpected response: expected Handled, got {response:?}");
242 };244 };
243 }245 }
244- Msg::Output { .. } => {246+ Msg::Output { output, .. } => {
245- let Response::Handled = response else {247+ let Response::OutputConfigChanged(response) = response else {
246- bail!("unexpected response: expected Handled, got {response:?}");248+ bail!("unexpected response: expected OutputConfigChanged, got {response:?}");
247 };249 };
250+
251+ if response == OutputConfigChanged::OutputWasMissing {
252+ println!("Output \"{output}\" is not connected.");
253+ println!("The change will apply when it is connected.");
254+ }
248 }255 }
249 }256 }
250 257
src/ipc/server.rsmodified+11 -2
@@ -8,7 +8,7 @@ use calloop::io::Async;
8 use directories::BaseDirs;8 use directories::BaseDirs;
9 use futures_util::io::{AsyncReadExt, BufReader};9 use futures_util::io::{AsyncReadExt, BufReader};
10 use futures_util::{AsyncBufReadExt, AsyncWriteExt};10 use futures_util::{AsyncBufReadExt, AsyncWriteExt};
11-use niri_ipc::{Reply, Request, Response};11+use niri_ipc::{OutputConfigChanged, Reply, Request, Response};
12 use smithay::desktop::Window;12 use smithay::desktop::Window;
13 use smithay::reexports::calloop::generic::Generic;13 use smithay::reexports::calloop::generic::Generic;
14 use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction};14 use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction};
@@ -170,10 +170,19 @@ fn process(ctx: &ClientCtx, request: Request) -> Reply {
170 Response::Handled170 Response::Handled
171 }171 }
172 Request::Output { output, action } => {172 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+
173 ctx.event_loop.insert_idle(move |state| {181 ctx.event_loop.insert_idle(move |state| {
174 state.apply_transient_output_config(&output, action);182 state.apply_transient_output_config(&output, action);
175 });183 });
176- Response::Handled184+
185+ Response::OutputConfigChanged(response)
177 }186 }
178 };187 };
179 188