diff --git a/doc/variables.xml b/doc/variables.xml
index 5e504146..54cf910e 100644
--- a/doc/variables.xml
+++ b/doc/variables.xml
@@ -1454,12 +1454,25 @@
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.
+
+ 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
+
+
diff --git a/src/conky.c b/src/conky.c
index c53063f2..e432aef8 100644
--- a/src/conky.c
+++ b/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 */
diff --git a/src/conky.h b/src/conky.h
index 21728775..ba429f30 100644
--- a/src/conky.h
+++ b/src/conky.h
@@ -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
diff --git a/src/nvidia.c b/src/nvidia.c
index 432ce3ea..59659a55 100644
--- a/src/nvidia.c
+++ b/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;
+}
diff --git a/src/nvidia.h b/src/nvidia.h
index 9dfffe9b..9b2fe2ae 100644
--- a/src/nvidia.h
+++ b/src/nvidia.h
@@ -27,12 +27,12 @@
*/
-#include
-#include
-
#ifndef NVIDIA_CONKY_H
#define NVIDIA_CONKY_H
+#include
+#include
+
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