Changed gpu printing logic

This commit is contained in:
TheDarkBug 2023-03-24 19:41:41 +01:00
parent 63850f3b6e
commit 879d5cc976
5 changed files with 37 additions and 29 deletions

View File

@ -5,9 +5,8 @@ os=true
host=true
kernel=true
cpu=true
gpu=0
gpu=3
gpu=1
gpu=1 # disables the gpu[1] (array goes from 0 to 255)
gpus=true # enables all gpus (except 1 that got disabled before)
ram=true
resolution=false
shell=true

View File

@ -282,6 +282,7 @@ void* get_ram(void* argp) {
// tries to get installed gpu(s)
void* get_gpu(void* argp) {
if (!((struct thread_varg*)argp)->thread_flags[2]) return 0;
LOG_I("getting gpu(s)");
char* buffer = ((struct thread_varg*)argp)->buffer;
struct info* user_info = ((struct thread_varg*)argp)->user_info;
int gpuc = 0; // gpu counter

View File

@ -106,7 +106,7 @@ struct info {
model[256], // model name
kernel[256], // kernel name (linux 5.x-whatever)
os_name[64], // os name (arch linux, windows, mac os)
cpu_model[256], gpu_model[64][256],
cpu_model[256], gpu_model[256][256],
pkgman_name[64], // package managers string
image_name[128];
int target_width, // for the truncate_str function

View File

@ -44,18 +44,17 @@ The user config file is located in $HOME/.config/uwufetch/config (you need to cr
.TP
.SH EXAMPLE
.EX
distro=arch
image=path/to/custom/image.png
#distro=arch
#image=~/Pictures/picture.png
user=true
os=true
host=true
kernel=true
cpu=true
gpu=0
gpu=3
gpu=1
gpu=1 # disables the gpu[1] (array goes from 0 to 255)
gpus=true # enables all gpus (except 1 that got disabled before)
ram=true
resolution=true
resolution=false
shell=true
pkgs=true
uptime=true

View File

@ -55,7 +55,8 @@ struct configuration {
struct flags show; // all true by default
bool show_image, // false by default
show_colors; // true by default
int show_gpu[256]; // if show_gpu[0] == -2, all gpus are shown, if == -3 no gpu is shown
bool show_gpu[256];
bool show_gpus; // global gpu toggle
};
// user's config stored on the disk
@ -72,10 +73,8 @@ struct configuration parse_config(struct info* user_info, struct user_config* us
// enabling all flags by default
struct configuration config_flags;
memset(&config_flags, true, sizeof(config_flags));
memset(&config_flags.show_gpu, -1, 256 * sizeof(int)); // -1 means 'undefined'
config_flags.show_gpu[0] = -2; // show all gpus
config_flags.show_image = false;
config_flags.show_image = false;
FILE* config = NULL; // config file pointer
@ -136,12 +135,27 @@ struct configuration parse_config(struct info* user_info, struct user_config* us
config_flags.show.cpu = strcmp(buffer, "false");
LOG_V(config_flags.show.cpu);
}
if (sscanf(buffer, "gpu=%d", &config_flags.show_gpu[gpu_cfg_count])) {
gpu_cfg_count++; // enabling single gpu
if (sscanf(buffer, "gpu=%[truefalse]", buffer)) {
if (strcmp(buffer, "false") == 0) config_flags.show_gpu[0] = -3; // enabling/disabling all gpus
LOG_V(config_flags.show_gpu[gpu_cfg_count]);
if (sscanf(buffer, "gpu=%d", &gpu_cfg_count)) {
if (gpu_cfg_count > 255) {
LOG_W("gpu config index is too high, setting it to 255");
gpu_cfg_count = 255;
} else if (gpu_cfg_count < 0) {
LOG_W("gpu config index is too low, setting it to 0");
gpu_cfg_count = 0;
}
config_flags.show_gpu[gpu_cfg_count] = false;
LOG_V(config_flags.show_gpu[gpu_cfg_count]);
}
if (sscanf(buffer, "gpus=%[truefalse]", buffer)) { // global gpu toggle
if (strcmp(buffer, "false") == 0) {
config_flags.show_gpus = false;
config_flags.show.gpu = false; // enable getting gpu info
} else {
config_flags.show_gpus = true;
config_flags.show.gpu = true;
}
LOG_V(config_flags.show_gpus);
LOG_V(config_flags.show.gpu);
}
if (sscanf(buffer, "ram=%[truefalse]", buffer)) {
config_flags.show.ram = strcmp(buffer, "false");
@ -171,7 +185,6 @@ struct configuration parse_config(struct info* user_info, struct user_config* us
LOG_V(user_info->os_name);
LOG_V(user_info->image_name);
fclose(config);
config_flags.show.gpu = (config_flags.show_gpu[0] == -2);
return config_flags;
}
@ -451,15 +464,10 @@ int print_info(struct configuration* config_flags, struct info* user_info) {
if (config_flags->show.cpu)
responsively_printf(print_buf, "%s%s%sCPUWU %s%s", MOVE_CURSOR, NORMAL, BOLD, NORMAL, user_info->cpu_model);
if (config_flags->show_gpu[0] == -2) { // print all gpu models
for (int i = 0; i < 256 && user_info->gpu_model[i][0]; i++)
responsively_printf(print_buf, "%s%s%sGPUWU %s%s", MOVE_CURSOR, NORMAL, BOLD, NORMAL, user_info->gpu_model[i]);
} else if (config_flags->show_gpu[0] != -3) { // print only the configured gpu models
for (int i = 0; i < 256; i++) {
if (config_flags->show_gpu[i] >= 0)
if (user_info->gpu_model[config_flags->show_gpu[i]][0])
responsively_printf(print_buf, "%s%s%sGPUWU %s%s", MOVE_CURSOR, NORMAL, BOLD, NORMAL, user_info->gpu_model[config_flags->show_gpu[i]]);
}
for (int i = 0; i < 256; i++) {
if (config_flags->show_gpu[i])
if (user_info->gpu_model[i][0])
responsively_printf(print_buf, "%s%s%sGPUWU %s%s", MOVE_CURSOR, NORMAL, BOLD, NORMAL, user_info->gpu_model[i]);
}
if (config_flags->show.ram) // print ram
@ -774,6 +782,7 @@ int main(int argc, char* argv[]) {
}
if (!user_config_file.read_enabled)
get_info(config_flags.show, &user_info);
LOG_V(user_info.gpu_model[1]);
if (user_config_file.write_enabled) {
write_cache(&user_info);