From 466195ac6acc88bdfe8c06adf3cc6c4e8ef63783 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Mon, 15 Apr 2024 17:17:34 +0600 Subject: [PATCH] Test fix for drivers getting --- source/CMakeLists.txt | 8 ++- source/ubl-settings-video.c | 129 ++++++++++++++++++++++-------------- source/ubl-settings-video.h | 2 + source/ubl-utils.c | 15 +++++ source/ubl-utils.h | 4 ++ 5 files changed, 106 insertions(+), 52 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index eaf0053..7e921c4 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -13,6 +13,11 @@ include_directories(${VTE291_INCLUDE_DIRS}) link_directories(${VTE291_LIBRARY_DIRS}) add_definitions(${VTE291_CFLAGS_OTHER}) +pkg_check_modules(JSON REQUIRED json-c) +include_directories(${JSON_INCLUDE_DIRS}) +link_directories(${JSON_LIBRARY_DIRS}) +add_definitions(${JSON_CFLAGS_OTHER}) + find_library(WEBKIT_LIBRARIES_FOUND webkit2gtk-4.0 webkit2gtk-web-extension-4.0) option(WEBKIT_FOUND "No" OFF) @@ -83,7 +88,8 @@ set(SOURCE_FILES set(LIBRARIES ${GTK_LIBRARIES} ${WEBKIT_LIBRARIES} - ${VTE291_LIBRARIES} + ${VTE291_LIBRARIES} + ${JSON_LIBRARIES} pthread) diff --git a/source/ubl-settings-video.c b/source/ubl-settings-video.c index 86613dd..f9c7aff 100644 --- a/source/ubl-settings-video.c +++ b/source/ubl-settings-video.c @@ -1526,57 +1526,84 @@ void yon_monitor_set_resolutions(){ void yon_adapter_window_setup(widgets_dict *widgets){ int size=0; gtk_overlay_add_overlay(GTK_OVERLAY(widgets->InformationOverlay),widgets->InformationCompanyLogoImage); - config_str rtn = yon_config_load(get_adapter_info,&size); - char *desc = yon_config_get_parameter(rtn,size,"description"); - yon_char_divide_search(desc,"=",-1); - char *product = yon_config_get_parameter(rtn,size,"product"); - yon_char_divide_search(product,"=",-1); - char *vendor = yon_config_get_parameter(rtn,size,"vendor"); - yon_char_divide_search(vendor,"=",-1); - char *driver_use = yon_config_get_parameter(rtn,size,"Kernel-driver-in-use"); - yon_char_divide_search(driver_use,"=",-1); - char *driver_all = yon_config_get_parameter(rtn,size,"Kernel-modules"); - yon_char_divide_search(driver_all,"=",-1); - char *final_text = yon_char_unite("",DESCRIPTION_LABEL,": ",_(desc), - "\n",VENDOR_LABEL,": ",vendor, - "\n",MODEL_LABEL,": ",product, - "\n",USED_KERNEL_DRIVER_LABEL,": ",driver_use, - "\n",AVALIABLE_KERNEL_DRIVERS_LABEL,": ",driver_all,"",NULL); - gtk_label_set_markup(GTK_LABEL(gtk_builder_get_object(widgets->builder,"InformationLabel")),final_text); - if (strstr(vendor,"Intel")){ - GtkIconTheme *icthm=gtk_icon_theme_get_default(); - gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->InformationCompanyLogoImage),gtk_icon_info_load_icon(gtk_icon_theme_lookup_icon_for_scale(icthm, "com.ublinux.ubl-settings-video.intel-logo",64,1,GTK_ICON_LOOKUP_FORCE_SVG),NULL)); - } - else if (strstr(vendor,"NVIDIA")){ - GtkIconTheme *icthm=gtk_icon_theme_get_default(); - gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->InformationCompanyLogoImage),gtk_icon_info_load_icon(gtk_icon_theme_lookup_icon_for_scale(icthm, "com.ublinux.ubl-settings-video.nvidia-logo",64,1,GTK_ICON_LOOKUP_FORCE_SVG),NULL)); - } - else if (strstr(vendor,"AMD")||strstr(vendor,"Advanced Micro Devices")){ - GtkIconTheme *icthm=gtk_icon_theme_get_default(); - gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->InformationCompanyLogoImage),gtk_icon_info_load_icon(gtk_icon_theme_lookup_icon_for_scale(icthm, "com.ublinux.ubl-settings-video.amd-logo",64,1,GTK_ICON_LOOKUP_FORCE_SVG),NULL)); - } - else if (strstr(vendor,"VMware")){ - GtkIconTheme *icthm=gtk_icon_theme_get_default(); - gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->InformationCompanyLogoImage),gtk_icon_info_load_icon(gtk_icon_theme_lookup_icon_for_scale(icthm, "com.ublinux.ubl-settings-video.vmware-logo",64,1,GTK_ICON_LOOKUP_FORCE_SVG),NULL)); - } - else { - gtk_widget_destroy(widgets->InformationCompanyLogoImage); - } - if (size>5){ - gtk_overlay_add_overlay(GTK_OVERLAY(widgets->InformationOverlay2),widgets->InformationCompanyLogoImage2); - rtn=yon_char_parsed_rip(rtn,&size,0); - rtn=yon_char_parsed_rip(rtn,&size,0); - rtn=yon_char_parsed_rip(rtn,&size,0); - char *desc = yon_config_get_parameter(rtn,size,"description"); - yon_char_divide_search(desc,"=",-1); - char *product = yon_config_get_parameter(rtn,size,"product"); - yon_char_divide_search(product,"=",-1); - char *vendor = yon_config_get_parameter(rtn,size,"vendor"); - yon_char_divide_search(vendor,"=",-1); - char *driver_use = yon_config_get_parameter(rtn,size,"Kernel-driver-in-use"); - yon_char_divide_search(driver_use,"=",-1); - char *driver_all = yon_config_get_parameter(rtn,size,"Kernel-modules"); - yon_char_divide_search(driver_all,"=",-1); + config_str rtn = yon_config_load(get_adapter_info_json,&size); + struct json_object *jsobject = json_tokener_parse(yon_char_parsed_to_string(rtn,size,""));{ + struct json_object *item_obj = json_object_array_get_idx(jsobject, 0); + struct json_object *unit_obj; + const char *desc=""; + if (json_object_object_get_ex(item_obj, "description", &unit_obj)) { + desc = json_object_get_string(unit_obj); + } + const char *product =""; + if (json_object_object_get_ex(item_obj, "product", &unit_obj)) { + product = json_object_get_string(unit_obj); + } + const char *vendor=""; + if (json_object_object_get_ex(item_obj, "vendor", &unit_obj)) { + vendor = json_object_get_string(unit_obj); + } + const char *driver_use=""; + if (json_object_object_get_ex(item_obj, "configuration", &unit_obj)) { + if (json_object_object_get_ex(unit_obj, "driver", &unit_obj)) + driver_use = json_object_get_string(unit_obj); + } + const char *driver_all=""; + if (json_object_object_get_ex(item_obj, "configuration", &unit_obj)) { + if (json_object_object_get_ex(unit_obj, "driver", &unit_obj)) + driver_all = json_object_get_string(unit_obj); + } + char *final_text = yon_char_unite("",DESCRIPTION_LABEL,": ",_(desc), + "\n",VENDOR_LABEL,": ",vendor, + "\n",MODEL_LABEL,": ",product, + "\n",USED_KERNEL_DRIVER_LABEL,": ",driver_use, + "\n",AVALIABLE_KERNEL_DRIVERS_LABEL,": ",driver_all,"",NULL); + gtk_label_set_markup(GTK_LABEL(gtk_builder_get_object(widgets->builder,"InformationLabel")),final_text); + if (strstr(vendor,"Intel")){ + GtkIconTheme *icthm=gtk_icon_theme_get_default(); + gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->InformationCompanyLogoImage),gtk_icon_info_load_icon(gtk_icon_theme_lookup_icon_for_scale(icthm, "com.ublinux.ubl-settings-video.intel-logo",64,1,GTK_ICON_LOOKUP_FORCE_SVG),NULL)); + } + else if (strstr(vendor,"NVIDIA")){ + GtkIconTheme *icthm=gtk_icon_theme_get_default(); + gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->InformationCompanyLogoImage),gtk_icon_info_load_icon(gtk_icon_theme_lookup_icon_for_scale(icthm, "com.ublinux.ubl-settings-video.nvidia-logo",64,1,GTK_ICON_LOOKUP_FORCE_SVG),NULL)); + } + else if (strstr(vendor,"AMD")||strstr(vendor,"Advanced Micro Devices")){ + GtkIconTheme *icthm=gtk_icon_theme_get_default(); + gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->InformationCompanyLogoImage),gtk_icon_info_load_icon(gtk_icon_theme_lookup_icon_for_scale(icthm, "com.ublinux.ubl-settings-video.amd-logo",64,1,GTK_ICON_LOOKUP_FORCE_SVG),NULL)); + } + else if (strstr(vendor,"VMware")){ + GtkIconTheme *icthm=gtk_icon_theme_get_default(); + gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->InformationCompanyLogoImage),gtk_icon_info_load_icon(gtk_icon_theme_lookup_icon_for_scale(icthm, "com.ublinux.ubl-settings-video.vmware-logo",64,1,GTK_ICON_LOOKUP_FORCE_SVG),NULL)); + } + else { + gtk_widget_destroy(widgets->InformationCompanyLogoImage); + } + } + gtk_overlay_add_overlay(GTK_OVERLAY(widgets->InformationOverlay2),widgets->InformationCompanyLogoImage2); + struct json_object *item_obj = json_object_array_get_idx(jsobject, 1); + if (item_obj){ + struct json_object *unit_obj; + const char *desc=""; + if (json_object_object_get_ex(item_obj, "description", &unit_obj)) { + desc = json_object_get_string(unit_obj); + } + const char *product =""; + if (json_object_object_get_ex(item_obj, "product", &unit_obj)) { + product = json_object_get_string(unit_obj); + } + const char *vendor=""; + if (json_object_object_get_ex(item_obj, "vendor", &unit_obj)) { + vendor = json_object_get_string(unit_obj); + } + const char *driver_use=""; + if (json_object_object_get_ex(item_obj, "capabilities", &unit_obj)) { + if (json_object_object_get_ex(unit_obj, "driver", &unit_obj)) + driver_use = json_object_get_string(unit_obj); + } + const char *driver_all=""; + if (json_object_object_get_ex(item_obj, "capabilities", &unit_obj)) { + if (json_object_object_get_ex(unit_obj, "driver", &unit_obj)) + driver_all = json_object_get_string(unit_obj); + } char *final_text = yon_char_unite("",DESCRIPTION_LABEL,": ",_(desc), "\n",VENDOR_LABEL,": ",vendor, "\n",MODEL_LABEL,": ",product, diff --git a/source/ubl-settings-video.h b/source/ubl-settings-video.h index 8a1dd84..5f13a03 100644 --- a/source/ubl-settings-video.h +++ b/source/ubl-settings-video.h @@ -16,6 +16,7 @@ #include #include #include +#include #include "ubl-utils.h" #include "ubl-strings.h" #ifndef UBL_SETINGS_VIDEO_H @@ -82,6 +83,7 @@ // #define get_proprietary_drivers_command "LC_ALL=C pacman -Ss ubm-nvidia-.* |grep -oE \"[a-zA-Z-]{1,}nvidia-[a-zA-Z0-9-]{1,}|installed\"|sed ':a;N;$!ba;s/\\ninstalled/ installed/g'" #define get_adapter_info "lshw -c display -quiet |grep -oE \"vendor:[0-9a-zA-Z ]{1,}|description:[0-9a-zA-Z ]{1,}|product:[]0-9a-zA-Z [-]{1,}\"|sed 's/: /=/g';lspci | grep -E ' VGA | Display ' | cut -d\" \" -f 1 | xargs -i lspci -v -s {} |grep -oE \"Kernel[:a-zA-Z0-9: ,_]{1,}\"|sed 's/: /=/g'|sed 's/ /-/g'" +#define get_adapter_info_json "lshw -c display -quiet -json" #define XORG_MONITOR(port) yon_char_append(" XORG_MONITOR[",yon_char_append(port,"] ")) diff --git a/source/ubl-utils.c b/source/ubl-utils.c index 1a1d565..ff1c3d0 100644 --- a/source/ubl-utils.c +++ b/source/ubl-utils.c @@ -704,6 +704,21 @@ char **yon_char_parsed_rip(char **char_string, int *size, int item_to_delete){ } else return NULL; } +char *yon_char_parsed_to_string(config_str parsed, int size, char *divider_replace){ + if (parsed && size>0){ + char *final_string = ""; + char *temp; + for (int i=0;i