Skip to content

Commit

Permalink
cosmic-comp-config crate, and default input config
Browse files Browse the repository at this point in the history
This adds a `input-default` setting, which is used for input settings if a
device isn't set in `input-devices`. More awkwardly, it also adds an
`input-touchpad` setting, which is used instead of `input-default` for
touchpad devices, so we can separate mouse and touchpad settings even
though they use the same capability and settings.

This no longer sets the input config, and only reads it. If we add a UI
for per-device config, we'll need some IPC mechanism to list connected
devices. (Assuming cosmic-settings can't use libinput directly for that.)

This moves `InputConfig` and `XkbConfig` to a new `cosmic-comp-config`
crate, so they can be used in `cosmic-settings`.
  • Loading branch information
ids1024 committed Aug 29, 2023
1 parent d259fb2 commit 7955b16
Show file tree
Hide file tree
Showing 9 changed files with 525 additions and 457 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ edition = "2021"
license = "GPL-3.0-only"
authors = ["Victoria Brekenfeld"]

[workspace]
members = [
"cosmic-comp-config"
]

[dependencies]
apply = "0.3.0"
anyhow = { version = "1.0.51", features = ["backtrace"] }
Expand All @@ -30,6 +35,7 @@ ron = "0.7"
libsystemd = { version = "0.5", optional = true }
wayland-backend = "0.1.0"
wayland-scanner = "0.30.0"
cosmic-comp-config = { path = "cosmic-comp-config" }
cosmic-config = { git = "https://github.com/pop-os/libcosmic/", rev = "4895b0c", features = ["calloop"] }
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", branch = "main", default-features = false, features = ["server"] }
libcosmic = { git = "https://github.com/pop-os/libcosmic/", rev = "4895b0c", default-features = false }
Expand Down
8 changes: 8 additions & 0 deletions cosmic-comp-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "cosmic-comp-config"
version = "0.1.0"
edition = "2021"

[dependencies]
input = "0.8.3"
serde = { version = "1", features = ["derive"] }
209 changes: 209 additions & 0 deletions cosmic-comp-config/src/input.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
// SPDX-License-Identifier: GPL-3.0-only

#![allow(non_snake_case)]

use input::{AccelProfile, ClickMethod, ScrollMethod, TapButtonMap};
use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Deserialize, Serialize)]
pub struct InputConfig {
pub state: DeviceState,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub acceleration: Option<AccelConfig>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub calibration: Option<[f32; 6]>,
#[serde(with = "ClickMethodDef")]
#[serde(skip_serializing_if = "Option::is_none", default)]
pub click_method: Option<ClickMethod>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub disable_while_typing: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub left_handed: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub middle_button_emulation: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub rotation_angle: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub scroll_config: Option<ScrollConfig>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub tap_config: Option<TapConfig>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct AccelConfig {
#[serde(with = "AccelProfileDef")]
pub profile: Option<AccelProfile>,
pub speed: f64,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ScrollConfig {
#[serde(with = "ScrollMethodDef")]
pub method: Option<ScrollMethod>,
pub natural_scroll: Option<bool>,
pub scroll_button: Option<u32>,
}

#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub enum DeviceState {
Enabled,
Disabled,
DisabledOnExternalMouse,
}

impl Default for DeviceState {
fn default() -> Self {
Self::Enabled
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct TapConfig {
pub enabled: bool,
#[serde(with = "TapButtonMapDef")]
pub button_map: Option<TapButtonMap>,
pub drag: bool,
pub drag_lock: bool,
}

mod ClickMethodDef {
use input::ClickMethod as ClickMethodOrig;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Debug, Serialize, Deserialize)]
pub enum ClickMethod {
ButtonAreas,
Clickfinger,
}

pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<ClickMethodOrig>, D::Error>
where
D: Deserializer<'de>,
{
let o = Option::deserialize(deserializer)?;
Ok(o.map(|x| match x {
ClickMethod::ButtonAreas => ClickMethodOrig::ButtonAreas,
ClickMethod::Clickfinger => ClickMethodOrig::Clickfinger,
}))
}

pub fn serialize<S>(arg: &Option<ClickMethodOrig>, ser: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let arg = match arg {
Some(ClickMethodOrig::ButtonAreas) => Some(ClickMethod::ButtonAreas),
Some(ClickMethodOrig::Clickfinger) => Some(ClickMethod::Clickfinger),
Some(_) | None => None,
};
Option::serialize(&arg, ser)
}
}

mod AccelProfileDef {
use input::AccelProfile as AccelProfileOrig;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Debug, Serialize, Deserialize)]
enum AccelProfile {
Flat,
Adaptive,
}

pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<AccelProfileOrig>, D::Error>
where
D: Deserializer<'de>,
{
let o = Option::deserialize(deserializer)?;
Ok(o.map(|x| match x {
AccelProfile::Flat => AccelProfileOrig::Flat,
AccelProfile::Adaptive => AccelProfileOrig::Adaptive,
}))
}

pub fn serialize<S>(arg: &Option<AccelProfileOrig>, ser: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let arg = match arg {
Some(AccelProfileOrig::Flat) => Some(AccelProfile::Flat),
Some(AccelProfileOrig::Adaptive) => Some(AccelProfile::Adaptive),
Some(_) | None => None,
};
Option::serialize(&arg, ser)
}
}

mod ScrollMethodDef {
use input::ScrollMethod as ScrollMethodOrig;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Debug, Serialize, Deserialize)]
pub enum ScrollMethod {
NoScroll,
TwoFinger,
Edge,
OnButtonDown,
}

pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<ScrollMethodOrig>, D::Error>
where
D: Deserializer<'de>,
{
let o = Option::deserialize(deserializer)?;
Ok(o.map(|x| match x {
ScrollMethod::NoScroll => ScrollMethodOrig::NoScroll,
ScrollMethod::TwoFinger => ScrollMethodOrig::TwoFinger,
ScrollMethod::Edge => ScrollMethodOrig::Edge,
ScrollMethod::OnButtonDown => ScrollMethodOrig::OnButtonDown,
}))
}

pub fn serialize<S>(arg: &Option<ScrollMethodOrig>, ser: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let arg = match arg {
Some(ScrollMethodOrig::NoScroll) => Some(ScrollMethod::NoScroll),
Some(ScrollMethodOrig::TwoFinger) => Some(ScrollMethod::TwoFinger),
Some(ScrollMethodOrig::Edge) => Some(ScrollMethod::Edge),
Some(ScrollMethodOrig::OnButtonDown) => Some(ScrollMethod::OnButtonDown),
Some(_) | None => None,
};
Option::serialize(&arg, ser)
}
}

mod TapButtonMapDef {
use input::TapButtonMap as TapButtonMapOrig;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Debug, Serialize, Deserialize)]
pub enum TapButtonMap {
LeftRightMiddle,
LeftMiddleRight,
}

pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<TapButtonMapOrig>, D::Error>
where
D: Deserializer<'de>,
{
let o = Option::deserialize(deserializer)?;
Ok(o.map(|x| match x {
TapButtonMap::LeftRightMiddle => TapButtonMapOrig::LeftRightMiddle,
TapButtonMap::LeftMiddleRight => TapButtonMapOrig::LeftMiddleRight,
}))
}

pub fn serialize<S>(arg: &Option<TapButtonMapOrig>, ser: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let arg = match arg {
Some(TapButtonMapOrig::LeftRightMiddle) => Some(TapButtonMap::LeftRightMiddle),
Some(TapButtonMapOrig::LeftMiddleRight) => Some(TapButtonMap::LeftMiddleRight),
Some(_) | None => None,
};
Option::serialize(&arg, ser)
}
}
26 changes: 26 additions & 0 deletions cosmic-comp-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: GPL-3.0-only

use serde::{Deserialize, Serialize};

pub mod input;

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct XkbConfig {
pub rules: String,
pub model: String,
pub layout: String,
pub variant: String,
pub options: Option<String>,
}

impl Default for XkbConfig {
fn default() -> XkbConfig {
XkbConfig {
rules: String::new(),
model: String::new(),
layout: String::new(),
variant: String::new(),
options: None,
}
}
}
Loading

0 comments on commit 7955b16

Please sign in to comment.