2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
29
#include "applet-struct.h"
30
#include "applet-nvidia.h"
32
void cd_sysmonitor_get_nvidia_data (CairoDockModuleInstance *myApplet)
34
gchar *cCommand = g_strdup_printf ("nvidia-settings -q GPUCoreTemp -t");
35
gchar *cResult = cairo_dock_launch_command_sync (cCommand);
40
iGpuTemp = atoi (cResult);
43
cd_warning("nVidia : couldn't acquire GPU temperature\n is 'nvidia-settings' installed on your system and its version >= 1.0 ?");
44
myData.bAcquisitionOK = FALSE;
47
myData.iGPUTemp = iGpuTemp;
50
if (myData.iGPUTemp <= myConfig.iLowerLimit)
51
myData.fGpuTempPercent = 0;
52
else if (myData.iGPUTemp >= myConfig.iUpperLimit)
53
myData.fGpuTempPercent = 100.;
55
myData.fGpuTempPercent = 100. * (myData.iGPUTemp - myConfig.iLowerLimit) / (myConfig.iUpperLimit - myConfig.iLowerLimit);
56
if (fabs (myData.fGpuTempPercent - myData.fPrevGpuTempPercent) > 1)
58
myData.fPrevGpuTempPercent = myData.fGpuTempPercent;
59
myData.bNeedsUpdate = TRUE;
64
static void _get_nvidia_info (CairoDockModuleInstance *myApplet)
66
gchar *cCommand = g_strdup_printf ("bash %s/nvidia-config", MY_APPLET_SHARE_DATA_DIR);
67
gchar *cResult = cairo_dock_launch_command_sync (cCommand);
69
if (cResult == NULL || *cResult == '\n')
71
myData.cGPUName = g_strdup ("none");
75
gchar **cInfopipesList = g_strsplit (cResult, "\n", -1);
80
g_free (myData.cGPUName);
81
myData.cGPUName = NULL;
82
g_free (myData.cDriverVersion);
83
myData.cDriverVersion = NULL;
85
for (i = 0; cInfopipesList[i] != NULL; i ++) {
86
cOneInfopipe = cInfopipesList[i];
87
if (*cOneInfopipe == '\0')
90
if ((i == 0) && (strcmp (cOneInfopipe,"nvidia") == 0)) {
91
cd_warning ("problem while getting nVidia GPU temperature.");
92
g_strfreev (cInfopipesList);
97
gchar *str = g_strstr_len (cOneInfopipe, strlen (cOneInfopipe), "version");
102
gchar *str2 = strchr (str, ' ');
105
int iMajorVersion=0, iMinorVersion=0, iMicroVersion=0;
106
cairo_dock_get_version_from_string (str, &iMajorVersion, &iMinorVersion, &iMicroVersion);
107
/*if (iMajorVersion == 0 || (iMajorVersion == 1 && iMinorVersion < 0)) { /// A confirmer ...
108
myData.bSettingsTooOld == TRUE;
109
cd_warning ("Attention : your nvidia-settings's version is too old (%d.%d.%d)", iMajorVersion, iMinorVersion, iMicroVersion);
114
else if (i == 1) { //GPU Name
115
myData.cGPUName = g_strdup (cOneInfopipe);
116
gchar *str = strchr (myData.cGPUName, ')');
120
else if (i == 2) { //Video Ram
121
myData.iVideoRam = atoi (cOneInfopipe);
122
myData.iVideoRam = myData.iVideoRam >> 10; // passage en Mo.
124
else if (i == 3) { //Driver Version
125
myData.cDriverVersion = g_strdup (cOneInfopipe);
130
cd_debug ("nVidia %s %dMB %sV %d°C", myData.cGPUName, myData.iVideoRam, myData.cDriverVersion, myData.iGPUTemp);
132
g_strfreev (cInfopipesList);
135
void cd_sysmonitor_get_nivdia_info (CairoDockModuleInstance *myApplet, GString *pInfo)
137
if (myData.cGPUName == NULL) // nvidia-config n'a encore jamais ete appele.
138
_get_nvidia_info (myApplet);
140
if (myData.cGPUName && strcmp (myData.cGPUName, "none") != 0) // nvidia-config est passe avec succes.
142
if (!myConfig.bShowNvidia)
143
cd_sysmonitor_get_nvidia_data (myApplet); // le thread ne passe pas par la => pas de conflit.
145
g_string_append_printf (pInfo, "\n%s: %s\n %s: %d%s \n %s: %s\n %s: %d°C",
146
D_("GPU model"), myData.cGPUName,
147
D_("Video Ram"), myData.iVideoRam, D_("Mb"),
148
D_("Driver Version"), myData.cDriverVersion,
149
D_("Core Temperature"), myData.iGPUTemp);
155
void cd_nvidia_alert (CairoDockModuleInstance *myApplet)
157
if (myData.bAlerted || ! myConfig.bAlert)
160
cairo_dock_remove_dialog_if_any (myIcon);
161
cairo_dock_show_temporary_dialog_with_icon_printf (D_("Alert! Graphic Card core temperature has reached %d°C"), myIcon, myContainer, 4e3, MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE, myData.iGPUTemp);
163
if (myConfig.bAlertSound)
164
cairo_dock_play_sound (myConfig.cSoundPath);
166
myData.bAlerted = TRUE;