diff --git a/src/btop.cpp b/src/btop.cpp index 5d44ae995..85656916e 100644 --- a/src/btop.cpp +++ b/src/btop.cpp @@ -1067,6 +1067,7 @@ static auto configure_tty_mode(std::optional force_tty) { Config::set_boxes("cpu mem net proc"); Config::set("shown_boxes", "cpu mem net proc"s); } + Config::set_seen_boxes(Config::getS("shown_boxes")); //? Update list of available themes and generate the selected theme Theme::updateThemes(); @@ -1163,7 +1164,7 @@ static auto configure_tty_mode(std::optional force_tty) { //? Trigger secondary thread to redraw if terminal has been resized if (Global::resized) { - Draw::calcSizes(); + Draw::calcSizes(false); Draw::update_clock(true); Global::resized = false; if (Menu::active) Menu::process(); diff --git a/src/btop_config.cpp b/src/btop_config.cpp index 1cf014f40..164399143 100644 --- a/src/btop_config.cpp +++ b/src/btop_config.cpp @@ -440,7 +440,9 @@ namespace Config { vector available_batteries = {"Auto"}; + bool did_proc_graph_symbol_change = false; vector current_boxes; + vector seen_boxes; vector preset_list = {"cpu:0:default,mem:0:default,net:0:default,proc:0:default"}; int current_preset = -1; @@ -509,6 +511,8 @@ namespace Config { if (vals.at(0).starts_with("gpu")) { set("graph_symbol_gpu", vals.at(2)); } else { + if (vals.at(0) == "proc" and getS("graph_symbol_proc") != vals.at(2)) + did_proc_graph_symbol_change = true; set(strings.find("graph_symbol_" + vals.at(0))->first, vals.at(2)); } } @@ -686,6 +690,20 @@ namespace Config { locked = false; } + // Add boxes to seen_boxes if they haven't been seen before + bool set_seen_boxes(const string& boxes) { + auto new_boxes = ssplit(boxes); + bool were_new_boxes_seen = false; + + for (auto& box : new_boxes) { + if (not v_contains(seen_boxes, box)) { + seen_boxes.push_back(box); + were_new_boxes_seen = true; + } + } + return were_new_boxes_seen; + } + bool set_boxes(const string& boxes) { auto new_boxes = ssplit(boxes); for (auto& box : new_boxes) { diff --git a/src/btop_config.hpp b/src/btop_config.hpp index ca9d90919..552ad6123 100644 --- a/src/btop_config.hpp +++ b/src/btop_config.hpp @@ -62,12 +62,16 @@ namespace Config { extern vector available_batteries; extern int current_preset; + extern bool did_proc_graph_symbol_change; extern bool write_new; constexpr int ONE_DAY_MILLIS = 1000 * 60 * 60 * 24; [[nodiscard]] std::optional get_config_dir() noexcept; + // Add boxes to seen_boxes if they haven't been seen before + bool set_seen_boxes(const string& boxes); + //* Check if string only contains space separated valid names for boxes and set current_boxes bool set_boxes(const string& boxes); diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index 7cb5f9e2a..316d2b1de 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -1562,7 +1562,6 @@ namespace Proc { int user_size, thread_size, prog_size, cmd_size, tree_size; int dgraph_x, dgraph_width, d_width, d_x, d_y; bool previous_proc_banner_state = false; - atomic resized (false); string box; @@ -2190,7 +2189,7 @@ namespace Proc { } namespace Draw { - void calcSizes() { + void calcSizes(const bool clear_proc_graphs) { atomic_wait(Runner::active); Config::unlock(); auto boxes = Config::getS("shown_boxes"); @@ -2207,7 +2206,7 @@ namespace Draw { Global::overlay.clear(); Runner::pause_output = false; Runner::redraw = true; - if (not (Proc::resized or Global::resized)) { + if (clear_proc_graphs) { Proc::p_counters.clear(); Proc::p_graphs.clear(); } diff --git a/src/btop_draw.hpp b/src/btop_draw.hpp index 9c516ad32..9f9611a1a 100644 --- a/src/btop_draw.hpp +++ b/src/btop_draw.hpp @@ -131,7 +131,7 @@ namespace Draw { }; //* Calculate sizes of boxes, draw outlines and save to enabled boxes namespaces - void calcSizes(); + void calcSizes(const bool clear_proc_graphs = true); } namespace Proc { diff --git a/src/btop_input.cpp b/src/btop_input.cpp index ffd4e02bd..67b398d6d 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -254,9 +254,11 @@ namespace Input { return; } Config::current_preset = -1; - Draw::calcSizes(); + Draw::calcSizes(!Proc::shown); Draw::update_clock(true); - Runner::run("all", false, true); + if (Config::set_seen_boxes(boxes.at(intKey))) + Runner::run(boxes.at(intKey), false, false); + Runner::run("all", true, true); return; } else if (is_in(key, "p", "P") and Config::preset_list.size() > 1) { @@ -273,9 +275,14 @@ namespace Input { Config::current_preset = old_preset; return; } - Draw::calcSizes(); + Draw::calcSizes(!Proc::shown or Config::did_proc_graph_symbol_change); + Config::did_proc_graph_symbol_change = false; Draw::update_clock(true); - Runner::run("all", false, true); + for (const auto& box : Config::current_boxes) { + if (Config::set_seen_boxes(box)) + Runner::run(box, false, false); + } + Runner::run("all", true, true); return; } else if (is_in(key, "ctrl_r")) { kill(getpid(), SIGUSR2); diff --git a/src/btop_shared.hpp b/src/btop_shared.hpp index a2d0bdc86..b3b1d019f 100644 --- a/src/btop_shared.hpp +++ b/src/btop_shared.hpp @@ -354,7 +354,6 @@ namespace Proc { extern int selected_pid, start, selected, collapse, expand, filter_found, selected_depth, toggle_children; extern int scroll_pos; extern string selected_name; - extern atomic resized; //? Contains the valid sorting options for processes const vector sort_vector = {