commit 9e5048d4f2c1f98f0c0a91892a82c66cad115042
parent 2bef02106aa7657a7b4bc41fce44e9ad403065be
Author: William Casarin <jb55@jb55.com>
Date: Fri, 24 May 2024 13:42:57 -0700
input: fix deadlock on resize
weird egui Context quirk
Fixes: https://github.com/damus-io/notedeck/issues/97
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/app.rs b/src/app.rs
@@ -106,9 +106,21 @@ fn send_initial_filters(damus: &mut Damus, relay_url: &str) {
}
}
-fn handle_key_events(input: &egui::InputState, damus: &mut Damus, ctx: &egui::Context) {
+enum ContextAction {
+ SetPixelsPerPoint(f32),
+}
+
+fn handle_key_events(
+ input: &egui::InputState,
+ pixels_per_point: f32,
+ damus: &mut Damus,
+) -> Option<ContextAction> {
let amount = 0.2;
+ // We can't do things like setting the pixels_per_point when we are holding
+ // on to an locked InputState context, so we need to pass actions externally
+ let mut context_action: Option<ContextAction> = None;
+
for event in &input.raw.events {
if let egui::Event::Key {
key, pressed: true, ..
@@ -116,10 +128,12 @@ fn handle_key_events(input: &egui::InputState, damus: &mut Damus, ctx: &egui::Co
{
match key {
egui::Key::Equals => {
- ctx.set_pixels_per_point(ctx.pixels_per_point() + amount);
+ context_action =
+ Some(ContextAction::SetPixelsPerPoint(pixels_per_point + amount));
}
egui::Key::Minus => {
- ctx.set_pixels_per_point(ctx.pixels_per_point() - amount);
+ context_action =
+ Some(ContextAction::SetPixelsPerPoint(pixels_per_point - amount));
}
egui::Key::J => {
damus.select_down();
@@ -137,10 +151,20 @@ fn handle_key_events(input: &egui::InputState, damus: &mut Damus, ctx: &egui::Co
}
}
}
+
+ context_action
}
fn try_process_event(damus: &mut Damus, ctx: &egui::Context) -> Result<()> {
- ctx.input(|i| handle_key_events(i, damus, ctx));
+ let ppp = ctx.pixels_per_point();
+ let res = ctx.input(|i| handle_key_events(i, ppp, damus));
+ if let Some(action) = res {
+ match action {
+ ContextAction::SetPixelsPerPoint(amt) => {
+ ctx.set_pixels_per_point(amt);
+ }
+ }
+ }
let ctx2 = ctx.clone();
let wakeup = move || {