mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-26 08:38:26 +00:00
little simplification and improvement of $nvidia
* check only the unique part of the argument * print temperatures like all others (%.1f) * do argument parsing in nvidia.c (so all specific stuff is at one place) * little header cleanup git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1231 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
bea18942cd
commit
d23271777d
@ -1454,12 +1454,25 @@
|
||||
</term>
|
||||
<listitem>
|
||||
Nvidia graficcard support for the XNVCtrl library.
|
||||
Each option gives back one integer value:
|
||||
(threshold): the thresholdtemperature at which the gpu slows down
|
||||
(temp): gives the gpu current temperature
|
||||
(gpufreq): gives the current gpu frequency
|
||||
(memfreq): gives the current mem frequency
|
||||
(imagequality): which imagequality should be choosen by OpenGL applications
|
||||
Each option can be shortened to the least significant part.
|
||||
Temperatures are printed as float, all other values as integer.
|
||||
<simplelist>
|
||||
<member><command>threshold</command>:
|
||||
the thresholdtemperature at which the gpu slows down
|
||||
</member>
|
||||
<member><command>temp</command>:
|
||||
gives the gpu current temperature
|
||||
</member>
|
||||
<member><command>gpufreq</command>:
|
||||
gives the current gpu frequency
|
||||
</member>
|
||||
<member><command>memfreq</command>:
|
||||
gives the current mem frequency
|
||||
</member>
|
||||
<member><command>imagequality</command>:
|
||||
which imagequality should be choosen by OpenGL applications
|
||||
</member>
|
||||
</simplelist>
|
||||
<para></para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
36
src/conky.c
36
src/conky.c
@ -4022,24 +4022,11 @@ static struct text_object *construct_text_object(const char *s,
|
||||
}
|
||||
#ifdef NVIDIA
|
||||
END OBJ(nvidia, 0)
|
||||
if (!arg){
|
||||
CRIT_ERR("nvidia needs one argument "
|
||||
"[temp,threshold,gpufreq,memfreq,imagequality]");
|
||||
} else {
|
||||
if (strcmp(arg, "temp") == 0)
|
||||
obj->data.nvidia.type = NV_TEMP;
|
||||
else if (strcmp(arg, "threshold") == 0)
|
||||
obj->data.nvidia.type = NV_TEMP_THRESHOLD;
|
||||
else if (strcmp(arg, "gpufreq") == 0)
|
||||
obj->data.nvidia.type = NV_GPU_FREQ;
|
||||
else if (strcmp(arg, "memfreq") == 0)
|
||||
obj->data.nvidia.type = NV_MEM_FREQ;
|
||||
else if (strcmp(arg, "imagequality") == 0)
|
||||
obj->data.nvidia.type = NV_IMAGE_QUALITY;
|
||||
else
|
||||
CRIT_ERR("you have to give one of these arguments "
|
||||
"[temp,threshold,gpufreq,memfreq,imagequality");
|
||||
strncpy((char*)&obj->data.nvidia.arg, arg, 20);
|
||||
if (!arg) {
|
||||
CRIT_ERR("nvidia needs an argument\n");
|
||||
} else if (set_nvidia_type(&obj->data.nvidia, arg)) {
|
||||
CRIT_ERR("nvidia: invalid argument"
|
||||
" specified: '%s'\n", arg);
|
||||
}
|
||||
#endif /* NVIDIA */
|
||||
END {
|
||||
@ -6321,13 +6308,14 @@ head:
|
||||
}
|
||||
#ifdef NVIDIA
|
||||
OBJ(nvidia) {
|
||||
int hol = (strcmp((char*)&obj->data.nvidia.arg, "gpufreq")) ? 1 : 0;
|
||||
if(!(obj->data.nvidia.value = get_nvidia_value(obj->data.nvidia.type, display, hol)))
|
||||
snprintf(p, p_max_size, "value unavailible");
|
||||
int value = get_nvidia_value(obj->data.nvidia.type, display);
|
||||
if(value == -1)
|
||||
snprintf(p, p_max_size, "N/A");
|
||||
else if (obj->data.nvidia.print_as_float &&
|
||||
value > 0 && value < 100)
|
||||
snprintf(p, p_max_size, "%.1f", (float)value);
|
||||
else
|
||||
spaced_print(p, p_max_size, "%*d", 4, "nvidia",
|
||||
4, obj->data.nvidia.value);
|
||||
|
||||
snprintf(p, p_max_size, "%d", value);
|
||||
}
|
||||
#endif /* NVIDIA */
|
||||
|
||||
|
@ -449,11 +449,4 @@ char *get_apm_battery_time(void);
|
||||
#include "hddtemp.h"
|
||||
#endif /* HDDTEMP */
|
||||
|
||||
/* in nvidia.c */
|
||||
#ifdef NVIDIA
|
||||
|
||||
int get_nvidia_value(QUERY_ID qid, Display *dpy, int highorlow);
|
||||
|
||||
#endif /* NVIDIA */
|
||||
|
||||
#endif
|
||||
|
46
src/nvidia.c
46
src/nvidia.c
@ -28,16 +28,44 @@
|
||||
|
||||
#include "nvidia.h"
|
||||
|
||||
int get_nvidia_value(QUERY_ID qid, Display *dpy, int highorlow){
|
||||
int get_nvidia_value(QUERY_ID qid, Display *dpy){
|
||||
int tmp;
|
||||
if(!XNVCTRLQueryAttribute(dpy, 0, 0, qid, &tmp)){
|
||||
return 0;
|
||||
} else if (qid == NV_GPU_FREQ){
|
||||
if (highorlow == 1)
|
||||
return tmp >> 16;
|
||||
else
|
||||
return tmp & 0x0000FFFF;
|
||||
} else
|
||||
return tmp;
|
||||
return -1;
|
||||
}
|
||||
/* FIXME: when are the low 2 bytes of NV_GPU_FREQ needed? */
|
||||
if (qid == NV_GPU_FREQ)
|
||||
return tmp >> 16;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
int set_nvidia_type(struct nvidia_s *nvidia, const char *arg)
|
||||
{
|
||||
if (!arg || !arg[0] || !arg[1])
|
||||
return 1;
|
||||
|
||||
nvidia->print_as_float = 0;
|
||||
switch(arg[0]) {
|
||||
case 't': // temp or threshold
|
||||
nvidia->print_as_float = 1;
|
||||
if (arg[1] == 'e')
|
||||
nvidia->type = NV_TEMP;
|
||||
else if (arg[1] == 'h')
|
||||
nvidia->type = NV_TEMP_THRESHOLD;
|
||||
else
|
||||
return 1;
|
||||
break;
|
||||
case 'g': // gpufreq
|
||||
nvidia->type = NV_GPU_FREQ;
|
||||
break;
|
||||
case 'm': // memfreq
|
||||
nvidia->type = NV_MEM_FREQ;
|
||||
break;
|
||||
case 'i': // imagequality
|
||||
nvidia->type = NV_IMAGE_QUALITY;
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
12
src/nvidia.h
12
src/nvidia.h
@ -27,12 +27,12 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <NVCtrl/NVCtrlLib.h>
|
||||
|
||||
#ifndef NVIDIA_CONKY_H
|
||||
#define NVIDIA_CONKY_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <NVCtrl/NVCtrlLib.h>
|
||||
|
||||
typedef enum _QUERY_ID {
|
||||
NV_TEMP = NV_CTRL_GPU_CORE_TEMPERATURE,
|
||||
NV_TEMP_THRESHOLD = NV_CTRL_GPU_CORE_THRESHOLD,
|
||||
@ -43,9 +43,11 @@ typedef enum _QUERY_ID {
|
||||
|
||||
struct nvidia_s {
|
||||
int interval;
|
||||
int value;
|
||||
char arg[20];
|
||||
int print_as_float;
|
||||
QUERY_ID type;
|
||||
};
|
||||
|
||||
int get_nvidia_value(QUERY_ID qid, Display *dpy);
|
||||
int set_nvidia_type(struct nvidia_s *, const char *);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user