Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/btop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,7 @@ static auto configure_tty_mode(std::optional<bool> 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();
Expand Down Expand Up @@ -1163,7 +1164,7 @@ static auto configure_tty_mode(std::optional<bool> 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();
Expand Down
18 changes: 18 additions & 0 deletions src/btop_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ namespace Config {

vector<string> available_batteries = {"Auto"};

bool did_proc_graph_symbol_change = false;
vector<string> current_boxes;
vector<string> seen_boxes;
vector<string> preset_list = {"cpu:0:default,mem:0:default,net:0:default,proc:0:default"};
int current_preset = -1;

Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/btop_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ namespace Config {
extern vector<string> 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<std::filesystem::path> 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);

Expand Down
5 changes: 2 additions & 3 deletions src/btop_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> resized (false);

string box;

Expand Down Expand Up @@ -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");
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/btop_draw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 11 additions & 4 deletions src/btop_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/btop_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> resized;

//? Contains the valid sorting options for processes
const vector<string> sort_vector = {
Expand Down
Loading