fix(cli): add monitor-information command

This commit adds a new monitor-information command to make it easier for
people to find the values they need to use the display_index_preferences
configuration option.

re #860
This commit is contained in:
LGUG2Z
2024-06-01 16:48:28 -07:00
parent 1320b7440e
commit aa24c41967
7 changed files with 31 additions and 15 deletions

5
Cargo.lock generated
View File

@@ -2408,6 +2408,7 @@ dependencies = [
"thiserror",
"uds_windows",
"which",
"win32-display-data",
"windows 0.54.0",
]
@@ -3819,9 +3820,9 @@ dependencies = [
[[package]]
name = "serde_json_lenient"
version = "0.1.8"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc61c66b53a4035fcce237ef38043f4b2f0ebf918fd0e69541a5166104065581"
checksum = "a5d0bae483150302560d7cb52e7932f39b69a6fbdd099e48d33ef060a8c9c078"
dependencies = [
"itoa",
"ryu",

View File

@@ -11,15 +11,16 @@ members = [
]
[workspace.dependencies]
windows-interface = { version = "0.53" }
windows-implement = { version = "0.53" }
dunce = "1"
dirs = "5"
color-eyre = "0.6"
serde_json = { package = "serde_json_lenient", version = "0.1" }
sysinfo = "0.30"
dirs = "5"
dunce = "1"
serde = { version = "1", features = ["derive"] }
serde_json = { package = "serde_json_lenient", version = "0.2" }
sysinfo = "0.30"
uds_windows = "1"
win32-display-data = { git = "https://github.com/LGUG2Z/win32-display-data", rev = "2a0f7166da154880a1750b91829b1186d9c6a00c" }
windows-implement = { version = "0.53" }
windows-interface = { version = "0.53" }
[workspace.dependencies.windows]
version = "0.54"

View File

@@ -168,6 +168,7 @@ pub enum SocketMessage {
State,
GlobalState,
VisibleWindows,
MonitorInformation,
Query(StateQuery),
FocusFollowsMouse(FocusFollowsMouseImplementation, bool),
ToggleFocusFollowsMouse(FocusFollowsMouseImplementation),

View File

@@ -42,13 +42,12 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
uds_windows = "1"
which = "6"
widestring = "1"
win32-display-data = { workspace = true }
windows = { workspace = true }
windows-implement = { workspace = true }
windows-interface = { workspace = true }
winput = "0.2"
winreg = "0.52"
win32-display-data = { git = "https://github.com/LGUG2Z/win32-display-data", rev = "2a0f7166da154880a1750b91829b1186d9c6a00c" }
[features]
deadlock_detection = ["parking_lot/deadlock_detection"]

View File

@@ -797,15 +797,22 @@ impl WindowManager {
}
}
let visible_windows_state =
match serde_json::to_string_pretty(&monitor_visible_windows) {
Ok(state) => state,
Err(error) => error.to_string(),
};
let visible_windows_state = serde_json::to_string_pretty(&monitor_visible_windows)
.unwrap_or_else(|error| error.to_string());
reply.write_all(visible_windows_state.as_bytes())?;
}
SocketMessage::MonitorInformation => {
let mut monitors = HashMap::new();
for monitor in self.monitors() {
monitors.insert(monitor.device_id(), monitor.size());
}
let monitors_state = serde_json::to_string_pretty(&monitors)
.unwrap_or_else(|error| error.to_string());
reply.write_all(monitors_state.as_bytes())?;
}
SocketMessage::Query(query) => {
let response = match query {
StateQuery::FocusedMonitorIndex => self.focused_monitor_idx(),

View File

@@ -32,6 +32,7 @@ sysinfo = { workspace = true }
thiserror = "1"
uds_windows = "1"
which = "6"
win32-display-data = { workspace = true }
windows = { workspace = true }
[build-dependencies]

View File

@@ -834,6 +834,9 @@ enum SubCommand {
Gui,
/// Show a JSON representation of visible windows
VisibleWindows,
/// Show information about connected monitors
#[clap(alias = "monitor-info")]
MonitorInformation,
/// Query the current window manager state
#[clap(arg_required_else_help = true)]
Query(Query),
@@ -2144,6 +2147,9 @@ Stop-Process -Name:komorebi -ErrorAction SilentlyContinue
SubCommand::VisibleWindows => {
print_query(&SocketMessage::VisibleWindows.as_bytes()?);
}
SubCommand::MonitorInformation => {
print_query(&SocketMessage::MonitorInformation.as_bytes()?);
}
SubCommand::Query(arg) => {
print_query(&SocketMessage::Query(arg.state_query).as_bytes()?);
}