You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ubl-settings-video/source/ubl-settings-video.h

373 lines
14 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <gtk/gtk.h>
#include <gtk/gtkx.h>
#include "ubl-cmake.h"
#ifdef WEBKIT_FOUND
#include <webkit2/webkit2.h>
#endif
#include <vte/vte.h>
#include <locale.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <libintl.h>
#include <sys/types.h>
#include <fcntl.h>
#include <getopt.h>
#include <libintl.h>
#include <time.h>
#include <json-c/json.h>
// #include "ubl-utils.h"
#include "ubl-strings.h"
#define VTE_INCLUDE
#include <libublsettings.h>
#include <libublsettings-gtk3.h>
#include <libublsettingsui-gtk3.h>
#ifndef UBL_SETINGS_VIDEO_H
#define UBL_SETINGS_VIDEO_H
#define WIKI_LINK " https://wiki.ublinux.ru/ru/Программное_обеспечениерограммы_и_утилиты/Все/ubl-settings-video"
#define HOMEPAGE_LINK _("https://wiki.ublinux.com")
#define icon_name "com.ublinux.ubl-settings-video"
#define banner_path "/com/ublinux/images/ubl-settings-video-banner.png"
#define glade_path "/com/ublinux/ui/ubl-settings-video.glade"
#define glade_path_monitor "/com/ublinux/ui/ubl-settings-video-monitor.glade"
#define glade_path_configuration "/com/ublinux/ui/ubl-settings-video-configuration.glade"
#define LocalePath "/usr/share/locale"
#define LocaleName "ubl-settings-video"
#define CssPath "/com/ublinux/css/ubl-settings-video.css"
#define StatusLoadGlobalFailed _("Failed to load global configuration")
#define StatusLoadLocalFailed _("Failed to load local configuration")
#define StatusSaveGlobalFailed _("Saving to global configuration Succeeded")
#define StatusSaveLocalFailed _("Saving to local configuration Succeeded")
#define get_ports_command "xrandr |grep -E \"*connected\" |cut -d' ' -f1"
#define get_resolutions_command "xrandr |grep -noP \"\\d+x+\\d+\""
#define get_resolution_ports_command "xrandr |grep -nwP \"connected\" |grep -oE \"[-0-9a-zA-Z:]{1,} connected\" |grep -oE \"[-0-9a-zA-Z:]{1,} \""
#define get_proprietary_drivers_info_command "cut -d';' -f2- /usr/share/ubl-settings-video/csv/video-drivers.csv"
#define get_resolutions_supportable_command "/usr/share/ubl-settings-video/csv/resolutions.csv"
#define get_frequences_command "xrandr |grep -v -n \"[a-z][a-z]\" |sed 's/ * / /g' |cut -d' ' -f1,3-"
#define load_drivers_command "/usr/bin/ubconfig --default --source "
#define load_drivers_global_command "/usr/bin/ubconfig --default --source global get video FAILSAFENVIDIA FAILSAFEATI OPTIRUN PRIMUSRUN VGADRV_AUTO "
#define save_drivers_global_command "/usr/bin/ubconfig --target global --noexecute set video "
#define save_drivers_global_local_command "/usr/bin/ubconfig set video "
#define load_drivers_local_command "/usr/bin/ubconfig --default --source system get video FAILSAFENVIDIA FAILSAFEATI OPTIRUN PRIMUSRUN VGADRV_AUTO "
#define save_drivers_local_command "/usr/bin/ubconfig --target system set video "
#define remove_drivers_global_command "/usr/bin/ubconfig --target system remove video "
#define remove_drivers_local_command "/usr/bin/ubconfig --target system remove video "
#define install_proprietary_command "pacman --quiet --needed --noconfirm -Sy "
#define delete_proprietary_command "pacman -R --noconfirm "
#define get_info_proprietary_command "pamac-manager --details="
#define get_version_proprietary_command "grep \"VERSION_ID=\" /etc/os-release | cut -d= -f2"
#define get_proprietary_drivers_command "pacman -Sysq 'ubm-nvidia-.*|amdgpu|^nvidia-[0-9]{1,}[a-zA-Z]{0,}-dkms|^mesa$|^xf86-video-intel$|^lib32-vulkan-intel$'"
#define get_proprietary_drivers_local_command "pacman -Qq |grep -E 'nvidia|^vulkan-amdgpu|^amdgpu-pro-libgl'"
#define get_proprietary_installed_command "pacman -Qsq 'ubm-nvidia-.*|amdgpu|^nvidia-[0-9]{1,}[a-zA-Z]{0,}-dkms|^mesa$|^xf86-video-intel$|^lib32-vulkan-intel$'"
// #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 get_drivers_for_card_command "lspci | grep -E ' VGA | Display ' | cut -d' ' -f 1 | xargs -i lspci -k -s {}|grep Kernel|sed -e 's/^\t*//g' -e 's/Kernel driver in use: /uses=/g' -e 's/Kernel modules: /all=/g'"
#define XORG_MONITOR(port) yon_char_append("XORG_MONITOR[",yon_char_append(port,"]"))
#define VGADRV_AUTO "VGADRV_AUTO"
#define VGADRV_NOFREE "VGADRV_NOFREE"
#define XORG_EXT "XORG_EXT"
#define XORG_DPI "XORG_DPI"
#define FAILSAFEATI "FAILSAFEATI"
#define FAILSAFENVIDIA "FAILSAFENVIDIA"
#define OPTIRUN "OPTIRUN"
#define PRIMUSRUN "PRIMUSRUN"
#define INTEGRATEDVGA "INTEGRATEDVGA"
#define KWIN_TRIPLE_BUFFER "\"export KWIN_TRIPLE_BUFFER"
#define GL_YIELD "\"export __GL_YIELD"
#define VGADRV_AUTO_command "ubconfig --source global get [video] VGADRV_AUTO"
#define VGADRV_NOFREE_command "ubconfig --source global get [video] VGADRV_NOFREE"
#define XORG_EXT_command "ubconfig --source global get [video] XORG_EXT"
#define XORG_DPI_command "ubconfig --source global get [video] XORG_DPI"
#define FAILSAFEATI_command "ubconfig --source global get [video] FAILSAFEATI"
#define FAILSAFENVIDIA_command "ubconfig --source global get [video] FAILSAFENVIDIA"
#define OPTIRUN_command "ubconfig --source global get [video] OPTIRUN"
#define PRIMUSRUN_command "ubconfig --source global get [video] PRIMUSRUN"
#define INTEGRATEDVGA_command "ubconfig --source global get [video] INTEGRATEDVGA"
#define KWIN_TRIPLE_BUFFER_command "ubconfig --source global get [/etc/profile.d/ublinux.sh] KWIN_TRIPLE_BUFFER"
#define GL_YIELD_command "ubconfig --source global get [/etc/profile.d/ublinux.sh] __GL_YIELD"
#define XORG_PARAMETER "XORG_MONITOR"
#define config_get_command(target) yon_char_append("cat ",target)
#define yon_config_get_custom_command(target) yon_char_unite("ubconfig --source ",target," get [video] XORG_MONITOR[*] VGADRV_AUTO VGADRV_NOFREE XORG_EXT XORG_DPI FAILSAFEATI FAILSAFENVIDIA OPTIRUN PRIMUSRUN INTEGRATEDVGA",NULL)
#define config_get_local_command "ubconfig --source system get [video] XORG_MONITOR[*] VGADRV_AUTO VGADRV_NOFREE XORG_EXT XORG_DPI FAILSAFEATI FAILSAFENVIDIA OPTIRUN PRIMUSRUN INTEGRATEDVGA"
#define config_get_global_command yon_char_new("ubconfig --source global get [video] XORG_MONITOR[*] VGADRV_AUTO VGADRV_NOFREE XORG_EXT XORG_DPI FAILSAFEATI FAILSAFENVIDIA OPTIRUN PRIMUSRUN INTEGRATEDVGA")
#define config_get_default_command ""
#define config_get_global_only_parameters ""
#define config_get_local_only_parameters ""
#define XORG_MONITOR_get_command "ubconfig --source global get [video] XORG_MONITOR[*]"
char *drivers_always_active[] = { "mesa","lib32-vulkan-intel","xf86-video-intel"};
int drivers_always_active_size = 3;
typedef struct{
char* command;
void *data;
} thread_input;
char *local;
typedef char *string;
string version_application;
#define _(String) gettext(String)
typedef dictionary* monitor_config;
typedef dictionary* proprietary_config;
typedef dictionary* monitor_view;
typedef struct {
config_str line;
int size;
} resolution_supported;
typedef struct
{
template_window_fields
GtkWidget *AutoDriverCombo;
GtkWidget *FreeDriverCombo;
GtkWidget *FailsafeNvidiaCombo;
GtkWidget *FailsafeAMDCombo;
GtkWidget *MonitorsBox;
GtkWidget *DontSwitchDisplaysOffCombo;
GtkWidget *DisplayScalingCombo;
GtkWidget *DisplayDiscreteOnly;
GtkWidget *OptirunCombo;
GtkWidget *OptirunEntry;
GtkWidget *OptirunButton;
GtkWidget *PrimusrunCombo;
GtkWidget *PrimusrunEntry;
GtkWidget *PrimusrunButton;
GtkWidget *FrameGapCombo;
GtkWidget *proprietaryTreeView;
GtkWidget *proprietaryInfoButton;
GtkWidget *proprietaryDeleteButton;
GtkWidget *proprietaryInstallButton;
GtkTreeSelection *proprietaryTreeSelection;
GtkWidget *driversTreeView;
GtkWidget *driversInfoButton;
GtkWidget *driversDeleteButton;
GtkWidget *driversInstallButton;
GtkTreeSelection *driversTreeSelection;
GtkTreeViewColumn *proprietartInstalledColumn;
GtkTreeViewColumn *ProprietaryPackageColumn;
GtkTreeViewColumn *ProprietaryDriverColumn;
GtkTreeViewColumn *ProprietaryDescriptionColumn;
GtkTreeViewColumn *ProprietarySupportedColumn;
GtkTreeViewColumn *driverInstalledColumn;
GtkTreeViewColumn *driverPackageColumn;
GtkTreeViewColumn *driverDriverColumn;
GtkTreeViewColumn *driverDescriptionColumn;
GtkTreeViewColumn *driverSupportedColumn;
GtkWidget *DriverModulesTab;
GtkWidget *DriversTab;
GtkWidget *MainTabLabel;
GtkWidget *DriversTabLabel;
GtkWidget *InformationTabLabel;
GtkWidget *InformationFrameLabel;
GtkWidget *InformationOverlay;
GtkWidget *InformationCompanyLogoImage;
GtkWidget *InformationOverlay2;
GtkWidget *InformationCompanyLogoImage2;
GtkWidget *InformationLabel;
GtkWidget *InformationLabel2;
GtkWidget *TerminalOverlay;
GtkWidget *TerminalBox;
GtkWidget *TerminalRevealer;
GtkWidget *TerminalInfoLabel;
GtkWidget *TerminalMoreButton;
GtkWidget *TerminalScroll;
GtkWidget *TerminalMoreRevieler;
GtkWidget *MenusTab;
GtkWidget *LoadDriversButton;
GtkWidget *proprietaryNotebook;
} main_window;
typedef struct
{
template_config_fields
config_str loaded_config;
int configsize;
int autoChooseDrivers;
monitor_view monitor_visuals;
monitor_config monitors;
proprietary_config proprietary;
dictionary *supported_resolutions;
GtkListStore *list;
GtkListStore *list2;
char *failsafenVidia;
char *failsafeATI;
int descreteOnly;
char *optirun;
char *primusrun;
int gapfix;
config_str ports;
int portssize;
config_str resolutions;
int resolutionssize;
render_data status_render;
dictionary *monitor_output_layers;
GtkWidget *pack_box;
int dblock;
int save_config;
main_window *widgets;
} config;
typedef struct
{
int main;
int enable;
int position;
char *position_port;
char *port;
char *resolution;
config_str resolutionCapabilities;
int frequency;
int rotation;
char *stringparameters;
int dpms;
int resolution_size;
int cvt;
int reduced;
int gtf;
int show_usupported;
} monitorconfig;
typedef struct {
GtkWidget *combo;
GtkWidget *tree;
} combo_tree;
typedef struct
{
char *curport;
config_str resolutions;
int resolutionssize;
GtkWidget *MainWindow;
GtkWidget *StatusBox;
GtkWidget *HeadLabel;
GtkWidget *EnableConfigurationBox;
GtkWidget *InterfaceConfigurationBox;
GtkWidget *EnableCheck;
GtkWidget *PortCombo;
GtkWidget *MainCheck;
GtkWidget *ResolutionCombo;
GtkWidget *UnsupportedCheck;
GtkWidget *FrequencyCombo;
GtkWidget *RotationCombo;
GtkWidget *PositionPosCombo;
GtkWidget *PositionPortCombo;
GtkWidget *DoNotSwitchOffCheck;
GtkWidget *ModelineCVTCheck;
GtkWidget *UseCVTReducedCheck;
GtkWidget *ModelineGTFCheck;
GtkWidget *ParameterLineCheck;
GtkWidget *ParameterLineEntry;
GtkWidget *CancelButton;
GtkWidget *SaveButton;
} monitor_edit_window;
typedef struct {
GtkWidget *ScreenOverlay;
GtkWidget *MonitorImage;
GtkWidget *MonitorInfoBox;
GtkWidget *NameLabel;
GtkWidget *ResoulutionLabel;
GtkWidget *DeleteButton;
GtkWidget *SwitchButton;
GtkWidget *ConfigureButton;
GtkWidget *AddButton;
} monitor_data;
typedef struct
{
GtkWidget *window;
GtkWidget *propriearyTreeView;
GtkTreeViewColumn *ProprietaryDriverColumn;
GtkTreeViewColumn *ProprietaryDescriptionColumn;
GtkListStore *list;
GtkWidget *ProprietaryCloseButton;
GtkWidget *ProprietaryAcceptButton;
} driver_window;
monitor_data *yon_monitor_new(main_window *widgets,int dull);
// void on_closed_configuration(GtkWidget *self, MonitorSettings *monitors);
// void on_save_configuration(GtkWidget self, MonitorSettings *monitors);
// void yon_parse_monitor();
// void on_config_fill_interface(main_window *widgets);
// void yon_update_config(main_window *widgets);
// void on_configuration_save_global(GtkWidget *self, main_window *widgets);
// void on_configuration_save__local_global(GtkWidget *self, main_window *widgets);
// void on_configuration_save__local(GtkWidget *self, main_window *widgets);
// void yon_config_monitor_string_parse(char *parameters, int *size);
// char *yon_char_parsed_get_resolution(config_str parsed_string, int size);
// void yon_monitor_set_resolutions();
// monitor_config yon_monitor_config_new(char *port);
// void yon_monitor_config_update(monitorconfig* monitor, char *port, char *config_string);
// void yon_monitor_view_new(monitor_config monitor);
// void on_configuration_save_global_local(GtkWidget *self, main_window *widgets);
// // void on_confugure_monitor_settings(GtkWidget *self, MonitorSettings *settings);
// void yon_monitor_view_draw_all();
// void on_monitor_configure(GtkWidget *self,monitor_window *window);
// void on_monitor_add(GtkWidget *self,monitor_window *window);
// void on_monitor_switch(GtkWidget *self,monitor_window *window);
// void on_monitor_delete(GtkWidget *self,monitor_view windowd);
// void yon_monitor_view_update();
// void yon_monitor_window_update(monitor_edit_window *window);
// char *yon_monitor_make_string(monitorconfig* config);
void yon_launch_with_output(char *command);
dictionary *yon_proprieary_get();
void yon_gtk_list_store_fill_with_proprietaries(GtkListStore *list);
void yon_monitor_view_update();
// void yon_setup_config(char *configcommand);
// void yon_monitor_view_setup(GtkWidget *container);
#endif