Skip to content

Commit 6296469

Browse files
committed
Fixed gpu boxes visibility state not saved and removed unnecessary comments
1 parent 057f459 commit 6296469

File tree

10 files changed

+110
-104
lines changed

10 files changed

+110
-104
lines changed

src/btop.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ namespace Global {
9696
string exit_error_msg;
9797
atomic<bool> thread_exception (false);
9898

99-
bool debuginit{}; // defaults to false
100-
bool debug{}; // defaults to false
101-
bool utf_force{}; // defaults to false
99+
bool debuginit{};
100+
bool debug{};
101+
bool utf_force{};
102102

103103
uint64_t start_time;
104104

@@ -107,9 +107,10 @@ namespace Global {
107107
atomic<bool> should_quit (false);
108108
atomic<bool> should_sleep (false);
109109
atomic<bool> _runner_started (false);
110+
atomic<bool> init_conf (false);
110111

111-
bool arg_tty{}; // defaults to false
112-
bool arg_low_color{}; // defaults to false
112+
bool arg_tty{};
113+
bool arg_low_color{};
113114
int arg_preset = -1;
114115
int arg_update = 0;
115116
}
@@ -418,7 +419,7 @@ namespace Runner {
418419

419420
string output;
420421
string empty_bg;
421-
bool pause_output{}; // defaults to false
422+
bool pause_output{};
422423
sigset_t mask;
423424
pthread_t runner_id;
424425
pthread_mutex_t mtx;
@@ -894,10 +895,10 @@ int main(int argc, char **argv) {
894895
}
895896

896897
//? Config init
897-
{ vector<string> load_warnings;
898+
{
899+
atomic_lock lck(Global::init_conf);
900+
vector<string> load_warnings;
898901
Config::load(Config::conf_file, load_warnings);
899-
900-
if (Config::current_boxes.empty()) Config::check_boxes(Config::getS("shown_boxes"));
901902
Config::set("lowcolor", (Global::arg_low_color ? true : not Config::getB("truecolor")));
902903

903904
if (Global::debug) {
@@ -918,7 +919,7 @@ int main(int argc, char **argv) {
918919
}
919920
else {
920921
string found;
921-
bool set_failure{}; // defaults to false
922+
bool set_failure{};
922923
for (const auto loc_env : array{"LANG", "LC_ALL"}) {
923924
if (std::getenv(loc_env) != nullptr and str_to_upper(s_replace((string)std::getenv(loc_env), "-", "")).ends_with("UTF8")) {
924925
found = std::getenv(loc_env);
@@ -1018,6 +1019,11 @@ int main(int argc, char **argv) {
10181019
clean_quit(1);
10191020
}
10201021

1022+
if (not Config::check_boxes(Config::getS("shown_boxes"))) {
1023+
Config::check_boxes("cpu mem net proc");
1024+
Config::set("shown_boxes", "cpu mem net proc"s);
1025+
}
1026+
10211027
//? Update list of available themes and generate the selected theme
10221028
Theme::updateThemes();
10231029
Theme::setTheme();

src/btop_config.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ namespace Config {
507507
else if (name.starts_with("graph_symbol_") and (value != "default" and not v_contains(valid_graph_symbols, value)))
508508
validError = fmt::format("Invalid graph symbol identifier for {}: {}", name, value);
509509

510-
else if (name == "shown_boxes" and not value.empty() and not check_boxes(value))
510+
else if (name == "shown_boxes" and not Global::init_conf and not value.empty() and not check_boxes(value))
511511
validError = "Invalid box name(s) in shown_boxes!";
512512

513513
#ifdef GPU_SUPPORT
@@ -619,8 +619,7 @@ namespace Config {
619619
if (not v_contains(valid_boxes, box)) return false;
620620
#ifdef GPU_SUPPORT
621621
if (box.starts_with("gpu")) {
622-
size_t gpu_num = stoi(box.substr(3));
623-
if (gpu_num == 0) gpu_num = 5;
622+
size_t gpu_num = stoi(box.substr(3)) + 1;
624623
if (std::cmp_greater(gpu_num, Gpu::gpu_names.size())) return false;
625624
}
626625
#endif

src/btop_draw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ namespace Draw {
307307
{"/uptime", ""}
308308
};
309309

310-
static time_t c_time{}; // defaults to 0
311-
static size_t clock_len{}; // defaults to 0
310+
static time_t c_time{};
311+
static size_t clock_len{};
312312
static string clock_str;
313313

314314
if (auto n_time = time(nullptr); not force and n_time == c_time)

src/btop_draw.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ namespace Draw {
6565

6666
//* An editable text field
6767
class TextEdit {
68-
size_t pos{}; // defaults to 0
69-
size_t upos{}; // defaults to 0
68+
size_t pos{};
69+
size_t upos{};
7070
bool numeric;
7171
public:
7272
string text;

src/btop_menu.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ namespace Menu {
4949
bool redraw{true};
5050
int currentMenu = -1;
5151
msgBox messageBox;
52-
int signalToSend{}; // defaults to 0
53-
int signalKillRet{}; // defaults to 0
52+
int signalToSend{};
53+
int signalKillRet{};
5454

5555
const array<string, 32> P_Signals = {
5656
"0",
@@ -868,8 +868,8 @@ namespace Menu {
868868

869869
int signalChoose(const string& key) {
870870
auto s_pid = (Config::getB("show_detailed") and Config::getI("selected_pid") == 0 ? Config::getI("detailed_pid") : Config::getI("selected_pid"));
871-
static int x{}; // defaults to 0
872-
static int y{}; // defaults to 0
871+
static int x{};
872+
static int y{};
873873
static int selected_signal = -1;
874874

875875
if (bg.empty()) selected_signal = -1;
@@ -1070,8 +1070,8 @@ namespace Menu {
10701070

10711071
int mainMenu(const string& key) {
10721072
enum MenuItems { Options, Help, Quit };
1073-
static int y{}; // defaults to 0
1074-
static int selected{}; // defaults to 0
1073+
static int y{};
1074+
static int selected{};
10751075
static vector<string> colors_selected;
10761076
static vector<string> colors_normal;
10771077
auto tty_mode = Config::getB("tty_mode");
@@ -1149,18 +1149,18 @@ namespace Menu {
11491149

11501150
int optionsMenu(const string& key) {
11511151
enum Predispositions { isBool, isInt, isString, is2D, isBrowseable, isEditable};
1152-
static int y{}; // defaults to 0
1153-
static int x{}; // defaults to 0
1154-
static int height{}; // defaults to 0
1155-
static int page{}; // defaults to 0
1156-
static int pages{}; // defaults to 0
1157-
static int selected{}; // defaults to 0
1158-
static int select_max{}; // defaults to 0
1159-
static int item_height{}; // defaults to 0
1160-
static int selected_cat{}; // defaults to 0
1161-
static int max_items{}; // defaults to 0
1162-
static int last_sel{}; // defaults to 0
1163-
static bool editing{}; // defaults to false
1152+
static int y{};
1153+
static int x{};
1154+
static int height{};
1155+
static int page{};
1156+
static int pages{};
1157+
static int selected{};
1158+
static int select_max{};
1159+
static int item_height{};
1160+
static int selected_cat{};
1161+
static int max_items{};
1162+
static int last_sel{};
1163+
static bool editing{};
11641164
static Draw::TextEdit editor;
11651165
static string warnings;
11661166
static bitset<8> selPred;
@@ -1196,9 +1196,9 @@ namespace Menu {
11961196
Theme::updateThemes();
11971197
}
11981198
int retval = Changed;
1199-
bool recollect{}; // defaults to false
1200-
bool screen_redraw{}; // defaults to false
1201-
bool theme_refresh{}; // defaults to false
1199+
bool recollect{};
1200+
bool screen_redraw{};
1201+
bool theme_refresh{};
12021202

12031203
//? Draw background if needed else process input
12041204
if (redraw) {
@@ -1500,11 +1500,11 @@ namespace Menu {
15001500
}
15011501

15021502
int helpMenu(const string& key) {
1503-
static int y{}; // defaults to 0
1504-
static int x{}; // defaults to 0
1505-
static int height{}; // defaults to 0
1506-
static int page{}; // defaults to 0
1507-
static int pages{}; // defaults to 0
1503+
static int y{};
1504+
static int x{};
1505+
static int height{};
1506+
static int page{};
1507+
static int pages{};
15081508

15091509
if (bg.empty()) page = 0;
15101510
int retval = Changed;

src/btop_menu.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ namespace Menu {
4646
//? Strings in content vector is not checked for box width overflow
4747
class msgBox {
4848
string box_contents, button_left, button_right;
49-
int height{}; // defaults to 0
50-
int width{}; // defaults to 0
51-
int boxtype{}; // defaults to 0
52-
int selected{}; // defaults to 0
53-
int x{}; // defaults to 0
54-
int y{}; // defaults to 0
49+
int height{};
50+
int width{};
51+
int boxtype{};
52+
int selected{};
53+
int x{};
54+
int y{};
5555
public:
5656
enum BoxTypes { OK, YES_NO, NO_YES };
5757
enum msgReturn {

src/btop_shared.hpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace Global {
5454
extern string overlay;
5555
extern string clock;
5656
extern uid_t real_uid, set_uid;
57+
extern atomic<bool> init_conf;
5758
}
5859

5960
namespace Runner {
@@ -228,11 +229,11 @@ namespace Mem {
228229
string name;
229230
string fstype{}; // defaults to ""
230231
std::filesystem::path stat{}; // defaults to ""
231-
int64_t total{}; // defaults to 0
232-
int64_t used{}; // defaults to 0
233-
int64_t free{}; // defaults to 0
234-
int used_percent{}; // defaults to 0
235-
int free_percent{}; // defaults to 0
232+
int64_t total{};
233+
int64_t used{};
234+
int64_t free{};
235+
int used_percent{};
236+
int free_percent{};
236237

237238
array<int64_t, 3> old_io = {0, 0, 0};
238239
deque<long long> io_read = {};
@@ -272,20 +273,20 @@ namespace Net {
272273
extern std::unordered_map<string, uint64_t> graph_max;
273274

274275
struct net_stat {
275-
uint64_t speed{}; // defaults to 0
276-
uint64_t top{}; // defaults to 0
277-
uint64_t total{}; // defaults to 0
278-
uint64_t last{}; // defaults to 0
279-
uint64_t offset{}; // defaults to 0
280-
uint64_t rollover{}; // defaults to 0
276+
uint64_t speed{};
277+
uint64_t top{};
278+
uint64_t total{};
279+
uint64_t last{};
280+
uint64_t offset{};
281+
uint64_t rollover{};
281282
};
282283

283284
struct net_info {
284285
std::unordered_map<string, deque<long long>> bandwidth = { {"download", {}}, {"upload", {}} };
285286
std::unordered_map<string, net_stat> stat = { {"download", {}}, {"upload", {}} };
286287
string ipv4{}; // defaults to ""
287288
string ipv6{}; // defaults to ""
288-
bool connected{}; // defaults to false
289+
bool connected{};
289290
};
290291

291292
extern std::unordered_map<string, net_info> current_net;
@@ -337,32 +338,32 @@ namespace Proc {
337338

338339
//* Container for process information
339340
struct proc_info {
340-
size_t pid{}; // defaults to 0
341+
size_t pid{};
341342
string name{}; // defaults to ""
342343
string cmd{}; // defaults to ""
343344
string short_cmd{}; // defaults to ""
344-
size_t threads{}; // defaults to 0
345-
int name_offset{}; // defaults to 0
345+
size_t threads{};
346+
int name_offset{};
346347
string user{}; // defaults to ""
347-
uint64_t mem{}; // defaults to 0
348+
uint64_t mem{};
348349
double cpu_p{}; // defaults to = 0.0
349350
double cpu_c{}; // defaults to = 0.0
350351
char state = '0';
351-
int64_t p_nice{}; // defaults to 0
352-
uint64_t ppid{}; // defaults to 0
353-
uint64_t cpu_s{}; // defaults to 0
354-
uint64_t cpu_t{}; // defaults to 0
352+
int64_t p_nice{};
353+
uint64_t ppid{};
354+
uint64_t cpu_s{};
355+
uint64_t cpu_t{};
355356
string prefix{}; // defaults to ""
356-
size_t depth{}; // defaults to 0
357-
size_t tree_index{}; // defaults to 0
358-
bool collapsed{}; // defaults to false
359-
bool filtered{}; // defaults to false
357+
size_t depth{};
358+
size_t tree_index{};
359+
bool collapsed{};
360+
bool filtered{};
360361
};
361362

362363
//* Container for process info box
363364
struct detail_container {
364-
size_t last_pid{}; // defaults to 0
365-
bool skip_smaps{}; // defaults to false
365+
size_t last_pid{};
366+
bool skip_smaps{};
366367
proc_info entry;
367368
string elapsed, parent, status, io_read, io_write, memory;
368369
long long first_mem = -1;

src/btop_tools.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ namespace rng = std::ranges;
5454
//* Collection of escape codes and functions for terminal manipulation
5555
namespace Term {
5656

57-
atomic<bool> initialized{}; // defaults to false
58-
atomic<int> width{}; // defaults to 0
59-
atomic<int> height{}; // defaults to 0
57+
atomic<bool> initialized{};
58+
atomic<int> width{};
59+
atomic<int> height{};
6060
string current_tty;
6161

6262
namespace {

src/btop_tools.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ namespace Tools {
406406
//* Sets atomic<bool> to true on construct, sets to false on destruct
407407
class atomic_lock {
408408
atomic<bool>& atom;
409-
bool not_true{}; // defaults to false
409+
bool not_true{};
410410
public:
411411
atomic_lock(atomic<bool>& atom, bool wait = false);
412412
~atomic_lock();

0 commit comments

Comments
 (0)