Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions config/src/window_rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ pub struct PreciseApplicationException {
pub enabled: bool,
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct WorkspaceAssignment {
pub appid: String,
pub title: String,
pub enabled: bool,
pub workspace_name: String,
}

// cosmic-config configuration state for `com.system76.CosmicSettings.WindowRules`
#[derive(Clone, Debug, Default, PartialEq, CosmicConfigEntry)]
#[version = 1]
pub struct Config {
pub tiling_exception_defaults: Vec<DefaultApplicationException>,
pub tiling_exception_custom: Vec<PreciseApplicationException>,
pub workspace_assignment: Vec<WorkspaceAssignment>,
}

impl Config {
Expand Down Expand Up @@ -117,3 +126,37 @@ pub fn tiling_exceptions(context: &cosmic_config::Config) -> Vec<ApplicationExce
})
.collect()
}

/// Get the current workspace assignment configuration
pub fn workspace_assignments(context: &cosmic_config::Config) -> Vec<WorkspaceAssignment> {
// Load custom assignments defined by the user.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are ..WindowRules/v1/workspace_assignment_defaults likely?
Wondering if we should use the file workspace_assignment instead or something else if a different naming is preferred.

let custom = context
.get::<Vec<WorkspaceAssignment>>("workspace_assignment_custom")
.unwrap_or_else(|why| {
if why.is_err()
&& let cosmic_config::Error::GetKey(_, err) = &why
&& err.kind() != std::io::ErrorKind::NotFound
{
tracing::error!("workspace assignment custom config error: {why}");
return Vec::new();
}
tracing::debug!("workspace assignment custom config not present: {why}");
Vec::new()
});

custom
.iter()
.filter_map(|assignment| {
if assignment.enabled {
Some(WorkspaceAssignment {
appid: assignment.appid.clone(),
title: assignment.title.clone(),
enabled: true, // Currently unused.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WorkspaceAssignment.enabled is not used in cosmic-comp.

We could instead have a WorkspaceAssignmentConfig struct { ... enabled: bool } and drop the enabled struct field from WorkspaceAssignment.

workspace_name: assignment.workspace_name.clone(),
})
} else {
None
}
})
.collect()
}