diff --git a/frontends/rioterm/src/application.rs b/frontends/rioterm/src/application.rs index 68db910ac..67ce955f0 100644 --- a/frontends/rioterm/src/application.rs +++ b/frontends/rioterm/src/application.rs @@ -161,7 +161,7 @@ impl ApplicationHandler for Application<'_> { } if route_id == route.window.screen.ctx().current_route() { - let timer_id = TimerId::new(Topic::RenderRoute, window_id); + let timer_id = TimerId::new(Topic::RenderRoute, route_id); let event = EventPayload::new( RioEventType::Rio(RioEvent::Render), window_id, @@ -265,7 +265,7 @@ impl ApplicationHandler for Application<'_> { self.router.routes.remove(&window_id); // Unschedule pending events. - self.scheduler.unschedule_window(window_id); + self.scheduler.unschedule_window(route_id); if self.router.routes.is_empty() { event_loop.exit(); @@ -289,21 +289,26 @@ impl ApplicationHandler for Application<'_> { } } RioEventType::Rio(RioEvent::PrepareRender(millis)) => { - let timer_id = TimerId::new(Topic::Render, window_id); - let event = - EventPayload::new(RioEventType::Rio(RioEvent::Render), window_id); - - if !self.scheduler.scheduled(timer_id) { - self.scheduler.schedule( - event, - Duration::from_millis(millis), - false, - timer_id, + if let Some(route) = self.router.routes.get(&window_id) { + let timer_id = TimerId::new( + Topic::Render, + route.window.screen.ctx().current_route(), ); + let event = + EventPayload::new(RioEventType::Rio(RioEvent::Render), window_id); + + if !self.scheduler.scheduled(timer_id) { + self.scheduler.schedule( + event, + Duration::from_millis(millis), + false, + timer_id, + ); + } } } RioEventType::Rio(RioEvent::PrepareRenderOnRoute(millis, route_id)) => { - let timer_id = TimerId::new(Topic::RenderRoute, window_id); + let timer_id = TimerId::new(Topic::RenderRoute, route_id); let event = EventPayload::new( RioEventType::Rio(RioEvent::RenderRoute(route_id)), window_id, @@ -319,7 +324,7 @@ impl ApplicationHandler for Application<'_> { } } RioEventType::Rio(RioEvent::BlinkCursor(millis, route_id)) => { - let timer_id = TimerId::new(Topic::CursorBlinking, window_id); + let timer_id = TimerId::new(Topic::CursorBlinking, route_id); let event = EventPayload::new( RioEventType::Rio(RioEvent::CursorBlinkingChangeOnRoute(route_id)), window_id, @@ -938,8 +943,10 @@ impl ApplicationHandler for Application<'_> { && key_event.state == ElementState::Released { // Scheduler must be cleaned after leave the terminal route - self.scheduler - .unschedule(TimerId::new(Topic::Render, window_id)); + self.scheduler.unschedule(TimerId::new( + Topic::Render, + route.window.screen.ctx().current_route(), + )); } return; } diff --git a/frontends/rioterm/src/context/grid.rs b/frontends/rioterm/src/context/grid.rs index 5c86d16a8..a8927b54e 100644 --- a/frontends/rioterm/src/context/grid.rs +++ b/frontends/rioterm/src/context/grid.rs @@ -301,7 +301,8 @@ impl ContextGrid { } pub fn remove_current(&mut self) { - let _current = &self.inner[self.current]; + // TODO: Adjust width and height of pointing contexts + // TODO: Adjust right and down of pointing contexts // let mut index = 0; // for context in &self.inner { @@ -316,15 +317,9 @@ impl ContextGrid { // index += 1; // } - println!("{:?}", self.inner[self.current].val.shell_pid); - let old = self.current; - // self.select_prev_split(); - println!("{:?}", self.inner[self.current].val.shell_pid); - println!("{:?} {:?}", self.current, old); - let size = self.inner.len(); - self.inner.swap(old, size - 1); - // self.inner.pop(); + self.select_prev_split(); + self.inner.remove(old); } pub fn split_right(&mut self, context: Context) { diff --git a/frontends/rioterm/src/context/mod.rs b/frontends/rioterm/src/context/mod.rs index bacec62f4..7c4317662 100644 --- a/frontends/rioterm/src/context/mod.rs +++ b/frontends/rioterm/src/context/mod.rs @@ -48,7 +48,6 @@ pub struct Context { impl Drop for Context { fn drop(&mut self) { - println!("drop {:?}", self.shell_pid); #[cfg(not(target_os = "windows"))] teletypewriter::kill_pid(self.shell_pid as i32); } @@ -690,6 +689,7 @@ impl ContextManager { #[inline] pub fn remove_current_grid(&mut self) { self.contexts[self.current_index].remove_current(); + self.current_route = self.contexts[self.current_index].current().route_id; } #[inline] @@ -697,12 +697,6 @@ impl ContextManager { &mut self.contexts[self.current_index] } - #[inline] - #[allow(unused)] - pub fn current_grid(&mut self) -> &ContextGrid { - &self.contexts[self.current_index] - } - #[cfg(test)] pub fn increase_capacity(&mut self, inc_val: usize) { self.capacity += inc_val; @@ -828,6 +822,7 @@ impl ContextManager { cloned_config.working_dir = working_dir; } + self.acc_current_route += 1; let current = self.current(); let cursor = current.cursor_from_ref(); @@ -846,6 +841,8 @@ impl ContextManager { } else { self.contexts[self.current_index].split_right(new_context); } + + self.current_route = self.acc_current_route; } Err(..) => { tracing::error!("not able to create a new context"); @@ -881,6 +878,7 @@ impl ContextManager { split_color: config.colors.split, }; + self.acc_current_route += 1; let current = self.current(); let cursor = current.cursor_from_ref(); @@ -899,6 +897,8 @@ impl ContextManager { } else { self.contexts[self.current_index].split_right(new_context); } + + self.current_route = self.acc_current_route; } Err(..) => { tracing::error!("not able to create a new context"); diff --git a/frontends/rioterm/src/scheduler.rs b/frontends/rioterm/src/scheduler.rs index 76de06962..530c14419 100644 --- a/frontends/rioterm/src/scheduler.rs +++ b/frontends/rioterm/src/scheduler.rs @@ -2,7 +2,6 @@ // which is licensed under Apache 2.0 license. use crate::event::EventPayload; -use rio_backend::event::WindowId; use std::collections::VecDeque; use std::time::{Duration, Instant}; @@ -12,11 +11,11 @@ use rio_window::event_loop::EventLoopProxy; #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct TimerId { topic: Topic, - id: WindowId, + id: usize, } impl TimerId { - pub fn new(topic: Topic, id: WindowId) -> Self { + pub fn new(topic: Topic, id: usize) -> Self { Self { topic, id } } } @@ -119,7 +118,7 @@ impl Scheduler { /// /// This must be called when a tab is removed to ensure that timers on intervals do not /// stick around forever and cause a memory leak. - pub fn unschedule_window(&mut self, id: WindowId) { + pub fn unschedule_window(&mut self, id: usize) { self.timers.retain(|timer| timer.id.id != id); } }