Skip to content

Commit 48fa699

Browse files
committed
Variable width proc box
1 parent 5521ba3 commit 48fa699

5 files changed

Lines changed: 38 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,9 @@ proc_info_smaps = false
14031403
#* Show proc box on left side of screen instead of right.
14041404
proc_left = false
14051405
1406+
#* Percentage value for proc box width when mem or net is shown.
1407+
proc_box_width_percent = 55
1408+
14061409
#* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop).
14071410
proc_filter_kernel = false
14081411

src/btop_config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ namespace Config {
118118

119119
{"proc_left", "#* Show proc box on left side of screen instead of right."},
120120

121+
{"proc_box_width_percent", "#* Percentage value for proc box width when mem or net is shown."},
122+
121123
{"proc_filter_kernel", "#* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop)."},
122124

123125
{"proc_follow_detailed", "#* Should the process list follow the selected process when detailed view is open."},
@@ -365,6 +367,7 @@ namespace Config {
365367
{"proc_selected", 0},
366368
{"proc_last_selected", 0},
367369
{"proc_followed", 0},
370+
{"proc_box_width_percent", 55},
368371
};
369372
std::unordered_map<std::string_view, int> intsTmp;
370373

src/btop_draw.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,8 @@ namespace Draw {
23762376
auto swap_disk = Config::getB("swap_disk");
23772377
auto mem_graphs = Config::getB("mem_graphs");
23782378

2379-
width = round((double)Term::width * (Proc::shown ? width_p : 100) / 100);
2379+
const int new_width = round((double)Term::width * (Proc::shown ? (100 - Config::getI("proc_box_width_percent")) : 100) / 100);
2380+
width = clamp(new_width, min_width, Term::width - Proc::min_width);
23802381
#ifdef GPU_SUPPORT
23812382
height = ceil((double)Term::height * (100 - Net::height_p * Net::shown*4 / ((Gpu::shown != 0 and Cpu::shown) + 4)) / 100) - Cpu::height - Gpu::total_height;
23822383
#else
@@ -2440,7 +2441,8 @@ namespace Draw {
24402441
//* Calculate and draw net box outlines
24412442
if (Net::shown) {
24422443
using namespace Net;
2443-
width = round((double)Term::width * (Proc::shown ? width_p : 100) / 100);
2444+
const int new_width = round((double)Term::width * (Proc::shown ? (100 - Config::getI("proc_box_width_percent")) : 100) / 100);
2445+
width = clamp(new_width, min_width, Term::width - Proc::min_width);
24442446
#ifdef GPU_SUPPORT
24452447
height = Term::height - Cpu::height - Gpu::total_height - Mem::height;
24462448
#else

src/btop_input.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ namespace Input {
5454
{"OB", "down"},
5555
{"[D", "left"},
5656
{"OD", "left"},
57+
{"[1;2D", "shift_left"},
5758
{"[C", "right"},
5859
{"OC", "right"},
60+
{"[1;2C", "shift_right"},
61+
{"[1;2B", "shift_down"},
5962
{"[2~", "insert"},
6063
{"[4h", "insert"},
6164
{"[3~", "delete"},
@@ -275,6 +278,28 @@ namespace Input {
275278
Draw::calcSizes();
276279
Runner::run("all", false, true);
277280
return;
281+
}
282+
else if (is_in(key, "shift_left", "shift_right")) {
283+
if (Proc::shown and (Mem::shown or Net::shown)) {
284+
int proc_box_width_percent = Config::getI("proc_box_width_percent");
285+
const int min_p = round(((double)Proc::min_width / (double)Term::width) * 100);
286+
const int max_p = round(100 - (((double)Mem::min_width / (double)Term::width) * 100));
287+
if (key == "shift_left")
288+
proc_box_width_percent = Config::getB("proc_left") ? std::max(min_p, --proc_box_width_percent) : std::min(max_p, ++proc_box_width_percent);
289+
else
290+
proc_box_width_percent = Config::getB("proc_left") ? std::min(max_p, ++proc_box_width_percent) : std::max(min_p, --proc_box_width_percent);
291+
292+
Config::set("proc_box_width_percent", proc_box_width_percent);
293+
Draw::calcSizes();
294+
Runner::run("all", false, true);
295+
}
296+
return;
297+
}
298+
else if (key == "shift_down") {
299+
Config::set("proc_box_width_percent", 55);
300+
Draw::calcSizes();
301+
Runner::run("all", false, true);
302+
return;
278303
} else if (is_in(key, "ctrl_r")) {
279304
kill(getpid(), SIGUSR2);
280305
return;

src/btop_menu.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ namespace Menu {
211211
{"Selected k", "Kill selected process with SIGKILL - 9."},
212212
{"Selected s", "Select or enter signal to send to process."},
213213
{"Selected N", "Select new nice value for selected process."},
214+
{"Shift + Left", "Make the proc box wider when mem or net shown."},
215+
{"Shift + Right", "Make the proc box narrower when mem or net shown."},
216+
{"Shift + Down", "Reset the proc width offset to 0"},
214217
{"", " "},
215218
{"", "For bug reporting and project updates, visit:"},
216219
{"", "https://github.com/aristocratos/btop"},

0 commit comments

Comments
 (0)