Skip to content

Commit d24c555

Browse files
committed
improved fix for metric updates for redraw
1 parent 633b4ba commit d24c555

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed

src/btop.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ static auto configure_tty_mode(std::optional<bool> force_tty) {
10671067
Config::set_boxes("cpu mem net proc");
10681068
Config::set("shown_boxes", "cpu mem net proc"s);
10691069
}
1070+
Config::set_seen_boxes(Config::getS("shown_boxes"));
10701071

10711072
//? Update list of available themes and generate the selected theme
10721073
Theme::updateThemes();
@@ -1163,7 +1164,7 @@ static auto configure_tty_mode(std::optional<bool> force_tty) {
11631164

11641165
//? Trigger secondary thread to redraw if terminal has been resized
11651166
if (Global::resized) {
1166-
Draw::calcSizes();
1167+
Draw::calcSizes(false);
11671168
Draw::update_clock(true);
11681169
Global::resized = false;
11691170
if (Menu::active) Menu::process();

src/btop_config.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,9 @@ namespace Config {
440440

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

443+
bool did_proc_graph_symbol_change = false;
443444
vector<string> current_boxes;
445+
vector<string> seen_boxes;
444446
vector<string> preset_list = {"cpu:0:default,mem:0:default,net:0:default,proc:0:default"};
445447
int current_preset = -1;
446448

@@ -509,6 +511,8 @@ namespace Config {
509511
if (vals.at(0).starts_with("gpu")) {
510512
set("graph_symbol_gpu", vals.at(2));
511513
} else {
514+
if (vals.at(0) == "proc" and getS("graph_symbol_proc") != vals.at(2))
515+
did_proc_graph_symbol_change = true;
512516
set(strings.find("graph_symbol_" + vals.at(0))->first, vals.at(2));
513517
}
514518
}
@@ -686,6 +690,20 @@ namespace Config {
686690
locked = false;
687691
}
688692

693+
// Add boxes to seen_boxes if they haven't been seen before
694+
bool set_seen_boxes(const string& boxes) {
695+
auto new_boxes = ssplit(boxes);
696+
bool were_new_boxes_seen = false;
697+
698+
for (auto& box : new_boxes) {
699+
if (not v_contains(seen_boxes, box)) {
700+
seen_boxes.push_back(box);
701+
were_new_boxes_seen = true;
702+
}
703+
}
704+
return were_new_boxes_seen;
705+
}
706+
689707
bool set_boxes(const string& boxes) {
690708
auto new_boxes = ssplit(boxes);
691709
for (auto& box : new_boxes) {

src/btop_config.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ namespace Config {
6262
extern vector<string> available_batteries;
6363
extern int current_preset;
6464

65+
extern bool did_proc_graph_symbol_change;
6566
extern bool write_new;
6667

6768
constexpr int ONE_DAY_MILLIS = 1000 * 60 * 60 * 24;
6869

6970
[[nodiscard]] std::optional<std::filesystem::path> get_config_dir() noexcept;
7071

72+
// Add boxes to seen_boxes if they haven't been seen before
73+
bool set_seen_boxes(const string& boxes);
74+
7175
//* Check if string only contains space separated valid names for boxes and set current_boxes
7276
bool set_boxes(const string& boxes);
7377

src/btop_draw.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,6 @@ namespace Proc {
15621562
int user_size, thread_size, prog_size, cmd_size, tree_size;
15631563
int dgraph_x, dgraph_width, d_width, d_x, d_y;
15641564
bool previous_proc_banner_state = false;
1565-
atomic<bool> resized (false);
15661565

15671566
string box;
15681567

@@ -2190,7 +2189,7 @@ namespace Proc {
21902189
}
21912190

21922191
namespace Draw {
2193-
void calcSizes() {
2192+
void calcSizes(const bool clear_proc_graphs) {
21942193
atomic_wait(Runner::active);
21952194
Config::unlock();
21962195
auto boxes = Config::getS("shown_boxes");
@@ -2207,7 +2206,7 @@ namespace Draw {
22072206
Global::overlay.clear();
22082207
Runner::pause_output = false;
22092208
Runner::redraw = true;
2210-
if (not (Proc::resized or Global::resized)) {
2209+
if (clear_proc_graphs) {
22112210
Proc::p_counters.clear();
22122211
Proc::p_graphs.clear();
22132212
}

src/btop_draw.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ namespace Draw {
131131
};
132132

133133
//* Calculate sizes of boxes, draw outlines and save to enabled boxes namespaces
134-
void calcSizes();
134+
void calcSizes(const bool clear_proc_graphs = true);
135135
}
136136

137137
namespace Proc {

src/btop_input.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,11 @@ namespace Input {
254254
return;
255255
}
256256
Config::current_preset = -1;
257-
Draw::calcSizes();
257+
Draw::calcSizes(!Proc::shown);
258258
Draw::update_clock(true);
259-
Runner::run("all", false, true);
259+
if (Config::set_seen_boxes(boxes.at(intKey)))
260+
Runner::run(boxes.at(intKey), false, false);
261+
Runner::run("all", true, true);
260262
return;
261263
}
262264
else if (is_in(key, "p", "P") and Config::preset_list.size() > 1) {
@@ -273,9 +275,14 @@ namespace Input {
273275
Config::current_preset = old_preset;
274276
return;
275277
}
276-
Draw::calcSizes();
278+
Draw::calcSizes(!Proc::shown or Config::did_proc_graph_symbol_change);
279+
Config::did_proc_graph_symbol_change = false;
277280
Draw::update_clock(true);
278-
Runner::run("all", false, true);
281+
for (const auto& box : Config::current_boxes) {
282+
if (Config::set_seen_boxes(box))
283+
Runner::run(box, false, false);
284+
}
285+
Runner::run("all", true, true);
279286
return;
280287
} else if (is_in(key, "ctrl_r")) {
281288
kill(getpid(), SIGUSR2);

src/btop_shared.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ namespace Proc {
354354
extern int selected_pid, start, selected, collapse, expand, filter_found, selected_depth, toggle_children;
355355
extern int scroll_pos;
356356
extern string selected_name;
357-
extern atomic<bool> resized;
358357

359358
//? Contains the valid sorting options for processes
360359
const vector<string> sort_vector = {

0 commit comments

Comments
 (0)