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/>.
20
//\________________ Add your name in the copyright file (and / or modify your name here)
22
#include <cairo-dock.h>
24
#include "applet-struct.h"
25
#include "applet-draw.h"
26
#include "applet-xml.h"
27
#include "applet-nvidia.h"
28
#include "applet-cpusage.h"
29
#include "applet-disk-usage.h"
30
#include "applet-rame.h"
32
gchar* ltrim( gchar* str, const gchar* t ) // Couper tout depuis la gauche
36
char look[ 256 ] = { 1, 0 };
38
look[ (unsigned char)*t++ ] = 1;
41
while( *curStr && look[ *curStr ] )
43
strcpy( str, curStr );
48
gchar* rtrim( gchar* str, const gchar* t ) // Couper tout depuis la droite
50
char* curEnd = str, *end = str;
52
char look[ 256 ] = { 1, 0 };
54
look[ (unsigned char)*t++ ] = 1;
68
gchar *g_str_replace (const gchar *cString, const gchar *cWord, const gchar *cReplace)
70
if (g_strstr_len (cString, -1, cWord) != NULL) // On remplace
72
gchar *cFinalString = g_strdup_printf("%s", cString);
73
while (g_strstr_len (cFinalString, -1, cWord) != NULL)
75
gchar *cPart1 = g_strdup_printf("%s", cFinalString);
76
gchar *cWordTemp = g_strdup_printf("%s", cWord);
77
g_strreverse (cPart1);
78
g_strreverse (cWordTemp);
79
cPart1 = strstr(cPart1, cWordTemp) ;
80
ltrim( cPart1, cWordTemp );
81
g_strreverse (cPart1);
82
gchar *cPart2 = g_strdup_printf("%s", cFinalString);
84
while (g_strstr_len (cPart2, -1, cWord) != NULL)
86
cPart2 = strstr(cPart2, cWord);
87
ltrim( cPart2, cWord );
89
// On colle le texte au milieu
90
cFinalString = g_strdup_printf ("%s%s%s", cPart1, g_strdup_printf("%s",cReplace), cPart2);
93
return g_strdup_printf("%s", cFinalString);
96
return g_strdup_printf("%s",cString); // On retourne la phrase d'origine
100
double _Ko_to_Mo (CairoDockModuleInstance *myApplet , double fValueInKo)
102
fValueInKo = fValueInKo / 1024;
106
double _Ko_to_Go (CairoDockModuleInstance *myApplet , double fValueInKo)
108
fValueInKo = _Ko_to_Mo (myApplet ,fValueInKo);
109
fValueInKo = _Ko_to_Mo (myApplet ,fValueInKo);
114
void cd_launch_command (CairoDockModuleInstance *myApplet)
118
myData.bNeedsUpdate = FALSE;
119
if (myConfig.bShowCpu)
120
cd_sysmonitor_get_cpu_data (myApplet);
121
if (myConfig.bShowRam || myConfig.bShowSwap)
122
cd_sysmonitor_get_ram_data (myApplet);
123
if (myConfig.bShowNvidia)
125
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.
126
cd_sysmonitor_get_nvidia_data (myApplet);
128
if (! myData.bInitialized)
130
cd_sysmonitor_get_cpu_info (myApplet);
131
myData.bInitialized = TRUE;
133
myData.iTimerCount ++;
141
for (it = myData.pTextZoneList; it != NULL; it = it->next)
143
pTextZone = it->data;
147
if (!pTextZone->bImgDraw && pTextZone->cImgPath != NULL) // L'image n'a pas encore été chargée
150
if (pTextZone->iWidth == 0 && pTextZone->iHeight ==0) // On n'a pas forcé le ratio
152
if (pTextZone->iImgSize == 0) // Oups !! -> Pas de taille de spécifié -> On en impose une !
153
pTextZone->iImgSize = 50;
155
double fImgW=0, fImgH=0;
156
CairoDockLoadImageModifier iLoadingModifier = 0; /// CAIRO_DOCK_FILL_SPACE
157
iLoadingModifier |= CAIRO_DOCK_KEEP_RATIO;
159
pTextZone->pImgSurface = cairo_dock_create_surface_from_image (pTextZone->cImgPath,
161
pTextZone->iImgSize, pTextZone->iImgSize,
166
//\_______________ On garde l'aire de la surface/texture.
167
pTextZone->iWidth = (int)fImgW;
168
pTextZone->iHeight = (int)fImgH;
171
pTextZone->pImgSurface = cairo_dock_create_surface_for_icon (pTextZone->cImgPath,
172
pTextZone->iWidth, pTextZone->iHeight);
174
pTextZone->bImgDraw = TRUE; // L'image est désormais chargée -> On peut la dessiner
181
if (pTextZone->iRefresh != 0)
185
if (pTextZone->bRefresh)
187
if (pTextZone->bIsBash) // C'est une commande bash !
188
pTextZone->cResult = cairo_dock_launch_command_sync (pTextZone->cCommand);
189
else if (pTextZone->bIsInternal)// C'est une commande interne !
192
if (strcmp (pTextZone->cCommand, "cpuperc") == 0)
194
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fCpuPercent);
196
if (atof(pTextZone->cResult) < 10)
197
pTextZone->cResult = g_strdup_printf ("%.1f", myData.fCpuPercent);
199
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fCpuPercent);
202
else if (strcmp (pTextZone->cCommand, "cpuperc2f") == 0) // Restreint à 2 chiffres : de 00 à 99 !
204
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fCpuPercent);
206
if (atof(pTextZone->cResult) < 10)
207
pTextZone->cResult = g_strdup_printf ("0%.0f", myData.fCpuPercent);
208
else if (atof(pTextZone->cResult) == 100)
209
pTextZone->cResult = g_strdup_printf ("99");
211
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fCpuPercent);
214
else if (strcmp (pTextZone->cCommand, "memperc") == 0)
216
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fRamPercent);
218
if (atof(pTextZone->cResult) < 10)
219
pTextZone->cResult = g_strdup_printf ("0%.0f", myData.fRamPercent);
220
else if (atof(pTextZone->cResult) == 100)
221
pTextZone->cResult = g_strdup_printf ("99");
223
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fRamPercent);
226
else if (strcmp (pTextZone->cCommand, "memperc2f") == 0) // Restreint à 2 chiffres : de 00 à 99 !
228
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fRamPercent);
230
if (atof(pTextZone->cResult) < 10)
231
pTextZone->cResult = g_strdup_printf ("%.1f", myData.fRamPercent);
233
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fRamPercent);
237
else if (strcmp (pTextZone->cCommand, "mem") == 0) // en Mo
239
pTextZone->cResult = g_strdup_printf ("%f", _Ko_to_Mo(myApplet, myData.ramTotal /100. * myData.fRamPercent));
240
pTextZone->cResult = g_strdup_printf ("%.0f", atof(pTextZone->cResult));
243
else if (strcmp (pTextZone->cCommand, "memg") == 0) // Identique à mem mais en Go
245
pTextZone->cResult = g_strdup_printf ("%f", _Ko_to_Go(myApplet, myData.ramTotal /100. * myData.fRamPercent));
246
pTextZone->cResult = g_strdup_printf ("%.2f", atof(pTextZone->cResult));
249
else if (strcmp (pTextZone->cCommand, "memmax") == 0) // en Mo
251
pTextZone->cResult = g_strdup_printf ("%f", _Ko_to_Mo(myApplet, myData.ramTotal));
252
pTextZone->cResult = g_strdup_printf ("%.0f", atof(pTextZone->cResult));
255
else if (strcmp (pTextZone->cCommand, "memmaxg") == 0) // Identique à memmax mais en Go
257
pTextZone->cResult = g_strdup_printf ("%f", _Ko_to_Go(myApplet, myData.ramTotal));
258
pTextZone->cResult = g_strdup_printf ("%.2f", atof(pTextZone->cResult));
262
else if (strcmp (pTextZone->cCommand, "swapperc") == 0)
264
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fSwapPercent);
266
if (atof(pTextZone->cResult) < 10)
267
pTextZone->cResult = g_strdup_printf ("%.1f", myData.fSwapPercent);
269
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fSwapPercent);
272
else if (strcmp (pTextZone->cCommand, "swapperc2f") == 0) // Restreint à 2 chiffres : de 00 à 99 !
274
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fSwapPercent);
276
if (atof(pTextZone->cResult) < 10)
277
pTextZone->cResult = g_strdup_printf ("0%.0f", myData.fSwapPercent);
278
else if (atof(pTextZone->cResult) == 100)
279
pTextZone->cResult = g_strdup_printf ("99");
281
pTextZone->cResult = g_strdup_printf ("%.0f", myData.fSwapPercent);
284
else if (strcmp (pTextZone->cCommand, "swap") == 0) // en Mo
286
pTextZone->cResult = g_strdup_printf ("%f", _Ko_to_Mo(myApplet, myData.swapUsed));
288
if (atof(pTextZone->cResult) < 10)
289
pTextZone->cResult = g_strdup_printf ("%.2f", atof(pTextZone->cResult));
290
else if (atof(pTextZone->cResult) < 100)
291
pTextZone->cResult = g_strdup_printf ("%.1f", atof(pTextZone->cResult));
293
pTextZone->cResult = g_strdup_printf ("%.0f", atof(pTextZone->cResult));
296
else if (strcmp (pTextZone->cCommand, "swapg") == 0) // Identique à swap mais en Go
298
pTextZone->cResult = g_strdup_printf ("%f", _Ko_to_Go(myApplet, myData.swapUsed));
299
pTextZone->cResult = g_strdup_printf ("%.2f", atof(pTextZone->cResult));
302
else if (strcmp (pTextZone->cCommand, "swapmax") == 0) // en Mo
304
pTextZone->cResult = g_strdup_printf ("%f", _Ko_to_Mo(myApplet, myData.swapTotal));
305
pTextZone->cResult = g_strdup_printf ("%.0f", atof(pTextZone->cResult));
308
else if (strcmp (pTextZone->cCommand, "swapmaxg") == 0) // Identique à swapmax mais en Go
310
pTextZone->cResult = g_strdup_printf ("%f", _Ko_to_Go(myApplet, myData.swapTotal));
311
pTextZone->cResult = g_strdup_printf ("%.2f", atof(pTextZone->cResult));
316
else if (strcmp (pTextZone->cCommand, "nvtemp") == 0)
318
myConfig.bShowNvidia = TRUE;
319
pTextZone->cResult = g_strdup_printf ("%i", myData.iGPUTemp);
322
else if (strcmp (pTextZone->cCommand, "nvname") == 0)
324
myConfig.bShowNvidia = TRUE;
325
cd_sysmonitor_get_nvidia_info (myApplet);
326
pTextZone->cResult = g_strdup_printf ("%s", myData.cGPUName);
329
else if (strcmp (pTextZone->cCommand, "nvdriver") == 0)
331
myConfig.bShowNvidia = TRUE;
332
cd_sysmonitor_get_nvidia_info (myApplet);
333
pTextZone->cResult = g_strdup_printf ("%s", myData.cDriverVersion);
336
else if (strcmp (pTextZone->cCommand, "nvram") == 0)
338
myConfig.bShowNvidia = TRUE;
339
cd_sysmonitor_get_nvidia_info (myApplet);
340
pTextZone->cResult = g_strdup_printf ("%i", myData.iVideoRam);
346
else if (strcmp (pTextZone->cCommand, "uptime") == 0)
348
gchar *cUpTime = NULL, *cActivityTime = NULL;
349
cd_sysmonitor_get_uptime (&cUpTime, &cActivityTime);
350
pTextZone->cResult = g_strdup_printf ("%s", cUpTime);
353
else if (strcmp (pTextZone->cCommand, "fs_size") == 0)
355
if (strcmp (pTextZone->cMountPoint, "") != 0)
356
pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 0));
359
else if (strcmp (pTextZone->cCommand, "fs_free") == 0)
360
pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 1));
362
else if (strcmp (pTextZone->cCommand, "fs_used") == 0)
363
pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 2));
365
else if (strcmp (pTextZone->cCommand, "fs_freeperc") == 0)
366
pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 3));
368
else if (strcmp (pTextZone->cCommand, "fs_usedperc") == 0)
370
if (strcmp (pTextZone->cMountPoint, "") == 0 || pTextZone->cMountPoint == NULL)
371
pTextZone->cMountPoint = g_strdup_printf ("/");
372
pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 4));
375
else if (strcmp (pTextZone->cCommand, "fs_type") == 0)
376
pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 5));
378
else if (strcmp (pTextZone->cCommand, "fs_device") == 0)
379
pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 6));
386
gboolean cd_retrieve_command_result (CairoDockModuleInstance *myApplet)
390
static double s_fValues[CD_SYSMONITOR_NB_MAX_VALUES];
393
if ( ! myData.bAcquisitionOK)
395
cd_warning ("One or more datas couldn't be retrieved");
396
memset (s_fValues, 0, sizeof (s_fValues));
397
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
401
if (! myData.bInitialized)
403
memset (s_fValues, 0, sizeof (s_fValues));
404
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
408
// Copier les donnes en memoire partagee...
410
//~ 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.
412
//~ gboolean bOneLine = (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_LABEL);
413
//~ GString *sInfo = g_string_new ("");
414
//~ if (myConfig.bShowCpu)
416
//~ g_string_printf (sInfo, (myData.fCpuPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
417
//~ (myDesklet ? "CPU:" : ""),
418
//~ myData.fCpuPercent,
419
//~ (bOneLine ? " - " : "\n"));
421
//~ if (myConfig.bShowRam)
423
//~ g_string_append_printf (sInfo, (myData.fRamPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
424
//~ (myDesklet ? "RAM:" : ""),
425
//~ myData.fRamPercent,
426
//~ (bOneLine ? " - " : "\n"));
428
//~ if (myConfig.bShowSwap)
430
//~ g_string_append_printf (sInfo, (myData.fSwapPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
431
//~ (myDesklet ? "SWAP:" : ""),
432
//~ myData.fSwapPercent,
433
//~ (bOneLine ? " - " : "\n"));
435
//~ if (myConfig.bShowNvidia)
437
//~ g_string_append_printf (sInfo, "%s%d°C%s",
438
//~ (myDesklet ? "GPU:" : ""),
440
//~ (bOneLine ? " - " : "\n"));
442
//~ sInfo->str[sInfo->len-(bOneLine?3:1)] = '\0';
444
//~ CD_APPLET_SET_NAME_FOR_MY_ICON (sInfo->str);
446
//~ CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (sInfo->str);
447
//~ g_string_free (sInfo, TRUE);
450
if (myData.bNeedsUpdate || myConfig.iDisplayType == CD_SYSMONITOR_GRAPH)
453
if (myConfig.bShowCpu)
455
s_fValues[i++] = myData.fCpuPercent / 100.;
457
if (myConfig.bShowRam)
459
s_fValues[i++] = myData.fRamPercent / 100.;
461
if (myConfig.bShowSwap)
462
s_fValues[i++] = (myData.swapTotal ? ((double)myData.swapUsed) / myData.swapTotal : 0.);
463
if (myConfig.bShowNvidia)
464
s_fValues[i++] = myData.fGpuTempPercent / 100.;
466
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
479
for (it = myData.pTextZoneList; it != NULL; it = it->next)
481
pTextZone = it->data;
483
if (pTextZone->iRefresh != 0 || pTextZone->bRefresh)
485
if (pTextZone->bRefresh && pTextZone->cResult != NULL)
487
pTextZone->cText = g_strdup_printf ("%s",pTextZone->cResult);
490
if (pTextZone->iRefresh != 0 && pTextZone->iTimer >= pTextZone->iRefresh)
492
pTextZone->bRefresh = TRUE;
493
pTextZone->iTimer = 0; // On remet le timer à 0
495
else // Pas de refresh de spécifié
498
if (pTextZone->cText == NULL || strcmp (pTextZone->cText, "") == 0) // La récupération s'est mal passé -> On relance !
499
pTextZone->bRefresh = TRUE;
501
pTextZone->bRefresh = FALSE; // On a récupéré l'info -> On arrête là !
505
cd_applet_update_my_icon (myApplet); // Quand tous les textes sont chargés, on peut dessiner
506
myData.pPeriodicRefreshTask = NULL;
508
CD_APPLET_LEAVE (myData.bAcquisitionOK);
512
void cd_applet_draw_my_desklet (CairoDockModuleInstance *myApplet, int iWidth, int iHeight)
514
PangoLayout *pLayout = pango_cairo_create_layout (myDrawContext);
515
PangoRectangle ink, log;
517
// On efface la surface cairo actuelle
518
cairo_dock_erase_cairo_context (myDrawContext);
520
// dessin du fond (optionnel).
521
if (myConfig.bDisplayBackground)
523
cairo_save (myDrawContext);
524
cairo_translate (myDrawContext,
525
.5*myConfig.iBorderThickness,
526
.5*myConfig.iBorderThickness);
527
cairo_pattern_t *pGradationPattern = cairo_pattern_create_linear (0.,
531
cairo_pattern_add_color_stop_rgba (pGradationPattern,
533
myConfig.fBackgroundColor1[0],
534
myConfig.fBackgroundColor1[1],
535
myConfig.fBackgroundColor1[2],
536
myConfig.fBackgroundColor1[3]);
537
cairo_pattern_add_color_stop_rgba (pGradationPattern,
539
myConfig.fBackgroundColor2[0],
540
myConfig.fBackgroundColor2[1],
541
myConfig.fBackgroundColor2[2],
542
myConfig.fBackgroundColor2[3]);
543
cairo_set_source (myDrawContext, pGradationPattern);
545
if (myConfig.iBackgroundRadius != 0) // On a besoin d'un rayon
547
cairo_dock_draw_rounded_rectangle (myDrawContext,
548
myConfig.iBackgroundRadius,
550
iWidth - myConfig.iBorderThickness - 2 * myConfig.iBackgroundRadius,
551
iHeight - myConfig.iBorderThickness);
553
else // Il ne faut pas de rayon
555
cairo_rectangle (myDrawContext,
557
iWidth - myConfig.iBorderThickness,
558
iHeight - myConfig.iBorderThickness);
560
cairo_fill (myDrawContext);
561
cairo_pattern_destroy (pGradationPattern);
562
cairo_restore (myDrawContext);
567
// ################################################################################################################################################################
568
// ############ DEBUT DU DESSIN DU TEXTE
569
// ################################################################################################################################################################
571
int iMargin = .5 * myConfig.iBorderThickness + (1. - sqrt (2) / 2) * myConfig.iBackgroundRadius; // marge a gauche et au-dessus, pour ne pas mordre sur le coin arrondi.
572
int iSpaceBetweenElements = 8; // Décalage horizontal entre les barres et les autres éléments <- Sinon, tout est collé et c'est pô bô ! :-D
574
myData.fCurrentX = iMargin + myConfig.iTextMargin; // position du curseur sur la ligne.
575
myData.fCurrentY = iMargin + myConfig.iTextMargin; // position de la ligne courante.
577
GList *it = myData.pTextZoneList;
581
gboolean bFirstPass=TRUE;
583
double fCurrentLineWidth = 0; // Dimension de la ligne complète (= avec plusieurs zones de textes)
584
double fCurrentLineHeight = 0;
585
gboolean bFirstTextInLine = TRUE;
588
if (myData.pTextZoneList == NULL)
591
it = myData.pTextZoneList;
596
//\_______ boucle sur it de it1 jusqu'à retour chariot => LINE_WIDTH & LINE_HEIGHT
599
pTextZone = it->data;
601
if (pTextZone->cFont == NULL || pTextZone->cFont =="") // Si aucune font -> on prend celle de la config
602
pTextZone->cFont = g_strdup_printf("%s", myConfig.cDefaultFont);
604
if (pTextZone->cText != NULL && ! (pTextZone->bBar || pTextZone->bLimitedBar || pTextZone->bImgDraw))
606
PangoFontDescription *fd = pango_font_description_from_string (pTextZone->cFont);
607
pango_layout_set_font_description (pLayout, fd);
608
pango_font_description_free (fd);
610
// On récupère la largeur d'un espace pour caler le texte à droite
611
pango_layout_set_text (pLayout, " ", -1);
612
pango_layout_get_pixel_extents (pLayout, &ink, &log);
613
pTextZone->iFontSizeWidth = (int)log.width;
614
pTextZone->iFontSizeHeight = (int)log.height;
616
// On récupère la largeur du texte à afficher
617
pango_layout_set_text (pLayout, pTextZone->cText, -1);
618
pango_layout_get_pixel_extents (pLayout, &ink, &log);
619
fCurrentLineWidth += log.width;
621
if (log.height > fCurrentLineHeight && ! myData.bLastWasSameLine)
622
fCurrentLineHeight = log.height;
623
else if (myData.bLastWasSameLine)
624
fCurrentLineHeight = (double)myData.iLastLineHeight;
627
else if (pTextZone->bLimitedBar || pTextZone->bImgDraw || pTextZone->bBar )
629
fCurrentLineWidth += pTextZone->iWidth;
631
if ( (pTextZone->iHeight > fCurrentLineHeight) && ! myData.bLastWasSameLine)
632
fCurrentLineHeight = (double)pTextZone->iHeight;
633
else if (myData.bLastWasSameLine)
634
fCurrentLineHeight = (double)myData.iLastLineHeight;
638
} while (it != NULL && ! pTextZone->bEndOfLine);
643
//\_______ boucle sur it de it1 jusqu'à retour chariot => DESSIN
648
pTextZone = it->data;
684
if (pTextZone->cFont == NULL || pTextZone->cFont =="") // Si aucune font -> on prend celle de la config
685
pTextZone->cFont = g_strdup_printf("%s", myConfig.cDefaultFont);
688
// On calcule le décalage WIDTH nécéssaire pour respecter l'alignement sur la largeur souhaité
689
if (bFirstTextInLine)
692
CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
694
if (strcmp (pTextZone->cAlignWidth, "left") == 0)
695
myData.fCurrentX = iMargin + myConfig.iTextMargin;
696
else if (strcmp (pTextZone->cAlignWidth, "center") == 0)
698
if (pTextZone->cImgPath != NULL)
699
myData.fCurrentX = (iWidth/2) - (pTextZone->iWidth/2);
701
myData.fCurrentX = (iWidth/2)- (fCurrentLineWidth/2);
703
else if (strcmp (pTextZone->cAlignWidth, "right") == 0)
705
if (pTextZone->cImgPath != NULL)
706
myData.fCurrentX = iWidth - iMargin - myConfig.iTextMargin - pTextZone->iWidth - pTextZone->iFontSizeWidth;
708
myData.fCurrentX = iWidth - iMargin - myConfig.iTextMargin - fCurrentLineWidth - pTextZone->iFontSizeWidth;
713
myData.fCurrentX -= iSpaceBetweenElements ; // Il y a un élément avant la barre -> On supprime l'espace
717
if (! bFirstTextInLine)
718
pTextZone->cAlignHeight = g_strdup_printf("%s", myData.cLastAlignHeight); // On récupère l'alignement de la ligne (=l'alignement du 1er élément)
720
myData.cLastAlignHeight = g_strdup_printf("%s", pTextZone->cAlignHeight); // On mémorise l'aligenement du 1er élément de la ligne
722
// On calcule le décalage HEIGHT nécéssaire pour respecter l'alignement sur la hauteur souhaité
723
if (strcmp (pTextZone->cAlignHeight, "middle") == 0)
725
if (pTextZone->cImgPath != NULL || pTextZone->bBar || pTextZone->bLimitedBar )
726
myData.fCurrentYalign = myData.fCurrentY + fCurrentLineHeight/2 - pTextZone->iHeight/2;
727
else // C'est un texte -> On décale un peu pour aligner
728
myData.fCurrentYalign = myData.fCurrentY + fCurrentLineHeight/2 - pTextZone->iFontSizeHeight/2;
730
else if (strcmp (pTextZone->cAlignHeight, "low") == 0)
732
if (pTextZone->cImgPath != NULL || pTextZone->bBar || pTextZone->bLimitedBar )
733
myData.fCurrentYalign = myData.fCurrentY + fCurrentLineHeight - pTextZone->iHeight;
734
else // C'est un texte -> On décale un peu pour aligner
735
myData.fCurrentYalign = myData.fCurrentY + fCurrentLineHeight - pTextZone->iFontSizeHeight;
737
else if (strcmp (pTextZone->cAlignHeight, "top") == 0)
739
if (pTextZone->cImgPath != NULL || pTextZone->bBar || pTextZone->bLimitedBar )
740
myData.fCurrentYalign = myData.fCurrentY; // On laisse à la position courante
741
else // C'est un texte -> On décale un peu pour aligner
742
myData.fCurrentYalign = myData.fCurrentY;
746
PangoFontDescription *fd = pango_font_description_from_string (pTextZone->cFont);
747
pango_layout_set_font_description (pLayout, fd);
748
pango_font_description_free (fd);
751
if (pTextZone->fTextColor[3]== 0 && pTextZone->cText != NULL) // Si aucune couleur alors qu'un texte est défini -> on prend celle de la config
752
cairo_set_source_rgba (myDrawContext, myConfig.fDefaultTextColor[0], myConfig.fDefaultTextColor[1], myConfig.fDefaultTextColor[2], myConfig.fDefaultTextColor[3]);
753
else // sinon, on utilise la couleur du .xml
754
cairo_set_source_rgba (myDrawContext, pTextZone->fTextColor[0], pTextZone->fTextColor[1], pTextZone->fTextColor[2], pTextZone->fTextColor[3]);
757
if (pTextZone->cText != NULL)
758
pango_layout_set_text (pLayout, pTextZone->cText, -1);
760
pango_layout_set_text (pLayout,"", -1);
761
pango_layout_get_pixel_extents (pLayout, &ink, &log);
764
if (pTextZone->bBar || pTextZone->bLimitedBar) // On dessine la barre
770
CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
771
if (bFirstTextInLine)
772
pTextZone->iWidth = iWidth - iMargin*2 - myConfig.iTextMargin*2;
774
pTextZone->iWidth = iWidth - myData.fCurrentX - iMargin - myConfig.iTextMargin - iSpaceBetweenElements;
778
for (i=0 ; i < 2 ; i++)
782
myData.cCurrentText = g_strdup_printf ("%s",pTextZone->cText); // Sinon, çà plante à la ligne d'en dessous
783
value = (int)((atof(myData.cCurrentText) / 100)*pTextZone->iWidth);
786
value = pTextZone->iWidth;
788
// On dessine la valeur PUIS le cadre
789
cairo_save (myDrawContext);
791
if (pTextZone->fTextColor[3]== 0 && pTextZone->cText != NULL) // Si aucune couleur
792
cairo_set_source_rgba (myDrawContext,
793
myConfig.fDefaultTextColor[0],
794
myConfig.fDefaultTextColor[1],
795
myConfig.fDefaultTextColor[2],
796
myConfig.fDefaultTextColor[3]);
798
cairo_set_source_rgba (myDrawContext,
799
pTextZone->fTextColor[0],
800
pTextZone->fTextColor[1],
801
pTextZone->fTextColor[2],
802
pTextZone->fTextColor[3]);
804
cairo_set_line_width (myDrawContext, 0.5);
807
cairo_translate (myDrawContext,
808
myData.fCurrentX + iSpaceBetweenElements + myData.iPrevOverrideW,
809
myData.fCurrentYalign + myData.iPrevOverrideH);
811
cairo_translate (myDrawContext,
812
myData.fCurrentX + myData.iPrevOverrideW,
813
myData.fCurrentYalign + myData.iPrevOverrideH);
815
cairo_dock_draw_rounded_rectangle (myDrawContext,
822
cairo_fill (myDrawContext);
824
cairo_stroke (myDrawContext);
825
cairo_restore (myDrawContext);
830
else if (pTextZone->bImgDraw) // Il y a une image
832
if (pTextZone->pImgSurface != NULL)
834
cairo_set_source_surface (myDrawContext, pTextZone->pImgSurface,
835
myData.fCurrentX + myData.iPrevOverrideW,
836
myData.fCurrentYalign + myData.iPrevOverrideH);
837
cairo_paint (myDrawContext);
840
else // C'est un texte !
842
cairo_move_to (myDrawContext,
843
myData.fCurrentX + myData.iPrevOverrideW,
844
myData.fCurrentYalign + myData.iPrevOverrideH);
845
pango_cairo_show_layout (myDrawContext, pLayout); // On dessine la ligne sur notre desklet
848
if (pTextZone->bEndOfLine) // On passe à la ligne du dessous
850
if (pTextZone->bNextNewLine) // C'est un <br/> (ou un <br>0</br> )-> On passe à la ligne d'en dessous
852
myData.fCurrentY += fCurrentLineHeight + myConfig.iSpaceBetweenLines + pTextZone->iSpaceBetweenLines;
853
myData.bLastWasSameLine = FALSE;
855
else // C'est un <nbr/> -> on reste sur la même ligne -> Utile pour avoir 1 zone alignée à gauche et 1 zone alignée à droite par exemple ;-)
857
myData.iLastLineHeight = (int)fCurrentLineHeight + pTextZone->iSpaceBetweenLines;
858
myData.bLastWasSameLine = TRUE;
861
myData.fCurrentX = iMargin + myConfig.iTextMargin;
863
bFirstTextInLine = TRUE;
864
fCurrentLineWidth = 0; // On remet la largeur de ligne à 0 pour le prochain calcul
865
fCurrentLineHeight = 0; // On remet la hauteur de ligne à 0 pour le prochain calcul
867
else // On laisse le curseur à la position actuelle
869
if (pTextZone->bBar || pTextZone->bLimitedBar || pTextZone->bImgDraw) // On prend en compte un éventuelle barre ou une image
870
myData.fCurrentX += pTextZone->iWidth;
871
else // valable pour les textes
874
pango_layout_get_pixel_extents (pLayout, &ink, &log);
876
w = log.width + log.x;
877
myData.fCurrentX += w;
880
bFirstTextInLine = FALSE;
884
if (pTextZone->iOverrideH != 0)
885
myData.iPrevOverrideH = pTextZone->iOverrideH;
887
myData.iPrevOverrideH = 0;
888
if (pTextZone->iOverrideW != 0)
889
myData.iPrevOverrideW = pTextZone->iOverrideW;
891
myData.iPrevOverrideW = 0;
894
} while (it != NULL && ! pTextZone->bEndOfLine);
898
} while (it != NULL);
900
// ################################################################################################################################################################
901
// ############ FIN DU DESSIN DU TEXTE
902
// ################################################################################################################################################################
905
// dessin du cadre (optionnel).
906
if (myConfig.bDisplayBackground)
908
cairo_save (myDrawContext);
909
cairo_set_source_rgba (myDrawContext,
910
myConfig.fBorderColor[0],
911
myConfig.fBorderColor[1],
912
myConfig.fBorderColor[2],
913
myConfig.fBorderColor[3]);
914
cairo_set_line_width (myDrawContext, myConfig.iBorderThickness);
915
cairo_translate (myDrawContext,
916
.5*myConfig.iBorderThickness,
917
.5*myConfig.iBorderThickness);
918
cairo_dock_draw_rounded_rectangle (myDrawContext,
919
myConfig.iBackgroundRadius,
921
iWidth - 2*myConfig.iBackgroundRadius - myConfig.iBorderThickness,
922
iHeight - myConfig.iBorderThickness);
923
cairo_stroke (myDrawContext);
924
cairo_restore (myDrawContext);
927
g_object_unref (pLayout);
930
// on met a jour la texture OpenGL.
931
if (CD_APPLET_MY_CONTAINER_IS_OPENGL)
933
cairo_dock_update_icon_texture (myIcon);
938
void cd_applet_update_my_icon (CairoDockModuleInstance *myApplet)
942
// taille de la texture.
944
CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
946
cd_applet_draw_my_desklet (myApplet, iWidth, iHeight);
948
CD_APPLET_REDRAW_MY_ICON;