translations, minor refactoring, wgui: gradient intensity in globals, dash-frontend: remove unused window_list, process_list and window_options

This commit is contained in:
Aleksander
2026-01-15 23:18:59 +01:00
committed by galister
parent 0181119393
commit dabd122a1d
43 changed files with 191 additions and 1056 deletions

View File

@@ -50,7 +50,7 @@ enum CompositorMode {
enum Task {
SetCompositor(CompositorMode),
SetRes(ResMode),
SetPos(PosMode),
SetPos(PosMode), // TODO?
SetOrientation(OrientationMode),
SetAutoStart(bool),
Launch,

View File

@@ -111,7 +111,7 @@ struct MultiSelectorParams<'a> {
fn mount_multi_selector(params: MultiSelectorParams) -> anyhow::Result<()> {
let globals = params.ess.layout.state.globals.clone();
let accent_color = globals.get().defaults.accent_color;
let accent_color = globals.defaults().accent_color;
for cell in params.cells {
let highlighted = cell.key == params.def_cell;

View File

@@ -10,7 +10,7 @@ use wgui::{
drawing::{self, GradientMode},
globals::WguiGlobals,
i18n::Translation,
layout::{Layout, WidgetID, WidgetPair},
layout::{Layout, WidgetID},
renderer_vk::text::{FontWeight, HorizontalAlign, TextShadow, TextStyle, custom_glyph::CustomGlyphData},
taffy::{
self, AlignItems, AlignSelf, JustifyContent, JustifySelf,
@@ -47,7 +47,6 @@ pub struct Params<'a, 'b> {
pub struct View {
pub button: Rc<ComponentButton>,
pair: WidgetPair,
id_image_parent: WidgetID,
app_name: String,
app_id: AppID,
@@ -289,7 +288,6 @@ impl View {
.detach();
Ok(View {
pair: widget_button,
button,
id_image_parent: image_parent.id,
app_name: params.manifest.name.clone(),

View File

@@ -18,7 +18,7 @@ use crate::{
util::{
cached_fetcher::CoverArt,
popup_manager::{MountPopupParams, PopupHandle},
steam_utils::{self, AppID, AppManifest, SteamUtils},
steam_utils::{self, AppID, SteamUtils},
various::AsyncExecutor,
},
views::{self, game_cover, game_launcher},
@@ -42,7 +42,6 @@ pub struct Params<'a> {
pub struct Cell {
view_cover: game_cover::View,
manifest: AppManifest,
}
struct State {
@@ -156,13 +155,7 @@ fn fill_game_list(
})
});
cells.insert(
manifest.app_id.clone(),
Cell {
view_cover,
manifest: manifest.clone(),
},
);
cells.insert(manifest.app_id.clone(), Cell { view_cover });
}
Ok(())

View File

@@ -3,6 +3,3 @@ pub mod audio_settings;
pub mod game_cover;
pub mod game_launcher;
pub mod game_list;
pub mod process_list;
pub mod window_list;
pub mod window_options;

View File

@@ -1,255 +0,0 @@
use std::rc::Rc;
use wayvr_ipc::packet_server::{self};
use wgui::{
assets::AssetPath,
components::{
self,
button::ComponentButton,
tooltip::{TooltipInfo, TooltipSide},
},
globals::WguiGlobals,
i18n::Translation,
layout::{Layout, WidgetID},
parser::{Fetchable, ParseDocumentParams, ParserState},
taffy::{self, prelude::length},
task::Tasks,
widget::{
ConstructEssentials,
div::WidgetDiv,
label::{WidgetLabel, WidgetLabelParams},
},
};
use wlx_common::{dash_interface::BoxDashInterface, desktop_finder::DesktopEntry};
use crate::util::{self, various::get_desktop_file_icon_path};
#[derive(Clone)]
enum Task {
Refresh,
TerminateProcess(packet_server::WvrProcess),
}
pub struct Params<'a> {
pub globals: WguiGlobals,
pub layout: &'a mut Layout,
pub parent_id: WidgetID,
}
pub struct View {
#[allow(dead_code)]
pub parser_state: ParserState,
tasks: Tasks<Task>,
globals: WguiGlobals,
id_list_parent: WidgetID,
}
impl View {
pub fn new(params: Params) -> anyhow::Result<Self> {
let doc_params = &ParseDocumentParams {
globals: params.globals.clone(),
path: AssetPath::BuiltIn("gui/view/process_list.xml"),
extra: Default::default(),
};
let parser_state = wgui::parser::parse_from_assets(doc_params, params.layout, params.parent_id)?;
let list_parent = parser_state.fetch_widget(&params.layout.state, "list_parent")?;
let tasks = Tasks::new();
tasks.push(Task::Refresh);
Ok(Self {
parser_state,
tasks,
globals: params.globals,
id_list_parent: list_parent.id,
})
}
pub fn update<T>(
&mut self,
layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
loop {
let tasks = self.tasks.drain();
if tasks.is_empty() {
break;
}
for task in tasks {
match task {
Task::Refresh => self.refresh(layout, interface, data)?,
Task::TerminateProcess(process) => self.action_terminate_process(interface, data, process)?,
}
}
}
Ok(())
}
}
fn get_desktop_entry_from_process(process: &packet_server::WvrProcess) -> Option<DesktopEntry> {
// TODO: refactor this after we ditch old wayvr-dashboard completely
let Some(dfile_str) = process.userdata.get("desktop-entry") else {
return None;
};
let Ok(desktop_file) = serde_json::from_str::<DesktopEntry>(dfile_str) else {
debug_assert!(false); // invalid json???
return None;
};
Some(desktop_file)
}
struct ProcessEntryResult {
btn_terminate: Rc<ComponentButton>,
}
fn construct_process_entry(
ess: &mut ConstructEssentials,
globals: &WguiGlobals,
process: &packet_server::WvrProcess,
) -> anyhow::Result<ProcessEntryResult> {
let (cell, _) = ess.layout.add_child(
ess.parent,
WidgetDiv::create(),
taffy::Style {
flex_direction: taffy::FlexDirection::Row,
align_items: Some(taffy::AlignItems::Center),
gap: length(8.0),
..Default::default()
},
)?;
let text_terminate_process = Translation::from_raw_text_string(globals.i18n().translate_and_replace(
"PROCESS_LIST.TERMINATE_PROCESS_NAMED_X",
("{PROCESS_NAME}", &process.name),
));
//"Terminate process" button
let (_, btn_terminate) = components::button::construct(
&mut ConstructEssentials {
layout: ess.layout,
parent: cell.id,
},
components::button::Params {
sprite_src: Some(AssetPath::BuiltIn("dashboard/remove_circle.svg")),
tooltip: Some(TooltipInfo {
text: text_terminate_process,
side: TooltipSide::Right,
}),
..Default::default()
},
)?;
if let Some(desktop_file) = get_desktop_entry_from_process(process) {
// desktop file icon and process name
util::various::mount_simple_sprite_square(
globals,
ess.layout,
cell.id,
24.0,
get_desktop_file_icon_path(&desktop_file).as_ref(),
)?;
util::various::mount_simple_label(
globals,
ess.layout,
cell.id,
Translation::from_raw_text_rc(desktop_file.app_name.clone()),
)?;
} else {
// just show a process name
util::various::mount_simple_label(
globals,
ess.layout,
cell.id,
Translation::from_raw_text_string(process.name.clone()),
)?;
}
Ok(ProcessEntryResult { btn_terminate })
}
fn fill_process_list(
globals: &WguiGlobals,
ess: &mut ConstructEssentials,
tasks: &Tasks<Task>,
list: &Vec<packet_server::WvrProcess>,
) -> anyhow::Result<()> {
for process_entry in list {
let entry_res = construct_process_entry(ess, globals, process_entry)?;
entry_res.btn_terminate.on_click({
let tasks = tasks.clone();
let entry = process_entry.clone();
Rc::new(move |_, _| {
tasks.push(Task::TerminateProcess(entry.clone()));
Ok(())
})
});
}
Ok(())
}
impl View {
fn refresh<T>(
&mut self,
layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
layout.remove_children(self.id_list_parent);
let mut text: Option<Translation> = None;
match interface.process_list(data) {
Ok(list) => {
if list.is_empty() {
text = Some(Translation::from_translation_key("PROCESS_LIST.NO_PROCESSES_FOUND"))
} else {
fill_process_list(
&self.globals,
&mut ConstructEssentials {
layout,
parent: self.id_list_parent,
},
&self.tasks,
&list,
)?;
}
}
Err(e) => text = Some(Translation::from_raw_text(&format!("Error: {:?}", e))),
}
if let Some(text) = text.take() {
layout.add_child(
self.id_list_parent,
WidgetLabel::create(
&mut self.globals.get(),
WidgetLabelParams {
content: text,
..Default::default()
},
),
Default::default(),
)?;
}
Ok(())
}
fn action_terminate_process<T>(
&mut self,
interface: &mut BoxDashInterface<T>,
data: &mut T,
process: packet_server::WvrProcess,
) -> anyhow::Result<()> {
interface.process_terminate(data, process.handle)?;
self.tasks.push(Task::Refresh);
Ok(())
}
}

View File

@@ -1,290 +0,0 @@
use std::{cell::RefCell, rc::Rc};
use wayvr_ipc::packet_server::{self, WvrWindowHandle};
use wgui::{
assets::AssetPath,
components::{self, button::ComponentButton},
globals::WguiGlobals,
i18n::Translation,
layout::{Layout, WidgetID, WidgetPair},
parser::{Fetchable, ParseDocumentParams, ParserState},
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
taffy::{self, prelude::length},
task::Tasks,
widget::{
ConstructEssentials,
label::{WidgetLabel, WidgetLabelParams},
},
};
use wlx_common::dash_interface::BoxDashInterface;
use crate::{
frontend::{FrontendTask, FrontendTasks},
util::popup_manager::{MountPopupParams, PopupHandle},
views::window_options,
};
#[derive(Clone)]
enum Task {
WindowClicked(packet_server::WvrWindow),
WindowOptionsFinish,
Refresh,
}
pub struct Params<'a> {
pub globals: WguiGlobals,
pub frontend_tasks: FrontendTasks,
pub layout: &'a mut Layout,
pub parent_id: WidgetID,
pub on_click: Option<Box<dyn Fn(WvrWindowHandle)>>,
}
struct State {
view_window_options: Option<(PopupHandle, window_options::View)>,
}
pub struct View {
#[allow(dead_code)]
pub parser_state: ParserState,
tasks: Tasks<Task>,
frontend_tasks: FrontendTasks,
globals: WguiGlobals,
state: Rc<RefCell<State>>,
id_list_parent: WidgetID,
on_click: Option<Box<dyn Fn(WvrWindowHandle)>>,
}
impl View {
pub fn new(params: Params) -> anyhow::Result<Self> {
let doc_params = &ParseDocumentParams {
globals: params.globals.clone(),
path: AssetPath::BuiltIn("gui/view/window_list.xml"),
extra: Default::default(),
};
let parser_state = wgui::parser::parse_from_assets(doc_params, params.layout, params.parent_id)?;
let list_parent = parser_state.fetch_widget(&params.layout.state, "list_parent")?;
let tasks = Tasks::new();
tasks.push(Task::Refresh);
let state = Rc::new(RefCell::new(State {
view_window_options: None,
}));
Ok(Self {
parser_state,
tasks,
frontend_tasks: params.frontend_tasks,
globals: params.globals.clone(),
state,
id_list_parent: list_parent.id,
on_click: params.on_click,
})
}
pub fn update<T>(
&mut self,
layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
loop {
let tasks = self.tasks.drain();
if tasks.is_empty() {
break;
}
for task in tasks {
match task {
Task::WindowClicked(display) => self.action_window_clicked(display)?,
Task::WindowOptionsFinish => self.action_window_options_finish(),
Task::Refresh => self.refresh(layout, interface, data)?,
}
}
}
let mut state = self.state.borrow_mut();
if let Some((_, view)) = &mut state.view_window_options {
view.update(layout, interface, data)?;
}
Ok(())
}
}
pub fn construct_window_button<T>(
ess: &mut ConstructEssentials,
interface: &mut BoxDashInterface<T>,
data: &mut T,
globals: &WguiGlobals,
window: &packet_server::WvrWindow,
) -> anyhow::Result<(WidgetPair, Rc<ComponentButton>)> {
let aspect = window.size_x as f32 / window.size_y as f32;
let height = 96.0;
let width = height * aspect;
let accent_color = globals.defaults().accent_color;
let (widget_button, button) = components::button::construct(
ess,
components::button::Params {
color: Some(accent_color.with_alpha(0.2)),
border_color: Some(accent_color),
style: taffy::Style {
align_items: Some(taffy::AlignItems::Center),
justify_content: Some(taffy::JustifyContent::Center),
size: taffy::Size {
width: length(width),
height: length(height),
},
..Default::default()
},
..Default::default()
},
)?;
let process_name = match interface.process_get(data, window.process_handle.clone()) {
Some(process) => process.name.clone(),
None => String::from("Unknown"),
};
let label_name = WidgetLabel::create(
&mut globals.get(),
WidgetLabelParams {
content: Translation::from_raw_text(&process_name),
style: TextStyle {
weight: Some(FontWeight::Bold),
wrap: true,
align: Some(HorizontalAlign::Center),
..Default::default()
},
},
);
let label_resolution = WidgetLabel::create(
&mut globals.get(),
WidgetLabelParams {
content: Translation::from_raw_text(""),
..Default::default()
},
);
ess.layout.add_child(widget_button.id, label_name, Default::default())?;
ess
.layout
.add_child(widget_button.id, label_resolution, Default::default())?;
Ok((widget_button, button))
}
fn fill_window_list<T>(
globals: &WguiGlobals,
ess: &mut ConstructEssentials,
interface: &mut BoxDashInterface<T>,
data: &mut T,
list: Vec<packet_server::WvrWindow>,
tasks: &Tasks<Task>,
) -> anyhow::Result<()> {
for entry in list {
let (_, button) = construct_window_button(ess, interface, data, globals, &entry)?;
button.on_click({
let tasks = tasks.clone();
Rc::new(move |_, _| {
tasks.push(Task::WindowClicked(entry.clone()));
Ok(())
})
});
}
Ok(())
}
impl View {
fn action_window_options_finish(&mut self) {
self.state.borrow_mut().view_window_options = None;
self.tasks.push(Task::Refresh);
}
fn refresh<T>(
&mut self,
layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
layout.remove_children(self.id_list_parent);
let mut text: Option<Translation> = None;
match interface.window_list(data) {
Ok(list) => {
if list.is_empty() {
text = Some(Translation::from_translation_key("NO_WINDOWS_FOUND"))
} else {
fill_window_list(
&self.globals,
&mut ConstructEssentials {
layout,
parent: self.id_list_parent,
},
interface,
data,
list,
&self.tasks,
)?
}
}
Err(e) => text = Some(Translation::from_raw_text(&format!("Error: {:?}", e))),
}
if let Some(text) = text.take() {
layout.add_child(
self.id_list_parent,
WidgetLabel::create(
&mut self.globals.get(),
WidgetLabelParams {
content: text,
..Default::default()
},
),
Default::default(),
)?;
}
Ok(())
}
fn action_window_clicked(&mut self, window: packet_server::WvrWindow) -> anyhow::Result<()> {
if let Some(on_click) = &mut self.on_click {
(*on_click)(window.handle);
} else {
self.frontend_tasks.push(FrontendTask::MountPopup(MountPopupParams {
title: Translation::from_translation_key("WINDOW_OPTIONS"),
on_content: {
let _frontend_tasks = self.frontend_tasks.clone();
let _globals = self.globals.clone();
let _state = self.state.clone();
let _tasks = self.tasks.clone();
//TODO
Rc::new(move |_data| {
// state.borrow_mut().view_window_options = Some((
// data.handle,
// window_options::View::new(window_options::Params {
// globals: globals.clone(),
// layout: data.layout,
// parent_id: data.id_content,
// on_submit: tasks.make_callback(Task::WindowOptionsFinish),
// window: window.clone(),
// frontend_tasks: frontend_tasks.clone(),
// })?,
// ));
Ok(())
})
},
}));
}
Ok(())
}
}

View File

@@ -1,162 +0,0 @@
use anyhow::Context;
use std::rc::Rc;
use wayvr_ipc::packet_server;
use wgui::{
assets::AssetPath,
components::button::ComponentButton,
globals::WguiGlobals,
i18n::Translation,
layout::{Layout, WidgetID},
parser::{Fetchable, ParseDocumentParams, ParserState},
task::Tasks,
widget::ConstructEssentials,
};
use wlx_common::dash_interface::BoxDashInterface;
use crate::{
frontend::{FrontendTask, FrontendTasks},
views::window_list::construct_window_button,
};
#[derive(Clone)]
enum Task {
SetVisible(bool),
Kill,
Close,
}
pub struct View {
#[allow(dead_code)]
pub state: ParserState,
tasks: Tasks<Task>,
frontend_tasks: FrontendTasks,
window: packet_server::WvrWindow,
on_submit: Rc<dyn Fn()>,
}
pub struct Params<'a, T> {
pub globals: WguiGlobals,
pub frontend_tasks: FrontendTasks,
pub layout: &'a mut Layout,
pub parent_id: WidgetID,
pub on_submit: Rc<dyn Fn()>,
pub window: packet_server::WvrWindow,
pub interface: &'a mut BoxDashInterface<T>,
pub data: &'a mut T,
}
impl View {
pub fn new<T>(params: Params<T>) -> anyhow::Result<Self> {
let doc_params = &ParseDocumentParams {
globals: params.globals.clone(),
path: AssetPath::BuiltIn("gui/view/window_options.xml"),
extra: Default::default(),
};
let state = wgui::parser::parse_from_assets(doc_params, params.layout, params.parent_id)?;
let tasks = Tasks::new();
let window_parent = state.get_widget_id("window_parent")?;
let btn_close = state.fetch_component_as::<ComponentButton>("btn_close")?;
let btn_kill = state.fetch_component_as::<ComponentButton>("btn_kill")?;
let btn_show_hide = state.fetch_component_as::<ComponentButton>("btn_show_hide")?;
construct_window_button(
&mut ConstructEssentials {
layout: params.layout,
parent: window_parent,
},
params.interface,
params.data,
&params.globals,
&params.window,
)?;
{
let mut c = params.layout.start_common();
btn_show_hide.set_text(
&mut c.common(),
Translation::from_translation_key(if params.window.visible { "HIDE" } else { "SHOW" }),
);
c.finish()?;
}
tasks.handle_button(&btn_close, Task::Close);
tasks.handle_button(&btn_kill, Task::Kill);
tasks.handle_button(&btn_show_hide, Task::SetVisible(!params.window.visible));
Ok(Self {
state,
tasks,
window: params.window,
frontend_tasks: params.frontend_tasks,
on_submit: params.on_submit,
})
}
pub fn update<T>(
&mut self,
_layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
for task in self.tasks.drain() {
match task {
Task::SetVisible(v) => self.action_set_visible(interface, data, v),
Task::Close => self.action_close(interface, data),
Task::Kill => self.action_kill(interface, data),
}
}
Ok(())
}
}
impl View {
fn action_set_visible<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T, visible: bool) {
if let Err(e) = interface.window_set_visible(data, self.window.handle.clone(), visible) {
self
.frontend_tasks
.push(FrontendTask::PushToast(Translation::from_raw_text_string(format!(
"Failed to set window visibility: {:?}",
e
))));
};
(*self.on_submit)();
}
fn action_close<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) {
if let Err(e) = interface.window_request_close(data, self.window.handle.clone()) {
self
.frontend_tasks
.push(FrontendTask::PushToast(Translation::from_raw_text_string(format!(
"Failed to close window: {:?}",
e
))));
};
(*self.on_submit)();
}
fn action_kill_process<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) -> anyhow::Result<()> {
let process = interface
.process_get(data, self.window.process_handle.clone())
.context("Process not found")?;
interface.process_terminate(data, process.handle)?;
Ok(())
}
fn action_kill<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) {
if let Err(e) = self.action_kill_process(interface, data) {
self
.frontend_tasks
.push(FrontendTask::PushToast(Translation::from_raw_text_string(format!(
"Failed to kill process: {:?}",
e
))));
};
(*self.on_submit)();
}
}