Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 1 addition & 3 deletions accessibility/src/a11y_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ impl A11yTree {

/// Helper for creating an A11y tree with a single root node and some children
pub fn node_with_child_tree(mut root: A11yNode, child_tree: Self) -> Self {
root.add_children(
child_tree.root.iter().map(|n| n.id()).cloned().collect(),
);
root.add_children(child_tree.root.iter().map(|n| n.id()).cloned().collect());
Self {
root: vec![root],
children: child_tree
Expand Down
20 changes: 7 additions & 13 deletions accessibility/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ impl From<Id> for A11yId {
impl IdEq for A11yId {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(A11yId::Widget(self_), A11yId::Widget(other)) => {
IdEq::eq(self_, other)
}
(A11yId::Widget(self_), A11yId::Widget(other)) => IdEq::eq(self_, other),
_ => self == other,
}
}
Expand Down Expand Up @@ -150,8 +148,7 @@ impl std::fmt::Display for Id {
// XXX WIndow IDs are made unique by adding u32::MAX to them
/// get window node id that won't conflict with other node ids for the duration of the program
pub fn window_node_id() -> u64 {
u32::MAX as u64
+ NEXT_WINDOW_ID.fetch_add(1, atomic::Ordering::Relaxed) as u64
u32::MAX as u64 + NEXT_WINDOW_ID.fetch_add(1, atomic::Ordering::Relaxed) as u64
}

// TODO refactor to make panic impossible?
Expand Down Expand Up @@ -189,17 +186,14 @@ impl IdEq for Internal {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Unique(l0), Self::Unique(r0)) => l0 == r0,
(Self::Custom(l0, l1), Self::Custom(r0, r1)) => {
l0 == r0 || l1 == r1
}
(Self::Custom(l0, l1), Self::Custom(r0, r1)) => l0 == r0 || l1 == r1,
// allow custom ids to be equal to unique ids
(Self::Unique(l0), Self::Custom(r0, _))
| (Self::Custom(l0, _), Self::Unique(r0)) => l0 == r0,
(Self::Unique(l0), Self::Custom(r0, _)) | (Self::Custom(l0, _), Self::Unique(r0)) => {
l0 == r0
}
(Self::Set(l0), Self::Set(r0)) => l0 == r0,
// allow set ids to just be equal to any of their members
(Self::Set(l0), r) | (r, Self::Set(l0)) => {
l0.iter().any(|l| l == r)
}
(Self::Set(l0), r) | (r, Self::Set(l0)) => l0.iter().any(|l| l == r),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions accessibility/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ impl A11yNode {
}

pub fn add_children(&mut self, children: Vec<A11yId>) {
let mut children =
children.into_iter().map(|id| id.into()).collect::<Vec<_>>();
let mut children = children.into_iter().map(|id| id.into()).collect::<Vec<_>>();
children.extend_from_slice(self.node.children());
self.node.set_children(children);
}
Expand Down
26 changes: 7 additions & 19 deletions beacon/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ async fn run(
is_connected: Arc<AtomicBool>,
mut receiver: mpsc::Receiver<Action>,
) {
let version = semver::Version::parse(env!("CARGO_PKG_VERSION"))
.expect("Parse package version");
let version = semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Parse package version");

let command_sender = {
// Discard by default
Expand Down Expand Up @@ -158,8 +157,7 @@ async fn run(
match receive(&mut reader, &mut buffer).await {
Ok(command) => {
match command {
Command::RewindTo { .. }
| Command::GoLive
Command::RewindTo { .. } | Command::GoLive
if !metadata.can_time_travel =>
{
continue;
Expand Down Expand Up @@ -191,17 +189,11 @@ async fn run(
match send(&mut writer, message).await {
Ok(()) => {}
Err(error) => {
if error.kind() != io::ErrorKind::BrokenPipe
{
log::warn!(
"Error sending message to server: {error}"
);
if error.kind() != io::ErrorKind::BrokenPipe {
log::warn!("Error sending message to server: {error}");
}

is_connected.store(
false,
atomic::Ordering::Relaxed,
);
is_connected.store(false, atomic::Ordering::Relaxed);
break;
}
}
Expand Down Expand Up @@ -229,8 +221,7 @@ async fn run(
pub fn server_address_from_env() -> String {
const DEFAULT_ADDRESS: &str = "127.0.0.1:9167";

std::env::var("ICED_BEACON_SERVER_ADDRESS")
.unwrap_or_else(|_| String::from(DEFAULT_ADDRESS))
std::env::var("ICED_BEACON_SERVER_ADDRESS").unwrap_or_else(|_| String::from(DEFAULT_ADDRESS))
}

async fn _connect() -> Result<net::TcpStream, io::Error> {
Expand All @@ -243,10 +234,7 @@ async fn _connect() -> Result<net::TcpStream, io::Error> {
Ok(stream)
}

async fn send(
stream: &mut net::tcp::OwnedWriteHalf,
message: Message,
) -> Result<(), io::Error> {
async fn send(stream: &mut net::tcp::OwnedWriteHalf, message: Message) -> Result<(), io::Error> {
let bytes = bincode::serialize(&message).expect("Encode input message");
let size = bytes.len() as u64;

Expand Down
215 changes: 84 additions & 131 deletions beacon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ pub struct Connection {
}

impl Connection {
pub fn rewind_to<'a>(
&self,
message: usize,
) -> impl Future<Output = ()> + 'a {
pub fn rewind_to<'a>(&self, message: usize) -> impl Future<Output = ()> + 'a {
let commands = self.commands.clone();

async move {
Expand Down Expand Up @@ -99,9 +96,7 @@ pub fn run() -> impl Stream<Item = Event> {
let mut buffer = Vec::new();

let server = loop {
match net::TcpListener::bind(client::server_address_from_env())
.await
{
match net::TcpListener::bind(client::server_address_from_env()).await {
Ok(server) => break server,
Err(error) => {
if error.kind() == io::ErrorKind::AddrInUse {
Expand Down Expand Up @@ -152,10 +147,9 @@ pub fn run() -> impl Stream<Item = Event> {
}
}

let _ =
send(&mut writer, command).await.inspect_err(|error| {
log::error!("Error when sending command: {error}")
});
let _ = send(&mut writer, command)
.await
.inspect_err(|error| log::error!("Error when sending command: {error}"));
}
}));

Expand Down Expand Up @@ -183,129 +177,88 @@ pub fn run() -> impl Stream<Item = Event> {
})
.await;
}
client::Message::EventLogged { at, event } => {
match event {
client::Event::ThemeChanged(palette) => {
let _ = output
.send(Event::ThemeChanged {
at,
palette,
})
.await;
}
client::Event::SubscriptionsTracked(
amount_alive,
) => {
last_subscriptions = amount_alive;
}
client::Event::MessageLogged {
number,
message,
} => {
last_update_number = number;
last_message = message;
}
client::Event::CommandsSpawned(
commands,
) => {
last_tasks = commands;
}
client::Event::LayersRendered(layers) => {
last_present_layers = layers;
}
client::Event::SpanStarted(
span::Stage::Update,
) => {
last_message.clear();
last_tasks = 0;
}
client::Event::SpanStarted(_) => {}
client::Event::SpanFinished(
stage,
duration,
) => {
let span = match stage {
span::Stage::Boot => Span::Boot,
span::Stage::Update => {
Span::Update {
number: last_update_number,
message: last_message
.clone(),
tasks: last_tasks,
subscriptions:
last_subscriptions,
client::Message::EventLogged { at, event } => match event {
client::Event::ThemeChanged(palette) => {
let _ = output.send(Event::ThemeChanged { at, palette }).await;
}
client::Event::SubscriptionsTracked(amount_alive) => {
last_subscriptions = amount_alive;
}
client::Event::MessageLogged { number, message } => {
last_update_number = number;
last_message = message;
}
client::Event::CommandsSpawned(commands) => {
last_tasks = commands;
}
client::Event::LayersRendered(layers) => {
last_present_layers = layers;
}
client::Event::SpanStarted(span::Stage::Update) => {
last_message.clear();
last_tasks = 0;
}
client::Event::SpanStarted(_) => {}
client::Event::SpanFinished(stage, duration) => {
let span = match stage {
span::Stage::Boot => Span::Boot,
span::Stage::Update => Span::Update {
number: last_update_number,
message: last_message.clone(),
tasks: last_tasks,
subscriptions: last_subscriptions,
},
span::Stage::View(window) => Span::View { window },
span::Stage::Layout(window) => Span::Layout { window },
span::Stage::Interact(window) => Span::Interact { window },
span::Stage::Draw(window) => Span::Draw { window },
span::Stage::Prepare(primitive)
| span::Stage::Render(primitive) => {
let stage = if matches!(stage, span::Stage::Prepare(_),)
{
&mut last_prepare
} else {
&mut last_render
};

let primitive = match primitive {
present::Primitive::Quad => &mut stage.quads,
present::Primitive::Triangle => {
&mut stage.triangles
}
}
span::Stage::View(window) => {
Span::View { window }
}
span::Stage::Layout(window) => {
Span::Layout { window }
}
span::Stage::Interact(window) => {
Span::Interact { window }
}
span::Stage::Draw(window) => {
Span::Draw { window }
}
span::Stage::Prepare(primitive)
| span::Stage::Render(primitive) => {
let stage = if matches!(
stage,
span::Stage::Prepare(_),
) {
&mut last_prepare
} else {
&mut last_render
};

let primitive = match primitive {
present::Primitive::Quad => &mut stage.quads,
present::Primitive::Triangle => &mut stage.triangles,
present::Primitive::Shader => &mut stage.shaders,
present::Primitive::Text => &mut stage.text,
present::Primitive::Image => &mut stage.images,
};

*primitive += duration;

continue;
}
span::Stage::Present(window) => {
let span = Span::Present {
window,
prepare: last_prepare,
render: last_render,
layers: last_present_layers,
};

last_prepare =
present::Stage::default();
last_render =
present::Stage::default();
last_present_layers = 0;

span
}
span::Stage::Custom(name) => {
Span::Custom { name }
}
};

let _ = output
.send(Event::SpanFinished {
at,
duration,
span,
})
.await;
}
present::Primitive::Shader => &mut stage.shaders,
present::Primitive::Text => &mut stage.text,
present::Primitive::Image => &mut stage.images,
};

*primitive += duration;

continue;
}
span::Stage::Present(window) => {
let span = Span::Present {
window,
prepare: last_prepare,
render: last_render,
layers: last_present_layers,
};

last_prepare = present::Stage::default();
last_render = present::Stage::default();
last_present_layers = 0;

span
}
span::Stage::Custom(name) => Span::Custom { name },
};

let _ = output
.send(Event::SpanFinished { at, duration, span })
.await;
}
}
},
client::Message::Quit { at } => {
let _ = output
.send(Event::QuitRequested { at })
.await;
let _ = output.send(Event::QuitRequested { at }).await;
}
};
}
Expand Down
Loading