From 4576b15315b739a5c4ba9d664dd1b75295e7e1b3 Mon Sep 17 00:00:00 2001 From: Miguel Diaz Date: Thu, 24 Aug 2023 21:35:53 -0400 Subject: [PATCH 1/2] Add key bindings that maximize a box --- src/btop_config.cpp | 6 ++++++ src/btop_config.hpp | 3 +++ src/btop_input.cpp | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/btop_config.cpp b/src/btop_config.cpp index 25b68dd..1f8c9c9 100644 --- a/src/btop_config.cpp +++ b/src/btop_config.cpp @@ -519,6 +519,12 @@ namespace Config { return true; } + void maximize_box(const string& box) { + current_boxes.clear(); + current_boxes.push_back(box); + Config::set("shown_boxes", box); + } + void toggle_box(const string& box) { auto old_boxes = current_boxes; auto box_pos = rng::find(current_boxes, box); diff --git a/src/btop_config.hpp b/src/btop_config.hpp index 95c6b68..2dd5a7c 100644 --- a/src/btop_config.hpp +++ b/src/btop_config.hpp @@ -56,6 +56,9 @@ namespace Config { //* Toggle box and update config string shown_boxes void toggle_box(const string& box); + //* Maximize box and update config string shown_boxes + void maximize_box(const string& box); + //* Parse and setup config value presets bool presetsValid(const string& presets); diff --git a/src/btop_input.cpp b/src/btop_input.cpp index ebdee3b..b6c516c 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -22,6 +22,7 @@ tab-size = 4 #include #include #include +#include #include "btop_input.hpp" #include "btop_tools.hpp" @@ -260,11 +261,21 @@ namespace Input { Menu::show(Menu::Menus::Options); return; } - else if (is_in(key, "1", "2", "3", "4")) { + else if (is_in(key, "1", "2", "3", "4", "!", "@", "#", "$")) { atomic_wait(Runner::active); Config::current_preset = -1; static const array boxes = {"cpu", "mem", "net", "proc"}; - Config::toggle_box(boxes.at(std::stoi(key) - 1)); + if (std::isdigit(key[0])) + Config::toggle_box(boxes.at(std::stoi(key) - 1)); + else { + static const unordered_flat_map binding = { + {"!", boxes.at(0)}, + {"@", boxes.at(1)}, + {"#", boxes.at(2)}, + {"$", boxes.at(3)}, + }; + Config::maximize_box(binding.at(key)); + } Draw::calcSizes(); Runner::run("all", false, true); return; From e823ff0e2becd61660f7694b71fd11c596c1b1c6 Mon Sep 17 00:00:00 2001 From: Miguel Diaz Date: Fri, 25 Aug 2023 15:03:54 -0400 Subject: [PATCH 2/2] Restore box layout from a maximized box --- src/btop_config.cpp | 10 ++++++++++ src/btop_config.hpp | 3 +++ src/btop_input.cpp | 10 +++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/btop_config.cpp b/src/btop_config.cpp index 1f8c9c9..87b4792 100644 --- a/src/btop_config.cpp +++ b/src/btop_config.cpp @@ -266,6 +266,7 @@ namespace Config { {"lowcolor", false}, {"show_detailed", false}, {"proc_filtering", false}, + {"is_maximized", false}, }; unordered_flat_map boolsTmp; @@ -519,10 +520,18 @@ namespace Config { return true; } + void restore(const string& boxes) { + current_boxes.clear(); + current_boxes = ssplit(boxes); + Config::set("shown_boxes", boxes); + Config::set("is_maximized", false); + } + void maximize_box(const string& box) { current_boxes.clear(); current_boxes.push_back(box); Config::set("shown_boxes", box); + Config::set("is_maximized", true); } void toggle_box(const string& box) { @@ -547,6 +556,7 @@ namespace Config { } Config::set("shown_boxes", new_boxes); + ssplit(new_boxes).size() == 1 ? Config::set("is_maximized", true) : Config::set("is_maximized", false); } void load(const fs::path& conf_file, vector& load_warnings) { diff --git a/src/btop_config.hpp b/src/btop_config.hpp index 2dd5a7c..43b1339 100644 --- a/src/btop_config.hpp +++ b/src/btop_config.hpp @@ -59,6 +59,9 @@ namespace Config { //* Maximize box and update config string shown_boxes void maximize_box(const string& box); + //* Restore boxes and update config string shown_boxes + void restore(const string& boxes); + //* Parse and setup config value presets bool presetsValid(const string& presets); diff --git a/src/btop_input.cpp b/src/btop_input.cpp index b6c516c..00da166 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -274,7 +274,15 @@ namespace Input { {"#", boxes.at(2)}, {"$", boxes.at(3)}, }; - Config::maximize_box(binding.at(key)); + if (Config::getB("is_maximized") && Config::getS("shown_boxes") == binding.at(key)) { + string str_boxes; + for (const auto& b : boxes) str_boxes += b + ' '; + str_boxes.pop_back(); + + Config::restore(str_boxes); + } + else + Config::maximize_box(binding.at(key)); } Draw::calcSizes(); Runner::run("all", false, true);