remember checked settings in memory

This commit is contained in:
Aleksander
2025-11-06 21:12:26 +01:00
parent e087eb3743
commit 433b7f53b5
13 changed files with 136 additions and 69 deletions

View File

@@ -10,20 +10,20 @@
<!-- Home screen --> <!-- Home screen -->
<rectangle macro="group_box"> <rectangle macro="group_box">
<GroupBoxTitle translation="HOME_SCREEN" src="dashboard/wayvr_dashboard.svg" /> <GroupBoxTitle translation="HOME_SCREEN" src="dashboard/wayvr_dashboard.svg" />
<CheckBox translation="APP_SETTINGS.HIDE_USERNAME" /> <CheckBox id="cb_hide_username" translation="APP_SETTINGS.HIDE_USERNAME" />
</rectangle> </rectangle>
<!-- General settings --> <!-- General settings -->
<rectangle macro="group_box"> <rectangle macro="group_box">
<GroupBoxTitle translation="GENERAL_SETTINGS" src="dashboard/settings.svg" /> <GroupBoxTitle translation="GENERAL_SETTINGS" src="dashboard/settings.svg" />
<CheckBox translation="APP_SETTINGS.12_HOUR_CLOCK" /> <CheckBox id="cb_am_pm_clock" text="AM/PM clock" />
<CheckBox translation="APP_SETTINGS.OPAQUE_BACKGROUND" /> <CheckBox id="cb_opaque_background" translation="APP_SETTINGS.OPAQUE_BACKGROUND" />
</rectangle> </rectangle>
<!-- Application launcher --> <!-- Application launcher -->
<rectangle macro="group_box"> <rectangle macro="group_box">
<GroupBoxTitle translation="APPLICATION_LAUNCHER" src="dashboard/apps.svg" /> <GroupBoxTitle translation="APPLICATION_LAUNCHER" src="dashboard/apps.svg" />
<CheckBox translation="APP_SETTINGS.RUN_IN_XWAYLAND_MODE_BY_DEFAULT" /> <CheckBox id="cb_xwayland_by_default" translation="APP_SETTINGS.RUN_IN_XWAYLAND_MODE_BY_DEFAULT" />
</rectangle> </rectangle>
<!-- headset settings --> <!-- headset settings -->

View File

@@ -10,7 +10,6 @@
"APPLICATION_LAUNCHER": "Anwendung Launcher", "APPLICATION_LAUNCHER": "Anwendung Launcher",
"APP_SETTINGS": { "APP_SETTINGS": {
"HIDE_USERNAME": "Benutzernamen ausblenden", "HIDE_USERNAME": "Benutzernamen ausblenden",
"12_HOUR_CLOCK": "12-Stunden-Uhr",
"OPAQUE_BACKGROUND": "Undurchsichtiger Hintergrund", "OPAQUE_BACKGROUND": "Undurchsichtiger Hintergrund",
"RUN_IN_XWAYLAND_MODE_BY_DEFAULT": "Standardmäßig in XWayland-Modus ausführen", "RUN_IN_XWAYLAND_MODE_BY_DEFAULT": "Standardmäßig in XWayland-Modus ausführen",
"WLX_OVERLAY_S_SETTINGS": "WlxOverlay-S Einstellungen", "WLX_OVERLAY_S_SETTINGS": "WlxOverlay-S Einstellungen",

View File

@@ -11,7 +11,6 @@
"APP_SETTINGS": { "APP_SETTINGS": {
"RESTART_SOFTWARE": "Restart software", "RESTART_SOFTWARE": "Restart software",
"HIDE_USERNAME": "Hide username", "HIDE_USERNAME": "Hide username",
"12_HOUR_CLOCK": "12-hour clock",
"OPAQUE_BACKGROUND": "Opaque background", "OPAQUE_BACKGROUND": "Opaque background",
"RUN_IN_XWAYLAND_MODE_BY_DEFAULT": "Run in XWayland mode by default", "RUN_IN_XWAYLAND_MODE_BY_DEFAULT": "Run in XWayland mode by default",
"WLX_OVERLAY_S_SETTINGS": "WlxOverlay-S settings", "WLX_OVERLAY_S_SETTINGS": "WlxOverlay-S settings",

View File

@@ -10,7 +10,6 @@
"APPLICATION_LAUNCHER": "Lanzador de aplicaciones", "APPLICATION_LAUNCHER": "Lanzador de aplicaciones",
"APP_SETTINGS": { "APP_SETTINGS": {
"HIDE_USERNAME": "Ocultar nombre de usuario", "HIDE_USERNAME": "Ocultar nombre de usuario",
"12_HOUR_CLOCK": "Reloj de 12 horas",
"OPAQUE_BACKGROUND": "Fondo opaco", "OPAQUE_BACKGROUND": "Fondo opaco",
"RUN_IN_XWAYLAND_MODE_BY_DEFAULT": "Ejecutar en modo XWayland por defecto", "RUN_IN_XWAYLAND_MODE_BY_DEFAULT": "Ejecutar en modo XWayland por defecto",
"WLX_OVERLAY_S_SETTINGS": "Configuración de WlxOverlay-S", "WLX_OVERLAY_S_SETTINGS": "Configuración de WlxOverlay-S",

View File

@@ -10,7 +10,6 @@
"APPLICATION_LAUNCHER": "アプリケーションランチャー", "APPLICATION_LAUNCHER": "アプリケーションランチャー",
"APP_SETTINGS": { "APP_SETTINGS": {
"HIDE_USERNAME": "ユーザー名を表示しない", "HIDE_USERNAME": "ユーザー名を表示しない",
"12_HOUR_CLOCK": "12時間表示",
"OPAQUE_BACKGROUND": "不透明な背景", "OPAQUE_BACKGROUND": "不透明な背景",
"RUN_IN_XWAYLAND_MODE_BY_DEFAULT": "XWaylandモードでデフォルトで実行する", "RUN_IN_XWAYLAND_MODE_BY_DEFAULT": "XWaylandモードでデフォルトで実行する",
"WLX_OVERLAY_S_SETTINGS": "WlxOverlay-Sの設定", "WLX_OVERLAY_S_SETTINGS": "WlxOverlay-Sの設定",

View File

@@ -10,7 +10,6 @@
"APPLICATION_LAUNCHER": "Uruchamiacz aplikacji", "APPLICATION_LAUNCHER": "Uruchamiacz aplikacji",
"APP_SETTINGS": { "APP_SETTINGS": {
"HIDE_USERNAME": "Ukryj nazwę użytkownika", "HIDE_USERNAME": "Ukryj nazwę użytkownika",
"12_HOUR_CLOCK": "12-godzinny zegar",
"OPAQUE_BACKGROUND": "Nieprzezroczysty tło", "OPAQUE_BACKGROUND": "Nieprzezroczysty tło",
"RUN_IN_XWAYLAND_MODE_BY_DEFAULT": "Uruchom domyślnie w trybie XWayland", "RUN_IN_XWAYLAND_MODE_BY_DEFAULT": "Uruchom domyślnie w trybie XWayland",
"WLX_OVERLAY_S_SETTINGS": "Ustawienia wlx-overlay-s", "WLX_OVERLAY_S_SETTINGS": "Ustawienia wlx-overlay-s",

View File

@@ -25,7 +25,7 @@ pub struct Frontend {
pub layout: RcLayout, pub layout: RcLayout,
globals: WguiGlobals, globals: WguiGlobals,
settings: settings::Settings, pub settings: settings::Settings,
#[allow(dead_code)] #[allow(dead_code)]
state: ParserState, state: ParserState,
@@ -99,19 +99,15 @@ impl Frontend {
fn tick(&mut self, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> { fn tick(&mut self, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> {
let mut layout = self.layout.borrow_mut(); let mut layout = self.layout.borrow_mut();
let mut alterables = EventAlterables::default(); let mut c = layout.start_common();
let mut common = CallbackDataCommon {
alterables: &mut alterables,
state: &layout.state,
};
// fixme: timer events instead of this thing // fixme: timer events instead of this thing
if self.ticks.is_multiple_of(1000) { if self.ticks.is_multiple_of(1000) {
self.update_time(&mut common); self.update_time(&mut c.common());
} }
c.finish()?;
layout.update(Vec2::new(width, height), timestep_alpha)?; layout.update(Vec2::new(width, height), timestep_alpha)?;
layout.process_alterables(alterables)?;
Ok(()) Ok(())
} }
@@ -154,6 +150,7 @@ impl Frontend {
layout: &mut layout, layout: &mut layout,
parent_id: widget_content.id, parent_id: widget_content.id,
frontend: rc_this, frontend: rc_this,
settings: &mut self.settings,
}; };
let tab: Box<dyn Tab> = match tab_type { let tab: Box<dyn Tab> = match tab_type {

View File

@@ -11,16 +11,9 @@ pub struct General {
pub opaque_background: bool, pub opaque_background: bool,
} }
#[derive(Default, Serialize, Deserialize)]
pub enum ApplicationRunMode {
#[default]
Native, /* use Smithay compositor */
XWaylandCage,
}
#[derive(Default, Serialize, Deserialize)] #[derive(Default, Serialize, Deserialize)]
pub struct Tweaks { pub struct Tweaks {
pub default_run_mode: ApplicationRunMode, pub xwayland_by_default: bool,
} }
#[derive(Default, Serialize, Deserialize)] #[derive(Default, Serialize, Deserialize)]

View File

@@ -2,6 +2,7 @@ use std::rc::Rc;
use wgui::{ use wgui::{
components::button::ComponentButton, components::button::ComponentButton,
event::CallbackDataCommon,
globals::WguiGlobals, globals::WguiGlobals,
layout::{Layout, WidgetID}, layout::{Layout, WidgetID},
}; };
@@ -30,6 +31,7 @@ pub struct TabParams<'a> {
pub layout: &'a mut Layout, pub layout: &'a mut Layout,
pub parent_id: WidgetID, pub parent_id: WidgetID,
pub frontend: &'a RcFrontend, pub frontend: &'a RcFrontend,
pub settings: &'a mut crate::settings::Settings,
} }
pub trait Tab { pub trait Tab {

View File

@@ -1,9 +1,17 @@
use std::rc::Rc;
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
parser::{ParseDocumentParams, ParserState}, components::checkbox::ComponentCheckbox,
event::CallbackDataCommon,
parser::{Fetchable, ParseDocumentParams, ParserState},
}; };
use crate::tab::{Tab, TabParams, TabType}; use crate::{
frontend::{Frontend, RcFrontend},
settings,
tab::{Tab, TabParams, TabType},
};
pub struct TabSettings { pub struct TabSettings {
#[allow(dead_code)] #[allow(dead_code)]
@@ -16,8 +24,27 @@ impl Tab for TabSettings {
} }
} }
fn init_setting_checkbox(
params: &mut TabParams,
checkbox: Rc<ComponentCheckbox>,
fetch_callback: fn(&mut settings::Settings) -> &mut bool,
) -> anyhow::Result<()> {
let mut c = params.layout.start_common();
checkbox.set_checked(&mut c.common(), *fetch_callback(params.settings));
let rc_frontend = params.frontend.clone();
checkbox.on_toggle(Box::new(move |_common, e| {
let mut frontend = rc_frontend.borrow_mut();
*fetch_callback(&mut frontend.settings) = e.checked;
Ok(())
}));
c.finish()?;
Ok(())
}
impl TabSettings { impl TabSettings {
pub fn new(params: TabParams) -> anyhow::Result<Self> { pub fn new(mut params: TabParams) -> anyhow::Result<Self> {
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
globals: params.globals.clone(), globals: params.globals.clone(),
@@ -28,6 +55,34 @@ impl TabSettings {
params.parent_id, params.parent_id,
)?; )?;
init_setting_checkbox(
&mut params,
state.data.fetch_component_as::<ComponentCheckbox>("cb_hide_username")?,
|settings| &mut settings.home_screen.hide_username,
)?;
init_setting_checkbox(
&mut params,
state.data.fetch_component_as::<ComponentCheckbox>("cb_am_pm_clock")?,
|settings| &mut settings.general.am_pm_clock,
)?;
init_setting_checkbox(
&mut params,
state
.data
.fetch_component_as::<ComponentCheckbox>("cb_opaque_background")?,
|settings| &mut settings.general.opaque_background,
)?;
init_setting_checkbox(
&mut params,
state
.data
.fetch_component_as::<ComponentCheckbox>("cb_xwayland_by_default")?,
|settings| &mut settings.tweaks.xwayland_by_default,
)?;
Ok(Self { state }) Ok(Self { state })
} }
} }

View File

@@ -84,18 +84,18 @@ fn set_box_checked(widgets: &layout::WidgetMap, data: &Data, checked: bool) {
} }
impl ComponentCheckbox { impl ComponentCheckbox {
pub fn set_text(&self, state: &LayoutState, common: &mut CallbackDataCommon, text: Translation) { pub fn set_text(&self, common: &mut CallbackDataCommon, text: Translation) {
let Some(mut label) = state.widgets.get_as::<WidgetLabel>(self.data.id_label) else { let Some(mut label) = common.state.widgets.get_as::<WidgetLabel>(self.data.id_label) else {
return; return;
}; };
label.set_text(common, text); label.set_text(common, text);
} }
pub fn set_checked(&self, state: &LayoutState, alterables: &mut EventAlterables, checked: bool) { pub fn set_checked(&self, common: &mut CallbackDataCommon, checked: bool) {
self.state.borrow_mut().checked = checked; self.state.borrow_mut().checked = checked;
set_box_checked(&state.widgets, &self.data, checked); set_box_checked(&common.state.widgets, &self.data, checked);
alterables.mark_redraw(); common.alterables.mark_redraw();
} }
pub fn on_toggle(&self, func: CheckboxToggleCallback) { pub fn on_toggle(&self, func: CheckboxToggleCallback) {

View File

@@ -6,7 +6,7 @@ use std::{
}; };
use glam::Vec2; use glam::Vec2;
use slotmap::{new_key_type, DenseSlotMap}; use slotmap::{DenseSlotMap, new_key_type};
use crate::{ use crate::{
animation::{self, Animation}, animation::{self, Animation},

View File

@@ -8,14 +8,14 @@ use std::{
use crate::{ use crate::{
animation::Animations, animation::Animations,
components::{Component, InitData}, components::{Component, InitData},
drawing::{self, push_scissor_stack, push_transform_stack, Boundary, ANSI_BOLD_CODE, ANSI_RESET_CODE}, drawing::{self, ANSI_BOLD_CODE, ANSI_RESET_CODE, Boundary, push_scissor_stack, push_transform_stack},
event::{self, CallbackDataCommon, EventAlterables}, event::{self, CallbackDataCommon, EventAlterables},
globals::WguiGlobals, globals::WguiGlobals,
widget::{self, div::WidgetDiv, EventParams, EventResult, WidgetObj, WidgetState}, widget::{self, EventParams, EventResult, WidgetObj, WidgetState, div::WidgetDiv},
}; };
use glam::{vec2, Vec2}; use glam::{Vec2, vec2};
use slotmap::{new_key_type, HopSlotMap, SecondaryMap}; use slotmap::{HopSlotMap, SecondaryMap, new_key_type};
use taffy::{NodeId, TaffyTree, TraversePartialTree}; use taffy::{NodeId, TaffyTree, TraversePartialTree};
new_key_type! { new_key_type! {
@@ -196,7 +196,34 @@ fn add_child_internal(
)) ))
} }
pub struct LayoutCommon<'a> {
alterables: EventAlterables,
layout: &'a mut Layout,
}
impl LayoutCommon<'_> {
pub const fn common(&mut self) -> CallbackDataCommon<'_> {
CallbackDataCommon {
alterables: &mut self.alterables,
state: &self.layout.state,
}
}
pub fn finish(self) -> anyhow::Result<()> {
self.layout.process_alterables(self.alterables)?;
Ok(())
}
}
impl Layout { impl Layout {
// helper function
pub fn start_common(&mut self) -> LayoutCommon<'_> {
LayoutCommon {
alterables: EventAlterables::default(),
layout: self,
}
}
pub fn as_rc(self) -> RcLayout { pub fn as_rc(self) -> RcLayout {
Rc::new(RefCell::new(self)) Rc::new(RefCell::new(self))
} }
@@ -580,9 +607,7 @@ impl Layout {
pub fn update(&mut self, size: Vec2, timestep_alpha: f32) -> anyhow::Result<()> { pub fn update(&mut self, size: Vec2, timestep_alpha: f32) -> anyhow::Result<()> {
let mut alterables = EventAlterables::default(); let mut alterables = EventAlterables::default();
self.animations.process(&self.state, &mut alterables, timestep_alpha); self.animations.process(&self.state, &mut alterables, timestep_alpha);
self.process_alterables(alterables)?; self.process_alterables(alterables)?;
self.try_recompute_layout(size)?; self.try_recompute_layout(size)?;
Ok(()) Ok(())