mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
Print message when output was not found
This commit is contained in:
@@ -58,6 +58,8 @@ pub enum Response {
|
||||
Outputs(HashMap<String, Output>),
|
||||
/// Information about the focused window.
|
||||
FocusedWindow(Option<Window>),
|
||||
/// Output configuration change result.
|
||||
OutputConfigChanged(OutputConfigChanged),
|
||||
}
|
||||
|
||||
/// Actions that niri can perform.
|
||||
@@ -456,6 +458,15 @@ pub struct Window {
|
||||
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 {
|
||||
type Err = &'static str;
|
||||
|
||||
|
||||
+11
-4
@@ -1,5 +1,7 @@
|
||||
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 crate::cli::Msg;
|
||||
@@ -241,10 +243,15 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
|
||||
bail!("unexpected response: expected Handled, got {response:?}");
|
||||
};
|
||||
}
|
||||
Msg::Output { .. } => {
|
||||
let Response::Handled = response else {
|
||||
bail!("unexpected response: expected Handled, got {response:?}");
|
||||
Msg::Output { output, .. } => {
|
||||
let Response::OutputConfigChanged(response) = response else {
|
||||
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
@@ -8,7 +8,7 @@ use calloop::io::Async;
|
||||
use directories::BaseDirs;
|
||||
use futures_util::io::{AsyncReadExt, BufReader};
|
||||
use futures_util::{AsyncBufReadExt, AsyncWriteExt};
|
||||
use niri_ipc::{Reply, Request, Response};
|
||||
use niri_ipc::{OutputConfigChanged, Reply, Request, Response};
|
||||
use smithay::desktop::Window;
|
||||
use smithay::reexports::calloop::generic::Generic;
|
||||
use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction};
|
||||
@@ -170,10 +170,19 @@ fn process(ctx: &ClientCtx, request: Request) -> Reply {
|
||||
Response::Handled
|
||||
}
|
||||
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| {
|
||||
state.apply_transient_output_config(&output, action);
|
||||
});
|
||||
Response::Handled
|
||||
|
||||
Response::OutputConfigChanged(response)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user