From f0a0577526673ad3f1032a12685af44c591b28de Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 6 Aug 2015 16:55:32 +0200 Subject: [PATCH] Now destroys running applications when juci exits. --- src/terminal.cc | 7 +++++++ src/terminal.h | 1 + src/window.cc | 9 +++------ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/terminal.cc b/src/terminal.cc index d558706..86e77ae 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -203,6 +203,13 @@ void Terminal::async_execute(const std::string &command, const std::string &path async_execute_thread.detach(); } +void Terminal::kill_executing() { + async_pid_mutex.lock(); + for(auto &pid: async_pid_descriptors) + kill(pid.first, SIGTERM); + async_pid_mutex.unlock(); +} + int Terminal::print(const std::string &message){ INFO("Terminal: PrintMessage"); text_view.get_buffer()->insert(text_view.get_buffer()->end(), message); diff --git a/src/terminal.h b/src/terminal.h index c7d477f..24c57a7 100644 --- a/src/terminal.h +++ b/src/terminal.h @@ -31,6 +31,7 @@ public: std::unordered_map > async_pid_descriptors; std::unordered_map async_pid_status; std::mutex async_pid_mutex; + void kill_executing(); int print(const std::string &message); void print(int line_nr, const std::string &message); diff --git a/src/window.cc b/src/window.cc index e297239..bba0803 100644 --- a/src/window.cc +++ b/src/window.cc @@ -258,12 +258,8 @@ void Window::create_menu() { bool Window::on_key_press_event(GdkEventKey *event) { if(event->keyval==GDK_KEY_Escape) { - if(entry_box.entries.size()==0) { - Singleton::terminal()->async_pid_mutex.lock(); - for(auto &pid: Singleton::terminal()->async_pid_descriptors) - kill(pid.first, SIGTERM); - Singleton::terminal()->async_pid_mutex.unlock(); - } + if(entry_box.entries.size()==0) + Singleton::terminal()->kill_executing(); entry_box.hide(); } #ifdef __APPLE__ //For Apple's Command-left, right, up, down keys @@ -307,6 +303,7 @@ void Window::hide() { if(!notebook.close_current_page()) return; } + Singleton::terminal()->kill_executing(); Gtk::Window::hide(); }