Skip to content

Commit

Permalink
Fixed gpu boxes visibility state not saved and removed unnecessary co…
Browse files Browse the repository at this point in the history
…mments
  • Loading branch information
aristocratos committed Jan 7, 2024
1 parent 057f459 commit 6296469
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 104 deletions.
26 changes: 16 additions & 10 deletions src/btop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ namespace Global {
string exit_error_msg;
atomic<bool> thread_exception (false);

bool debuginit{}; // defaults to false
bool debug{}; // defaults to false
bool utf_force{}; // defaults to false
bool debuginit{};
bool debug{};
bool utf_force{};

uint64_t start_time;

Expand All @@ -107,9 +107,10 @@ namespace Global {
atomic<bool> should_quit (false);
atomic<bool> should_sleep (false);
atomic<bool> _runner_started (false);
atomic<bool> init_conf (false);

bool arg_tty{}; // defaults to false
bool arg_low_color{}; // defaults to false
bool arg_tty{};
bool arg_low_color{};
int arg_preset = -1;
int arg_update = 0;
}
Expand Down Expand Up @@ -418,7 +419,7 @@ namespace Runner {

string output;
string empty_bg;
bool pause_output{}; // defaults to false
bool pause_output{};
sigset_t mask;
pthread_t runner_id;
pthread_mutex_t mtx;
Expand Down Expand Up @@ -894,10 +895,10 @@ int main(int argc, char **argv) {
}

//? Config init
{ vector<string> load_warnings;
{
atomic_lock lck(Global::init_conf);
vector<string> load_warnings;
Config::load(Config::conf_file, load_warnings);

if (Config::current_boxes.empty()) Config::check_boxes(Config::getS("shown_boxes"));
Config::set("lowcolor", (Global::arg_low_color ? true : not Config::getB("truecolor")));

if (Global::debug) {
Expand All @@ -918,7 +919,7 @@ int main(int argc, char **argv) {
}
else {
string found;
bool set_failure{}; // defaults to false
bool set_failure{};
for (const auto loc_env : array{"LANG", "LC_ALL"}) {
if (std::getenv(loc_env) != nullptr and str_to_upper(s_replace((string)std::getenv(loc_env), "-", "")).ends_with("UTF8")) {
found = std::getenv(loc_env);
Expand Down Expand Up @@ -1018,6 +1019,11 @@ int main(int argc, char **argv) {
clean_quit(1);
}

if (not Config::check_boxes(Config::getS("shown_boxes"))) {
Config::check_boxes("cpu mem net proc");
Config::set("shown_boxes", "cpu mem net proc"s);
}

//? Update list of available themes and generate the selected theme
Theme::updateThemes();
Theme::setTheme();
Expand Down
5 changes: 2 additions & 3 deletions src/btop_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ namespace Config {
else if (name.starts_with("graph_symbol_") and (value != "default" and not v_contains(valid_graph_symbols, value)))
validError = fmt::format("Invalid graph symbol identifier for {}: {}", name, value);

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

#ifdef GPU_SUPPORT
Expand Down Expand Up @@ -619,8 +619,7 @@ namespace Config {
if (not v_contains(valid_boxes, box)) return false;
#ifdef GPU_SUPPORT
if (box.starts_with("gpu")) {
size_t gpu_num = stoi(box.substr(3));
if (gpu_num == 0) gpu_num = 5;
size_t gpu_num = stoi(box.substr(3)) + 1;
if (std::cmp_greater(gpu_num, Gpu::gpu_names.size())) return false;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/btop_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ namespace Draw {
{"/uptime", ""}
};

static time_t c_time{}; // defaults to 0
static size_t clock_len{}; // defaults to 0
static time_t c_time{};
static size_t clock_len{};
static string clock_str;

if (auto n_time = time(nullptr); not force and n_time == c_time)
Expand Down
4 changes: 2 additions & 2 deletions src/btop_draw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ namespace Draw {

//* An editable text field
class TextEdit {
size_t pos{}; // defaults to 0
size_t upos{}; // defaults to 0
size_t pos{};
size_t upos{};
bool numeric;
public:
string text;
Expand Down
52 changes: 26 additions & 26 deletions src/btop_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ namespace Menu {
bool redraw{true};
int currentMenu = -1;
msgBox messageBox;
int signalToSend{}; // defaults to 0
int signalKillRet{}; // defaults to 0
int signalToSend{};
int signalKillRet{};

const array<string, 32> P_Signals = {
"0",
Expand Down Expand Up @@ -868,8 +868,8 @@ namespace Menu {

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

if (bg.empty()) selected_signal = -1;
Expand Down Expand Up @@ -1070,8 +1070,8 @@ namespace Menu {

int mainMenu(const string& key) {
enum MenuItems { Options, Help, Quit };
static int y{}; // defaults to 0
static int selected{}; // defaults to 0
static int y{};
static int selected{};
static vector<string> colors_selected;
static vector<string> colors_normal;
auto tty_mode = Config::getB("tty_mode");
Expand Down Expand Up @@ -1149,18 +1149,18 @@ namespace Menu {

int optionsMenu(const string& key) {
enum Predispositions { isBool, isInt, isString, is2D, isBrowseable, isEditable};
static int y{}; // defaults to 0
static int x{}; // defaults to 0
static int height{}; // defaults to 0
static int page{}; // defaults to 0
static int pages{}; // defaults to 0
static int selected{}; // defaults to 0
static int select_max{}; // defaults to 0
static int item_height{}; // defaults to 0
static int selected_cat{}; // defaults to 0
static int max_items{}; // defaults to 0
static int last_sel{}; // defaults to 0
static bool editing{}; // defaults to false
static int y{};
static int x{};
static int height{};
static int page{};
static int pages{};
static int selected{};
static int select_max{};
static int item_height{};
static int selected_cat{};
static int max_items{};
static int last_sel{};
static bool editing{};
static Draw::TextEdit editor;
static string warnings;
static bitset<8> selPred;
Expand Down Expand Up @@ -1196,9 +1196,9 @@ namespace Menu {
Theme::updateThemes();
}
int retval = Changed;
bool recollect{}; // defaults to false
bool screen_redraw{}; // defaults to false
bool theme_refresh{}; // defaults to false
bool recollect{};
bool screen_redraw{};
bool theme_refresh{};

//? Draw background if needed else process input
if (redraw) {
Expand Down Expand Up @@ -1500,11 +1500,11 @@ namespace Menu {
}

int helpMenu(const string& key) {
static int y{}; // defaults to 0
static int x{}; // defaults to 0
static int height{}; // defaults to 0
static int page{}; // defaults to 0
static int pages{}; // defaults to 0
static int y{};
static int x{};
static int height{};
static int page{};
static int pages{};

if (bg.empty()) page = 0;
int retval = Changed;
Expand Down
12 changes: 6 additions & 6 deletions src/btop_menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ namespace Menu {
//? Strings in content vector is not checked for box width overflow
class msgBox {
string box_contents, button_left, button_right;
int height{}; // defaults to 0
int width{}; // defaults to 0
int boxtype{}; // defaults to 0
int selected{}; // defaults to 0
int x{}; // defaults to 0
int y{}; // defaults to 0
int height{};
int width{};
int boxtype{};
int selected{};
int x{};
int y{};
public:
enum BoxTypes { OK, YES_NO, NO_YES };
enum msgReturn {
Expand Down
53 changes: 27 additions & 26 deletions src/btop_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Global {
extern string overlay;
extern string clock;
extern uid_t real_uid, set_uid;
extern atomic<bool> init_conf;
}

namespace Runner {
Expand Down Expand Up @@ -228,11 +229,11 @@ namespace Mem {
string name;
string fstype{}; // defaults to ""
std::filesystem::path stat{}; // defaults to ""
int64_t total{}; // defaults to 0
int64_t used{}; // defaults to 0
int64_t free{}; // defaults to 0
int used_percent{}; // defaults to 0
int free_percent{}; // defaults to 0
int64_t total{};
int64_t used{};
int64_t free{};
int used_percent{};
int free_percent{};

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

struct net_stat {
uint64_t speed{}; // defaults to 0
uint64_t top{}; // defaults to 0
uint64_t total{}; // defaults to 0
uint64_t last{}; // defaults to 0
uint64_t offset{}; // defaults to 0
uint64_t rollover{}; // defaults to 0
uint64_t speed{};
uint64_t top{};
uint64_t total{};
uint64_t last{};
uint64_t offset{};
uint64_t rollover{};
};

struct net_info {
std::unordered_map<string, deque<long long>> bandwidth = { {"download", {}}, {"upload", {}} };
std::unordered_map<string, net_stat> stat = { {"download", {}}, {"upload", {}} };
string ipv4{}; // defaults to ""
string ipv6{}; // defaults to ""
bool connected{}; // defaults to false
bool connected{};
};

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

//* Container for process information
struct proc_info {
size_t pid{}; // defaults to 0
size_t pid{};
string name{}; // defaults to ""
string cmd{}; // defaults to ""
string short_cmd{}; // defaults to ""
size_t threads{}; // defaults to 0
int name_offset{}; // defaults to 0
size_t threads{};
int name_offset{};
string user{}; // defaults to ""
uint64_t mem{}; // defaults to 0
uint64_t mem{};
double cpu_p{}; // defaults to = 0.0
double cpu_c{}; // defaults to = 0.0
char state = '0';
int64_t p_nice{}; // defaults to 0
uint64_t ppid{}; // defaults to 0
uint64_t cpu_s{}; // defaults to 0
uint64_t cpu_t{}; // defaults to 0
int64_t p_nice{};
uint64_t ppid{};
uint64_t cpu_s{};
uint64_t cpu_t{};
string prefix{}; // defaults to ""
size_t depth{}; // defaults to 0
size_t tree_index{}; // defaults to 0
bool collapsed{}; // defaults to false
bool filtered{}; // defaults to false
size_t depth{};
size_t tree_index{};
bool collapsed{};
bool filtered{};
};

//* Container for process info box
struct detail_container {
size_t last_pid{}; // defaults to 0
bool skip_smaps{}; // defaults to false
size_t last_pid{};
bool skip_smaps{};
proc_info entry;
string elapsed, parent, status, io_read, io_write, memory;
long long first_mem = -1;
Expand Down
6 changes: 3 additions & 3 deletions src/btop_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ namespace rng = std::ranges;
//* Collection of escape codes and functions for terminal manipulation
namespace Term {

atomic<bool> initialized{}; // defaults to false
atomic<int> width{}; // defaults to 0
atomic<int> height{}; // defaults to 0
atomic<bool> initialized{};
atomic<int> width{};
atomic<int> height{};
string current_tty;

namespace {
Expand Down
2 changes: 1 addition & 1 deletion src/btop_tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ namespace Tools {
//* Sets atomic<bool> to true on construct, sets to false on destruct
class atomic_lock {
atomic<bool>& atom;
bool not_true{}; // defaults to false
bool not_true{};
public:
atomic_lock(atomic<bool>& atom, bool wait = false);
~atomic_lock();
Expand Down
Loading

0 comments on commit 6296469

Please sign in to comment.