more useful parser warnings + cleanups

This commit is contained in:
galister
2026-01-08 19:16:11 +09:00
parent 76f328a16e
commit cdf4ed3882
20 changed files with 399 additions and 360 deletions

View File

@@ -108,7 +108,7 @@
<!-- An app with a single icon. -->
<template name="App">
<Button macro="button_style" id="overlay_${idx}" tooltip_str="${name}" _context_name="${name}" _press="::ContextMenuOpen menu_app">
<sprite width="38" height="38" color="~text_color" src_ext="${icon}" />
<sprite width="38" height="38" color="~color_text" src_ext="${icon}" />
</Button>
</template>
@@ -123,7 +123,7 @@
<!-- A screen with a shortened connector name, e.g. "H1" for HDMI-A-1 or "D2" for DP-2 -->
<template name="Screen">
<Button macro="button_style" id="overlay_${idx}" tooltip_str="${name}" _context_name="${name}" _press="::ContextMenuOpen menu_screen">
<sprite width="38" height="38" color="~text_color" src_builtin="edit/screen.svg" />
<sprite width="38" height="38" color="~color_text" src_builtin="edit/screen.svg" />
<div position="absolute" margin_top="-7" margin_left="-1">
<label text="${display}" size="18" color="~color_faded_20" weight="bold" />
</div>
@@ -141,7 +141,7 @@
<template name="Panel">
<Button macro="button_style" id="overlay_${idx}" tooltip_str="${name}" _context_name="${name}" _press="::ContextMenuOpen menu_panel">
<sprite width="38" height="38" color="~text_color" src_builtin="edit/panel.svg" />
<sprite width="38" height="38" color="~color_text" src_builtin="edit/panel.svg" />
</Button>
</template>
@@ -156,7 +156,7 @@
<template name="Mirror">
<Button macro="button_style" id="overlay_${idx}" tooltip_str="${name}" _context_name="${name}" _press="::ContextMenuOpen menu_mirror">
<sprite width="38" height="38" color="~text_color" src_builtin="edit/mirror.svg" />
<sprite width="38" height="38" color="~color_text" src_builtin="edit/mirror.svg" />
<div position="absolute" margin_top="5" margin_left="13">
<label text="${display}" size="20" color="~color_faded_20" weight="bold" />
</div>
@@ -174,7 +174,7 @@
<template name="Set">
<Button macro="button_style" id="set_${idx}" _press="::SetSwitch ${idx}" tooltip="WATCH.SWITCH_TO_SET" tooltip_side="bottom">
<sprite width="38" height="38" color="~text_color" src_builtin="watch/set2.svg" />
<sprite width="38" height="38" color="~color_text" src_builtin="watch/set2.svg" />
<div position="absolute" margin_top="10" margin_left="-7">
<label text="${display}" size="20" color="~color_faded_20" weight="bold" />
</div>
@@ -186,32 +186,23 @@
<rectangle macro="bg_rect" padding="10" align_items="center" justify_content="space_between">
<div gap="10">
<Button macro="button_style" id="btn_dashboard" _press="::DashToggle">
<sprite width="38" height="38" color="~text_color" src="watch/wayvr_dashboard_mono.svg" />
<sprite width="38" height="38" color="~color_text" src="watch/wayvr_dashboard_mono.svg" />
</Button>
<VerticalSeparator />
<div id="panels_root" gap="6">
<Screen idx="0" display="H1" name="HDMI-A-1" />
<Screen idx="1" display="D2" name="Screen: DP-2" />
<Mirror idx="1" display="1" name="M1" />
<Panel idx="1" display="Test" name="Test" />
</div>
<VerticalSeparator />
<div id="apps_root" gap="6">
<App id="test1" name="Blender" icon="/usr/share/icons/hicolor/scalable/apps/blender-5.0.svg" />
<App id="test2" name="Inkscape" icon="/usr/share/icons/hicolor/scalable/apps/org.inkscape.Inkscape.svg" />
<App id="test3" name="GIMP" icon="/usr/share/icons/hicolor/scalable/apps/gimp.svg" />
</div>
</div>
<div id="tray_root" flex_direction="row" gap="10">
<Button macro="button_style" _press="::ContextMenuOpen menu_burger">
<sprite width="38" height="38" color="~text_color" src_builtin="keyboard/burger.svg" />
<sprite width="38" height="38" color="~color_text" src_builtin="keyboard/burger.svg" />
</Button>
<VerticalSeparator />
<div id="sets_root" flex_direction="row" gap="6">
<Set idx="0" display="1" />
<Set idx="1" display="2" />
</div>
<VerticalSeparator />

View File

@@ -40,7 +40,7 @@
<template name="Screen">
<Button macro="button_style" id="overlay_${idx}" tooltip_str="${name}" _press="::OverlayToggle ${name}">
<sprite width="38" height="38" color="~text_color" src_builtin="edit/screen.svg" />
<sprite width="38" height="38" color="~color_text" src_builtin="edit/screen.svg" />
<div position="absolute" margin_top="-7" margin_left="-1">
<label text="${display}" size="18" color="~color_faded_20" weight="bold" />
</div>
@@ -48,12 +48,12 @@
</template>
<template name="Panel">
<Button macro="button_style" id="overlay_${idx}" tooltip_str="${name}" _press="::OverlayToggle ${name}">
<sprite width="38" height="38" color="~text_color" src_builtin="edit/panel.svg" />
<sprite width="38" height="38" color="~color_text" src_builtin="edit/panel.svg" />
</Button>
</template>
<template name="Mirror">
<Button macro="button_style" id="overlay_${idx}" tooltip_str="${name}" _press="::OverlayToggle ${name}">
<sprite width="38" height="38" color="~text_color" src_builtin="edit/mirror.svg" />
<sprite width="38" height="38" color="~color_text" src_builtin="edit/mirror.svg" />
<div position="absolute" margin_top="5" margin_left="13">
<label text="${display}" size="20" color="~color_faded_20" weight="bold" />
</div>
@@ -61,13 +61,13 @@
</template>
<template name="App">
<Button macro="button_style" id="overlay_${idx}" tooltip_str="${name}" _press="::OverlayToggle ${name}">
<sprite width="38" height="38" color="~text_color" src_ext="${icon}" />
<sprite width="38" height="38" color="~color_text" src_ext="${icon}" />
</Button>
</template>
<template name="Set">
<Button macro="button_style" id="set_${idx}" _press="::SetToggle ${idx}" tooltip="WATCH.SWITCH_TO_SET" tooltip_side="top">
<sprite width="40" height="40" color="~text_color" src_builtin="watch/set2.svg" />
<sprite width="40" height="40" color="~color_text" src_builtin="watch/set2.svg" />
<div position="absolute" margin_top="9">
<label text="${display}" size="24" color="#00050F" weight="bold" />
</div>
@@ -77,10 +77,10 @@
<template name="Clock">
<div gap="12" flex_direction="column" padding="4">
<div flex_direction="column" >
<label text="11:22 PM" _source="clock" _display="time" color="~text_color" size="~clock0_size" weight="bold" align="center" />
<label text="11:22 PM" _source="clock" _display="time" color="~color_text" size="~clock0_size" weight="bold" align="center" />
<div padding_left="2" gap="16" flex_direction="row" justify_content="center">
<label text="Tue" _source="clock" _display="dow_short" color="~clock0_color" size="~clock0_dow_size" weight="bold" />
<label text="22/2/2022" _source="clock" _display="date" color="~clock0_color" size="~clock0_date_size" weight="bold" />
<label text="Tue" _source="clock" _display="dow_short" color="~color_text" size="~clock0_dow_size" weight="bold" />
<label text="22/2/2022" _source="clock" _display="date" color="~color_text" size="~clock0_date_size" weight="bold" />
</div>
</div>
<div flex_direction="row" gap="8" justify_content="space_around">
@@ -131,15 +131,15 @@
<sprite src_builtin="watch/keyboard.svg" width="40" height="40" />
</Button>
<Button id="btn_edit_mode" macro="button_style" _press="::EditToggle" tooltip="WATCH.EDIT_MODE" tooltip_side="left">
<sprite color="~text_color" width="40" height="40" src="watch/edit.svg" />
<sprite color="~color_text" width="40" height="40" src="watch/edit.svg" />
</Button>
</div>
<div gap="8">
<Button macro="button_style" _press="::PlayspaceRecenter" tooltip="WATCH.RECENTER" tooltip_side="left">
<sprite width="40" height="40" color="~text_color" src="watch/recenter.svg" />
<sprite width="40" height="40" color="~color_text" src="watch/recenter.svg" />
</Button>
<Button macro="button_style" _press="::PlayspaceFixFloor" tooltip="WATCH.FIX_FLOOR" tooltip_side="left">
<sprite width="40" height="40" color="~text_color" src="watch/fix-floor.svg" />
<sprite width="40" height="40" color="~color_text" src="watch/fix-floor.svg" />
</Button>
</div>
</div>
@@ -149,7 +149,7 @@
<div flex_direction="row" gap="8">
<div gap="4">
<Button id="btn_dashboard" macro="button_style" _press="::DashToggle" tooltip="WATCH.DASHBOARD" tooltip_side="top">
<sprite color="~text_color" width="40" height="40" src="watch/wayvr_dashboard_mono.svg" />
<sprite color="~color_text" width="40" height="40" src="watch/wayvr_dashboard_mono.svg" />
</Button>
</div>
<VerticalSeparator />
@@ -162,8 +162,8 @@
<div id="panels_root" gap="4" display="none">
<!-- Will populate tags at runtime -->
<!-- These are examples for uidev -->
<Screen idx="0" display="H1" />
<Screen idx="1" display="D2" />
<Screen idx="0" display="H1" name="HDMI-A-1" />
<Screen idx="1" display="D2" name="DP-2"/>
</div>
</div>
</div>

View File

@@ -30,6 +30,7 @@ use crate::{
task::{OverlayTask, PlayspaceTask, TaskType, ToggleMode},
wayvr::process::KillSignal,
},
gui::panel::{log_cmd_invalid_arg, log_cmd_missing_arg},
overlays::{custom::create_custom, toast::Toast, wayvr::WvrCommand},
state::AppState,
subsystem::hid::VirtualKey,
@@ -192,6 +193,8 @@ pub(super) fn setup_custom_button<S: 'static>(
on_custom_attribs: &parser::OnCustomAttribsFunc,
button: Rc<ComponentButton>,
) {
const TAG: &str = "Button";
for (name, kind, test_button, test_duration) in &BUTTON_EVENTS {
let Some(action) = attribs.get_value(name) else {
continue;
@@ -207,10 +210,7 @@ pub(super) fn setup_custom_button<S: 'static>(
let callback: EventCallback<AppState, S> = match command {
"::ContextMenuOpen" => {
let Some(template_name) = args.next() else {
log::error!(
"{:?}: {command} has invalid arguments",
parser_state.path.get_path_buf()
);
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
@@ -252,18 +252,13 @@ pub(super) fn setup_custom_button<S: 'static>(
}
"::ElementSetDisplay" => {
let (Some(id), Some(value)) = (args.next(), args.next()) else {
log::error!(
"{:?}: {command} has invalid arguments",
parser_state.path.get_path_buf()
);
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
let Ok(widget_id) = parser_state.data.get_widget_id(id) else {
log::warn!(
"{:?}: {command}: no element exists with ID '{id}'",
parser_state.path.get_path_buf()
);
let msg = format!("no element with ID \"{id}\"");
log_cmd_invalid_arg(parser_state, TAG, name, command, &msg);
return;
};
@@ -273,7 +268,8 @@ pub(super) fn setup_custom_button<S: 'static>(
"block" => taffy::Display::Block,
"grid" => taffy::Display::Grid,
_ => {
log::warn!("{command} has invalid display argument: '{value}'");
let msg = format!("unexpected \"{value}\"");
log_cmd_invalid_arg(parser_state, TAG, name, command, &msg);
return;
}
};
@@ -297,10 +293,8 @@ pub(super) fn setup_custom_button<S: 'static>(
"::SetToggle" => {
let arg = args.next().unwrap_or_default();
let Ok(set_idx) = arg.parse() else {
log::error!(
"{:?}: {command} has invalid argument: \"{arg}\"",
parser_state.path.get_path_buf()
);
let msg = format!("expected integer, found \"{arg}\"");
log_cmd_invalid_arg(parser_state, TAG, name, command, &msg);
return;
};
Box::new(move |_common, data, app, _| {
@@ -316,10 +310,8 @@ pub(super) fn setup_custom_button<S: 'static>(
"::SetSwitch" => {
let arg = args.next().unwrap_or_default();
let Ok(set_idx) = arg.parse::<i32>() else {
log::error!(
"{:?}: {command} has invalid argument: \"{arg}\"",
parser_state.path.get_path_buf()
);
let msg = format!("expected integer, found \"{arg}\"");
log_cmd_invalid_arg(parser_state, TAG, name, command, &msg);
return;
};
let maybe_set = if set_idx < 0 {
@@ -340,10 +332,7 @@ pub(super) fn setup_custom_button<S: 'static>(
"::OverlayReset" => {
let arg: Arc<str> = args.collect::<Vec<_>>().join(" ").into();
if arg.len() < 1 {
log::error!(
"{:?}: {command} has missing arguments",
parser_state.path.get_path_buf()
);
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
@@ -362,10 +351,7 @@ pub(super) fn setup_custom_button<S: 'static>(
"::OverlayToggle" => {
let arg: Arc<str> = args.collect::<Vec<_>>().join(" ").into();
if arg.len() < 1 {
log::error!(
"{:?}: {command} has missing arguments",
parser_state.path.get_path_buf()
);
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
@@ -385,10 +371,7 @@ pub(super) fn setup_custom_button<S: 'static>(
"::OverlayDrop" => {
let arg: Arc<str> = args.collect::<Vec<_>>().join(" ").into();
if arg.len() < 1 {
log::error!(
"{:?}: {command} has missing arguments",
parser_state.path.get_path_buf()
);
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
@@ -424,10 +407,7 @@ pub(super) fn setup_custom_button<S: 'static>(
"::CustomOverlayReload" => {
let arg: Arc<str> = args.collect::<Vec<_>>().join(" ").into();
if arg.len() < 1 {
log::error!(
"{:?}: {command} has missing arguments",
parser_state.path.get_path_buf()
);
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
@@ -465,10 +445,7 @@ pub(super) fn setup_custom_button<S: 'static>(
"::WvrOverlayCloseWindow" => {
let arg: Arc<str> = args.collect::<Vec<_>>().join(" ").into();
if arg.len() < 1 {
log::error!(
"{:?}: {command} has missing arguments",
parser_state.path.get_path_buf()
);
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
Box::new(move |_common, data, app, _| {
@@ -491,10 +468,7 @@ pub(super) fn setup_custom_button<S: 'static>(
"::WvrOverlayKillProcess" | "::WvrOverlayTermProcess" => {
let arg: Arc<str> = args.collect::<Vec<_>>().join(" ").into();
if arg.len() < 1 {
log::error!(
"{:?}: {command} has missing arguments",
parser_state.path.get_path_buf()
);
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
@@ -615,24 +589,28 @@ pub(super) fn setup_custom_button<S: 'static>(
Ok(EventResult::Consumed)
}),
"::SendKey" => {
let Some(key) = args.next().and_then(|s| VirtualKey::from_str(s).ok()) else {
log::error!(
"{:?}: {command} has bad/missing arguments",
parser_state.path.get_path_buf()
);
let Some(arg) = args.next() else {
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
let Some(down) = args.next().and_then(|s| match s.to_lowercase().as_str() {
"down" => Some(true),
"up" => Some(false),
_ => None,
}) else {
log::error!(
"{:?}: {command} has bad/missing arguments",
parser_state.path.get_path_buf()
);
let Ok(key) = VirtualKey::from_str(arg) else {
let msg = format!("expected VirtualKey, found \"{arg}\"");
log_cmd_invalid_arg(parser_state, TAG, name, command, &msg);
return;
};
let Some(arg) = args.next() else {
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
let down = match arg.to_lowercase().as_str() {
"down" => true,
"up" => false,
_ => {
let msg = format!("expected \"down\" or \"up\", found \"{arg}\"");
log_cmd_invalid_arg(parser_state, TAG, name, command, &msg);
return;
}
};
Box::new(move |_common, data, app, _| {
if !test_button(data) || !test_duration(&button, app) {
return Ok(EventResult::Pass);
@@ -677,18 +655,17 @@ pub(super) fn setup_custom_button<S: 'static>(
use crate::subsystem::osc::parse_osc_value;
let Some(address) = args.next().map(std::string::ToString::to_string) else {
log::error!(
"{:?}: {command} has bad/missing arguments",
parser_state.path.get_path_buf()
);
log_cmd_missing_arg(parser_state, TAG, name, command);
return;
};
let mut osc_args = vec![];
for arg in args {
let Ok(osc_arg) = parse_osc_value(arg)
.inspect_err(|e| log::error!("Could not parse OSC value '{arg}': {e:?}"))
.inspect_err(|e| log::warn!("Could not parse OSC value '{arg}': {e:?}"))
else {
let msg = format!("expected OscValue, found \"{arg}\"");
log_cmd_invalid_arg(parser_state, TAG, name, command, &msg);
return;
};
osc_args.push(osc_arg);

View File

@@ -46,8 +46,6 @@ impl DeviceList {
let template = device.role.as_ref();
log::warn!("creating {template} tag for {i}");
params.insert("idx".into(), i.to_string().into());
parser_state.instantiate_template(
&doc_params,

View File

@@ -7,30 +7,38 @@ use wgui::{
event::{self, EventCallback},
i18n::Translation,
layout::Layout,
parser::{CustomAttribsInfoOwned, parse_color_hex},
parser::{CustomAttribsInfoOwned, ParserState, parse_color_hex},
widget::{EventResult, label::WidgetLabel},
};
use crate::state::AppState;
use crate::{
gui::panel::{log_invalid_attrib, log_missing_attrib},
state::AppState,
};
#[allow(clippy::too_many_lines)]
pub(super) fn setup_custom_label<S: 'static>(
layout: &mut Layout,
parser_state: &ParserState,
attribs: &CustomAttribsInfoOwned,
app: &AppState,
) {
const TAG: &str = "label";
let Some(source) = attribs.get_value("_source") else {
log::warn!("custom label with no source!");
log_missing_attrib(parser_state, TAG, "_source");
return;
};
let callback: EventCallback<AppState, S> = match source {
"battery" => {
let Some(device) = attribs
.get_value("_device")
.and_then(|s| s.parse::<usize>().ok())
else {
log::warn!("label with battery source but no device attribute!");
let Some(device) = attribs.get_value("_device") else {
log_missing_attrib(parser_state, TAG, "_device");
return;
};
let Ok(device) = device.parse::<usize>() else {
let msg = format!("expected integer, found \"{device}\"");
log_invalid_attrib(parser_state, TAG, "_device", &msg);
return;
};
@@ -60,19 +68,33 @@ pub(super) fn setup_custom_label<S: 'static>(
}
"clock" => {
let Some(display) = attribs.get_value("_display") else {
log::warn!("label with clock source but no display attribute!");
log_missing_attrib(parser_state, TAG, "_display");
return;
};
let tz_str = attribs
.get_value("_timezone")
.and_then(|tz| {
tz.parse::<usize>()
.inspect_err(|_| {
let msg = format!("expected integer, found \"{tz}\"");
log_invalid_attrib(parser_state, TAG, "_timezone", &msg);
})
.ok()
})
.and_then(|tz_idx| {
app.session.config.timezones.get(tz_idx).or_else(|| {
let msg = format!("timezone index \"{tz_idx}\" is out of range");
log_invalid_attrib(parser_state, TAG, "_timezone", &msg);
None
})
});
let format = match display {
"name" => {
let maybe_pretty_tz = attribs
.get_value("_timezone")
.and_then(|tz| tz.parse::<usize>().ok())
.and_then(|tz_idx| app.session.config.timezones.get(tz_idx))
.and_then(|tz_name| {
tz_name.split('/').next_back().map(|x| x.replace('_', " "))
});
let maybe_pretty_tz = tz_str.and_then(|tz_name| {
tz_name.split('/').next_back().map(|x| x.replace('_', " "))
});
let pretty_tz = maybe_pretty_tz.as_ref().map_or("Local", |x| x.as_str());
@@ -102,11 +124,6 @@ pub(super) fn setup_custom_label<S: 'static>(
}
};
let tz_str = attribs
.get_value("_timezone")
.and_then(|tz| tz.parse::<usize>().ok())
.and_then(|tz_idx| app.session.config.timezones.get(tz_idx));
let state = ClockLabelState {
timezone: tz_str.and_then(|tz| {
tz.parse()
@@ -126,7 +143,7 @@ pub(super) fn setup_custom_label<S: 'static>(
Ok(EventResult::Pass)
}),
unk => {
log::warn!("Unknown source value for label: {unk}");
log_invalid_attrib(parser_state, TAG, "_source", unk);
return;
}
};

View File

@@ -1,4 +1,4 @@
use std::{any, cell::RefCell, rc::Rc};
use std::{cell::RefCell, rc::Rc};
use button::setup_custom_button;
use glam::{Affine2, Vec2, vec2};
@@ -192,7 +192,7 @@ impl<S: 'static> GuiPanel<S> {
.get_as::<WidgetLabel>(elem.widget_id)
.is_some()
{
setup_custom_label::<S>(&mut self.layout, elem, app);
setup_custom_label::<S>(&mut self.layout, &self.parser_state, elem, app);
} else if let Ok(button) = self
.parser_state
.fetch_component_from_widget_id_as::<ComponentButton>(elem.widget_id)
@@ -440,3 +440,37 @@ impl<S: 'static> OverlayBackend for GuiPanel<S> {
false
}
}
fn log_missing_attrib(parser_state: &ParserState, tag_name: &str, attrib: &str) {
log::warn!(
"{:?}: <{tag_name}> is missing \"{attrib}\"",
parser_state.path.get_path_buf()
)
}
fn log_invalid_attrib(parser_state: &ParserState, tag_name: &str, attrib: &str, value: &str) {
log::warn!(
"{:?}: <{tag_name}> value for \"{attrib}\" is invalid: {value}",
parser_state.path.get_path_buf()
)
}
fn log_cmd_missing_arg(parser_state: &ParserState, tag_name: &str, attrib: &str, command: &str) {
log::warn!(
"{:?}: <{tag_name}> \"{attrib}\": \"{command}\" has missing arguments",
parser_state.path.get_path_buf()
)
}
fn log_cmd_invalid_arg(
parser_state: &ParserState,
tag_name: &str,
attrib: &str,
command: &str,
arg: &str,
) {
log::warn!(
"{:?}: <{tag_name}> \"{attrib}\": \"{command}\" has invalid argument: {arg}",
parser_state.path.get_path_buf()
)
}

View File

@@ -283,6 +283,7 @@ fn logging_init(args: &mut Args) {
.from_env_lossy()
.add_directive("symphonia_core::probe=warn".parse().unwrap())
.add_directive("zbus=warn".parse().unwrap())
.add_directive("usvg=error".parse().unwrap())
.add_directive("cosmic_text=warn".parse().unwrap())
.add_directive("wlx_capture::wayland=info".parse().unwrap())
.add_directive("smithay=debug".parse().unwrap()), /* GLES render spam */