Add resolution support

This commit is contained in:
Guaxinim5573 2021-04-15 18:52:12 -03:00
parent 63593a9328
commit de452de49c

View file

@ -50,12 +50,15 @@ int ram_total, ram_used = 0;
int pkgs, target_width = 0;
// all flags available
int ascii_image_flag = 0,
screen_width = 0,
screen_height = 0,
show_user_info = 1,
show_os = 1,
show_kernel = 1,
show_cpu = 1,
show_gpu = 1,
show_ram = 1,
show_resolution = 1,
show_shell = 1,
show_pkgs = 1,
show_uptime = 1,
@ -161,6 +164,8 @@ void parse_config()
show_gpu = 0;
if (sscanf(line, "noram%s", temp_buffer))
show_ram = 0;
if (sscanf(line, "noresolution%s", temp_buffer))
show_resolution = 0;
if (sscanf(line, "noshell%s", temp_buffer))
show_shell = 0;
if (sscanf(line, "nopkgs%s", temp_buffer))
@ -239,6 +244,9 @@ void print_info()
if (show_ram)
printf("\033[18C%s%sWAM %s%i MB/%i MB\n",
NORMAL, BOLD, NORMAL, (ram_used), ram_total);
if (show_resolution)
printf("\033[18C%s%sRESOLUTION%s %dx%d\n",
NORMAL, BOLD, NORMAL, screen_width, screen_height);
if (show_shell)
printf("\033[18C%s%sSHELL %s%s\n",
NORMAL, BOLD, NORMAL, shell);
@ -263,7 +271,7 @@ void get_info()
// terminal width used to truncate long names
ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
target_width = win.ws_col - 28;
target_width = win.ws_col - 30;
// os version
FILE *os_release = fopen("/etc/os-release", "r");
@ -373,6 +381,14 @@ void get_info()
truncate_name(gpu_model[i]);
}
// Resolution
FILE *resolution = popen("xwininfo -root 2> /dev/null | grep -E 'Width|Height'", "r");
while (fgets(line, sizeof(line), resolution))
{
sscanf(line, " Width: %d", &screen_width);
sscanf(line, " Height: %d", &screen_height);
}
// package count
pkgs = pkgman();
}