diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch) | |
tree | 8d927b7b47a90c4adb646482a52613f58acd6f8c /ksim/monitors/lm_sensors | |
download | tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.tar.gz tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksim/monitors/lm_sensors')
-rw-r--r-- | ksim/monitors/lm_sensors/Lm_sensors.desktop | 84 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/Makefile.am | 26 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/NVCtrl.c | 357 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/NVCtrl.h | 807 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/NVCtrlLib.h | 184 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/ksimsensors.cpp | 189 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/ksimsensors.h | 91 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/ksimsensorsiface.h | 33 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/nv_control.h | 205 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/sensorbase.cpp | 254 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/sensorbase.h | 175 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/sensorsconfig.cpp | 241 | ||||
-rw-r--r-- | ksim/monitors/lm_sensors/sensorsconfig.h | 69 |
13 files changed, 2715 insertions, 0 deletions
diff --git a/ksim/monitors/lm_sensors/Lm_sensors.desktop b/ksim/monitors/lm_sensors/Lm_sensors.desktop new file mode 100644 index 0000000..d700e0d --- /dev/null +++ b/ksim/monitors/lm_sensors/Lm_sensors.desktop @@ -0,0 +1,84 @@ +[Desktop Entry] +Comment=Lm_sensors Status Monitor +Comment[ar]=مراقب حالة Lm_sensors +Comment[bg]=Мониторинг на Lm_sensors +Comment[bs]=Nadzor statusa lm_sensors +Comment[ca]=Monitor de l'estat de Lm_sensors +Comment[cs]=Monitor stavu lm_sensorů +Comment[cy]=Monitr Statws Lm_sensors +Comment[da]=Statusovervågning af lm_følere +Comment[de]=Statusanzeige für LM-Sensoren +Comment[el]=Επόπτης κατάστασης lm_sensors +Comment[eo]=Rigardilo por la stato de Lm-sentiloj +Comment[es]=Monitor de estado de los sensores Lm +Comment[et]=Lm_sensors olekute monitooring +Comment[eu]=Lm_sentsoreen Egoera Begiralea +Comment[fa]=Lm_نمایشگر وضعیت حسگرهای +Comment[fi]=Lm_sensors tilavalvonta +Comment[fr]=Indicateur d'état lm_sensors +Comment[ga]=Monatóir Stádais Lm_sensors +Comment[he]=צג מצב Lm_sensors +Comment[hi]=एलएम_सेंसर्स स्थिति मॉनीटर +Comment[hu]=Lm_sensors hardvermonitor +Comment[is]=Eftirlit með stöðu Lm_sensors +Comment[it]=Controllo di stato Lm_sensors +Comment[ja]=Lm センサーの状態モニタ +Comment[ka]=Lm_sensors სტატუსის მონიტორი +Comment[kk]=Lm_sensor сенсорларының күйін бақылау +Comment[km]=កម្មវិធីត្រួតពិនិត្យស្ថានភាព Lm_sensors +Comment[lt]=Lm_sensors būsenos stebėtojas +Comment[mk]=Монитор за статусот на Lm_sensors +Comment[ms]=Pemerhati Status Lm_sensors +Comment[nb]=Statusovervåkning av Lm_sensorer +Comment[nds]=LM_Sensors-Statuskieker +Comment[ne]=Lm_sensors स्थिति मोनिटर +Comment[nl]=Lm_sensors statusmonitor +Comment[nn]=Lm_sensors-statusovervaking +Comment[pa]=Lm_sensors ਹਾਲਤ ਨਿਗਰਾਨ +Comment[pl]=Stan Lm_sensors +Comment[pt]=Monitor de Estado do Lm_sensors +Comment[pt_BR]=Monitor de estado dos sensores do sistema +Comment[ro]=Monitor stare lm_sensors +Comment[ru]=Монитор состояния датчиков lm_sensors +Comment[sk]=Monitor stavu lm_sensors +Comment[sl]=Nadzornik stanja Lm_senzorji +Comment[sr]=Надгледање статуса lm-сензора +Comment[sr@Latn]=Nadgledanje statusa lm-senzora +Comment[sv]=Lm_sensors statusövervakare +Comment[ta]=Lm_உணர்கருவி நிலை கண்காணி +Comment[tg]=Дидабони Ҳолати Lm_sensors +Comment[th]=Lm_sensors - เครื่องมือสอดส่องสถานะ +Comment[tr]=Lm_sensors Durum İzleyici +Comment[uk]=Монітор стану Lm_sensors +Comment[zh_CN]=Lm_sensors 状态监视器 +Comment[zh_TW]=Lm_sensors 狀態監視器 +Comment[zu]=Umlawuli Wezinga we-Lm_sensors +Icon=memory +Name=Lm_sensors +Name[cs]=Lm_sensory +Name[da]=Lm_følere +Name[de]=LM-Sensoren +Name[eo]=Lm-sentiloj +Name[es]=Sensores Lm +Name[eu]=Lm_sentsoreak +Name[fa]=Lm_حسگرهای +Name[he]=חיישנים +Name[hi]=एलएम_सेंसर्स +Name[ja]=Lm センサー +Name[kk]=Lm_sensor сенсорлары +Name[ko]=Lm 센서 +Name[lv]=Lm_sensori +Name[nb]=Lm_sensorer +Name[nds]=LM-Sensoren +Name[ro]=Senzori LM +Name[ru]=Датчики lm_sensors +Name[sl]=Lm_senzorji +Name[sr]=Lm-сензори +Name[sr@Latn]=Lm-senzori +Name[ta]= Lm_சென்சார்ஸ் +X-KSIM-VERSION=0.1 +X-KSIM-LIBRARY=sensors +X-KSIM-PREFS=Sensors +X-KSIM-AUTHOR=Robbie Ward +X-KSIM-EMAIL=linuxphreak@gmx.co.uk +X-KSIM-COPYRIGHT=(C) 2001 Robbie Ward diff --git a/ksim/monitors/lm_sensors/Makefile.am b/ksim/monitors/lm_sensors/Makefile.am new file mode 100644 index 0000000..182e01c --- /dev/null +++ b/ksim/monitors/lm_sensors/Makefile.am @@ -0,0 +1,26 @@ +kde_module_LTLIBRARIES = ksim_sensors.la + +if include_nv +NVCTRL_LIB= NVCtrl.la +NVCtrl_la_SOURCES = NVCtrl.c +NVCtrl_la_LDFLAGS = -module $(all_libraries) $(KDE_PLUGIN) +endif + +noinst_LTLIBRARIES = $(NVCTRL_LIB) + +ksim_sensors_la_SOURCES = ksimsensors.cpp sensorsconfig.cpp \ + sensorbase.cpp ksimsensorsiface.skel + +ksim_sensors_la_LDFLAGS = $(all_libraries) -module -avoid-version +ksim_sensors_la_LIBADD = ../../library/libksimcore.la $(NVCTRL_LIB) + +EXTRA_DIST = Lm_sensors.desktop + +INCLUDES = -I$(top_srcdir)/ksim/library \ + -I$(top_srcdir)/ksim \ + $(all_includes) + +METASOURCES = AUTO + +mon_DATA = Lm_sensors.desktop +mondir = $(kde_datadir)/ksim/monitors diff --git a/ksim/monitors/lm_sensors/NVCtrl.c b/ksim/monitors/lm_sensors/NVCtrl.c new file mode 100644 index 0000000..6c61b8a --- /dev/null +++ b/ksim/monitors/lm_sensors/NVCtrl.c @@ -0,0 +1,357 @@ +/* + * Copyright (C) 2004 NVIDIA Corporation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of Version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See Version 2 + * of the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + */ + +#define NEED_EVENTS +#define NEED_REPLIES +#include <X11/Xlibint.h> +#include <X11/Xutil.h> +#include <X11/extensions/Xext.h> +#include <X11/extensions/extutil.h> +#include "NVCtrlLib.h" +#include "nv_control.h" + + +static XExtensionInfo _nvctrl_ext_info_data; +static XExtensionInfo *nvctrl_ext_info = &_nvctrl_ext_info_data; +static const char *nvctrl_extension_name = NV_CONTROL_NAME; + +#define XNVCTRLCheckExtension(dpy,i,val) \ + XextCheckExtension (dpy, i, nvctrl_extension_name, val) +#define XNVCTRLSimpleCheckExtension(dpy,i) \ + XextSimpleCheckExtension (dpy, i, nvctrl_extension_name) + +static int close_display(); +static Bool wire_to_event(); +static const XExtensionHooks nvctrl_extension_hooks = { + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + close_display, /* close_display */ + wire_to_event, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ +}; + +static XEXT_GENERATE_FIND_DISPLAY (find_display, nvctrl_ext_info, + nvctrl_extension_name, + &nvctrl_extension_hooks, + NV_CONTROL_EVENTS, NULL) + +static XEXT_GENERATE_CLOSE_DISPLAY (close_display, nvctrl_ext_info) + +Bool XNVCTRLQueryExtension ( + Display *dpy, + int *event_basep, + int *error_basep +){ + XExtDisplayInfo *info = find_display (dpy); + + if (XextHasExtension(info)) { + if (event_basep) *event_basep = info->codes->first_event; + if (error_basep) *error_basep = info->codes->first_error; + return True; + } else { + return False; + } +} + + +Bool XNVCTRLQueryVersion ( + Display *dpy, + int *major, + int *minor +){ + XExtDisplayInfo *info = find_display (dpy); + xnvCtrlQueryExtensionReply rep; + xnvCtrlQueryExtensionReq *req; + + if(!XextHasExtension(info)) + return False; + + XNVCTRLCheckExtension (dpy, info, False); + + LockDisplay (dpy); + GetReq (nvCtrlQueryExtension, req); + req->reqType = info->codes->major_opcode; + req->nvReqType = X_nvCtrlQueryExtension; + if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; + } + if (major) *major = rep.major; + if (minor) *minor = rep.minor; + UnlockDisplay (dpy); + SyncHandle (); + return True; +} + + +Bool XNVCTRLIsNvScreen ( + Display *dpy, + int screen +){ + XExtDisplayInfo *info = find_display (dpy); + xnvCtrlIsNvReply rep; + xnvCtrlIsNvReq *req; + Bool isnv; + + if(!XextHasExtension(info)) + return False; + + XNVCTRLCheckExtension (dpy, info, False); + + LockDisplay (dpy); + GetReq (nvCtrlIsNv, req); + req->reqType = info->codes->major_opcode; + req->nvReqType = X_nvCtrlIsNv; + req->screen = screen; + if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; + } + isnv = rep.isnv; + UnlockDisplay (dpy); + SyncHandle (); + return isnv; +} + + +void XNVCTRLSetAttribute ( + Display *dpy, + int screen, + unsigned int display_mask, + unsigned int attribute, + int value +){ + XExtDisplayInfo *info = find_display (dpy); + xnvCtrlSetAttributeReq *req; + + XNVCTRLSimpleCheckExtension (dpy, info); + + LockDisplay (dpy); + GetReq (nvCtrlSetAttribute, req); + req->reqType = info->codes->major_opcode; + req->nvReqType = X_nvCtrlSetAttribute; + req->screen = screen; + req->display_mask = display_mask; + req->attribute = attribute; + req->value = value; + UnlockDisplay (dpy); + SyncHandle (); +} + + +Bool XNVCTRLQueryAttribute ( + Display *dpy, + int screen, + unsigned int display_mask, + unsigned int attribute, + int *value +){ + XExtDisplayInfo *info = find_display (dpy); + xnvCtrlQueryAttributeReply rep; + xnvCtrlQueryAttributeReq *req; + Bool exists; + + if(!XextHasExtension(info)) + return False; + + XNVCTRLCheckExtension (dpy, info, False); + + LockDisplay (dpy); + GetReq (nvCtrlQueryAttribute, req); + req->reqType = info->codes->major_opcode; + req->nvReqType = X_nvCtrlQueryAttribute; + req->screen = screen; + req->display_mask = display_mask; + req->attribute = attribute; + if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; + } + if (value) *value = rep.value; + exists = rep.flags; + UnlockDisplay (dpy); + SyncHandle (); + return exists; +} + + +Bool XNVCTRLQueryStringAttribute ( + Display *dpy, + int screen, + unsigned int display_mask, + unsigned int attribute, + char **ptr +){ + XExtDisplayInfo *info = find_display (dpy); + xnvCtrlQueryStringAttributeReply rep; + xnvCtrlQueryStringAttributeReq *req; + Bool exists; + int length, numbytes, slop; + + if (!ptr) return False; + + if(!XextHasExtension(info)) + return False; + + XNVCTRLCheckExtension (dpy, info, False); + + LockDisplay (dpy); + GetReq (nvCtrlQueryStringAttribute, req); + req->reqType = info->codes->major_opcode; + req->nvReqType = X_nvCtrlQueryStringAttribute; + req->screen = screen; + req->display_mask = display_mask; + req->attribute = attribute; + if (!_XReply (dpy, (xReply *) &rep, 0, False)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; + } + length = rep.length; + numbytes = rep.n; + slop = numbytes & 3; + *ptr = (char *) Xmalloc(numbytes); + if (! *ptr) { + _XEatData(dpy, length); + UnlockDisplay (dpy); + SyncHandle (); + return False; + } else { + _XRead(dpy, (char *) *ptr, numbytes); + if (slop) _XEatData(dpy, 4-slop); + } + exists = rep.flags; + UnlockDisplay (dpy); + SyncHandle (); + return exists; +} + +Bool XNVCTRLQueryValidAttributeValues ( + Display *dpy, + int screen, + unsigned int display_mask, + unsigned int attribute, + NVCTRLAttributeValidValuesRec *values +){ + XExtDisplayInfo *info = find_display (dpy); + xnvCtrlQueryValidAttributeValuesReply rep; + xnvCtrlQueryValidAttributeValuesReq *req; + Bool exists; + + if (!values) return False; + + if(!XextHasExtension(info)) + return False; + + XNVCTRLCheckExtension (dpy, info, False); + + LockDisplay (dpy); + GetReq (nvCtrlQueryValidAttributeValues, req); + req->reqType = info->codes->major_opcode; + req->nvReqType = X_nvCtrlQueryValidAttributeValues; + req->screen = screen; + req->display_mask = display_mask; + req->attribute = attribute; + if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { + UnlockDisplay (dpy); + SyncHandle (); + return False; + } + exists = rep.flags; + values->type = rep.attr_type; + if (rep.attr_type == ATTRIBUTE_TYPE_RANGE) { + values->u.range.min = rep.min; + values->u.range.max = rep.max; + } + if (rep.attr_type == ATTRIBUTE_TYPE_INT_BITS) { + values->u.bits.ints = rep.bits; + } + values->permissions = rep.perms; + UnlockDisplay (dpy); + SyncHandle (); + return exists; +} + +Bool XNVCtrlSelectNotify ( + Display *dpy, + int screen, + int type, + Bool onoff +){ + XExtDisplayInfo *info = find_display (dpy); + xnvCtrlSelectNotifyReq *req; + + if(!XextHasExtension (info)) + return False; + + XNVCTRLCheckExtension (dpy, info, False); + + LockDisplay (dpy); + GetReq (nvCtrlSelectNotify, req); + req->reqType = info->codes->major_opcode; + req->nvReqType = X_nvCtrlSelectNotify; + req->screen = screen; + req->notifyType = type; + req->onoff = onoff; + UnlockDisplay (dpy); + SyncHandle (); + + return True; +} + +static Bool wire_to_event (Display *dpy, XEvent *host, xEvent *wire) +{ + XExtDisplayInfo *info = find_display (dpy); + XNVCtrlEvent *re = (XNVCtrlEvent *) host; + xnvctrlEvent *event = (xnvctrlEvent *) wire; + + XNVCTRLCheckExtension (dpy, info, False); + + switch ((event->u.u.type & 0x7F) - info->codes->first_event) { + case ATTRIBUTE_CHANGED_EVENT: + re->attribute_changed.type = event->u.u.type & 0x7F; + re->attribute_changed.serial = + _XSetLastRequestRead(dpy, (xGenericReply*) event); + re->attribute_changed.send_event = ((event->u.u.type & 0x80) != 0); + re->attribute_changed.display = dpy; + re->attribute_changed.time = event->u.attribute_changed.time; + re->attribute_changed.screen = event->u.attribute_changed.screen; + re->attribute_changed.display_mask = + event->u.attribute_changed.display_mask; + re->attribute_changed.attribute = event->u.attribute_changed.attribute; + re->attribute_changed.value = event->u.attribute_changed.value; + break; + default: + return False; + } + + return True; +} + diff --git a/ksim/monitors/lm_sensors/NVCtrl.h b/ksim/monitors/lm_sensors/NVCtrl.h new file mode 100644 index 0000000..81c9432 --- /dev/null +++ b/ksim/monitors/lm_sensors/NVCtrl.h @@ -0,0 +1,807 @@ +/* + * Copyright (C) 2004 NVIDIA Corporation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of Version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See Version 2 + * of the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + */ + +#ifndef __NVCTRL_H +#define __NVCTRL_H + +/**************************************************************************/ +/* + * Integer attributes; these are settable/gettable via + * XNVCTRLSetAttribute() and XNVCTRLQueryAttribute, respectively. + * Some attributes may only be read; some may require a display_mask + * argument. This information is encoded in the "permission" comment + * after each attribute #define, and can be queried at run time with + * XNVCTRLQueryValidAttributeValues(). + * + * Key to Integer Attribute "Permissions": + * + * R: The attribute is readable (in general, all attributes will be + * readable) + * + * W: The attribute is writable (attributes may not be writable for + * various reasons: they represent static system information, they + * can only be changed by changing an XF86Config option, etc). + * + * D: The attribute requires the display mask argument. The + * attributes NV_CTRL_CONNECTED_DISPLAYS and NV_CTRL_ENABLED_DISPLAYS + * will be a bitmask of what display devices are connected and what + * display devices are enabled for use in X, respectively. Each bit + * in the bitmask represents a display device; it is these bits which + * should be used as the display_mask when dealing with attributes + * designated with "D" below. For attributes that do not require the + * display mask, the argument is ignored. + */ + + +/**************************************************************************/ + + +/* + * NV_CTRL_FLATPANEL_SCALING - the current flatpanel scaling state; + * possible values are: + * + * 0: default (the driver will use whatever state is current) + * 1: native (the driver will use the panel's scaler, if possible) + * 2: scaled (the driver will use the GPU's scaler, if possible) + * 3: centered (the driver will center the image) + * 4: aspect scaled (scale with the GPU's scaler, but keep the aspect + * ratio correct) + */ + +#define NV_CTRL_FLATPANEL_SCALING 2 /* RWD */ +#define NV_CTRL_FLATPANEL_SCALING_DEFAULT 0 +#define NV_CTRL_FLATPANEL_SCALING_NATIVE 1 +#define NV_CTRL_FLATPANEL_SCALING_SCALED 2 +#define NV_CTRL_FLATPANEL_SCALING_CENTERED 3 +#define NV_CTRL_FLATPANEL_SCALING_ASPECT_SCALED 4 + + +/* + * NV_CTRL_FLATPANEL_DITHERING - the current flatpanel dithering + * state; possible values are: + * + * 0: default (the driver will decide when to dither) + * 1: enabled (the driver will always dither when possible) + * 2: disabled (the driver will never dither) + */ + +#define NV_CTRL_FLATPANEL_DITHERING 3 /* RWD */ +#define NV_CTRL_FLATPANEL_DITHERING_DEFAULT 0 +#define NV_CTRL_FLATPANEL_DITHERING_ENABLED 1 +#define NV_CTRL_FLATPANEL_DITHERING_DISABLED 2 + + +/* + * NV_CTRL_DIGITAL_VIBRANCE - sets the digital vibrance level for the + * specified display device. + */ + +#define NV_CTRL_DIGITAL_VIBRANCE 4 /* RWD */ + + +/* + * NV_CTRL_BUS_TYPE - returns the Bus type through which the GPU + * driving the specified X screen is connected to the computer. + */ + +#define NV_CTRL_BUS_TYPE 5 /* R-- */ +#define NV_CTRL_BUS_TYPE_AGP 0 +#define NV_CTRL_BUS_TYPE_PCI 1 +#define NV_CTRL_BUS_TYPE_PCI_EXPRESS 2 + + +/* + * NV_CTRL_VIDEO_RAM - returns the amount of video ram on the GPU + * driving the specified X screen. + */ + +#define NV_CTRL_VIDEO_RAM 6 /* R-- */ + + +/* + * NV_CTRL_IRQ - returns the interrupt request line used by the GPU + * driving the specified X screen. + */ + +#define NV_CTRL_IRQ 7 /* R-- */ + + +/* + * NV_CTRL_OPERATING_SYSTEM - returns the operating system on which + * the X server is running. + */ + +#define NV_CTRL_OPERATING_SYSTEM 8 /* R-- */ +#define NV_CTRL_OPERATING_SYSTEM_LINUX 0 +#define NV_CTRL_OPERATING_SYSTEM_FREEBSD 1 + + +/* + * NV_CTRL_SYNC_TO_VBLANK - enables sync to vblank for OpenGL clients. + * This setting is only applied to OpenGL clients that are started + * after this setting is applied. + */ + +#define NV_CTRL_SYNC_TO_VBLANK 9 /* RW- */ +#define NV_CTRL_SYNC_TO_VBLANK_OFF 0 +#define NV_CTRL_SYNC_TO_VBLANK_ON 1 + + +/* + * NV_CTRL_LOG_ANISO - enables anisotropic filtering for OpenGL + * clients; on some NVIDIA hardware, this can only be enabled or + * disabled; on other hardware different levels of anisotropic + * filtering can be specified. This setting is only applied to OpenGL + * clients that are started after this setting is applied. + */ + +#define NV_CTRL_LOG_ANISO 10 /* RW- */ + + +/* + * NV_CTRL_FSAA_MODE - the FSAA setting for OpenGL clients; possible + * FSAA modes: + * + * NV_CTRL_FSAA_MODE_2x "2x Bilinear Multisampling" + * NV_CTRL_FSAA_MODE_2x_5t "2x Quincunx Multisampling" + * NV_CTRL_FSAA_MODE_15x15 "1.5 x 1.5 Supersampling" + * NV_CTRL_FSAA_MODE_2x2 "2 x 2 Supersampling" + * NV_CTRL_FSAA_MODE_4x "4x Bilinear Multisampling" + * NV_CTRL_FSAA_MODE_4x_9t "4x Gaussian Multisampling" + * NV_CTRL_FSAA_MODE_8x "2x Bilinear Multisampling by 4x Supersampling" + * NV_CTRL_FSAA_MODE_16x "4x Bilinear Multisampling by 4x Supersampling" + * + * This setting is only applied to OpenGL clients that are started + * after this setting is applied. + */ + +#define NV_CTRL_FSAA_MODE 11 /* RW- */ +#define NV_CTRL_FSAA_MODE_NONE 0 +#define NV_CTRL_FSAA_MODE_2x 1 +#define NV_CTRL_FSAA_MODE_2x_5t 2 +#define NV_CTRL_FSAA_MODE_15x15 3 +#define NV_CTRL_FSAA_MODE_2x2 4 +#define NV_CTRL_FSAA_MODE_4x 5 +#define NV_CTRL_FSAA_MODE_4x_9t 6 +#define NV_CTRL_FSAA_MODE_8x 7 +#define NV_CTRL_FSAA_MODE_16x 8 + + +/* + * NV_CTRL_TEXTURE_SHARPEN - enables texture sharpening for OpenGL + * clients. This setting is only applied to OpenGL clients that are + * started after this setting is applied. + */ + +#define NV_CTRL_TEXTURE_SHARPEN 12 /* RW- */ +#define NV_CTRL_TEXTURE_SHARPEN_OFF 0 +#define NV_CTRL_TEXTURE_SHARPEN_ON 1 + + +/* + * NV_CTRL_UBB - returns whether UBB is enabled for the specified X + * screen. + */ + +#define NV_CTRL_UBB 13 /* R-- */ +#define NV_CTRL_UBB_OFF 0 +#define NV_CTRL_UBB_ON 1 + + +/* + * NV_CTRL_OVERLAY - returns whether the RGB overlay is enabled for + * the specified X screen. + */ + +#define NV_CTRL_OVERLAY 14 /* R-- */ +#define NV_CTRL_OVERLAY_OFF 0 +#define NV_CTRL_OVERLAY_ON 1 + + +/* + * NV_CTRL_STEREO - returns whether stereo (and what type) is enabled + * for the specified X screen. + */ + +#define NV_CTRL_STEREO 16 /* R-- */ +#define NV_CTRL_STEREO_OFF 0 +#define NV_CTRL_STEREO_DDC 1 +#define NV_CTRL_STEREO_BLUELINE 2 +#define NV_CTRL_STEREO_DIN 3 +#define NV_CTRL_STEREO_TWINVIEW 4 + + +/* + * NV_CTRL_EMULATE - controls OpenGL software emulation of future + * NVIDIA GPUs. + */ + +#define NV_CTRL_EMULATE 17 /* RW- */ +#define NV_CTRL_EMULATE_NONE 0 + + +/* + * NV_CTRL_TWINVIEW - returns whether TwinView is enabled for the + * specified X screen. + */ + +#define NV_CTRL_TWINVIEW 18 /* R-- */ +#define NV_CTRL_TWINVIEW_NOT_ENABLED 0 +#define NV_CTRL_TWINVIEW_ENABLED 1 + + +/* + * NV_CTRL_CONNECTED_DISPLAYS - returns a display mask indicating what + * display devices are connected to the GPU driving the specified X + * screen. + */ + +#define NV_CTRL_CONNECTED_DISPLAYS 19 /* R-- */ + + +/* + * NV_CTRL_ENABLED_DISPLAYS - returns a display mask indicating what + * display devices are enabled for use on the specified X screen. + */ + +#define NV_CTRL_ENABLED_DISPLAYS 20 /* R-- */ + +/**************************************************************************/ +/* + * Integer attributes specific to configuring FrameLock on boards that + * support it. + */ + + +/* + * NV_CTRL_FRAMELOCK - returns whether this X screen supports + * FrameLock. All of the other FrameLock attributes are only + * applicable if NV_CTRL_FRAMELOCK is _SUPPORTED. + */ + +#define NV_CTRL_FRAMELOCK 21 /* R-- */ +#define NV_CTRL_FRAMELOCK_NOT_SUPPORTED 0 +#define NV_CTRL_FRAMELOCK_SUPPORTED 1 + + +/* + * NV_CTRL_FRAMELOCK_MASTER - get/set whether this X screen is the + * FrameLock master for the entire sync group. Note that only one + * node in the sync group should be configured as the master. + */ + +#define NV_CTRL_FRAMELOCK_MASTER 22 /* RW- */ +#define NV_CTRL_FRAMELOCK_MASTER_FALSE 0 +#define NV_CTRL_FRAMELOCK_MASTER_TRUE 1 + + +/* + * NV_CTRL_FRAMELOCK_POLARITY - sync either to the rising edge of the + * framelock pulse, or both the rising and falling edges of the + * framelock pulse. + */ + +#define NV_CTRL_FRAMELOCK_POLARITY 23 /* RW- */ +#define NV_CTRL_FRAMELOCK_POLARITY_RISING_EDGE 0x1 +#define NV_CTRL_FRAMELOCK_POLARITY_BOTH_EDGES 0x3 + + +/* + * NV_CTRL_FRAMELOCK_SYNC_DELAY - delay between the framelock pulse + * and the GPU sync. This is an 11 bit value which is multipled by + * 7.81 to determine the sync delay in microseconds. + */ + +#define NV_CTRL_FRAMELOCK_SYNC_DELAY 24 /* RW- */ +#define NV_CTRL_FRAMELOCK_SYNC_DELAY_MAX 2047 +#define NV_CTRL_FRAMELOCK_SYNC_DELAY_FACTOR 7.81 + +/* + * NV_CTRL_FRAMELOCK_SYNC_INTERVAL - how many house sync pulses + * between the FrameLock sync generation (0 == sync every house sync); + * this only applies to the master when receiving house sync. + */ + +#define NV_CTRL_FRAMELOCK_SYNC_INTERVAL 25 /* RW- */ + + +/* + * NV_CTRL_FRAMELOCK_PORT0_STATUS - status of the rj45 port0. + */ + +#define NV_CTRL_FRAMELOCK_PORT0_STATUS 26 /* R-- */ +#define NV_CTRL_FRAMELOCK_PORT0_STATUS_INPUT 0 +#define NV_CTRL_FRAMELOCK_PORT0_STATUS_OUTPUT 1 + + +/* + * NV_CTRL_FRAMELOCK_PORT1_STATUS - status of the rj45 port1. + */ + +#define NV_CTRL_FRAMELOCK_PORT1_STATUS 27 /* R-- */ +#define NV_CTRL_FRAMELOCK_PORT1_STATUS_INPUT 0 +#define NV_CTRL_FRAMELOCK_PORT1_STATUS_OUTPUT 1 + + +/* + * NV_CTRL_FRAMELOCK_HOUSE_STATUS - status of the house input (the BNC + * connector). + */ + +#define NV_CTRL_FRAMELOCK_HOUSE_STATUS 28 /* R-- */ +#define NV_CTRL_FRAMELOCK_HOUSE_STATUS_NOT_DETECTED 0 +#define NV_CTRL_FRAMELOCK_HOUSE_STATUS_DETECTED 1 + + +/* + * NV_CTRL_FRAMELOCK_SYNC - enable/disable the syncing of the + * specified display devices to the FrameLock pulse. + */ + +#define NV_CTRL_FRAMELOCK_SYNC 29 /* RWD */ +#define NV_CTRL_FRAMELOCK_SYNC_DISABLE 0 +#define NV_CTRL_FRAMELOCK_SYNC_ENABLE 1 + + +/* + * NV_CTRL_FRAMELOCK_SYNC_READY - reports whether a slave FrameLock + * board is receiving sync (regardless of whether or not any display + * devices are using the sync). + */ + +#define NV_CTRL_FRAMELOCK_SYNC_READY 30 /* R-- */ +#define NV_CTRL_FRAMELOCK_SYNC_READY_FALSE 0 +#define NV_CTRL_FRAMELOCK_SYNC_READY_TRUE 1 + + +/* + * NV_CTRL_FRAMELOCK_STEREO_SYNC - this indicates that the GPU stereo + * signal is in sync with the framelock stereo signal. + */ + +#define NV_CTRL_FRAMELOCK_STEREO_SYNC 31 /* R-- */ +#define NV_CTRL_FRAMELOCK_STEREO_SYNC_FALSE 0 +#define NV_CTRL_FRAMELOCK_STEREO_SYNC_TRUE 1 + + +/* + * NV_CTRL_FRAMELOCK_TEST_SIGNAL - to test the connections in the sync + * group, tell the master to enable a test signal, then query port[01] + * status and sync_ready on all slaves. When done, tell the master to + * disable the test signal. Test signal should only be manipulated + * while NV_CTRL_FRAMELOCK_SYNC is enabled. + * + * The TEST_SIGNAL is also used to reset the Universal Frame Count (as + * returned by the glXQueryFrameCountNV() function in the + * GLX_NV_swap_group extension). Note: for best accuracy of the + * Universal Frame Count, it is recommended to toggle the TEST_SIGNAL + * on and off after enabling FrameLock. + */ + +#define NV_CTRL_FRAMELOCK_TEST_SIGNAL 32 /* RW- */ +#define NV_CTRL_FRAMELOCK_TEST_SIGNAL_DISABLE 0 +#define NV_CTRL_FRAMELOCK_TEST_SIGNAL_ENABLE 1 + + +/* + * NV_CTRL_FRAMELOCK_ETHERNET_DETECTED - The FrameLock boards are + * cabled together using regular cat5 cable, connecting to rj45 ports + * on the backplane of the card. There is some concern that users may + * think these are ethernet ports and connect them to a + * router/hub/etc. The hardware can detect this and will shut off to + * prevent damage (either to itself or to the router). + * NV_CTRL_FRAMELOCK_ETHERNET_DETECTED may be called to find out if + * ethernet is connected to one of the rj45 ports. An appropriate + * error message should then be displayed. The _PORT0 and PORT1 + * values may be or'ed together. + */ + +#define NV_CTRL_FRAMELOCK_ETHERNET_DETECTED 33 /* R-- */ +#define NV_CTRL_FRAMELOCK_ETHERNET_DETECTED_NONE 0 +#define NV_CTRL_FRAMELOCK_ETHERNET_DETECTED_PORT0 0x1 +#define NV_CTRL_FRAMELOCK_ETHERNET_DETECTED_PORT1 0x2 + + +/* + * NV_CTRL_FRAMELOCK_VIDEO_MODE - get/set the video mode of the house + * input. + */ + +#define NV_CTRL_FRAMELOCK_VIDEO_MODE 34 /* RW- */ +#define NV_CTRL_FRAMELOCK_VIDEO_MODE_NONE 0 +#define NV_CTRL_FRAMELOCK_VIDEO_MODE_TTL 1 +#define NV_CTRL_FRAMELOCK_VIDEO_MODE_NTSCPALSECAM 2 +#define NV_CTRL_FRAMELOCK_VIDEO_MODE_HDTV 3 + +/* + * During FRAMELOCK bring-up, the above values were redefined to + * these: + */ + +#define NV_CTRL_FRAMELOCK_VIDEO_MODE_COMPOSITE_AUTO 0 +#define NV_CTRL_FRAMELOCK_VIDEO_MODE_TTL 1 +#define NV_CTRL_FRAMELOCK_VIDEO_MODE_COMPOSITE_BI_LEVEL 2 +#define NV_CTRL_FRAMELOCK_VIDEO_MODE_COMPOSITE_TRI_LEVEL 3 + + +/* + * NV_CTRL_FRAMELOCK_SYNC_RATE - this is the refresh rate that the + * framelock board is sending to the GPU, in milliHz. + */ + +#define NV_CTRL_FRAMELOCK_SYNC_RATE 35 /* R-- */ + + + +/**************************************************************************/ + +/* + * NV_CTRL_FORCE_GENERIC_CPU - inhibit the use of CPU specific + * features such as MMX, SSE, or 3DNOW! for OpenGL clients; this + * option may result in performance loss, but may be useful in + * conjunction with software such as the Valgrind memory debugger. + * This setting is only applied to OpenGL clients that are started + * after this setting is applied. + */ + +#define NV_CTRL_FORCE_GENERIC_CPU 37 /* RW- */ +#define NV_CTRL_FORCE_GENERIC_CPU_DISABLE 0 +#define NV_CTRL_FORCE_GENERIC_CPU_ENABLE 1 + + +/* + * NV_CTRL_OPENGL_AA_LINE_GAMMA - for OpenGL clients, allow + * Gamma-corrected antialiased lines to consider variances in the + * color display capabilities of output devices when rendering smooth + * lines. Only available on recent Quadro GPUs. This setting is only + * applied to OpenGL clients that are started after this setting is + * applied. + */ + +#define NV_CTRL_OPENGL_AA_LINE_GAMMA 38 /* RW- */ +#define NV_CTRL_OPENGL_AA_LINE_GAMMA_DISABLE 0 +#define NV_CTRL_OPENGL_AA_LINE_GAMMA_ENABLE 1 + + +/* + * NV_CTRL_FRAMELOCK_TIMING - this is TRUE when the framelock board is + * receiving timing input. + */ + +#define NV_CTRL_FRAMELOCK_TIMING 39 /* RW- */ +#define NV_CTRL_FRAMELOCK_TIMING_FALSE 0 +#define NV_CTRL_FRAMELOCK_TIMING_TRUE 1 + +/* + * NV_CTRL_FLIPPING_ALLOWED - when TRUE, OpenGL will swap by flipping + * when possible; when FALSE, OpenGL will alway swap by blitting. XXX + * can this be enabled dynamically? + */ + +#define NV_CTRL_FLIPPING_ALLOWED 40 /* RW- */ +#define NV_CTRL_FLIPPING_ALLOWED_FALSE 0 +#define NV_CTRL_FLIPPING_ALLOWED_TRUE 1 + +/* + * NV_CTRL_ARCHITECTURE - returns the architecture on which the X server is + * running. + */ + +#define NV_CTRL_ARCHITECTURE 41 /* R-- */ +#define NV_CTRL_ARCHITECTURE_X86 0 +#define NV_CTRL_ARCHITECTURE_X86_64 1 +#define NV_CTRL_ARCHITECTURE_IA64 2 + + +/* + * NV_CTRL_TEXTURE_CLAMPING - texture clamping mode in OpenGL. By + * default, NVIDIA's OpenGL implementation uses CLAMP_TO_EDGE, which + * is not strictly conformant, but some applications rely on the + * non-conformant behavior, and not all GPUs support conformant + * texture clamping in hardware. _SPEC forces OpenGL texture clamping + * to be conformant, but may introduce slower performance on older + * GPUS, or incorrect texture clamping in certain applications. + */ + +#define NV_CTRL_TEXTURE_CLAMPING 42 /* RW- */ +#define NV_CTRL_TEXTURE_CLAMPING_EDGE 0 +#define NV_CTRL_TEXTURE_CLAMPING_SPEC 1 + + + +#define NV_CTRL_CURSOR_SHADOW 43 /* RW- */ +#define NV_CTRL_CURSOR_SHADOW_DISABLE 0 +#define NV_CTRL_CURSOR_SHADOW_ENABLE 1 + +#define NV_CTRL_CURSOR_SHADOW_ALPHA 44 /* RW- */ +#define NV_CTRL_CURSOR_SHADOW_RED 45 /* RW- */ +#define NV_CTRL_CURSOR_SHADOW_GREEN 46 /* RW- */ +#define NV_CTRL_CURSOR_SHADOW_BLUE 47 /* RW- */ + +#define NV_CTRL_CURSOR_SHADOW_X_OFFSET 48 /* RW- */ +#define NV_CTRL_CURSOR_SHADOW_Y_OFFSET 49 /* RW- */ + + + +/* + * When Application Control for FSAA is enabled, then what the + * application requests is used, and NV_CTRL_FSAA_MODE is ignored. If + * this is disabled, then any application setting is overridden with + * NV_CTRL_FSAA_MODE + */ + +#define NV_CTRL_FSAA_APPLICATION_CONTROLLED 50 /* RW- */ +#define NV_CTRL_FSAA_APPLICATION_CONTROLLED_ENABLED 1 +#define NV_CTRL_FSAA_APPLICATION_CONTROLLED_DISABLED 0 + + +/* + * When Application Control for LogAniso is enabled, then what the + * application requests is used, and NV_CTRL_LOG_ANISO is ignored. If + * this is disabled, then any application setting is overridden with + * NV_CTRL_LOG_ANISO + */ + +#define NV_CTRL_LOG_ANISO_APPLICATION_CONTROLLED 51 /* RW- */ +#define NV_CTRL_LOG_ANISO_APPLICATION_CONTROLLED_ENABLED 1 +#define NV_CTRL_LOG_ANISO_APPLICATION_CONTROLLED_DISABLED 0 + + +/* + * IMAGE_SHARPENING adjusts the sharpness of the display's image + * quality by amplifying high frequency content. Valid values will + * normally be in the range [0,32). Only available on GeForceFX or + * newer. + */ + +#define NV_CTRL_IMAGE_SHARPENING 52 /* RWD */ + + +/* + * NV_CTRL_TV_OVERSCAN adjusts the amount of overscan on the specified + * display device. + */ + +#define NV_CTRL_TV_OVERSCAN 53 /* RWD */ + + +/* + * NV_CTRL_TV_FLICKER_FILTER adjusts the amount of flicker filter on + * the specified display device. + */ + +#define NV_CTRL_TV_FLICKER_FILTER 54 /* RWD */ + + +/* + * NV_CTRL_TV_BRIGHTNESS adjusts the amount of brightness on the + * specified display device. + */ + +#define NV_CTRL_TV_BRIGHTNESS 55 /* RWD */ + + +/* + * NV_CTRL_TV_HUE adjusts the amount of hue on the specified display + * device. + */ + +#define NV_CTRL_TV_HUE 56 /* RWD */ + + +/* + * NV_CTRL_TV_CONTRAST adjusts the amount of contrast on the specified + * display device. + */ + +#define NV_CTRL_TV_CONTRAST 57 /* RWD */ + + +/* + * NV_CTRL_TV_SATURATION adjusts the amount of saturation on the + * specified display device. + */ + +#define NV_CTRL_TV_SATURATION 58 /* RWD */ + + +/* + * NV_CTRL_TV_RESET_SETTINGS - this write-only attribute can be used + * to request that all TV Settings be reset to their default values; + * typical usage would be that this attribute be sent, and then all + * the TV attributes be queried to retrieve their new values. + */ + +#define NV_CTRL_TV_RESET_SETTINGS 59 /* -WD */ + + +/* + * NV_CTRL_GPU_CORE_TEMPERATURE reports the current core temperature + * of the GPU driving the X screen. + */ + +#define NV_CTRL_GPU_CORE_TEMPERATURE 60 /* R-- */ + + +/* + * NV_CTRL_GPU_CORE_THRESHOLD reports the current GPU core slowdown + * threshold temperature, NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD and + * NV_CTRL_GPU_MAX_CORE_THRESHOLD report the default and MAX core + * slowdown threshold temperatures. + * + * NV_CTRL_GPU_CORE_THRESHOLD reflects the temperature at which the + * GPU is throttled to prevent overheating. + */ + +#define NV_CTRL_GPU_CORE_THRESHOLD 61 /* R-- */ +#define NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD 62 /* R-- */ +#define NV_CTRL_GPU_MAX_CORE_THRESHOLD 63 /* R-- */ + + +/* + * NV_CTRL_AMBIENT_TEMPERATURE reports the current temperature in the + * immediate neighbourhood of the GPU driving the X screen. + */ + +#define NV_CTRL_AMBIENT_TEMPERATURE 64 /* R-- */ + + +/* + * NV_CTRL_PBUFFER_SCANOUT_SUPPORTED - returns whether this X screen + * supports scanout of FP pbuffers; + * + * if this screen does not support PBUFFER_SCANOUT, then all other + * PBUFFER_SCANOUT attributes are unavailable. + */ + +#define NV_CTRL_PBUFFER_SCANOUT_SUPPORTED 65 /* R-- */ +#define NV_CTRL_PBUFFER_SCANOUT_FALSE 0 +#define NV_CTRL_PBUFFER_SCANOUT_TRUE 1 + +/* + * NV_CTRL_PBUFFER_SCANOUT_XID indicates the XID of the pbuffer used for + * scanout. + */ +#define NV_CTRL_PBUFFER_SCANOUT_XID 66 /* RW- */ + +#define NV_CTRL_LAST_ATTRIBUTE NV_CTRL_PBUFFER_SCANOUT_XID + +/**************************************************************************/ + +/* + * String Attributes: + */ + + +/* + * NV_CTRL_STRING_PRODUCT_NAME - the GPU product name on which the + * specified X screen is running. + */ + +#define NV_CTRL_STRING_PRODUCT_NAME 0 /* R-- */ + + +/* + * NV_CTRL_STRING_VBIOS_VERSION - the video bios version on the GPU on + * which the specified X screen is running. + */ + +#define NV_CTRL_STRING_VBIOS_VERSION 1 /* R-- */ + + +/* + * NV_CTRL_STRING_NVIDIA_DRIVER_VERSION - string representation of the + * NVIDIA driver version number for the NVIDIA X driver in use. + */ + +#define NV_CTRL_STRING_NVIDIA_DRIVER_VERSION 3 /* R-- */ + + +/* + * NV_CTRL_STRING_DISPLAY_DEVICE_NAME - name of the display device + * specified in the display_mask argument. + */ + +#define NV_CTRL_STRING_DISPLAY_DEVICE_NAME 4 /* R-D */ + + +/* + * NV_CTRL_STRING_TV_ENCODER_NAME - name of the TV encoder used by the + * specified display device; only valid if the display device is a TV. + */ + +#define NV_CTRL_STRING_TV_ENCODER_NAME 5 /* R-D */ + +#define NV_CTRL_STRING_LAST_ATTRIBUTE NV_CTRL_STRING_TV_ENCODER_NAME + + + +/**************************************************************************/ +/* + * CTRLAttributeValidValuesRec - + * + * structure and related defines used by + * XNVCTRLQueryValidAttributeValues() to describe the valid values of + * a particular attribute. The type field will be one of: + * + * ATTRIBUTE_TYPE_INTEGER : the attribute is an integer value; there + * is no fixed range of valid values. + * + * ATTRIBUTE_TYPE_BITMASK : the attribute is an integer value, + * interpretted as a bitmask. + * + * ATTRIBUTE_TYPE_BOOL : the attribute is a boolean, valid values are + * either 1 (on/true) or 0 (off/false). + * + * ATTRIBUTE_TYPE_RANGE : the attribute can have any integer value + * between NVCTRLAttributeValidValues.u.range.min and + * NVCTRLAttributeValidValues.u.range.max (inclusive). + * + * ATTRIBUTE_TYPE_INT_BITS : the attribute can only have certain + * integer values, indicated by which bits in + * NVCTRLAttributeValidValues.u.bits.ints are on (for example: if bit + * 0 is on, then 0 is a valid value; if bit 5 is on, then 5 is a valid + * value, etc). This is useful for attributes like NV_CTRL_FSAA_MODE, + * which can only have certain values, depending on GPU. + * + * + * The permissions field of NVCTRLAttributeValidValuesRec is a bitmask + * that may contain: + * + * ATTRIBUTE_TYPE_READ + * ATTRIBUTE_TYPE_WRITE + * ATTRIBUTE_TYPE_DISPLAY + * + * See 'Key to Integer Attribute "Permissions"' at the top of this + * file for a description of what these three permission bits mean. + */ + +#define ATTRIBUTE_TYPE_UNKNOWN 0 +#define ATTRIBUTE_TYPE_INTEGER 1 +#define ATTRIBUTE_TYPE_BITMASK 2 +#define ATTRIBUTE_TYPE_BOOL 3 +#define ATTRIBUTE_TYPE_RANGE 4 +#define ATTRIBUTE_TYPE_INT_BITS 5 + +#define ATTRIBUTE_TYPE_READ 0x1 +#define ATTRIBUTE_TYPE_WRITE 0x2 +#define ATTRIBUTE_TYPE_DISPLAY 0x4 + +typedef struct _NVCTRLAttributeValidValues { + int type; + union { + struct { + int min; + int max; + } range; + struct { + unsigned int ints; + } bits; + } u; + unsigned int permissions; +} NVCTRLAttributeValidValuesRec; + + + +#define ATTRIBUTE_CHANGED_EVENT 0 + + +#endif /* __NVCTRL_H */ diff --git a/ksim/monitors/lm_sensors/NVCtrlLib.h b/ksim/monitors/lm_sensors/NVCtrlLib.h new file mode 100644 index 0000000..8d9cec4 --- /dev/null +++ b/ksim/monitors/lm_sensors/NVCtrlLib.h @@ -0,0 +1,184 @@ +#ifndef __NVCTRLLIB_H +#define __NVCTRLLIB_H + +#include "NVCtrl.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +/* + * XNVCTRLQueryExtension - + * + * Returns True if the extension exists, returns False otherwise. + * event_basep and error_basep are the extension event and error + * bases. Currently, no extension specific errors or events are + * defined. + */ + +Bool XNVCTRLQueryExtension ( + Display *dpy, + int *event_basep, + int *error_basep +); + +/* + * XNVCTRLQueryVersion - + * + * Returns True if the extension exists, returns False otherwise. + * major and minor are the extension's major and minor version + * numbers. + */ + +Bool XNVCTRLQueryVersion ( + Display *dpy, + int *major, + int *minor +); + + +/* + * XNVCTRLIsNvScreen + * + * Returns True is the specified screen is controlled by the NVIDIA + * driver. Returns False otherwise. + */ + +Bool XNVCTRLIsNvScreen ( + Display *dpy, + int screen +); + +/* + * XNVCTRLSetAttribute - + * + * Sets the attribute to the given value. The attributes and their + * possible values are listed in NVCtrl.h. + * + * Not all attributes require the display_mask parameter; see + * NVCtrl.h for details. + * + * Possible errors: + * BadValue - The screen or attribute doesn't exist. + * BadMatch - The NVIDIA driver is not present on that screen. + */ + +void XNVCTRLSetAttribute ( + Display *dpy, + int screen, + unsigned int display_mask, + unsigned int attribute, + int value +); + +/* + * XNVCTRLQueryAttribute - + * + * Returns True if the attribute exists. Returns False otherwise. + * If XNVCTRLQueryAttribute returns True, value will contain the + * value of the specified attribute. + * + * Not all attributes require the display_mask parameter; see + * NVCtrl.h for details. + * + * Possible errors: + * BadValue - The screen doesn't exist. + * BadMatch - The NVIDIA driver is not present on that screen. + */ + + +Bool XNVCTRLQueryAttribute ( + Display *dpy, + int screen, + unsigned int display_mask, + unsigned int attribute, + int *value +); + +/* + * XNVCTRLQueryStringAttribute - + * + * Returns True if the attribute exists. Returns False otherwise. + * If XNVCTRLQueryStringAttribute returns True, *ptr will point to an + * allocated string containing the string attribute requested. It is + * the caller's responsibility to free the string when done. + * + * Possible errors: + * BadValue - The screen doesn't exist. + * BadMatch - The NVIDIA driver is not present on that screen. + * BadAlloc - Insufficient resources to fulfill the request. + */ + +Bool XNVCTRLQueryStringAttribute ( + Display *dpy, + int screen, + unsigned int display_mask, + unsigned int attribute, + char **ptr +); + +/* + * XNVCTRLQueryValidAttributeValues - + * + * Returns True if the attribute exists. Returns False otherwise. If + * XNVCTRLQueryValidAttributeValues returns True, values will indicate + * the valid values for the specified attribute; see the description + * of NVCTRLAttributeValidValues in NVCtrl.h. + */ + +Bool XNVCTRLQueryValidAttributeValues ( + Display *dpy, + int screen, + unsigned int display_mask, + unsigned int attribute, + NVCTRLAttributeValidValuesRec *values +); + +/* + * XNVCtrlSelectNotify - + * + * This enables/disables receiving of NV-CONTROL events. The type + * specifies the type of event to enable (currently, the only type is + * ATTRIBUTE_CHANGED_EVENT); onoff controls whether receiving this + * type of event should be enabled (True) or disabled (False). + * + * Returns True if successful, or False if the screen is not + * controlled by the NVIDIA driver. + */ + +Bool XNVCtrlSelectNotify ( + Display *dpy, + int screen, + int type, + Bool onoff +); + + + +/* + * XNVCtrlEvent structure + */ + +typedef struct { + int type; + unsigned long serial; + Bool send_event; /* always FALSE, we don't allow send_events */ + Display *display; + Time time; + int screen; + unsigned int display_mask; + unsigned int attribute; + int value; +} XNVCtrlAttributeChangedEvent; + +typedef union { + int type; + XNVCtrlAttributeChangedEvent attribute_changed; + long pad[24]; +} XNVCtrlEvent; + +#if defined(__cplusplus) +} +#endif + +#endif /* __NVCTRLLIB_H */ diff --git a/ksim/monitors/lm_sensors/ksimsensors.cpp b/ksim/monitors/lm_sensors/ksimsensors.cpp new file mode 100644 index 0000000..e63f5cf --- /dev/null +++ b/ksim/monitors/lm_sensors/ksimsensors.cpp @@ -0,0 +1,189 @@ +/* ksim - a system monitor for kde + * + * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "ksimsensors.h" +#include "ksimsensors.moc" + +#include <kdebug.h> +#include <kapplication.h> +#include <klocale.h> +#include <kaboutapplication.h> +#include <kaboutdata.h> +#include <kconfig.h> + +#include <qlayout.h> + +#include <label.h> +#include <themetypes.h> +#include "sensorsconfig.h" +#include "sensorbase.h" + +KSIM_INIT_PLUGIN(PluginModule) + +PluginModule::PluginModule(const char *name) + : KSim::PluginObject(name) +{ + setConfigFileName(instanceName()); +} + +PluginModule::~PluginModule() +{ +} + +KSim::PluginView *PluginModule::createView(const char *className) +{ + return new SensorsView(this, className); +} + +KSim::PluginPage *PluginModule::createConfigPage(const char *className) +{ + return new SensorsConfig(this, className); +} + +void PluginModule::showAbout() +{ + QString version = kapp->aboutData()->version(); + + KAboutData aboutData(instanceName(), + I18N_NOOP("KSim Sensors Plugin"), version.latin1(), + I18N_NOOP("An lm_sensors plugin for KSim"), + KAboutData::License_GPL, "(C) 2001 Robbie Ward"); + + aboutData.addAuthor("Robbie Ward", I18N_NOOP("Author"), + "linuxphreak@gmx.co.uk"); + + KAboutApplication(&aboutData).exec(); +} + +SensorsView::SensorsView(KSim::PluginObject *parent, const char *name) + : DCOPObject("sensors"), KSim::PluginView(parent, name) +{ + config()->setGroup("Sensors"); + (new QVBoxLayout(this))->setAutoAdd(true); + + connect(SensorBase::self(), SIGNAL(updateSensors(const SensorList &)), + this, SLOT(updateSensors(const SensorList &))); + + insertSensors(); +} + +SensorsView::~SensorsView() +{ +} + +void SensorsView::reparseConfig() +{ + config()->setGroup("Sensors"); + bool displayFahrenheit = config()->readBoolEntry("displayFahrenheit", false); + int updateVal = config()->readNumEntry("sensorUpdateValue", 5); + SensorBase::self()->setDisplayFahrenheit(displayFahrenheit); + SensorBase::self()->setUpdateSpeed(updateVal * 1000); + + QString label; + QStringList names; + SensorItemList sensorItemList; + const SensorList &list = SensorBase::self()->sensorsList(); + + SensorList::ConstIterator it; + for (it = list.begin(); it != list.end(); ++it) { + config()->setGroup("Sensors"); + label = (*it).sensorType() + "/" + (*it).sensorName(); + names = QStringList::split(':', config()->readEntry(label)); + if (names[0] == "1") + sensorItemList.append(SensorItem((*it).sensorId(), names[1])); + } + + if (sensorItemList == m_sensorItemList) + return; + + m_sensorItemList.clear(); + m_sensorItemList = sensorItemList; + insertSensors(false); +} + +void SensorsView::insertSensors(bool createList) +{ + const SensorList &list = SensorBase::self()->sensorsList(); + + if (createList) { + QString label; + QStringList names; + + config()->setGroup("Sensors"); + bool displayFahrenheit = config()->readBoolEntry("displayFahrenheit", false); + int updateVal = config()->readNumEntry("sensorUpdateValue", 5); + SensorBase::self()->setDisplayFahrenheit(displayFahrenheit); + SensorBase::self()->setUpdateSpeed(updateVal * 1000); + + SensorList::ConstIterator it; + for (it = list.begin(); it != list.end(); ++it) { + label = (*it).sensorType() + "/" + (*it).sensorName(); + names = QStringList::split(':', config()->readEntry(label)); + if (names[0] == "1") + m_sensorItemList.append(SensorItem((*it).sensorId(), names[1])); + } + } + + SensorItemList::Iterator item; + for (item = m_sensorItemList.begin(); item != m_sensorItemList.end(); ++item) + (*item).setLabel(new KSim::Label(KSim::Types::None, this)); + + updateSensors(list); +} + +void SensorsView::updateSensors(const SensorList &sensorList) +{ + if (sensorList.isEmpty() || m_sensorItemList.isEmpty()) + return; + + SensorList::ConstIterator it; + for (it = sensorList.begin(); it != sensorList.end(); ++it) { + SensorItemList::Iterator item; + for (item = m_sensorItemList.begin(); item != m_sensorItemList.end(); ++item) { + if ((*item).id == (*it).sensorId()) { + if (!(*item).label->isVisible()) + (*item).label->show(); + + (*item).label->setText((*item).name + ": " + + (*it).sensorValue() + (*it).sensorUnit()); + } + } + } +} + +QString SensorsView::sensorValue(const QString &sensor, + const QString &label1) +{ + const SensorList &list = SensorBase::self()->sensorsList(); + config()->setGroup("Sensors"); + QStringList names = QStringList::split(':', + config()->readEntry(sensor + "/" + label1)); + + if (names[0] == "0" || list.isEmpty()) + return i18n("Sensor specified not found."); + + SensorList::ConstIterator it; + for (it = list.begin(); it != list.end(); ++it) { + if (sensor == (*it).sensorType() && label1 == (*it).sensorName()) { + return names[1] + QString(": ") + (*it).sensorValue() + (*it).sensorUnit(); + } + } + + return i18n("Sensor specified not found."); +} diff --git a/ksim/monitors/lm_sensors/ksimsensors.h b/ksim/monitors/lm_sensors/ksimsensors.h new file mode 100644 index 0000000..8446931 --- /dev/null +++ b/ksim/monitors/lm_sensors/ksimsensors.h @@ -0,0 +1,91 @@ +/* ksim - a system monitor for kde + * + * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef SENSORS_H +#define SENSORS_H + +#include <pluginmodule.h> +#include <label.h> +#include "ksimsensorsiface.h" + +class KConfig; +class SensorList; +class KInstance; + +/** + * This class is the lm_sensors monitor plugin + * + * @author Robbie Ward <linuxphreak@gmx.co.uk> + */ +class PluginModule : public KSim::PluginObject +{ + public: + PluginModule(const char *name); + ~PluginModule(); + + virtual KSim::PluginView *createView(const char *); + virtual KSim::PluginPage *createConfigPage(const char *); + + virtual void showAbout(); +}; + +class SensorsView : public KSim::PluginView, public KSimSensorsIface +{ + Q_OBJECT + public: + SensorsView(KSim::PluginObject *parent, const char *name); + ~SensorsView(); + + virtual void reparseConfig(); + virtual QString sensorValue(const QString &, const QString &); + + private slots: + void updateSensors(const SensorList &); + + private: + void insertSensors(bool createList = true); + + class SensorItem + { + public: + SensorItem() : id(-1), label(0) {} + SensorItem(int i, const QString &na) + : id(i), name(na), label(0) {} + ~SensorItem() { delete label; } + + bool operator==(const SensorItem &rhs) const + { + return (id == rhs.id && name == rhs.name); + } + + void setLabel(KSim::Label *lab) + { + delete label; + label = lab; + } + + int id; + QString name; + KSim::Label *label; + }; + + typedef QValueList<SensorItem> SensorItemList; + SensorItemList m_sensorItemList; +}; +#endif diff --git a/ksim/monitors/lm_sensors/ksimsensorsiface.h b/ksim/monitors/lm_sensors/ksimsensorsiface.h new file mode 100644 index 0000000..4bd50ce --- /dev/null +++ b/ksim/monitors/lm_sensors/ksimsensorsiface.h @@ -0,0 +1,33 @@ +/* ksim - a system monitor for kde + * + * Copyright (C) 2001 - 2004 Robbie Ward <linuxphreak@gmx.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KSIMSENSORSIFACE_H +#define KSIMSENSORSIFACE_H + +#include <dcopobject.h> + +class KSimSensorsIface : virtual public DCOPObject +{ + K_DCOP + k_dcop: + virtual QString sensorValue(const QString &sensorType, + const QString &sensorName) = 0; +}; + +#endif // KSIMSENSORSIFACE_H diff --git a/ksim/monitors/lm_sensors/nv_control.h b/ksim/monitors/lm_sensors/nv_control.h new file mode 100644 index 0000000..d94ee95 --- /dev/null +++ b/ksim/monitors/lm_sensors/nv_control.h @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2004 NVIDIA Corporation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of Version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See Version 2 + * of the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + * + */ + +#ifndef __NVCONTROL_H +#define __NVCONTROL_H + +#define NV_CONTROL_ERRORS 0 +#define NV_CONTROL_EVENTS 1 +#define NV_CONTROL_NAME "NV-CONTROL" + +#define NV_CONTROL_MAJOR 1 +#define NV_CONTROL_MINOR 6 + +#define X_nvCtrlQueryExtension 0 +#define X_nvCtrlIsNv 1 +#define X_nvCtrlQueryAttribute 2 +#define X_nvCtrlSetAttribute 3 +#define X_nvCtrlQueryStringAttribute 4 +#define X_nvCtrlQueryValidAttributeValues 5 +#define X_nvCtrlSelectNotify 6 +#define X_nvCtrlLastRequest (X_nvCtrlSelectNotify + 1) + +typedef struct { + CARD8 reqType; + CARD8 nvReqType; + CARD16 length B16; +} xnvCtrlQueryExtensionReq; +#define sz_xnvCtrlQueryExtensionReq 4 + +typedef struct { + BYTE type; /* X_Reply */ + CARD8 padb1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 major B16; + CARD16 minor B16; + CARD32 padl4 B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; +} xnvCtrlQueryExtensionReply; +#define sz_xnvCtrlQueryExtensionReply 32 + +typedef struct { + CARD8 reqType; + CARD8 nvReqType; + CARD16 length B16; + CARD32 screen B32; +} xnvCtrlIsNvReq; +#define sz_xnvCtrlIsNvReq 8 + +typedef struct { + BYTE type; /* X_Reply */ + CARD8 padb1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 isnv B32; + CARD32 padl4 B32; + CARD32 padl5 B32; + CARD32 padl6 B32; + CARD32 padl7 B32; + CARD32 padl8 B32; +} xnvCtrlIsNvReply; +#define sz_xnvCtrlIsNvReply 32 + +typedef struct { + CARD8 reqType; + CARD8 nvReqType; + CARD16 length B16; + CARD32 screen B32; + CARD32 display_mask B32; + CARD32 attribute B32; +} xnvCtrlQueryAttributeReq; +#define sz_xnvCtrlQueryAttributeReq 16 + +typedef struct { + BYTE type; + BYTE pad0; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 flags B32; + INT32 value B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; + CARD32 pad7 B32; +} xnvCtrlQueryAttributeReply; +#define sz_xnvCtrlQueryAttributeReply 32 + +typedef struct { + CARD8 reqType; + CARD8 nvReqType; + CARD16 length B16; + CARD32 screen B32; + CARD32 display_mask B32; + CARD32 attribute B32; + INT32 value B32; +} xnvCtrlSetAttributeReq; +#define sz_xnvCtrlSetAttributeReq 20 + +typedef struct { + CARD8 reqType; + CARD8 nvReqType; + CARD16 length B16; + CARD32 screen B32; + CARD32 display_mask B32; + CARD32 attribute B32; +} xnvCtrlQueryStringAttributeReq; +#define sz_xnvCtrlQueryStringAttributeReq 16 + +/* + * CtrlQueryStringAttribute reply struct + * n indicates the length of the string. + */ +typedef struct { + BYTE type; + BYTE pad0; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 flags B32; + CARD32 n B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; + CARD32 pad7 B32; +} xnvCtrlQueryStringAttributeReply; +#define sz_xnvCtrlQueryStringAttributeReply 32 + +typedef struct { + CARD8 reqType; + CARD8 nvReqType; + CARD16 length B16; + CARD32 screen B32; + CARD32 display_mask B32; + CARD32 attribute B32; +} xnvCtrlQueryValidAttributeValuesReq; +#define sz_xnvCtrlQueryValidAttributeValuesReq 16 + +typedef struct { + BYTE type; + BYTE pad0; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 flags B32; + INT32 attr_type B32; + INT32 min B32; + INT32 max B32; + CARD32 bits B32; + CARD32 perms B32; +} xnvCtrlQueryValidAttributeValuesReply; +#define sz_xnvCtrlQueryValidAttributeValuesReply 32 + +typedef struct { + CARD8 reqType; + CARD8 nvReqType; + CARD16 length B16; + CARD32 screen B32; + CARD16 notifyType B16; + CARD16 onoff B16; +} xnvCtrlSelectNotifyReq; +#define sz_xnvCtrlSelectNotifyReq 12 + +typedef struct { + union { + struct { + BYTE type; + BYTE detail; + CARD16 sequenceNumber B16; + } u; + struct { + BYTE type; + BYTE detail; + CARD16 sequenceNumber B16; + Time time B32; + CARD32 screen B32; + CARD32 display_mask B32; + CARD32 attribute B32; + CARD32 value B32; + CARD32 pad0 B32; + CARD32 pad1 B32; + } attribute_changed; + } u; +} xnvctrlEvent; + + +#endif /* __NVCONTROL_H */ diff --git a/ksim/monitors/lm_sensors/sensorbase.cpp b/ksim/monitors/lm_sensors/sensorbase.cpp new file mode 100644 index 0000000..9ccb247 --- /dev/null +++ b/ksim/monitors/lm_sensors/sensorbase.cpp @@ -0,0 +1,254 @@ +/* ksim - a system monitor for kde + * + * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "sensorbase.h" +#include "sensorbase.moc" +#include <ksimconfig.h> + +#include <kdebug.h> +#include <klocale.h> +#include <qglobal.h> +#include <klibloader.h> +#include <kstandarddirs.h> +#include <kconfig.h> + +#include <qtimer.h> +#include <qfile.h> +#include <qregexp.h> + +#include <stdio.h> + +#include <X11/Xlib.h> + +#include "NVCtrl.h" +#include "NVCtrlLib.h" + +SensorBase *SensorBase::m_self = 0; +SensorBase *SensorBase::self() +{ + if (!m_self) { + m_self = new SensorBase; + qAddPostRoutine(cleanup); + } + + return m_self; +} + +SensorBase::SensorBase() : QObject() +{ + KSim::Config::config()->setGroup("Sensors"); + QCString sensorsName("libsensors.so"); + + QStringList sensorLocations = KSim::Config::config()->readListEntry("sensorLocations"); + + QStringList::ConstIterator it; + for (it = sensorLocations.begin(); it != sensorLocations.end(); ++it) { + if (QFile::exists((*it).local8Bit() + sensorsName)) { + m_libLocation = (*it).local8Bit() + sensorsName; + break; + } + } + + m_library = KLibLoader::self()->library(m_libLocation); + kdDebug(2003) << sensorsName << " location = " << m_libLocation << endl; + m_loaded = init(); + + { + int eventBase; + int errorBase; + m_hasNVControl = XNVCTRLQueryExtension(qt_xdisplay(), &eventBase, &errorBase) == True; + } + + m_updateTimer = new QTimer(this); + connect(m_updateTimer, SIGNAL(timeout()), SLOT(update())); +} + +SensorBase::~SensorBase() +{ + if (!m_libLocation.isNull()) { + if (m_cleanup) m_cleanup(); + KLibLoader::self()->unloadLibrary(m_libLocation); + } +} + +void SensorBase::setUpdateSpeed(uint speed) +{ + if (m_updateTimer->isActive()) + m_updateTimer->stop(); + + update(); // just to make sure the display is updated ASAP + + if (speed == 0) + return; + + m_updateTimer->start(speed); +} + +void SensorBase::update() +{ + if (!m_loaded) + return; + + m_sensorList.clear(); + const ChipName *chip; + int currentSensor = 0; + int sensor = 0; + + while ((chip = m_detectedChips(&sensor)) != NULL) { + int first = 0, second = 0; + const FeatureData *sFeature = 0; + while ((sFeature = m_allFeatures(*chip, &first, &second)) != NULL) { + if (sFeature->mapping == NoMapping) { + char *name; + double value; + m_label(*chip, sFeature->number, &name); + m_feature(*chip, sFeature->number, &value); + + float returnValue = formatValue(QString::fromUtf8(name), float(value)); + QString label = formatString(QString::fromUtf8(name), returnValue); + QString chipset = chipsetString(chip); + + m_sensorList.append(SensorInfo(currentSensor++, label, + QString::fromUtf8(name), QString::fromUtf8(chip->prefix), + chipset, sensorType(QString::fromLatin1(name)))); + } + } + } + + if (m_hasNVControl) { + int temp = 0; + if (XNVCTRLQueryAttribute(qt_xdisplay(), qt_xscreen(), 0 /* not used? */, NV_CTRL_GPU_CORE_TEMPERATURE, &temp)) { + QString name = QString::fromLatin1("GPU Temp"); + m_sensorList.append(SensorInfo(currentSensor++, QString::number(temp), + name, QString::null, QString::null, sensorType(name))); + } + + if (XNVCTRLQueryAttribute(qt_xdisplay(), qt_xscreen(), 0 /* not used? */, NV_CTRL_AMBIENT_TEMPERATURE, &temp)) { + QString name = QString::fromLatin1("GPU Ambient Temp"); + m_sensorList.append(SensorInfo(currentSensor++, QString::number(temp), + name, QString::null, QString::null, sensorType(name))); + } + + } + + emit updateSensors(m_sensorList); +} + +void SensorBase::cleanup() +{ + if (!m_self) + return; + + delete m_self; + m_self = 0; +} + +bool SensorBase::init() +{ + if (m_libLocation.isNull()) { + kdError() << "Unable to find libsensors.so" << endl; + return false; + } + + m_init = (Init)m_library->symbol("sensors_init"); + if (!m_init) + return false; + + m_error = (Error)m_library->symbol("sensors_strerror"); + if (!m_error) + return false; + + m_detectedChips = (GetDetectedChips *)m_library->symbol("sensors_get_detected_chips"); + m_allFeatures = (GetAllFeatures *)m_library->symbol("sensors_get_all_features"); + m_label = (Label)m_library->symbol("sensors_get_label"); + m_feature = (Feature)m_library->symbol("sensors_get_feature"); + + if (!m_detectedChips || !m_allFeatures || !m_label || !m_feature) + return false; + + m_cleanup = (Cleanup)m_library->symbol("sensors_cleanup"); + if (!m_cleanup) + return false; + + int res; + FILE *input; + + if ((input = fopen("/etc/sensors.conf", "r")) == 0) + return false; + + if ((res = m_init(input))) { + if (res == ProcError) { + kdError() << "There was an error reading the sensor information\n" + << "Make sure sensors.o and i2c-proc.o are loaded" << endl; + } + else { + kdError() << m_error(res) << endl; + } + + fclose(input); + return false; + } + + fclose(input); + + return true; +} + +QString SensorBase::sensorType(const QString &name) +{ + if (name.findRev("fan", -1, false) != -1) + return i18n("Rounds per minute", " RPM"); + + if (name.findRev("temp", -1, false) != -1) + if (SensorBase::fahrenheit()) + return QString::fromLatin1("F"); + else + return QString::fromLatin1("C"); + + if (name.findRev(QRegExp("[^\\+]?[^\\-]?V$")) != -1) + return i18n("Volt", "V"); + + return QString::null; +} + +QString SensorBase::chipsetString(const ChipName *c) +{ + QString data = QString::fromUtf8(c->prefix); + + if (c->bus == BusISA) + return QString().sprintf("%s-isa-%04x", data.utf8().data(), c->addr); + + return QString().sprintf("%s-i2c-%d-%02x", data.utf8().data(), c->bus, c->addr); +} + +float SensorBase::formatValue(const QString &label, float value) +{ + if (label.findRev("temp", -1, false) != -1) + return toFahrenheit(value); + + return value; +} + +QString SensorBase::formatString(const QString &label, float value) +{ + if (label.findRev("fan", -1, false) != -1) + return QString::number(value); + + return QString::number(value,'f',2); +} diff --git a/ksim/monitors/lm_sensors/sensorbase.h b/ksim/monitors/lm_sensors/sensorbase.h new file mode 100644 index 0000000..c819d48 --- /dev/null +++ b/ksim/monitors/lm_sensors/sensorbase.h @@ -0,0 +1,175 @@ +/* ksim - a system monitor for kde + * + * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef SENSORBASE_H +#define SENSORBASE_H + +#include <qobject.h> +#include <qvaluelist.h> +#include <qcstring.h> + +class QTimer; +class KLibrary; + +class SensorInfo +{ + public: + SensorInfo() {} + SensorInfo(int id, + const QString &sensorValue, + const QString &sensorName, + const QString &sensorType, + const QString &chipsetName, + const QString &sensorUnit) + : m_id(id), m_sensor(sensorValue), + m_sensorName(sensorName), + m_sensorType(sensorType), + m_chipsetName(chipsetName), + m_sensorUnit(sensorUnit) {} + + /** + * @return the sensor Id + */ + int sensorId() const { return m_id; } + /** + * @return the current value, eg: 5000 + */ + const QString &sensorValue() const { return m_sensor; } + /** + * @return the sensor name, eg: temp1, fan2 + */ + const QString &sensorName() const { return m_sensorName; } + /** + * @return the sensor type name, eg: w83782d + */ + const QString &sensorType() const { return m_sensorType; } + /** + * @return the chipset name, eg: w83782d-i2c-0-2d + */ + const QString &chipsetName() const { return m_chipsetName; } + /** + * @return the unit name, eg: RPM, C or F if display fahrenheit is enabled + */ + const QString &sensorUnit() const { return m_sensorUnit; } + + private: + int m_id; + QString m_sensor; + QString m_sensorName; + QString m_sensorType; + QString m_chipsetName; + QString m_sensorUnit; +}; + +class SensorList : public QValueList<SensorInfo> +{ + public: + SensorList() {} + SensorList(const SensorList &sensorList) + : QValueList<SensorInfo>(sensorList) {} + SensorList(const QValueList<SensorInfo> &sensorList) + : QValueList<SensorInfo>(sensorList) {} + SensorList(const SensorInfo &sensor) { append(sensor); } +}; + +class SensorBase : public QObject +{ + Q_OBJECT + public: + static SensorBase *self(); + + const SensorList &sensorsList() const { return m_sensorList; } + bool fahrenheit() { return m_fahrenheit; } + + signals: + void updateSensors(const SensorList&); + + public slots: + void setUpdateSpeed(uint); + void setDisplayFahrenheit(bool fah) { m_fahrenheit = fah; } + + private slots: + void update(); + + protected: + SensorBase(); + ~SensorBase(); + + private: + SensorBase(const SensorBase &); + SensorBase &operator=(const SensorBase &); + + static void cleanup(); + struct ChipName + { + char *prefix; + int bus; + int addr; + char *busname; + }; + + struct FeatureData + { + int number; + const char *name; + int mapping; + int unused; + int mode; + }; + + enum { ProcError=4, NoMapping=-1, BusISA=-1 }; + typedef void (*Cleanup)(); + typedef int (*Init)(FILE *); + typedef const char *(*Error)(int); + typedef const ChipName *(GetDetectedChips)(int *); + typedef const FeatureData *(GetAllFeatures)(ChipName, int *, int *); + typedef int (*Label)(ChipName, int, char **); + typedef int (*Feature)(ChipName, int, double *); + + bool init(); + float toFahrenheit(float value); + QString sensorType(const QString &name); + QString chipsetString(const ChipName *c); + float formatValue(const QString &label, float value); + QString formatString(const QString &label, float value); + + SensorList m_sensorList; + QTimer *m_updateTimer; + KLibrary *m_library; + QCString m_libLocation; + bool m_loaded; + bool m_fahrenheit; + + bool m_hasNVControl; + + Init m_init; + Error m_error; + GetDetectedChips *m_detectedChips; + GetAllFeatures *m_allFeatures; + Label m_label; + Feature m_feature; + Cleanup m_cleanup; + static SensorBase *m_self; +}; + +inline float SensorBase::toFahrenheit(float value) +{ + return fahrenheit() ? (value * (9.0F / 5.0F) + 32.0F) : value; +} +#endif // SENSORBASE_H diff --git a/ksim/monitors/lm_sensors/sensorsconfig.cpp b/ksim/monitors/lm_sensors/sensorsconfig.cpp new file mode 100644 index 0000000..6e2b4b3 --- /dev/null +++ b/ksim/monitors/lm_sensors/sensorsconfig.cpp @@ -0,0 +1,241 @@ +/* ksim - a system monitor for kde + * + * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "sensorsconfig.h" +#include "sensorsconfig.moc" +#include "sensorbase.h" + +#include <klocale.h> +#include <kiconloader.h> +#include <klistview.h> +#include <knuminput.h> +#include <kconfig.h> +#include <kdebug.h> +#include <kinputdialog.h> + +#include <qtimer.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qcheckbox.h> +#include <qcursor.h> +#include <qpopupmenu.h> +#include <qpushbutton.h> + +class SensorViewItem : public QCheckListItem +{ + public: + SensorViewItem(QListView *parent, const QString &text1, + const QString &text2, const QString &text3, + const QString &text4) + : QCheckListItem(parent, text1, CheckBox) + { + setText(1, text2); + setText(2, text3); + setText(3, text4); + } +}; + +SensorsConfig::SensorsConfig(KSim::PluginObject *parent, const char *name) + : KSim::PluginPage(parent, name) +{ + m_layout = new QGridLayout(this); + m_layout->setSpacing(6); + m_neverShown = true; + + m_sensorView = new KListView(this); + m_sensorView->addColumn(i18n("No.")); + m_sensorView->addColumn(i18n("Label")); + m_sensorView->addColumn(i18n("Sensors")); + m_sensorView->addColumn(i18n("Value")); + m_sensorView->setColumnWidth(0, 40); + m_sensorView->setColumnWidth(1, 60); + m_sensorView->setColumnWidth(2, 80); + m_sensorView->setAllColumnsShowFocus(true); + connect(m_sensorView, SIGNAL(contextMenu(KListView *, + QListViewItem *, const QPoint &)), this, SLOT(menu(KListView *, + QListViewItem *, const QPoint &))); + + connect( m_sensorView, SIGNAL( doubleClicked( QListViewItem * ) ), + SLOT( modify( QListViewItem * ) ) ); + + m_layout->addMultiCellWidget(m_sensorView, 1, 1, 0, 3); + + m_modify = new QPushButton( this ); + m_modify->setText( i18n( "Modify..." ) ); + connect( m_modify, SIGNAL( clicked() ), SLOT( modify() ) ); + m_layout->addMultiCellWidget( m_modify, 2, 2, 3, 3 ); + + m_fahrenBox = new QCheckBox(i18n("Display Fahrenheit"), this); + m_layout->addMultiCellWidget(m_fahrenBox, 3, 3, 0, 3); + + m_updateLabel = new QLabel(this); + m_updateLabel->setText(i18n("Update interval:")); + m_updateLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, + QSizePolicy::Fixed)); + m_layout->addMultiCellWidget(m_updateLabel, 4, 4, 0, 0); + + m_sensorSlider = new KIntSpinBox(this); + m_layout->addMultiCellWidget(m_sensorSlider, 4, 4, 1, 1); + + QLabel *intervalLabel = new QLabel(this); + intervalLabel->setText(i18n("seconds")); + intervalLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, + QSizePolicy::Fixed)); + m_layout->addMultiCellWidget(intervalLabel, 4, 4, 2, 2); +} + +SensorsConfig::~SensorsConfig() +{ +} + +void SensorsConfig::saveConfig() +{ + config()->setGroup("Sensors"); + config()->writeEntry("sensorUpdateValue", m_sensorSlider->value()); + config()->writeEntry("displayFahrenheit", m_fahrenBox->isChecked()); + + for (QListViewItemIterator it(m_sensorView); it.current(); ++it) { + config()->setGroup("Sensors"); + config()->writeEntry(it.current()->text(2), + QString::number(static_cast<QCheckListItem *>(it.current())->isOn()) + + ":" + it.current()->text(1)); + } +} + +void SensorsConfig::readConfig() +{ + config()->setGroup("Sensors"); + m_fahrenBox->setChecked(config()->readBoolEntry("displayFahrenheit", false)); + m_sensorSlider->setValue(config()->readNumEntry("sensorUpdateValue", 15)); + + QStringList names; + for (QListViewItemIterator it(m_sensorView); it.current(); ++it) { + config()->setGroup("Sensors"); + names = QStringList::split(":", config()->readEntry(it.current()->text(2), "0:")); + if (!names[1].isNull()) + it.current()->setText(1, names[1]); + static_cast<QCheckListItem *>(it.current())->setOn(names[0].toInt()); + } +} + +void SensorsConfig::menu(KListView *, QListViewItem *, const QPoint &) +{ + m_popupMenu = new QPopupMenu(this); + + m_popupMenu->insertItem(i18n("Select All"), 1); + m_popupMenu->insertItem(i18n("Unselect All"), 2); + m_popupMenu->insertItem(i18n("Invert Selection"), 3); + + switch (m_popupMenu->exec(QCursor::pos())) { + case 1: + selectAll(); + break; + case 2: + unSelectAll(); + break; + case 3: + invertSelect(); + break; + } + + delete m_popupMenu; +} + +void SensorsConfig::selectAll() +{ + for (QListViewItemIterator it(m_sensorView); it.current(); ++it) + static_cast<QCheckListItem *>(it.current())->setOn(true); +} + +void SensorsConfig::unSelectAll() +{ + for (QListViewItemIterator it(m_sensorView); it.current(); ++it) + static_cast<QCheckListItem *>(it.current())->setOn(false); +} + +void SensorsConfig::invertSelect() +{ + for (QListViewItemIterator it(m_sensorView); it.current(); ++it) { + QCheckListItem *item = static_cast<QCheckListItem *>(it.current()); + if (item->isOn()) + item->setOn(false); + else + item->setOn(true); + } +} + +void SensorsConfig::initSensors() +{ + const SensorList &sensorList = SensorBase::self()->sensorsList(); + + int i = 0; + QString label; + QStringList sensorInfo; + SensorList::ConstIterator it; + for (it = sensorList.begin(); it != sensorList.end(); ++it) { + label.sprintf("%02i", ++i); + (void) new SensorViewItem(m_sensorView, label, + (*it).sensorName(), (*it).sensorType() + "/" + (*it).sensorName(), + (*it).sensorValue() + (*it).sensorUnit()); + } + + QStringList names; + for (QListViewItemIterator it(m_sensorView); it.current(); ++it) { + config()->setGroup("Sensors"); + names = QStringList::split(":", config()->readEntry(it.current()->text(2), "0:")); + if (!names[1].isNull()) + it.current()->setText(1, names[1]); + static_cast<QCheckListItem *>(it.current())->setOn(names[0].toInt()); + } +} + +void SensorsConfig::modify( QListViewItem * item ) +{ + if ( !item ) + return; + + bool ok = false; + QString text = KInputDialog::getText( i18n( "Modify Sensor Label" ), i18n( "Sensor label:" ), + item->text( 1 ), &ok, this ); + + if ( ok ) + item->setText( 1, text ); +} + +void SensorsConfig::modify() +{ + modify( m_sensorView->selectedItem() ); +} + +void SensorsConfig::showEvent(QShowEvent *) +{ + if (m_neverShown) { + initSensors(); + m_neverShown = false; + } + else { + const SensorList &list = SensorBase::self()->sensorsList(); + SensorList::ConstIterator it; + for (it = list.begin(); it != list.end(); ++it) { + QListViewItem *item = m_sensorView->findItem((*it).sensorName(), 1); + if (item) + item->setText(3, (*it).sensorValue() + (*it).sensorUnit()); + } + } +} diff --git a/ksim/monitors/lm_sensors/sensorsconfig.h b/ksim/monitors/lm_sensors/sensorsconfig.h new file mode 100644 index 0000000..28d656e --- /dev/null +++ b/ksim/monitors/lm_sensors/sensorsconfig.h @@ -0,0 +1,69 @@ +/* ksim - a system monitor for kde + * + * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef SENSORSIMPL_H +#define SENSORSIMPL_H + +#include <pluginmodule.h> + +class QPushButton; +class QCheckListItem; +class QGridLayout; +class QLabel; +class KListView; +class QListViewItem; +class QPopupMenu; +class KIntSpinBox; +class QCheckBox; +class QTimer; + +class SensorsConfig : public KSim::PluginPage +{ + Q_OBJECT + public: + SensorsConfig(KSim::PluginObject *parent, const char *name); + ~SensorsConfig(); + + void saveConfig(); + void readConfig(); + + private slots: + void menu(KListView *, QListViewItem *, const QPoint &); + void initSensors(); + void selectAll(); + void unSelectAll(); + void invertSelect(); + + void modify( QListViewItem * ); + void modify(); + + protected: + void showEvent(QShowEvent *); + + private: + bool m_neverShown; + QLabel *m_updateLabel; + KIntSpinBox *m_sensorSlider; + KListView *m_sensorView; + QCheckBox *m_fahrenBox; + QGridLayout *m_layout; + QPopupMenu *m_popupMenu; + QPushButton * m_modify; +}; +#endif |