diff --git a/src/btop.cpp b/src/btop.cpp index 5d44ae9..b99432d 100644 --- a/src/btop.cpp +++ b/src/btop.cpp @@ -191,7 +191,7 @@ void term_resize(bool force) { if (intKey > 0 and intKey < 5) { #endif const auto& box = all_boxes.at(intKey); - Config::current_preset = -1; + Config::current_preset.reset(); Config::toggle_box(box); boxes = Config::getS("shown_boxes"); } @@ -1104,7 +1104,7 @@ static auto configure_tty_mode(std::optional force_tty) { Config::presetsValid(Config::getS("presets")); if (cli.preset.has_value()) { Config::current_preset = min(static_cast(cli.preset.value()), static_cast(Config::preset_list.size() - 1)); - Config::apply_preset(Config::preset_list.at(Config::current_preset)); + Config::apply_preset(Config::preset_list.at(Config::current_preset.value())); } { diff --git a/src/btop_config.cpp b/src/btop_config.cpp index 1cf014f..36555e3 100644 --- a/src/btop_config.cpp +++ b/src/btop_config.cpp @@ -65,6 +65,12 @@ namespace Config { {"force_tty", "#* Set to true to force tty mode regardless if a real tty has been detected or not.\n" "#* Will force 16-color mode and TTY theme, set all graph symbols to \"tty\" and swap out other non tty friendly symbols."}, + {"disable_presets", "#* Option to disable presets. Either the default preset, custom presets, or all presets.\n" + "#* \"Off\" All presets are enabled.\n" + "#* \"Default\" preset is disabled." + "#* \"Custom\" presets are disabled." + "#* \"All\" presets are disabled."}, + {"presets", "#* Define presets for the layout of the boxes. Preset 0 is always all boxes shown with default settings. Max 9 presets.\n" "#* Format: \"box_name:P:G,box_name:P:G\" P=(0 or 1) for alternate positions, G=graph symbol to use for box.\n" "#* Use whitespace \" \" as separator between different presets.\n" @@ -247,6 +253,7 @@ namespace Config { {"color_theme", "Default"}, {"shown_boxes", "cpu mem net proc"}, {"graph_symbol", "braille"}, + {"disable_presets", "Off"}, {"presets", "cpu:1:default,proc:0:default cpu:0:default,mem:0:default,net:0:default cpu:0:block,net:0:tty"}, {"graph_symbol_cpu", "default"}, {"graph_symbol_gpu", "default"}, @@ -442,7 +449,7 @@ namespace Config { vector current_boxes; vector preset_list = {"cpu:0:default,mem:0:default,net:0:default,proc:0:default"}; - int current_preset = -1; + std::optional current_preset; bool presetsValid(const string& presets) { vector new_presets = {preset_list.at(0)}; diff --git a/src/btop_config.hpp b/src/btop_config.hpp index ca9d909..ba92d14 100644 --- a/src/btop_config.hpp +++ b/src/btop_config.hpp @@ -59,8 +59,9 @@ namespace Config { const vector base_10_bitrate_values = { "Auto", "True", "False" }; extern vector current_boxes; extern vector preset_list; + const vector disable_preset_options = { "Off", "Default", "Custom", "All" }; extern vector available_batteries; - extern int current_preset; + extern std::optional current_preset; extern bool write_new; diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index 7cb5f9e..131f898 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -594,7 +594,7 @@ namespace Cpu { out += Mv::to(button_y, x + 10) + title_left + Theme::c("hi_fg") + Fx::b + 'm' + Theme::c("title") + "enu" + Fx::ub + title_right; Input::mouse_mappings["m"] = {button_y, x + 11, 1, 4}; out += Mv::to(button_y, x + 16) + title_left + Theme::c("hi_fg") + Fx::b + 'p' + Theme::c("title") + "reset " - + (Config::current_preset < 0 ? "*" : to_string(Config::current_preset)) + Fx::ub + title_right; + + (!Config::current_preset.has_value() ? "*" : to_string(Config::current_preset.value())) + Fx::ub + title_right; Input::mouse_mappings["p"] = {button_y, x + 17, 1, 8}; const string update = to_string(Config::getI("update_ms")) + "ms"; out += Mv::to(button_y, x + width - update.size() - 8) + title_left + Fx::b + Theme::c("hi_fg") + "- " + Theme::c("title") + update diff --git a/src/btop_input.cpp b/src/btop_input.cpp index ffd4e02..28a9667 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -253,22 +253,27 @@ namespace Input { Menu::show(Menu::Menus::SizeError); return; } - Config::current_preset = -1; + Config::current_preset.reset(); Draw::calcSizes(); Draw::update_clock(true); Runner::run("all", false, true); return; } - else if (is_in(key, "p", "P") and Config::preset_list.size() > 1) { + else if (is_in(key, "p", "P") and Config::getS("disable_presets") != "All") { + if (Config::getS("disable_presets") == "Default" and Config::preset_list.size() <= 1) return; const auto old_preset = Config::current_preset; - if (key == "p") { - if (++Config::current_preset >= (int)Config::preset_list.size()) Config::current_preset = 0; - } - else { - if (--Config::current_preset < 0) Config::current_preset = Config::preset_list.size() - 1; + const int first_preset = (Config::getS("disable_presets") == "Default") ? 1 : 0; + if (Config::getS("disable_presets") == "Custom") Config::current_preset = 0; + else if (Config::current_preset.has_value()) { + if (key == "p") { + if(++(*Config::current_preset) >= static_cast(Config::preset_list.size())) Config::current_preset = first_preset; + } + else if (--(*Config::current_preset) < first_preset) Config::current_preset = Config::preset_list.size() - 1; } + else Config::current_preset = (key == "p") ? first_preset : Config::preset_list.size() - 1; + if (Config::current_preset == old_preset) return; atomic_wait(Runner::active); - if (not Config::apply_preset(Config::preset_list.at(Config::current_preset))) { + if (not Config::apply_preset(Config::preset_list.at(Config::current_preset.value()))) { Menu::show(Menu::Menus::SizeError); Config::current_preset = old_preset; return; diff --git a/src/btop_menu.cpp b/src/btop_menu.cpp index 45baa7d..e9450e8 100644 --- a/src/btop_menu.cpp +++ b/src/btop_menu.cpp @@ -263,6 +263,16 @@ namespace Menu { "is accessible while holding shift."}, {"disable_mouse", "Disable all mouse events."}, + {"disable_presets", + "Disable the presets.", + "", + "\"Off\" All presets are enabled.", + "", + "\"Default\" preset is disabled.", + "", + "\"Custom\" presets are disabled.", + "", + "\"All\" presets are disabled."}, {"presets", "Define presets for the layout of the boxes.", "", @@ -1285,6 +1295,7 @@ static int optionsMenu(const string& key) { {"cpu_sensor", std::cref(Cpu::available_sensors)}, {"selected_battery", std::cref(Config::available_batteries)}, {"base_10_bitrate", std::cref(Config::base_10_bitrate_values)}, + {"disable_presets", std::cref(Config::disable_preset_options)}, #ifdef GPU_SUPPORT {"show_gpu_info", std::cref(Config::show_gpu_values)}, {"graph_symbol_gpu", std::cref(Config::valid_graph_symbols_def)}, @@ -1344,7 +1355,7 @@ static int optionsMenu(const string& key) { screen_redraw = true; else if (is_in(option, "shown_boxes", "presets")) { screen_redraw = true; - Config::current_preset = -1; + Config::current_preset.reset(); } else if (option == "clock_format") { Draw::update_clock(true); @@ -1497,6 +1508,8 @@ static int optionsMenu(const string& key) { } else if (is_in(option, "proc_sorting", "cpu_sensor", "show_gpu_info") or option.starts_with("graph_symbol") or option.starts_with("cpu_graph_")) screen_redraw = true; + else if (option == "disable_presets" and optList.at(i) != "Off") + Config::current_preset.reset(); } else retval = NoChange;