mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Add DBUS methods to toggle next/previous aura mode
This commit is contained in:
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Correctly disable GFX control via config
|
- Correctly disable GFX control via config
|
||||||
- Panic and exit if config can't be parsed
|
- 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 fan/thermal profile
|
||||||
|
- Add DBUS method to toggle to next/prev Aura mode
|
||||||
|
|
||||||
# [2.0.5] - 2020-09-29
|
# [2.0.5] - 2020-09-29
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -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.
|
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
|
# BUILDING
|
||||||
|
|
||||||
Requirements are:
|
Requirements are:
|
||||||
|
|||||||
@@ -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
|
/// Return the current mode data
|
||||||
fn led_mode(&self) -> String {
|
fn led_mode(&self) -> String {
|
||||||
if let Ok(ctrl) = self.inner.try_lock() {
|
if let Ok(ctrl) = self.inner.try_lock() {
|
||||||
@@ -165,11 +183,11 @@ impl crate::CtrlTask for CtrlKbdBacklight {
|
|||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.open(&self.bright_node)
|
.open(&self.bright_node)
|
||||||
.map_err(|err| {
|
.map_err(|err| match err.kind() {
|
||||||
match err.kind() {
|
std::io::ErrorKind::NotFound => {
|
||||||
std::io::ErrorKind::NotFound => RogError::MissingLedBrightNode((&self.bright_node).into(), err),
|
RogError::MissingLedBrightNode((&self.bright_node).into(), err)
|
||||||
_ => RogError::Path((&self.bright_node).into(), err),
|
|
||||||
}
|
}
|
||||||
|
_ => RogError::Path((&self.bright_node).into(), err),
|
||||||
})?;
|
})?;
|
||||||
let mut buf = [0u8; 1];
|
let mut buf = [0u8; 1];
|
||||||
file.read_exact(&mut buf)
|
file.read_exact(&mut buf)
|
||||||
@@ -324,7 +342,9 @@ impl CtrlKbdBacklight {
|
|||||||
fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
||||||
if let Some(led_node) = &self.led_node {
|
if let Some(led_node) = &self.led_node {
|
||||||
if let Ok(mut file) = OpenOptions::new().write(true).open(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)
|
Err(RogError::NotSupported)
|
||||||
@@ -380,6 +400,38 @@ impl CtrlKbdBacklight {
|
|||||||
Ok(())
|
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]
|
#[inline]
|
||||||
fn write_mode(&mut self, mode: &AuraModes) -> Result<(), RogError> {
|
fn write_mode(&mut self, mode: &AuraModes) -> Result<(), RogError> {
|
||||||
match mode {
|
match mode {
|
||||||
|
|||||||
@@ -44,7 +44,11 @@ enum CliCommand {
|
|||||||
struct LedModeCommand {
|
struct LedModeCommand {
|
||||||
#[options(help = "print help message")]
|
#[options(help = "print help message")]
|
||||||
help: bool,
|
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>,
|
command: Option<SetAuraBuiltin>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +122,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
match parsed.command {
|
match parsed.command {
|
||||||
Some(CliCommand::LedMode(mode)) => {
|
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())?
|
writer.write_builtin_mode(&command.into())?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,6 +231,28 @@ impl AuraDbusClient {
|
|||||||
Ok(())
|
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]
|
#[inline]
|
||||||
pub fn get_gfx_pwr(&self) -> Result<String, Box<dyn std::error::Error>> {
|
pub fn get_gfx_pwr(&self) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let proxy = self.connection.with_proxy(
|
let proxy = self.connection.with_proxy(
|
||||||
@@ -323,7 +345,7 @@ impl AuraDbusClient {
|
|||||||
"/org/asuslinux/Led",
|
"/org/asuslinux/Led",
|
||||||
Duration::from_secs(2),
|
Duration::from_secs(2),
|
||||||
);
|
);
|
||||||
match proxy.led_bright()? {
|
match proxy.led_brightness()? {
|
||||||
-1 => Ok(LedBrightness::new(None)),
|
-1 => Ok(LedBrightness::new(None)),
|
||||||
level => Ok(LedBrightness::new(Some(level as u8))),
|
level => Ok(LedBrightness::new(Some(level as u8))),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ use dbus::blocking;
|
|||||||
|
|
||||||
pub trait OrgAsuslinuxDaemon {
|
pub trait OrgAsuslinuxDaemon {
|
||||||
fn set_led_mode(&self, data: &str) -> Result<(), dbus::Error>;
|
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_mode(&self) -> Result<String, dbus::Error>;
|
||||||
fn led_modes(&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> {
|
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, ))
|
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> {
|
fn led_mode(&self) -> Result<String, dbus::Error> {
|
||||||
self.method_call("org.asuslinux.Daemon", "LedMode", ())
|
self.method_call("org.asuslinux.Daemon", "LedMode", ())
|
||||||
.and_then(|r: (String, )| Ok(r.0, ))
|
.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, ))
|
.and_then(|r: (String, )| Ok(r.0, ))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn led_bright(&self) -> Result<i16, dbus::Error> {
|
fn led_brightness(&self) -> Result<i16, dbus::Error> {
|
||||||
self.method_call("org.asuslinux.Daemon", "LedBright", ())
|
self.method_call("org.asuslinux.Daemon", "LedBrightness", ())
|
||||||
.and_then(|r: (i16, )| Ok(r.0, ))
|
.and_then(|r: (i16, )| Ok(r.0, ))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user