mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Trying different strategies for non-blocking UI
This commit is contained in:
@@ -42,18 +42,18 @@ versions.workspace = true
|
||||
nix = "^0.26.1"
|
||||
tempfile = "3.3.0"
|
||||
|
||||
i-slint-backend-selector = { git = "https://github.com/slint-ui/slint.git" }
|
||||
i-slint-core = { git = "https://github.com/slint-ui/slint.git" }
|
||||
i-slint-backend-winit = { git = "https://github.com/slint-ui/slint.git" }
|
||||
i-slint-backend-selector = { git = "https://github.com/flukejones/sixtyfps.git" }
|
||||
i-slint-core = { git = "https://github.com/flukejones/sixtyfps.git" }
|
||||
i-slint-backend-winit = { git = "https://github.com/flukejones/sixtyfps.git" }
|
||||
winit = "*"
|
||||
|
||||
[dependencies.slint]
|
||||
git = "https://github.com/slint-ui/slint.git"
|
||||
git = "https://github.com/flukejones/sixtyfps.git"
|
||||
default-features = false
|
||||
features = ["std", "compat-1-0", "backend-winit-wayland", "backend-linuxkms", "renderer-femtovg"]
|
||||
|
||||
[build-dependencies.slint-build]
|
||||
git = "https://github.com/slint-ui/slint.git"
|
||||
git = "https://github.com/flukejones/sixtyfps.git"
|
||||
|
||||
[dev-dependencies]
|
||||
cargo-husky.workspace = true
|
||||
@@ -19,6 +19,7 @@ use rog_control_center::{
|
||||
get_ipc_file, on_tmp_dir_exists, print_versions, AvailableSystemProperties, MainWindow,
|
||||
RogDbusClientBlocking, SystemPage, QUIT_APP, SHOWING_GUI, SHOW_GUI,
|
||||
};
|
||||
use rog_dbus::zbus_platform::{PlatformProxy, PlatformProxyBlocking};
|
||||
use tokio::runtime::Runtime;
|
||||
// use winit::monitor::VideoMode;
|
||||
// use winit::window::{Fullscreen, WindowLevel};
|
||||
@@ -176,37 +177,77 @@ fn setup_window(_states: Arc<Mutex<SystemState>>) -> MainWindow {
|
||||
// slint::platform::set_platform(Box::new(i_slint_backend_winit::Backend::new().
|
||||
// unwrap())).unwrap();
|
||||
let ui = MainWindow::new().unwrap();
|
||||
// Example of how to do work in another thread.
|
||||
// The thread itself can keep its own state, and then update vars in the UI
|
||||
// when required.
|
||||
let ui_handle = ui.as_weak();
|
||||
spawn(move || loop {
|
||||
sleep(Duration::from_secs(1));
|
||||
// This is where the actual update happens
|
||||
ui_handle
|
||||
.upgrade_in_event_loop(move |handle| {
|
||||
// handle.set_counter(handle.get_counter() + 1);
|
||||
use i_slint_backend_winit::WinitWindowAccessor;
|
||||
handle
|
||||
.window()
|
||||
.with_winit_window(|winit_window: &winit::window::Window| {
|
||||
// winit_window.set_fullscreen(Some(Fullscreen::Borderless(None)));
|
||||
if !winit_window.has_focus() {
|
||||
// slint::quit_event_loop().unwrap();
|
||||
// handle.hide().unwrap();
|
||||
}
|
||||
});
|
||||
})
|
||||
.ok();
|
||||
|
||||
let handle = ui.as_weak();
|
||||
ui.global::<SystemPage>().on_cancelled(move || {
|
||||
handle.upgrade_in_event_loop(|_handle| {}).ok();
|
||||
});
|
||||
|
||||
ui.global::<SystemPage>().on_set_charge(|v1, v2| {
|
||||
if v1 != v2 {
|
||||
dbg!(v1);
|
||||
dbg!(v2);
|
||||
}
|
||||
// TODO: macro
|
||||
let conn = zbus::blocking::Connection::system().unwrap();
|
||||
let proxy = PlatformProxyBlocking::new(&conn).unwrap();
|
||||
let proxy2 = proxy.clone();
|
||||
ui.global::<SystemPage>().on_set_charge_limit(move |limit| {
|
||||
dbg!(limit);
|
||||
proxy.set_charge_control_end_threshold(limit as u8).unwrap();
|
||||
});
|
||||
|
||||
ui.global::<SystemPage>().on_set_panel_od(move |od| {
|
||||
dbg!(od);
|
||||
proxy2.set_panel_od(od).unwrap();
|
||||
});
|
||||
|
||||
// let handle = ui.as_weak();
|
||||
// ui.global::<SystemPage>().on_applied(move || {
|
||||
// handle
|
||||
// .upgrade_in_event_loop(|handle| {
|
||||
// let data = handle.global::<SystemPage>();
|
||||
// let charge_changed = data.get_charge_limit() as i32 !=
|
||||
// data.get_last_charge_limit(); let charge =
|
||||
// data.get_charge_limit() as u8; tokio::spawn(async move {
|
||||
// let conn = zbus::Connection::system().await.unwrap();
|
||||
// let proxy = PlatformProxy::new(&conn).await.unwrap();
|
||||
// if charge_changed {
|
||||
// proxy
|
||||
// .set_charge_control_end_threshold(charge)
|
||||
// .await
|
||||
// .unwrap();
|
||||
// }
|
||||
// });
|
||||
// })
|
||||
// .ok();
|
||||
// });
|
||||
|
||||
// or
|
||||
// let handle = ui.as_weak();
|
||||
// tokio::spawn(async move {
|
||||
// // TODO: macro
|
||||
// let conn = zbus::Connection::system().await.unwrap();
|
||||
// let proxy = PlatformProxy::new(&conn).await.unwrap();
|
||||
// let proxy2 = proxy.clone();
|
||||
// handle.upgrade_in_event_loop(move |handle| {
|
||||
// handle
|
||||
// .global::<SystemPage>()
|
||||
// .on_set_charge_limit(move |limit| {
|
||||
// let proxy = proxy.clone();
|
||||
// tokio::spawn(async move {
|
||||
// dbg!(limit);
|
||||
// proxy
|
||||
// .set_charge_control_end_threshold(limit as u8)
|
||||
// .await
|
||||
// .unwrap();
|
||||
// });
|
||||
// });
|
||||
// handle.global::<SystemPage>().on_set_panel_od(move |od| {
|
||||
// let proxy2 = proxy2.clone();
|
||||
// tokio::spawn(async move {
|
||||
// dbg!(od);
|
||||
// proxy2.set_panel_od(od).await.unwrap();
|
||||
// });
|
||||
// });
|
||||
// }).ok();
|
||||
// });
|
||||
|
||||
let props = AvailableSystemProperties {
|
||||
ac_command: true,
|
||||
bat_command: true,
|
||||
|
||||
@@ -2,8 +2,6 @@ import { VerticalBox , StandardButton, Button} from "std-widgets.slint";
|
||||
import { Theme } from "globals.slint";
|
||||
|
||||
export component SquareImageButton inherits Rectangle {
|
||||
// if (AppConsts.sdfsdf.length < 0): Rectangle { background: red; }
|
||||
|
||||
callback clicked;
|
||||
in-out property <image> img;
|
||||
border-radius: 7px;
|
||||
@@ -13,7 +11,7 @@ export component SquareImageButton inherits Rectangle {
|
||||
touch := TouchArea {
|
||||
clicked => {
|
||||
root.clicked();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +39,7 @@ export component RoundImageButton inherits Rectangle {
|
||||
touch := TouchArea {
|
||||
clicked => {
|
||||
root.clicked();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +64,7 @@ export component SquareCharButton inherits Rectangle {
|
||||
touch := TouchArea {
|
||||
clicked => {
|
||||
root.clicked();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,26 +92,26 @@ export component ValueBar inherits Rectangle {
|
||||
// do a percentage of each half as 0-50%
|
||||
if (value >= max + min) {
|
||||
return (value - (max + min) / 2) / (max - min);
|
||||
|
||||
|
||||
}
|
||||
return 0.50 - (value - (min - max) / 2) / (max - min);
|
||||
|
||||
|
||||
}
|
||||
return (value - min) / (max - min);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function set_x(min: float, max: float, value: float, width: length) -> length{
|
||||
if (min < 0.0 && max > 0.0) {
|
||||
if (value < max + min) {
|
||||
return width / 2 - width * (percentage(min, max, value));
|
||||
|
||||
|
||||
}
|
||||
return width / 2;
|
||||
|
||||
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
@@ -152,7 +150,7 @@ export component SpinBoxUni inherits Rectangle {
|
||||
clicked => {
|
||||
if (root.value > root.minimum) {
|
||||
root.value -= 1;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,7 +176,7 @@ export component SpinBoxUni inherits Rectangle {
|
||||
clicked => {
|
||||
if (root.value < root.maximum) {
|
||||
root.value += 1;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,7 +238,7 @@ export component PopupNotification {
|
||||
|
||||
public function show() {
|
||||
_p.show();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ValueBar } from "../common_widgets.slint";
|
||||
import { ValueBar, SquareCharButton } from "../common_widgets.slint";
|
||||
import { Theme } from "../globals.slint";
|
||||
import { HorizontalBox , VerticalBox, ScrollView, Slider} from "std-widgets.slint";
|
||||
import { HorizontalBox , VerticalBox, ScrollView, Slider, Button, Switch} from "std-widgets.slint";
|
||||
|
||||
export struct AvailableSystemProperties {
|
||||
charge_limit: bool,
|
||||
@@ -28,126 +28,175 @@ export struct SystemValues {
|
||||
}
|
||||
|
||||
export global SystemPage {
|
||||
in-out property <int> charge-limit;
|
||||
callback set_charge(/* charge limit */ int, /* last limit */ int);
|
||||
in-out property <float> charge_limit;
|
||||
in-out property <int> last_charge_limit;
|
||||
callback set_charge_limit(/* charge limit */ int);
|
||||
|
||||
in-out property <bool> panel_od;
|
||||
in-out property <bool> last_panel_od;
|
||||
callback set_panel_od(/* panel_od */ bool);
|
||||
|
||||
callback applied();
|
||||
callback cancelled();
|
||||
|
||||
in-out property <AvailableSystemProperties> available;
|
||||
in-out property <SystemValues> values;
|
||||
}
|
||||
|
||||
export component PageSystem inherits Rectangle {
|
||||
background: Theme.background-color;
|
||||
ScrollView {
|
||||
VerticalLayout {
|
||||
// padding: 10px;
|
||||
|
||||
VerticalLayout {
|
||||
ScrollView {
|
||||
VerticalLayout {
|
||||
// padding: 10px;
|
||||
spacing: 10px;
|
||||
min-height: root.height;
|
||||
if SystemPage.available.charge-limit: Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("ChargeMode" => "Charging mode");
|
||||
}
|
||||
min-height: root.height;
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("ChargeLimit" => "Charge limit");
|
||||
}
|
||||
if SystemPage.available.charge-limit: Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
|
||||
charge_slider := Slider {
|
||||
value: SystemPage.values.charge_limit;
|
||||
changed => {
|
||||
if SystemPage.values.last_charge_limit != charge_slider.value {
|
||||
SystemPage.set_charge(charge_slider.value, SystemPage.values.last_charge_limit);
|
||||
SystemPage.values.last_charge_limit = charge_slider.value;
|
||||
HorizontalBox {
|
||||
alignment: LayoutAlignment.start;
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("ChargeLimit" => "Charge limit");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: "\{Math.floor(SystemPage.charge_limit)}";
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalBox {
|
||||
TouchArea { }
|
||||
|
||||
charge_slider := Slider {
|
||||
maximum: 100;
|
||||
minimum: 20;
|
||||
value <=> SystemPage.charge_limit;
|
||||
released => {
|
||||
SystemPage.set_charge_limit(SystemPage.charge_limit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if SystemPage.available.panel-od: Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PanelOverdrive" => "Panel Overdrive");
|
||||
if SystemPage.available.panel-od: Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
HorizontalBox {
|
||||
alignment: LayoutAlignment.start;
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PanelOverdrive" => "Panel Overdrive");
|
||||
}
|
||||
Switch {
|
||||
checked <=> SystemPage.panel_od;
|
||||
toggled => {
|
||||
SystemPage.set_panel_od(SystemPage.panel_od)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PerformanceProfile" => "Performance Profile");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PerformanceProfile" => "Performance Profile");
|
||||
Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("nv_dynamic_boost" => "nv_dynamic_boost");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("nv_temp_target" => "nv_temp_target");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("ppt_pl1_spl" => "ppt_pl1_spl");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("ppt_pl2_sppt" => "ppt_pl2_sppt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PanelOverdrive" => "Panel Overdrive");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PerformanceProfile" => "Performance Profile");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PanelOverdrive" => "Panel Overdrive");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PerformanceProfile" => "Performance Profile");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PanelOverdrive" => "Panel Overdrive");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PerformanceProfile" => "Performance Profile");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("nv_dynamic_boost" => "nv_dynamic_boost");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("nv_temp_target" => "nv_temp_target");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("ppt_pl1_spl" => "ppt_pl1_spl");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("ppt_pl2_sppt" => "ppt_pl2_sppt");
|
||||
HorizontalLayout {
|
||||
Button {
|
||||
text: "Apply";
|
||||
clicked => {
|
||||
if SystemPage.last_charge_limit != Math.floor(SystemPage.charge_limit) {
|
||||
SystemPage.set_charge_limit(SystemPage.charge_limit);
|
||||
SystemPage.last_charge_limit = Math.floor(SystemPage.charge_limit);
|
||||
}
|
||||
SystemPage.applied();
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PanelOverdrive" => "Panel Overdrive");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PerformanceProfile" => "Performance Profile");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PanelOverdrive" => "Panel Overdrive");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PerformanceProfile" => "Performance Profile");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
background: Theme.background-color;
|
||||
VerticalBox {
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PanelOverdrive" => "Panel Overdrive");
|
||||
}
|
||||
|
||||
Text {
|
||||
color: Theme.text-foreground-color;
|
||||
text: @tr("PerformanceProfile" => "Performance Profile");
|
||||
}
|
||||
Button {
|
||||
text: "Cancel";
|
||||
clicked => {
|
||||
SystemPage.charge_limit = SystemPage.last_charge_limit;
|
||||
SystemPage.cancelled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user