Add DBUS methods to toggle next/previous aura mode

This commit is contained in:
Luke D Jones
2020-10-25 15:43:33 +13:00
parent 0558f919c4
commit de3b803f14
6 changed files with 121 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Correctly disable GFX control via config
- Panic and exit if config can't be parsed
- Add DBUS method to toggle to next fan/thermal profile
- Add DBUS method to toggle to next/prev Aura mode
# [2.0.5] - 2020-09-29
### Changed

View File

@@ -117,6 +117,20 @@ If you model isn't getting the correct led modes, you can edit the file
use `cat /sys/class/dmi/id/product_name` to get details about your laptop.
# Keybinds
To switch to next/previous Aura modes you will need to bind both the aura keys (if available) to one of:
**Next**
```
asusctl led-mode -n
```
**Previous**
```
asusctl led-mode -p
```
To switch Fan/Thermal profiles you need to bind the Fn+F5 key to `asusctl profile -n`.
# BUILDING
Requirements are:

View File

@@ -72,6 +72,24 @@ impl DbusKbdBacklight {
}
}
fn next_led_mode(&self) {
if let Ok(mut ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.clone().try_lock() {
ctrl.toggle_mode(false, &mut cfg)
.unwrap_or_else(|err| warn!("{}", err));
}
}
}
fn prev_led_mode(&self) {
if let Ok(mut ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.clone().try_lock() {
ctrl.toggle_mode(true, &mut cfg)
.unwrap_or_else(|err| warn!("{}", err));
}
}
}
/// Return the current mode data
fn led_mode(&self) -> String {
if let Ok(ctrl) = self.inner.try_lock() {
@@ -165,11 +183,11 @@ impl crate::CtrlTask for CtrlKbdBacklight {
let mut file = OpenOptions::new()
.read(true)
.open(&self.bright_node)
.map_err(|err| {
match err.kind() {
std::io::ErrorKind::NotFound => RogError::MissingLedBrightNode((&self.bright_node).into(), err),
_ => RogError::Path((&self.bright_node).into(), err),
.map_err(|err| match err.kind() {
std::io::ErrorKind::NotFound => {
RogError::MissingLedBrightNode((&self.bright_node).into(), err)
}
_ => RogError::Path((&self.bright_node).into(), err),
})?;
let mut buf = [0u8; 1];
file.read_exact(&mut buf)
@@ -324,7 +342,9 @@ impl CtrlKbdBacklight {
fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
if let Some(led_node) = &self.led_node {
if let Ok(mut file) = OpenOptions::new().write(true).open(led_node) {
return file.write_all(message).map_err(|err| RogError::Write("write_bytes".into(), err));
return file
.write_all(message)
.map_err(|err| RogError::Write("write_bytes".into(), err));
}
}
Err(RogError::NotSupported)
@@ -380,6 +400,38 @@ impl CtrlKbdBacklight {
Ok(())
}
#[inline]
fn toggle_mode(&mut self, reverse: bool, config: &mut Config) -> Result<(), RogError> {
let current = config.kbd_backlight_mode;
if let Some(idx) = self.supported_modes.iter().position(|v| *v == current) {
let mut idx = idx;
// goes past end of array
if reverse {
if idx == 0 {
idx = self.supported_modes.len() - 1;
} else {
idx -= 1;
}
} else {
idx += 1;
if idx == self.supported_modes.len() {
idx = 0;
}
}
let next = self.supported_modes[idx];
config.read();
if let Some(data) = config.get_led_mode_data(next) {
self.write_mode(&data)?;
config.kbd_backlight_mode = next;
}
config.write();
}
Ok(())
}
#[inline]
fn write_mode(&mut self, mode: &AuraModes) -> Result<(), RogError> {
match mode {

View File

@@ -44,7 +44,11 @@ enum CliCommand {
struct LedModeCommand {
#[options(help = "print help message")]
help: bool,
#[options(command, required)]
#[options(help = "switch to next aura mode")]
next_mode: bool,
#[options(help = "switch to previous aura mode")]
prev_mode: bool,
#[options(command)]
command: Option<SetAuraBuiltin>,
}
@@ -118,7 +122,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
match parsed.command {
Some(CliCommand::LedMode(mode)) => {
if let Some(command) = mode.command {
if mode.next_mode && mode.prev_mode {
println!("Please specify either next or previous")
}
if mode.next_mode {
writer.next_keyboard_led_mode()?;
} else if mode.prev_mode {
writer.prev_keyboard_led_mode()?;
} else if let Some(command) = mode.command {
writer.write_builtin_mode(&command.into())?
}
}

View File

@@ -231,6 +231,28 @@ impl AuraDbusClient {
Ok(())
}
#[inline]
pub fn next_keyboard_led_mode(&self) -> Result<(), Box<dyn std::error::Error>> {
let proxy = self.connection.with_proxy(
"org.asuslinux.Daemon",
"/org/asuslinux/Led",
Duration::from_secs(2),
);
proxy.next_led_mode()?;
Ok(())
}
#[inline]
pub fn prev_keyboard_led_mode(&self) -> Result<(), Box<dyn std::error::Error>> {
let proxy = self.connection.with_proxy(
"org.asuslinux.Daemon",
"/org/asuslinux/Led",
Duration::from_secs(2),
);
proxy.prev_led_mode()?;
Ok(())
}
#[inline]
pub fn get_gfx_pwr(&self) -> Result<String, Box<dyn std::error::Error>> {
let proxy = self.connection.with_proxy(
@@ -323,7 +345,7 @@ impl AuraDbusClient {
"/org/asuslinux/Led",
Duration::from_secs(2),
);
match proxy.led_bright()? {
match proxy.led_brightness()? {
-1 => Ok(LedBrightness::new(None)),
level => Ok(LedBrightness::new(Some(level as u8))),
}

View File

@@ -6,9 +6,11 @@ use dbus::blocking;
pub trait OrgAsuslinuxDaemon {
fn set_led_mode(&self, data: &str) -> Result<(), dbus::Error>;
fn next_led_mode(&self) -> Result<(), dbus::Error>;
fn prev_led_mode(&self) -> Result<(), dbus::Error>;
fn led_mode(&self) -> Result<String, dbus::Error>;
fn led_modes(&self) -> Result<String, dbus::Error>;
fn led_bright(&self) -> Result<i16, dbus::Error>;
fn led_brightness(&self) -> Result<i16, dbus::Error>;
}
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgAsuslinuxDaemon for blocking::Proxy<'a, C> {
@@ -17,6 +19,14 @@ impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgAsuslin
self.method_call("org.asuslinux.Daemon", "SetLedMode", (data, ))
}
fn next_led_mode(&self) -> Result<(), dbus::Error> {
self.method_call("org.asuslinux.Daemon", "NextLedMode", ())
}
fn prev_led_mode(&self) -> Result<(), dbus::Error> {
self.method_call("org.asuslinux.Daemon", "PrevLedMode", ())
}
fn led_mode(&self) -> Result<String, dbus::Error> {
self.method_call("org.asuslinux.Daemon", "LedMode", ())
.and_then(|r: (String, )| Ok(r.0, ))
@@ -27,8 +37,8 @@ impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgAsuslin
.and_then(|r: (String, )| Ok(r.0, ))
}
fn led_bright(&self) -> Result<i16, dbus::Error> {
self.method_call("org.asuslinux.Daemon", "LedBright", ())
fn led_brightness(&self) -> Result<i16, dbus::Error> {
self.method_call("org.asuslinux.Daemon", "LedBrightness", ())
.and_then(|r: (i16, )| Ok(r.0, ))
}
}