Skip to content

Commit

Permalink
handle azin's empty device_path output (maybe?)
Browse files Browse the repository at this point in the history
  • Loading branch information
LGUG2Z committed Jul 14, 2024
1 parent faa7786 commit 7435089
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
16 changes: 11 additions & 5 deletions komorebi/src/monitor_reconciliator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ pub fn attached_display_devices() -> color_eyre::Result<Vec<Monitor>> {
.flatten()
.map(|display| {
let path = display.device_path;
let mut split: Vec<_> = path.split('#').collect();
split.remove(0);
split.remove(split.len() - 1);
let device = split[0].to_string();
let device_id = split.join("-");

let (device, device_id) = if path.is_empty() {
(String::from("UNKNOWN"), String::from("UNKNOWN"))
} else {
let mut split: Vec<_> = path.split('#').collect();
split.remove(0);
split.remove(split.len() - 1);
let device = split[0].to_string();
let device_id = split.join("-");
(device, device_id)
};

let name = display.device_name.trim_start_matches(r"\\.\").to_string();
let name = name.split('\\').collect::<Vec<_>>()[0].to_string();
Expand Down
32 changes: 22 additions & 10 deletions komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,17 @@ impl WindowsApi {
pub fn load_monitor_information(monitors: &mut Ring<Monitor>) -> Result<()> {
'read: for display in win32_display_data::connected_displays_all().flatten() {
let path = display.device_path.clone();
let mut split: Vec<_> = path.split('#').collect();
split.remove(0);
split.remove(split.len() - 1);
let device = split[0].to_string();
let device_id = split.join("-");

let (device, device_id) = if path.is_empty() {
(String::from("UNKNOWN"), String::from("UNKNOWN"))
} else {
let mut split: Vec<_> = path.split('#').collect();
split.remove(0);
split.remove(split.len() - 1);
let device = split[0].to_string();
let device_id = split.join("-");
(device, device_id)
};

let name = display.device_name.trim_start_matches(r"\\.\").to_string();
let name = name.split('\\').collect::<Vec<_>>()[0].to_string();
Expand Down Expand Up @@ -809,11 +815,17 @@ impl WindowsApi {
for display in win32_display_data::connected_displays_all().flatten() {
if display.hmonitor == hmonitor {
let path = display.device_path;
let mut split: Vec<_> = path.split('#').collect();
split.remove(0);
split.remove(split.len() - 1);
let device = split[0].to_string();
let device_id = split.join("-");

let (device, device_id) = if path.is_empty() {
(String::from("UNKNOWN"), String::from("UNKNOWN"))
} else {
let mut split: Vec<_> = path.split('#').collect();
split.remove(0);
split.remove(split.len() - 1);
let device = split[0].to_string();
let device_id = split.join("-");
(device, device_id)
};

let name = display.device_name.trim_start_matches(r"\\.\").to_string();
let name = name.split('\\').collect::<Vec<_>>()[0].to_string();
Expand Down

0 comments on commit 7435089

Please sign in to comment.