mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
feature: add UI controls fro screenpad
This commit is contained in:
@@ -57,6 +57,7 @@ impl CtrlBacklight {
|
|||||||
.screenpad_sync_primary
|
.screenpad_sync_primary
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
// If sync is enabled and we're setting screenpad brightness, set primary first
|
||||||
if sync && *device_type == BacklightType::Screenpad {
|
if sync && *device_type == BacklightType::Screenpad {
|
||||||
if let Some(primary) = self.get_backlight(&BacklightType::Primary) {
|
if let Some(primary) = self.get_backlight(&BacklightType::Primary) {
|
||||||
if let Ok(primary_max) = primary.get_max_brightness() {
|
if let Ok(primary_max) = primary.get_max_brightness() {
|
||||||
@@ -88,6 +89,8 @@ impl CtrlBacklight {
|
|||||||
FdoErr::Failed(format!("Failed to set brightness: {}", e))
|
FdoErr::Failed(format!("Failed to set brightness: {}", e))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
// If sync is enabled and we're setting primary brightness, set screenpad
|
||||||
|
// afterward
|
||||||
if sync && *device_type == BacklightType::Primary {
|
if sync && *device_type == BacklightType::Primary {
|
||||||
for other in self
|
for other in self
|
||||||
.backlights
|
.backlights
|
||||||
@@ -118,7 +121,7 @@ impl CtrlBacklight {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_brightness_percent(&self, device_type: &BacklightType) -> Result<i32, FdoErr> {
|
async fn get_brightness_percent(&self, device_type: &BacklightType) -> Result<i32, FdoErr> {
|
||||||
if let Some(backlight) = self.get_backlight(device_type) {
|
if let Some(backlight) = self.get_backlight(device_type) {
|
||||||
let brightness = backlight.get_brightness().map_err(|e| {
|
let brightness = backlight.get_brightness().map_err(|e| {
|
||||||
warn!("Failed to get brightness: {}", e);
|
warn!("Failed to get brightness: {}", e);
|
||||||
@@ -130,7 +133,14 @@ impl CtrlBacklight {
|
|||||||
FdoErr::Failed(format!("Failed to get max brightness: {}", e))
|
FdoErr::Failed(format!("Failed to get max brightness: {}", e))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok((brightness as u32 * 100 / max as u32) as i32)
|
if *device_type == BacklightType::Screenpad {
|
||||||
|
let gamma = self.config.lock().await.screenpad_gamma.unwrap_or(1.0);
|
||||||
|
let normalized = brightness as f32 / max as f32;
|
||||||
|
let corrected = normalized.powf(1.0 / gamma);
|
||||||
|
Ok((corrected * 100.0).round() as i32)
|
||||||
|
} else {
|
||||||
|
Ok(brightness * 100 / max)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(FdoErr::NotSupported(format!(
|
Err(FdoErr::NotSupported(format!(
|
||||||
"Backlight {:?} not found",
|
"Backlight {:?} not found",
|
||||||
@@ -164,12 +174,19 @@ impl CtrlBacklight {
|
|||||||
if !sync {
|
if !sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if sync.is_none() {
|
} else if backlights
|
||||||
|
.config
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.screenpad_sync_primary
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let level = backlights
|
let level = backlights
|
||||||
.get_brightness_percent(&BacklightType::Primary)
|
.get_brightness_percent(&BacklightType::Primary)
|
||||||
|
.await
|
||||||
.unwrap_or(60);
|
.unwrap_or(60);
|
||||||
backlights
|
backlights
|
||||||
.set_brightness_with_sync(&BacklightType::Screenpad, level)
|
.set_brightness_with_sync(&BacklightType::Screenpad, level)
|
||||||
@@ -231,7 +248,7 @@ impl CtrlBacklight {
|
|||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn primary_brightness(&self) -> Result<i32, FdoErr> {
|
async fn primary_brightness(&self) -> Result<i32, FdoErr> {
|
||||||
self.get_brightness_percent(&BacklightType::Primary)
|
self.get_brightness_percent(&BacklightType::Primary).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
@@ -253,13 +270,13 @@ impl CtrlBacklight {
|
|||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn screenpad_brightness(&self) -> Result<i32, FdoErr> {
|
async fn screenpad_brightness(&self) -> Result<i32, FdoErr> {
|
||||||
self.get_brightness_percent(&BacklightType::Screenpad)
|
self.get_brightness_percent(&BacklightType::Screenpad).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn set_screenpad_brightness(
|
async fn set_screenpad_brightness(
|
||||||
&self,
|
&self,
|
||||||
#[zbus(signal_context)] ctxt: SignalEmitter<'_>,
|
// #[zbus(signal_context)] ctxt: SignalEmitter<'_>,
|
||||||
level: i32,
|
level: i32,
|
||||||
) -> Result<(), zbus::Error> {
|
) -> Result<(), zbus::Error> {
|
||||||
if level > 100 {
|
if level > 100 {
|
||||||
@@ -268,7 +285,7 @@ impl CtrlBacklight {
|
|||||||
|
|
||||||
self.set_brightness_with_sync(&BacklightType::Screenpad, level)
|
self.set_brightness_with_sync(&BacklightType::Screenpad, level)
|
||||||
.await?;
|
.await?;
|
||||||
self.screenpad_brightness_changed(&ctxt).await?;
|
// self.screenpad_brightness_changed(&ctxt).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
use concat_idents::concat_idents;
|
use concat_idents::concat_idents;
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use rog_dbus::asus_armoury::AsusArmouryProxy;
|
use rog_dbus::asus_armoury::AsusArmouryProxy;
|
||||||
|
use rog_dbus::zbus_backlight::BacklightProxy;
|
||||||
use rog_dbus::zbus_platform::{PlatformProxy, PlatformProxyBlocking};
|
use rog_dbus::zbus_platform::{PlatformProxy, PlatformProxyBlocking};
|
||||||
use rog_platform::asus_armoury::FirmwareAttribute;
|
use rog_platform::asus_armoury::FirmwareAttribute;
|
||||||
use rog_platform::platform::Properties;
|
use rog_platform::platform::Properties;
|
||||||
@@ -40,6 +41,7 @@ pub fn setup_system_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) {
|
|||||||
ui.global::<SystemPageData>().set_panel_overdrive(-1);
|
ui.global::<SystemPageData>().set_panel_overdrive(-1);
|
||||||
ui.global::<SystemPageData>().set_boot_sound(-1);
|
ui.global::<SystemPageData>().set_boot_sound(-1);
|
||||||
ui.global::<SystemPageData>().set_mini_led_mode(-1);
|
ui.global::<SystemPageData>().set_mini_led_mode(-1);
|
||||||
|
ui.global::<SystemPageData>().set_screenpad_brightness(-1);
|
||||||
ui.global::<SystemPageData>().set_ppt_pl1_spl(MINMAX);
|
ui.global::<SystemPageData>().set_ppt_pl1_spl(MINMAX);
|
||||||
ui.global::<SystemPageData>().set_ppt_pl2_sppt(MINMAX);
|
ui.global::<SystemPageData>().set_ppt_pl2_sppt(MINMAX);
|
||||||
ui.global::<SystemPageData>().set_ppt_pl3_fppt(MINMAX);
|
ui.global::<SystemPageData>().set_ppt_pl3_fppt(MINMAX);
|
||||||
@@ -288,6 +290,13 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc<Mutex<Config>>)
|
|||||||
log::error!("Failed to create platform proxy: {}", e);
|
log::error!("Failed to create platform proxy: {}", e);
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let backlight = BacklightProxy::builder(&conn)
|
||||||
|
.build()
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
log::error!("Failed to create backlight proxy: {}", e);
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
debug!("Setting up system page profile callbacks");
|
debug!("Setting up system page profile callbacks");
|
||||||
set_ui_props_async!(
|
set_ui_props_async!(
|
||||||
@@ -381,6 +390,24 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc<Mutex<Config>>)
|
|||||||
|
|
||||||
set_ui_props_async!(handle, platform, SystemPageData, enable_ppt_group);
|
set_ui_props_async!(handle, platform, SystemPageData, enable_ppt_group);
|
||||||
|
|
||||||
|
set_ui_props_async!(handle, backlight, SystemPageData, screenpad_brightness);
|
||||||
|
if let Ok(value) = backlight.screenpad_gamma().await {
|
||||||
|
handle
|
||||||
|
.upgrade_in_event_loop(move |handle| {
|
||||||
|
handle
|
||||||
|
.global::<SystemPageData>()
|
||||||
|
.set_screenpad_gamma(value.parse().unwrap_or(1.0));
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
set_ui_props_async!(
|
||||||
|
handle,
|
||||||
|
backlight,
|
||||||
|
SystemPageData,
|
||||||
|
screenpad_sync_with_primary
|
||||||
|
);
|
||||||
|
|
||||||
let platform_copy = platform.clone();
|
let platform_copy = platform.clone();
|
||||||
handle
|
handle
|
||||||
.upgrade_in_event_loop(move |handle| {
|
.upgrade_in_event_loop(move |handle| {
|
||||||
@@ -501,6 +528,27 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc<Mutex<Config>>)
|
|||||||
"Throttle policy on battery enabled: {}",
|
"Throttle policy on battery enabled: {}",
|
||||||
"Setting Throttle policy on AC failed"
|
"Setting Throttle policy on AC failed"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
set_ui_callbacks!(handle,
|
||||||
|
SystemPageData(as i32),
|
||||||
|
backlight.screenpad_brightness(as i32),
|
||||||
|
"Screenpad successfully set to {}",
|
||||||
|
"Setting screenpad brightness failed"
|
||||||
|
);
|
||||||
|
|
||||||
|
set_ui_callbacks!(handle,
|
||||||
|
SystemPageData(as bool),
|
||||||
|
backlight.screenpad_sync_with_primary(as bool),
|
||||||
|
"Screenpad successfully set to {}",
|
||||||
|
"Setting screenpad brightness failed"
|
||||||
|
);
|
||||||
|
|
||||||
|
set_ui_callbacks!(handle,
|
||||||
|
SystemPageData(.parse().unwrap_or(1.0)),
|
||||||
|
backlight.screenpad_gamma(.to_string().as_str()),
|
||||||
|
"Screenpad successfully set to {}",
|
||||||
|
"Setting screenpad brightness failed"
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { SystemSlider, SystemDropdown, SystemToggle, SystemToggleInt } from "../widgets/common.slint";
|
import { SystemSlider, SystemDropdown, SystemToggle, SystemToggleInt, RogItem } from "../widgets/common.slint";
|
||||||
import { Palette, HorizontalBox , VerticalBox, ScrollView, Slider, Button, Switch, ComboBox, GroupBox, StandardButton} from "std-widgets.slint";
|
import { Palette, HorizontalBox , VerticalBox, ScrollView, Slider, Button, Switch, ComboBox, GroupBox, StandardButton} from "std-widgets.slint";
|
||||||
|
|
||||||
export struct AttrMinMax {
|
export struct AttrMinMax {
|
||||||
@@ -53,6 +53,15 @@ export global SystemPageData {
|
|||||||
callback cb_boot_sound(int);
|
callback cb_boot_sound(int);
|
||||||
in-out property <int> mini_led_mode;
|
in-out property <int> mini_led_mode;
|
||||||
callback cb_mini_led_mode(int);
|
callback cb_mini_led_mode(int);
|
||||||
|
|
||||||
|
in-out property <float> screenpad_gamma;
|
||||||
|
callback cb_screenpad_gamma(float);
|
||||||
|
// percentage
|
||||||
|
in-out property <int> screenpad_brightness: 50;
|
||||||
|
callback cb_screenpad_brightness(int);
|
||||||
|
in-out property <bool> screenpad_sync_with_primary: false;
|
||||||
|
callback cb_screenpad_sync_with_primary(bool);
|
||||||
|
|
||||||
in-out property <bool> asus_armoury_loaded: false;
|
in-out property <bool> asus_armoury_loaded: false;
|
||||||
|
|
||||||
in-out property <AttrMinMax> ppt_pl1_spl: {
|
in-out property <AttrMinMax> ppt_pl1_spl: {
|
||||||
@@ -185,6 +194,52 @@ export component PageSystem inherits Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if SystemPageData.screenpad_brightness != -1: RogItem {
|
||||||
|
HorizontalLayout {
|
||||||
|
padding-left: 10px;
|
||||||
|
padding-right: 20px;
|
||||||
|
HorizontalLayout {
|
||||||
|
width: 38%;
|
||||||
|
alignment: LayoutAlignment.space-between;
|
||||||
|
padding-right: 15px;
|
||||||
|
Text {
|
||||||
|
font-size: 16px;
|
||||||
|
vertical-alignment: TextVerticalAlignment.center;
|
||||||
|
color: Palette.control-foreground;
|
||||||
|
text: @tr("Screenpad brightness");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalLayout {
|
||||||
|
width: 38%;
|
||||||
|
alignment: LayoutAlignment.stretch;
|
||||||
|
screen_bright := Slider {
|
||||||
|
enabled: true;
|
||||||
|
minimum: 0;
|
||||||
|
maximum: 100;
|
||||||
|
value: SystemPageData.screenpad_brightness;
|
||||||
|
released(value) => {
|
||||||
|
// SystemPageData.screenpad_brightness = self.value;
|
||||||
|
SystemPageData.cb_screenpad_brightness(Math.floor(self.value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalLayout {
|
||||||
|
width: 20%;
|
||||||
|
padding-left: 10px;
|
||||||
|
alignment: LayoutAlignment.stretch;
|
||||||
|
Switch {
|
||||||
|
text: @tr("Sync with primary");
|
||||||
|
checked <=> SystemPageData.screenpad_sync_with_primary;
|
||||||
|
toggled => {
|
||||||
|
SystemPageData.cb_screenpad_sync_with_primary(self.checked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
background: Palette.alternate-background;
|
background: Palette.alternate-background;
|
||||||
border-color: Palette.accent-background;
|
border-color: Palette.accent-background;
|
||||||
|
|||||||
Reference in New Issue
Block a user