Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore layout from a maximized box #604

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/btop_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ namespace Config {
{"lowcolor", false},
{"show_detailed", false},
{"proc_filtering", false},
{"is_maximized", false},
};
unordered_flat_map<std::string_view, bool> boolsTmp;

Expand Down Expand Up @@ -521,6 +522,20 @@ 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) {
auto old_boxes = current_boxes;
auto box_pos = rng::find(current_boxes, box);
Expand All @@ -543,6 +558,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) {
Expand Down
6 changes: 6 additions & 0 deletions src/btop_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ 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);

//* Restore boxes and update config string shown_boxes
void restore(const string& boxes);

//* Parse and setup config value presets
bool presetsValid(const string& presets);

Expand Down
23 changes: 21 additions & 2 deletions src/btop_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tab-size = 4
#include <thread>
#include <mutex>
#include <signal.h>
#include <ctype.h>

#include "btop_input.hpp"
#include "btop_tools.hpp"
Expand Down Expand Up @@ -260,11 +261,29 @@ 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<string, 4> 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<string, string> binding = {
{"!", boxes.at(0)},
{"@", boxes.at(1)},
{"#", boxes.at(2)},
{"$", boxes.at(3)},
};
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);
return;
Expand Down