Compare commits

...

2 Commits

Author SHA1 Message Date
TingPing
0c2501032e sysinfo: Strip trailing space on video card 2015-03-02 19:03:09 -05:00
TingPing
4f891e21b3 sysinfo: Add display resolution 2015-03-02 18:34:03 -05:00
3 changed files with 57 additions and 1 deletions

View File

@ -26,6 +26,7 @@ char *sysinfo_backend_get_disk(void);
char *sysinfo_backend_get_memory(void);
char *sysinfo_backend_get_cpu(void);
char *sysinfo_backend_get_gpu(void);
char *sysinfo_backend_get_resolution (void);
char *sysinfo_backend_get_sound(void);
char *sysinfo_backend_get_uptime(void);
char *sysinfo_backend_get_network(void);

View File

@ -64,6 +64,7 @@ static hwinfo hwinfos[] = {
{"memory", "Memory", sysinfo_backend_get_memory},
{"storage", "Storage", sysinfo_backend_get_disk},
{"vga", "VGA", sysinfo_backend_get_gpu},
{"display", "Display", sysinfo_backend_get_resolution, TRUE},
{"sound", "Sound", sysinfo_backend_get_sound, TRUE},
{"ethernet", "Ethernet", sysinfo_backend_get_network, TRUE},
{"uptime", "Uptime", sysinfo_backend_get_uptime},

View File

@ -42,6 +42,7 @@ typedef enum
QUERY_WMI_CPU,
QUERY_WMI_VGA,
QUERY_WMI_HDD,
QUERY_WMI_RES,
} QueryWmiType;
void print_info (void);
@ -49,6 +50,7 @@ int get_cpu_arch (void);
char *query_wmi (QueryWmiType mode);
char *read_os_name (IWbemClassObject *object);
char *read_cpu_info (IWbemClassObject *object);
char *read_res_info (IWbemClassObject *object);
char *read_vga_name (IWbemClassObject *object);
guint64 hdd_capacity;
@ -117,6 +119,12 @@ sysinfo_backend_get_gpu (void)
return g_strdup (vga_name);
}
char *
sysinfo_backend_get_resolution (void)
{
return query_wmi (QUERY_WMI_RES);
}
char *
sysinfo_backend_get_os (void)
{
@ -203,6 +211,9 @@ static char *query_wmi (QueryWmiType type)
case QUERY_WMI_HDD:
query = SysAllocString (L"SELECT Name, Capacity, FreeSpace FROM Win32_Volume");
break;
case QUERY_WMI_RES:
query = SysAllocString (L"SELECT CurrentHorizontalResolution, CurrentVerticalResolution, CurrentRefreshRate FROM Win32_VideoController");
break;
default:
goto release_queryLanguageName;
}
@ -245,6 +256,10 @@ static char *query_wmi (QueryWmiType type)
line = read_hdd_info (object);
break;
case QUERY_WMI_RES:
line = read_res_info (object);
break;
default:
break;
}
@ -390,7 +405,43 @@ static char *read_vga_name (IWbemClassObject *object)
return NULL;
}
return name_utf8;
return g_strchomp (name_utf8);
}
static char *read_res_info (IWbemClassObject *object)
{
HRESULT hr;
VARIANT variant;
guint64 xres, yres, rate;
hr = object->lpVtbl->Get (object, L"CurrentHorizontalResolution", 0, &variant, NULL, NULL);
if (FAILED (hr))
{
return NULL;
}
xres = variant_to_uint64 (&variant);
VariantClear (&variant);
hr = object->lpVtbl->Get (object, L"CurrentVerticalResolution", 0, &variant, NULL, NULL);
if (FAILED (hr))
{
return NULL;
}
yres = variant_to_uint64 (&variant);
VariantClear (&variant);
hr = object->lpVtbl->Get (object, L"CurrentRefreshRate", 0, &variant, NULL, NULL);
if (FAILED (hr))
{
return NULL;
}
rate = variant_to_uint64 (&variant);
VariantClear (&variant);
return g_strdup_printf ("%"G_GUINT64_FORMAT"x%"G_GUINT64_FORMAT" (%"G_GUINT64_FORMAT"Hz)", xres, yres, rate);
}
static char *read_hdd_info (IWbemClassObject *object)
@ -481,6 +532,9 @@ static guint64 variant_to_uint64 (VARIANT *variant)
{
switch (V_VT (variant))
{
case VT_I4:
return (guint64)MAX(variant->intVal, 0);
case VT_UI8:
return variant->ullVal;