Skip to content

Commit

Permalink
use route_id as topic id
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Oct 16, 2024
1 parent 97f7a3c commit c658393
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
39 changes: 23 additions & 16 deletions frontends/rioterm/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl ApplicationHandler<EventPayload> 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,
Expand Down Expand Up @@ -265,7 +265,7 @@ impl ApplicationHandler<EventPayload> 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();
Expand All @@ -289,21 +289,26 @@ impl ApplicationHandler<EventPayload> 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,
Expand All @@ -319,7 +324,7 @@ impl ApplicationHandler<EventPayload> 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,
Expand Down Expand Up @@ -938,8 +943,10 @@ impl ApplicationHandler<EventPayload> 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;
}
Expand Down
13 changes: 4 additions & 9 deletions frontends/rioterm/src/context/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ impl<T: rio_backend::event::EventListener> ContextGrid<T> {
}

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 {
Expand All @@ -316,15 +317,9 @@ impl<T: rio_backend::event::EventListener> ContextGrid<T> {
// 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<T>) {
Expand Down
14 changes: 7 additions & 7 deletions frontends/rioterm/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub struct Context<T: EventListener> {

impl<T: rio_backend::event::EventListener> Drop for Context<T> {
fn drop(&mut self) {
println!("drop {:?}", self.shell_pid);
#[cfg(not(target_os = "windows"))]
teletypewriter::kill_pid(self.shell_pid as i32);
}
Expand Down Expand Up @@ -690,19 +689,14 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
#[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]
pub fn current_grid_mut(&mut self) -> &mut ContextGrid<T> {
&mut self.contexts[self.current_index]
}

#[inline]
#[allow(unused)]
pub fn current_grid(&mut self) -> &ContextGrid<T> {
&self.contexts[self.current_index]
}

#[cfg(test)]
pub fn increase_capacity(&mut self, inc_val: usize) {
self.capacity += inc_val;
Expand Down Expand Up @@ -828,6 +822,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
cloned_config.working_dir = working_dir;
}

self.acc_current_route += 1;
let current = self.current();
let cursor = current.cursor_from_ref();

Expand All @@ -846,6 +841,8 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
} 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");
Expand Down Expand Up @@ -881,6 +878,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
split_color: config.colors.split,
};

self.acc_current_route += 1;
let current = self.current();
let cursor = current.cursor_from_ref();

Expand All @@ -899,6 +897,8 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
} 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");
Expand Down
7 changes: 3 additions & 4 deletions frontends/rioterm/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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 }
}
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit c658393

Please sign in to comment.