Skip to content

Commit 314315e

Browse files
committed
Adjust proc_box width with Shift+arrow keys
1 parent 42404c5 commit 314315e

5 files changed

Lines changed: 42 additions & 14 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,8 +1403,9 @@ proc_info_smaps = false
14031403
#* Show proc box on left side of screen instead of right.
14041404
proc_left = false
14051405
1406-
#* Make the proc box wider when Net or Mem boxes are shown.
1407-
proc_box_wide = false
1406+
#* Offset value for proc box width when mem or net is shown.
1407+
#* negative values make the proc box larger, positive values make it smaller
1408+
proc_box_width_offset = 0
14081409
14091410
#* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop).
14101411
proc_filter_kernel = false

src/btop_config.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@ namespace Config {
117117
{"proc_info_smaps", "#* Use /proc/[pid]/smaps for memory information in the process info box (very slow but more accurate)"},
118118

119119
{"proc_left", "#* Show proc box on left side of screen instead of right."},
120-
121-
{"proc_box_wide", "#* Make the proc box wider when Net or Mem boxes are shown."},
122120

121+
{"proc_box_width_offset", "#* Offset value for proc box width when mem or net is shown.\n"
122+
"#* negative values make the proc box larger, positive values make it smaller"},
123+
123124
{"proc_filter_kernel", "#* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop)."},
124125

125126
{"proc_follow_detailed", "#* Should the process list follow the selected process when detailed view is open."},
@@ -342,7 +343,6 @@ namespace Config {
342343
{"proc_follow_detailed", true},
343344
{"follow_process", false},
344345
{"update_following", false},
345-
{"proc_box_wide", false},
346346
#ifdef GPU_SUPPORT
347347
{"nvml_measure_pcie_speeds", true},
348348
{"rsmi_measure_pcie_speeds", true},
@@ -366,6 +366,7 @@ namespace Config {
366366
{"proc_selected", 0},
367367
{"proc_last_selected", 0},
368368
{"proc_followed", 0},
369+
{"proc_box_width_offset", 0},
369370
};
370371
std::unordered_map<std::string_view, int> intsTmp;
371372

src/btop_draw.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,8 +2347,11 @@ namespace Draw {
23472347
auto swap_disk = Config::getB("swap_disk");
23482348
auto mem_graphs = Config::getB("mem_graphs");
23492349

2350-
const bool is_proc_box_wide = Config::getB("proc_box_wide") and Proc::shown;
2351-
width = is_proc_box_wide ? min_width : round((double)Term::width * (Proc::shown ? width_p : 100) / 100);
2350+
width = round((double)Term::width * (Proc::shown ? width_p : 100) / 100) + (Proc::shown ? Config::getI("proc_box_width_offset") : 0);
2351+
if (width < min_width) {
2352+
Config::set("proc_box_width_offset", Config::getI("proc_box_width_offset") + (min_width - width));
2353+
width = min_width;
2354+
}
23522355
#ifdef GPU_SUPPORT
23532356
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;
23542357
#else
@@ -2412,8 +2415,11 @@ namespace Draw {
24122415
//* Calculate and draw net box outlines
24132416
if (Net::shown) {
24142417
using namespace Net;
2415-
const bool is_proc_box_wide = Config::getB("proc_box_wide") and Proc::shown;
2416-
width = is_proc_box_wide ? min_width : round((double)Term::width * (Proc::shown ? width_p : 100) / 100);
2418+
width = round((double)Term::width * (Proc::shown ? width_p : 100) / 100) + (Proc::shown ? Config::getI("proc_box_width_offset") : 0);
2419+
if (width < min_width) {
2420+
Config::set("proc_box_width_offset", Config::getI("proc_box_width_offset") + (min_width - width));
2421+
width = min_width;
2422+
}
24172423
#ifdef GPU_SUPPORT
24182424
height = Term::height - Cpu::height - Gpu::total_height - Mem::height;
24192425
#else
@@ -2448,6 +2454,11 @@ namespace Draw {
24482454
if (Proc::shown) {
24492455
using namespace Proc;
24502456
width = Term::width - (Mem::shown ? Mem::width : (Net::shown ? Net::width : 0));
2457+
if (width < min_width) {
2458+
Config::set("proc_box_width_offset", Config::getI("proc_box_width_offset") - (min_width - width));
2459+
width = min_width;
2460+
calcSizes();
2461+
}
24512462
#ifdef GPU_SUPPORT
24522463
height = Term::height - Cpu::height - Gpu::total_height;
24532464
#else

src/btop_input.cpp

Lines changed: 17 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,20 @@ 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+
Config::set("proc_box_width_offset", Config::getI("proc_box_width_offset") + (key == "shift_left" ? (Config::getB("proc_left") ? 1 : -1) : (Config::getB("proc_left") ? -1 : 1)));
285+
Draw::calcSizes();
286+
Runner::run("all", false, true);
287+
}
288+
return;
289+
}
290+
else if (key == "shift_down") {
291+
Config::set("proc_box_width_offset", 0);
292+
Draw::calcSizes();
293+
Runner::run("all", false, true);
294+
return;
278295
} else if (is_in(key, "ctrl_r")) {
279296
kill(getpid(), SIGUSR2);
280297
return;

src/btop_menu.cpp

Lines changed: 3 additions & 5 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"},
@@ -795,11 +798,6 @@ namespace Menu {
795798
"",
796799
"Show proc box on left side of screen",
797800
"instead of right."},
798-
{"proc_box_wide",
799-
"Wider proc box.",
800-
"",
801-
"The proc box will be wider when the",
802-
"net or mem boxes are shown."},
803801
{"graph_symbol_proc",
804802
"Graph symbol to use for graphs in proc box.",
805803
"",

0 commit comments

Comments
 (0)