Use HashSet for available layout names to avoid monitor-layout dup
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -192,7 +192,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swayout"
|
||||
version = "1.1.0"
|
||||
version = "1.1.1"
|
||||
dependencies = [
|
||||
"kdl",
|
||||
"serde",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "swayout"
|
||||
version = "1.1.0"
|
||||
version = "1.1.1"
|
||||
edition = "2021"
|
||||
description = "A tool to configure sway outputs"
|
||||
authors = ["Stephen Byrne"]
|
||||
|
||||
13
src/lib.rs
13
src/lib.rs
@@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
mod config;
|
||||
use crate::config::{get_config, Config, Layout, OutputConfig};
|
||||
@@ -11,18 +11,17 @@ use crate::sway::{apply_outputs, get_outputs, Output};
|
||||
/// for which all outputs are available,
|
||||
/// one for each monitor defined in the configuration file (for using just that monitor),
|
||||
/// and one for each available output that is not a configured monitor (for using just that output).
|
||||
fn get_layouts() -> Vec<String> {
|
||||
fn get_layouts() -> HashSet<String> {
|
||||
let available_outputs = get_outputs();
|
||||
let config = get_config();
|
||||
|
||||
|
||||
let mut layout_names: Vec<String> = Vec::new();
|
||||
let mut layout_names: HashSet<String> = HashSet::new();
|
||||
|
||||
// Add each layout defined in the config file for which all outputs are available
|
||||
get_available_layouts(&config, &available_outputs)
|
||||
.iter()
|
||||
.for_each(|layout| {
|
||||
layout_names.push(String::from(&layout.name));
|
||||
layout_names.insert(String::from(&layout.name));
|
||||
});
|
||||
|
||||
// add each individual output (by monitor name if the monitor is defined, else by output name)
|
||||
@@ -35,9 +34,9 @@ fn get_layouts() -> Vec<String> {
|
||||
&& monitor.serial == output.serial
|
||||
});
|
||||
if let Some(monitor) = monitor_opt {
|
||||
layout_names.push(String::from(&monitor.name));
|
||||
layout_names.insert(String::from(&monitor.name));
|
||||
} else {
|
||||
layout_names.push(String::from(&output.name));
|
||||
layout_names.insert(String::from(&output.name));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user