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/>.
28
#include "applet-struct.h"
29
#include "applet-notifications.h"
30
#include "applet-cpusage.h"
31
#include "applet-rame.h"
32
#include "applet-nvidia.h"
33
#include "applet-monitor.h"
36
void cd_sysmonitor_get_data (CairoDockModuleInstance *myApplet)
38
myData.bNeedsUpdate = FALSE;
40
if (myConfig.bShowCpu)
42
cd_sysmonitor_get_cpu_data (myApplet);
44
if (myConfig.bShowRam || myConfig.bShowSwap)
46
cd_sysmonitor_get_ram_data (myApplet);
48
if (myConfig.bShowNvidia)
50
if ((myData.iTimerCount % 3) == 0) // la temperature ne varie pas tres vite et le script nvidia-settings est lours, on decide donc de ne mettre a jour qu'une fois sur 3.
51
cd_sysmonitor_get_nvidia_data (myApplet);
54
if (! myData.bInitialized)
56
cd_sysmonitor_get_cpu_info (myApplet);
57
myData.bInitialized = TRUE;
59
myData.iTimerCount ++;
63
gboolean cd_sysmonitor_update_from_data (CairoDockModuleInstance *myApplet)
65
static double s_fValues[CD_SYSMONITOR_NB_MAX_VALUES];
68
if ( ! myData.bAcquisitionOK)
70
cd_warning ("One or more datas couldn't be retrieved");
71
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON ("N/A"); // plus discret qu'une bulle de dialogue.
72
if (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_LABEL)
73
CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.defaultTitle);
74
memset (s_fValues, 0, sizeof (s_fValues));
75
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
79
if (! myData.bInitialized)
81
if (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_ICON)
82
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (myDock ? "..." : D_("Loading"));
83
memset (s_fValues, 0, sizeof (s_fValues));
84
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
88
// Copier les donnes en memoire partagee...
90
if (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_ICON || (myDock && myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_LABEL)) // on affiche les valeurs soit en info-rapide, soit sur l'etiquette en mode dock.
92
gboolean bOneLine = (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_LABEL);
93
GString *sInfo = g_string_new ("");
94
if (myConfig.bShowCpu)
96
g_string_printf (sInfo, (myData.fCpuPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
97
(myDesklet ? "CPU:" : ""),
99
(bOneLine ? " - " : "\n"));
101
if (myConfig.bShowRam)
103
g_string_append_printf (sInfo, (myData.fRamPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
104
(myDesklet ? "RAM:" : ""),
106
(bOneLine ? " - " : "\n"));
108
if (myConfig.bShowSwap)
110
g_string_append_printf (sInfo, (myData.fSwapPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
111
(myDesklet ? "SWAP:" : ""),
113
(bOneLine ? " - " : "\n"));
115
if (myConfig.bShowNvidia)
117
g_string_append_printf (sInfo, "%s%d°C%s",
118
(myDesklet ? "GPU:" : ""),
120
(bOneLine ? " - " : "\n"));
122
sInfo->str[sInfo->len-(bOneLine?3:1)] = '\0';
124
CD_APPLET_SET_NAME_FOR_MY_ICON (sInfo->str);
126
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (sInfo->str);
127
g_string_free (sInfo, TRUE);
130
if (myData.bNeedsUpdate || myConfig.iDisplayType == CD_SYSMONITOR_GRAPH)
133
if (myConfig.bShowCpu)
135
s_fValues[i++] = myData.fCpuPercent / 100.;
137
if (myConfig.bShowRam)
139
s_fValues[i++] = myData.fRamPercent / 100.;
141
if (myConfig.bShowSwap)
143
s_fValues[i++] = (myData.swapTotal ? (myConfig.bShowFreeMemory ? (double)myData.swapFree : (double)myData.swapUsed) / myData.swapTotal : 0.);
145
if (myConfig.bShowNvidia)
147
s_fValues[i++] = myData.fGpuTempPercent / 100.;
148
if (myData.bAlerted && myData.iGPUTemp < myConfig.iAlertLimit)
149
myData.bAlerted = FALSE; //On reinitialise l'alerte quand la temperature descend en dessou de la limite.
151
if (!myData.bAlerted && myData.iGPUTemp >= myConfig.iAlertLimit)
152
cd_nvidia_alert (myApplet);
154
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
159
CD_APPLET_LEAVE (myData.bAcquisitionOK);
160
//return myData.bAcquisitionOK;
164
void cd_sysmonitor_format_value (double fValue, int iNumValue, gchar *cFormatBuffer, int iBufferLength, CairoDockModuleInstance *myApplet)
167
if (myConfig.bShowCpu)
170
if (i == iNumValue) // c'est celle-la qu'on veut afficher.
172
snprintf (cFormatBuffer, iBufferLength, fValue < .0995 ? "%.1f%%" : (fValue < 1 ? " %.0f%%" : "%.0f%%"), fValue * 100.);
176
if (myConfig.bShowRam)
181
snprintf (cFormatBuffer, iBufferLength, fValue < .0995 ? "%.1f%%" : (fValue < 1 ? " %.0f%%" : "%.0f%%"), fValue * 100.);
185
if (myConfig.bShowSwap)
190
snprintf (cFormatBuffer, iBufferLength, fValue < .0995 ? "%.1f%%" : (fValue < 1 ? " %.0f%%" : "%.0f%%"), fValue * 100.);
194
if (myConfig.bShowNvidia)
199
double fTemp = myConfig.iLowerLimit + fValue * (myConfig.iUpperLimit - myConfig.iLowerLimit);
200
snprintf (cFormatBuffer, iBufferLength, fTemp < 100. ? " %.0f�" : "%.0f�", fTemp);
204
snprintf (cFormatBuffer, iBufferLength, fValue < .0995 ? "%.1f" : (fValue < 1 ? " %.0f" : "%.0f"), fValue * 100.);