Use cosmic-config for dynamic workspace settings
`WorkspaceAmount`, `WorkspaceMode`, and `WorkspaceLayout` can all be changed dynamically now.
This commit is contained in:
parent
25f5edd6cf
commit
81efd42dd5
9 changed files with 88 additions and 51 deletions
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::shell::{focus::FocusDirection, grabs::ResizeEdge, Direction, ResizeDirection};
|
||||
use cosmic_comp_config::workspace::WorkspaceLayout;
|
||||
use serde::Deserialize;
|
||||
use smithay::{
|
||||
backend::input::KeyState,
|
||||
|
|
@ -8,7 +9,7 @@ use smithay::{
|
|||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::{types::*, WorkspaceLayout};
|
||||
use super::types::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||
pub enum KeyModifier {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::{
|
||||
shell::{Shell, WorkspaceAmount},
|
||||
shell::Shell,
|
||||
state::{BackendData, State},
|
||||
wayland::protocols::output_configuration::OutputConfigurationState,
|
||||
};
|
||||
|
|
@ -29,7 +29,11 @@ mod key_bindings;
|
|||
pub use key_bindings::{Action, KeyModifier, KeyModifiers, KeyPattern};
|
||||
mod types;
|
||||
pub use self::types::*;
|
||||
use cosmic_comp_config::{input::InputConfig, XkbConfig};
|
||||
use cosmic_comp_config::{
|
||||
input::InputConfig,
|
||||
workspace::{WorkspaceConfig, WorkspaceLayout},
|
||||
XkbConfig,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Config {
|
||||
|
|
@ -40,30 +44,15 @@ pub struct Config {
|
|||
pub input_default: InputConfig,
|
||||
pub input_touchpad: InputConfig,
|
||||
pub input_devices: HashMap<String, InputConfig>,
|
||||
pub workspace: WorkspaceConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct StaticConfig {
|
||||
pub key_bindings: HashMap<key_bindings::KeyPattern, key_bindings::Action>,
|
||||
pub workspace_mode: WorkspaceMode,
|
||||
pub workspace_amount: WorkspaceAmount,
|
||||
#[serde(default = "default_workspace_layout")]
|
||||
pub workspace_layout: WorkspaceLayout,
|
||||
pub tiling_enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum WorkspaceMode {
|
||||
OutputBound,
|
||||
Global,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum WorkspaceLayout {
|
||||
Vertical,
|
||||
Horizontal,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DynamicConfig {
|
||||
outputs: (Option<PathBuf>, OutputsConfig),
|
||||
|
|
@ -96,10 +85,6 @@ fn default_enabled() -> bool {
|
|||
true
|
||||
}
|
||||
|
||||
fn default_workspace_layout() -> WorkspaceLayout {
|
||||
WorkspaceLayout::Vertical
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
|
||||
pub struct OutputConfig {
|
||||
pub mode: ((i32, i32), Option<u32>),
|
||||
|
|
@ -155,18 +140,23 @@ impl Config {
|
|||
})
|
||||
.expect("Failed to add cosmic-config to the event loop");
|
||||
let xdg = xdg::BaseDirectories::new().ok();
|
||||
let workspace = get_config::<WorkspaceConfig>(&config, "workspaces");
|
||||
Config {
|
||||
static_conf: Self::load_static(xdg.as_ref()),
|
||||
static_conf: Self::load_static(xdg.as_ref(), workspace.workspace_layout),
|
||||
dynamic_conf: Self::load_dynamic(xdg.as_ref()),
|
||||
xkb: get_config(&config, "xkb-config"),
|
||||
input_default: get_config(&config, "input-default"),
|
||||
input_touchpad: get_config(&config, "input-touchpad"),
|
||||
input_devices: get_config(&config, "input-devices"),
|
||||
workspace,
|
||||
config,
|
||||
}
|
||||
}
|
||||
|
||||
fn load_static(xdg: Option<&xdg::BaseDirectories>) -> StaticConfig {
|
||||
fn load_static(
|
||||
xdg: Option<&xdg::BaseDirectories>,
|
||||
workspace_layout: WorkspaceLayout,
|
||||
) -> StaticConfig {
|
||||
let mut locations = if let Some(base) = xdg {
|
||||
vec![
|
||||
base.get_config_file("cosmic-comp.ron"),
|
||||
|
|
@ -192,10 +182,7 @@ impl Config {
|
|||
ron::de::from_reader(OpenOptions::new().read(true).open(path).unwrap())
|
||||
.expect("Malformed config file");
|
||||
|
||||
key_bindings::add_default_bindings(
|
||||
&mut config.key_bindings,
|
||||
config.workspace_layout,
|
||||
);
|
||||
key_bindings::add_default_bindings(&mut config.key_bindings, workspace_layout);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
|
@ -203,9 +190,6 @@ impl Config {
|
|||
|
||||
StaticConfig {
|
||||
key_bindings: HashMap::new(),
|
||||
workspace_mode: WorkspaceMode::Global,
|
||||
workspace_amount: WorkspaceAmount::Dynamic,
|
||||
workspace_layout: WorkspaceLayout::Vertical,
|
||||
tiling_enabled: false,
|
||||
}
|
||||
}
|
||||
|
|
@ -516,6 +500,11 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
|
|||
state.common.config.input_devices = value;
|
||||
update_input(state);
|
||||
}
|
||||
"workspaces" => {
|
||||
state.common.config.workspace =
|
||||
get_config::<WorkspaceConfig>(&config, "workspaces");
|
||||
state.common.shell.update_config(&state.common.config);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue