Skip to content

Commit

Permalink
Fixed parent to exclude itself
Browse files Browse the repository at this point in the history
  • Loading branch information
mbwilding committed Dec 21, 2023
1 parent 7f733b3 commit 7fba543
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions dygma-layer-switcher/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,33 @@ fn check_parent(config: &Configuration, app_details: &AppDetails) -> Option<u8>
.values()
.find(|p| p.name() == app_details.process);

let mut parent_level = 0;

if let Some(proc) = specified_process {
// Check each parent process of the specified process.
let mut current_proc = Some(proc);
while let Some(proc) = current_proc {
for (&layer_number, layer) in &config.mappings {
for app in &layer.apps {
if let Mode::Parent(ref parent) = app.mode {
if app.is_enabled && parent.name == proc.name() {
// Check if the process is disabled or is not excluded.
let is_excluded = parent.excludes.iter().any(|exclude| {
exclude.is_enabled
&& exclude.name.to_lowercase()
== app_details.process.to_lowercase()
});

if !is_excluded {
return Some(layer_number);
if parent_level != 0 {
info!("Parent {}: {}", parent_level, proc.name());
for (&layer_number, layer) in &config.mappings {
for app in &layer.apps {
if let Mode::Parent(ref parent) = app.mode {
if app.is_enabled && parent.name == proc.name() {
let is_excluded = parent.excludes.iter().any(|exclude| {
exclude.is_enabled
&& exclude.name.to_lowercase()
== app_details.process.to_lowercase()
});

if !is_excluded {
return Some(layer_number);
}
}
}
}
}
}

// Move to the parent process in the next iteration.
parent_level += 1;
current_proc = proc.parent().and_then(|pid| sys.process(pid));
}
}
Expand Down

0 comments on commit 7fba543

Please sign in to comment.