-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cosmic-comp-config
crate, and default input config
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
Showing
9 changed files
with
525 additions
and
457 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} | ||
} |
Oops, something went wrong.