Skip to content

Commit 4c4b47c

Browse files
authored
Merge pull request #25 from TimoNotThy/master
Add profile cycle functionality
2 parents 51a79d2 + 2af3fc1 commit 4c4b47c

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "surface"
3-
version = "0.4.10"
3+
version = "0.4.11"
44
authors = ["Maximilian Luz <[email protected]>"]
55
description = "Control various aspects of Microsoft Surface devices on Linux from the Command-Line"
66

pkg/fedora/surface-control.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: surface-control
2-
Version: 0.4.10
2+
Version: 0.4.11
33
Release: 1%{?dist}
44
Summary: Control various aspects of Microsoft Surface devices from the shell
55

@@ -39,6 +39,9 @@ install -D -m644 "target/surface.fish" "%{buildroot}/usr/share/fish/vendor_compl
3939
/usr/share/fish/vendor_completions.d/surface.fish
4040

4141
%changelog
42+
* Sat Jan 03 2026 Vandevenne Timo <[email protected]> - 0.4.11-1
43+
- Update to 0.4.11
44+
4245
* Tue Dec 30 2025 Maximilian Luz <[email protected]> - 0.4.10-1
4346
- Update dependencies
4447

src/cli/profile.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ impl DynCommand for Command {
2828
.about("Get the current platform profile"))
2929
.subcommand(clap::Command::new("list")
3030
.about("List all available platform profiles"))
31+
.subcommand(clap::Command::new("cycle")
32+
.about("Cycle to the next platform profile"))
3133
}
3234

3335
fn execute(&self, m: &clap::ArgMatches) -> Result<()> {
3436
match m.subcommand() {
3537
Some(("set", m)) => self.profile_set(m),
3638
Some(("get", m)) => self.profile_get(m),
3739
Some(("list", m)) => self.profile_list(m),
40+
Some(("cycle", m)) => self.profile_cycle(m),
3841
_ => unreachable!(),
3942
}
4043
}
@@ -104,4 +107,35 @@ impl Command {
104107

105108
Ok(())
106109
}
110+
111+
fn profile_cycle(&self, m: &clap::ArgMatches) -> Result<()> {
112+
let dev = sys::profile::Device::open()
113+
.context("Failed to open platform profile device")?;
114+
115+
let supported = dev.get_supported()
116+
.context("Failed to get supported platform profiles")?;
117+
118+
if supported.is_empty() {
119+
anyhow::bail!("No platform profiles available");
120+
}
121+
122+
let current_profile = dev.get()
123+
.context("Failed to get current platform profile")?;
124+
125+
// Find the next profile in the list, wrapping around to the start
126+
let next_profile = supported.iter()
127+
.cycle()
128+
.skip_while(|&p| p != &current_profile)
129+
.nth(1)
130+
.unwrap_or(&supported[0]);
131+
132+
dev.set(next_profile)
133+
.context("Failed to set platform profile")?;
134+
135+
if !m.get_flag("quiet") {
136+
println!("Platform profile cycled from '{current_profile}' to '{next_profile}'");
137+
}
138+
139+
Ok(())
140+
}
107141
}

0 commit comments

Comments
 (0)