From 2af3fc1423f3c8c0be231c2a29707bb03b7c4c5a Mon Sep 17 00:00:00 2001 From: Timo Vandevenne Date: Sat, 3 Jan 2026 14:51:04 +0100 Subject: [PATCH] Add profile cycle functionality Changes the profile to the next one in the list. --- Cargo.lock | 2 +- Cargo.toml | 2 +- pkg/fedora/surface-control.spec | 5 ++++- src/cli/profile.rs | 34 +++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5fc8d8b..1df3eff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -407,7 +407,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "surface" -version = "0.4.10" +version = "0.4.11" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index f5cf9b1..72b3047 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "surface" -version = "0.4.10" +version = "0.4.11" authors = ["Maximilian Luz "] description = "Control various aspects of Microsoft Surface devices on Linux from the Command-Line" diff --git a/pkg/fedora/surface-control.spec b/pkg/fedora/surface-control.spec index e731cf6..180a6b2 100644 --- a/pkg/fedora/surface-control.spec +++ b/pkg/fedora/surface-control.spec @@ -1,5 +1,5 @@ Name: surface-control -Version: 0.4.10 +Version: 0.4.11 Release: 1%{?dist} Summary: Control various aspects of Microsoft Surface devices from the shell @@ -39,6 +39,9 @@ install -D -m644 "target/surface.fish" "%{buildroot}/usr/share/fish/vendor_compl /usr/share/fish/vendor_completions.d/surface.fish %changelog +* Sat Jan 03 2026 Vandevenne Timo - 0.4.11-1 +- Update to 0.4.11 + * Tue Dec 30 2025 Maximilian Luz - 0.4.10-1 - Update dependencies diff --git a/src/cli/profile.rs b/src/cli/profile.rs index a4981e5..4f09c1f 100644 --- a/src/cli/profile.rs +++ b/src/cli/profile.rs @@ -28,6 +28,8 @@ impl DynCommand for Command { .about("Get the current platform profile")) .subcommand(clap::Command::new("list") .about("List all available platform profiles")) + .subcommand(clap::Command::new("cycle") + .about("Cycle to the next platform profile")) } fn execute(&self, m: &clap::ArgMatches) -> Result<()> { @@ -35,6 +37,7 @@ impl DynCommand for Command { Some(("set", m)) => self.profile_set(m), Some(("get", m)) => self.profile_get(m), Some(("list", m)) => self.profile_list(m), + Some(("cycle", m)) => self.profile_cycle(m), _ => unreachable!(), } } @@ -104,4 +107,35 @@ impl Command { Ok(()) } + + fn profile_cycle(&self, m: &clap::ArgMatches) -> Result<()> { + let dev = sys::profile::Device::open() + .context("Failed to open platform profile device")?; + + let supported = dev.get_supported() + .context("Failed to get supported platform profiles")?; + + if supported.is_empty() { + anyhow::bail!("No platform profiles available"); + } + + let current_profile = dev.get() + .context("Failed to get current platform profile")?; + + // Find the next profile in the list, wrapping around to the start + let next_profile = supported.iter() + .cycle() + .skip_while(|&p| p != ¤t_profile) + .nth(1) + .unwrap_or(&supported[0]); + + dev.set(next_profile) + .context("Failed to set platform profile")?; + + if !m.get_flag("quiet") { + println!("Platform profile cycled from '{current_profile}' to '{next_profile}'"); + } + + Ok(()) + } }