fix: fixes for shell/Terminal issues and CPU burn
This commit is contained in:
@@ -45,6 +45,9 @@ static bool g_should_exit = false;
|
||||
static bool g_force_redraw = true;
|
||||
static int g_last_win_w = 0;
|
||||
static int g_last_win_h = 0;
|
||||
static Montauk::ProcInfo g_kill_procs[256];
|
||||
static int g_kill_pids[256];
|
||||
static int g_kill_pid_count = 0;
|
||||
|
||||
static bool left_pressed(const Montauk::WinEvent& ev) {
|
||||
return (ev.mouse.buttons & 1) && !(ev.mouse.prev_buttons & 1);
|
||||
@@ -54,9 +57,40 @@ static void term_request_redraw() {
|
||||
g_force_redraw = true;
|
||||
}
|
||||
|
||||
static bool term_proc_alive(uint8_t state) {
|
||||
return state == 1 || state == 2 || state == 3;
|
||||
}
|
||||
|
||||
static void term_collect_child_pids(int parent_pid, int proc_count) {
|
||||
for (int i = 0; i < proc_count; i++) {
|
||||
if (!term_proc_alive(g_kill_procs[i].state)) continue;
|
||||
if (g_kill_procs[i].parentPid != parent_pid) continue;
|
||||
|
||||
int child_pid = g_kill_procs[i].pid;
|
||||
term_collect_child_pids(child_pid, proc_count);
|
||||
if (g_kill_pid_count < (int)(sizeof(g_kill_pids) / sizeof(g_kill_pids[0])))
|
||||
g_kill_pids[g_kill_pid_count++] = child_pid;
|
||||
}
|
||||
}
|
||||
|
||||
static void term_kill_process_tree(int root_pid) {
|
||||
if (root_pid <= 0) return;
|
||||
|
||||
g_kill_pid_count = 0;
|
||||
int proc_count = montauk::proclist(g_kill_procs,
|
||||
(int)(sizeof(g_kill_procs) / sizeof(g_kill_procs[0])));
|
||||
if (proc_count > 0)
|
||||
term_collect_child_pids(root_pid, proc_count);
|
||||
|
||||
for (int i = 0; i < g_kill_pid_count; i++)
|
||||
montauk::kill(g_kill_pids[i]);
|
||||
|
||||
montauk::kill(root_pid);
|
||||
}
|
||||
|
||||
static void term_free_tab(TerminalState* ts) {
|
||||
if (!ts) return;
|
||||
if (ts->child_pid > 0) montauk::kill(ts->child_pid);
|
||||
if (ts->child_pid > 0) term_kill_process_tree(ts->child_pid);
|
||||
if (ts->cells) montauk::free(ts->cells);
|
||||
if (ts->alt_cells) montauk::free(ts->alt_cells);
|
||||
montauk::mfree(ts);
|
||||
@@ -367,9 +401,7 @@ extern "C" void _start() {
|
||||
g_win.present();
|
||||
|
||||
while (!g_should_exit) {
|
||||
bool redraw = term_poll_tabs();
|
||||
if (g_should_exit) break;
|
||||
|
||||
bool redraw = false;
|
||||
Montauk::WinEvent ev;
|
||||
bool quit = false;
|
||||
int r = 0;
|
||||
@@ -400,6 +432,9 @@ extern "C" void _start() {
|
||||
|
||||
if (r < 0 || quit) break;
|
||||
|
||||
redraw |= term_poll_tabs();
|
||||
if (g_should_exit) break;
|
||||
|
||||
if (redraw && term_render())
|
||||
g_win.present();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user