Restore box layout from a maximized box

This commit is contained in:
Miguel Diaz 2023-08-25 15:03:54 -04:00
parent 4576b15315
commit e823ff0e2b
No known key found for this signature in database
GPG key ID: B2E40D92506E6347
3 changed files with 22 additions and 1 deletions

View file

@ -266,6 +266,7 @@ namespace Config {
{"lowcolor", false},
{"show_detailed", false},
{"proc_filtering", false},
{"is_maximized", false},
};
unordered_flat_map<string, bool> 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<string>& load_warnings) {

View file

@ -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);

View file

@ -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);