~cairo-dock-team/cairo-dock-core/popup_from_shortkey

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
/**
* This file is a part of the Cairo-Dock project
*
* Copyright : (C) see the 'copyright' file.
* E-mail    : see the 'copyright' file.
*
* 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 3
* 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, see <http://www.gnu.org/licenses/>.
*/

#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define __USE_POSIX
#include <signal.h>

#include <cairo.h>

#include "gldi-config.h"
#include "cairo-dock-icon-manager.h"
#include "cairo-dock-indicator-manager.h"  // myIndicatorsParam.bDrawIndicatorOnAppli
#include "cairo-dock-class-icon-manager.h"
#include "cairo-dock-animations.h"  // cairo_dock_trigger_icon_removal_from_dock
#include "cairo-dock-dock-facility.h"  // cairo_dock_update_dock_size
#include "cairo-dock-icon-facility.h"  // gldi_icon_set_name
#include "cairo-dock-container.h"
#include "cairo-dock-object.h"
#include "cairo-dock-log.h"
#include "cairo-dock-config.h"
#include "cairo-dock-dock-manager.h"
#include "cairo-dock-desktop-manager.h"  // NOTIFICATION_DESKTOP_CHANGED
#include "cairo-dock-class-manager.h"
#include "cairo-dock-draw-opengl.h"  // cairo_dock_create_texture_from_surface
#include "cairo-dock-keyfile-utilities.h"  // cairo_dock_open_key_file
#include "cairo-dock-application-facility.h"
#include "cairo-dock-windows-manager.h"
#include "cairo-dock-overlay.h"  // cairo_dock_print_overlay_on_icon
#define _MANAGER_DEF_
#include "cairo-dock-applications-manager.h"

#define CAIRO_DOCK_DEFAULT_APPLI_ICON_NAME "default-icon-appli.svg"

// public (manager, config, data)
CairoTaskbarParam myTaskbarParam;
CairoTaskbarManager myTaskbarMgr;

// dependancies
extern CairoDock *g_pMainDock;
extern gboolean g_bUseOpenGL;
//extern int g_iDamageEvent;

// private
static GHashTable *s_hXWindowTable = NULL;  // table des fenetres affichees dans le dock.
static int s_bAppliManagerIsRunning = FALSE;
static GldiWindowActor *s_pCurrentActiveWindow = NULL;

static void cairo_dock_unregister_appli (Icon *icon);


static Icon * cairo_dock_create_icon_from_window (GldiWindowActor *actor)
{
	if (actor->bDisplayed)
		return (Icon*)gldi_object_new (GLDI_MANAGER (&myTaskbarMgr), actor);
	else
		return NULL;
}

static Icon *_get_appli_icon (GldiWindowActor *actor)
{
	return g_hash_table_lookup (s_hXWindowTable, actor);
}


  ///////////////
 // Callbacks //
///////////////

static gboolean _on_window_created (G_GNUC_UNUSED gpointer data, GldiWindowActor *actor)
{
	Icon *pIcon = _get_appli_icon (actor);
	g_return_val_if_fail (pIcon == NULL, GLDI_NOTIFICATION_LET_PASS);
	
	// create an appli-icon
	pIcon = cairo_dock_create_icon_from_window (actor);
	if (pIcon != NULL)
	{
		// insert into the dock
		if (myTaskbarParam.bShowAppli)
		{
			cd_message (" insertion de %s ...", pIcon->cName);
			cairo_dock_insert_appli_in_dock (pIcon, g_pMainDock, CAIRO_DOCK_ANIMATE_ICON);
		}
	}
	
	return GLDI_NOTIFICATION_LET_PASS;
}

static gboolean _on_window_destroyed (G_GNUC_UNUSED gpointer data, GldiWindowActor *actor)
{
	cd_debug ("window %s (%p) is destroyed", actor->cName, actor);
	Icon *icon = _get_appli_icon (actor);
	if (icon != NULL)
	{
		if (actor->bDemandsAttention)  // force the stop demanding attention, in case the icon was in a sub-dock (the main icon is also animating).
			cairo_dock_appli_stops_demanding_attention (icon);
		
		CairoDock *pParentDock = gldi_dock_get (icon->cParentDockName);
		if (pParentDock != NULL)
		{
			cd_message ("  va etre supprimee");
			cairo_dock_unregister_appli (icon);  // unregister the icon immediately, since it doesn't represent anything any more; it unsets pAppli, so that when the animation is over, the icon will be destroyed.
			
			cairo_dock_trigger_icon_removal_from_dock (icon);
		}
		else  // n'etait pas dans un dock, on la detruit donc immediatement.
		{
			cd_message ("  pas dans un container, on la detruit donc immediatement");
			cairo_dock_update_name_on_inhibitors (icon->cClass, actor, NULL);
			gldi_object_unref (GLDI_OBJECT (icon));  // will call cairo_dock_unregister_appli and update the inhibitors.
		}
	}
	
	if (s_pCurrentActiveWindow == actor)
		s_pCurrentActiveWindow = NULL;
	
	return GLDI_NOTIFICATION_LET_PASS;
}

static gboolean _on_window_name_changed (G_GNUC_UNUSED gpointer data, GldiWindowActor *actor)
{
	Icon *pIcon = _get_appli_icon (actor);
	if (pIcon == NULL)
		return GLDI_NOTIFICATION_LET_PASS;
	
	gldi_icon_set_name (pIcon, actor->cName);
	
	cairo_dock_update_name_on_inhibitors (actor->cClass, actor, pIcon->cName);
	return GLDI_NOTIFICATION_LET_PASS;
}

static gboolean _on_window_icon_changed (G_GNUC_UNUSED gpointer data, GldiWindowActor *actor)
{
	Icon *icon = _get_appli_icon (actor);
	if (icon == NULL)
		return GLDI_NOTIFICATION_LET_PASS;
	
	if (cairo_dock_class_is_using_xicon (icon->cClass) || ! myTaskbarParam.bOverWriteXIcons)
	{
		GldiContainer *pContainer = cairo_dock_get_icon_container (icon);
		if (pContainer != NULL)  // if the icon is not in a container (for instance inhibited), it's no use trying to load its image. It's not even useful to mark it as 'damaged', since anyway it will be loaded when inserted inside a container.
		{
			cairo_dock_load_icon_image (icon, pContainer);
			if (CAIRO_DOCK_IS_DOCK (pContainer))
			{
				CairoDock *pDock = CAIRO_DOCK (pContainer);
				if (pDock->iRefCount != 0)
					cairo_dock_trigger_redraw_subdock_content (pDock);
			}
			cairo_dock_redraw_icon (icon);
		}
	}
	
	return GLDI_NOTIFICATION_LET_PASS;
}

static gboolean _on_window_attention_changed (G_GNUC_UNUSED gpointer data, GldiWindowActor *actor)
{
	Icon *pIcon = _get_appli_icon (actor);
	if (pIcon == NULL)
		return GLDI_NOTIFICATION_LET_PASS;
	
	if (actor->bDemandsAttention)
	{
		cd_debug ("%s demande votre attention", pIcon->cName);
		if (myTaskbarParam.bDemandsAttentionWithDialog || myTaskbarParam.cAnimationOnDemandsAttention)
		{
			cairo_dock_appli_demands_attention (pIcon);
		}
	}
	else
	{
		cd_debug ("%s se tait", pIcon->cName);
		cairo_dock_appli_stops_demanding_attention (pIcon);
	}
	
	return GLDI_NOTIFICATION_LET_PASS;
}

static gboolean _on_window_size_position_changed (G_GNUC_UNUSED gpointer data, GldiWindowActor *actor)
{
	Icon *icon = _get_appli_icon (actor);
	if (icon == NULL)
		return GLDI_NOTIFICATION_LET_PASS;
	
	// on regarde si l'appli est sur le viewport courant.
	if (! gldi_window_is_on_current_desktop (actor))  // not on this desktop/viewport any more
	{
		// applis du bureau courant seulement.
		if (myTaskbarParam.bAppliOnCurrentDesktopOnly)
		{
			if (icon->cParentDockName != NULL)
			{
				CairoDock *pParentDock = cairo_dock_detach_appli (icon);
				if (pParentDock)
					gtk_widget_queue_draw (pParentDock->container.pWidget);
			}
			else
				cairo_dock_detach_Xid_from_inhibitors (actor, icon->cClass);
		}
	}
	else  // elle est sur le viewport courant.
	{
		// applis du bureau courant seulement.
		if (myTaskbarParam.bAppliOnCurrentDesktopOnly && icon->cParentDockName == NULL && myTaskbarParam.bShowAppli)
		{
			//cd_message ("cette fenetre est sur le bureau courant (%d;%d)", x, y);
			cairo_dock_insert_appli_in_dock (icon, g_pMainDock, ! CAIRO_DOCK_ANIMATE_ICON);  // the icon might be on this desktop and yet not in a dock (inhibited), in which case this function does nothing.
		}
	}
	
	return GLDI_NOTIFICATION_LET_PASS;
}

static gboolean _on_window_state_changed (G_GNUC_UNUSED gpointer data, GldiWindowActor *actor, gboolean bHiddenChanged, G_GNUC_UNUSED gboolean bMaximizedChanged, G_GNUC_UNUSED gboolean bFullScreenChanged)
{
	Icon *icon = _get_appli_icon (actor);
	if (icon == NULL)
		return GLDI_NOTIFICATION_LET_PASS;
	
	// on gere le cachage/apparition de l'icone (transparence ou miniature, applis minimisees seulement).
	CairoDock *pParentDock = gldi_dock_get (icon->cParentDockName);
	if (bHiddenChanged)
	{
		cd_message ("  changement de visibilite -> %d", actor->bIsHidden);
		
		// drawing of hidden appli-icons.
		if (g_bUseOpenGL && myTaskbarParam.iMinimizedWindowRenderType == 2)
		{
			if (pParentDock != NULL)
			{
				cairo_dock_draw_hidden_appli_icon (icon, CAIRO_CONTAINER (pParentDock), TRUE);
			}
		}
		else if (myTaskbarParam.iMinimizedWindowRenderType == 0)
		{
			// transparence sur les inhibiteurs.
			cairo_dock_update_visibility_on_inhibitors (icon->cClass, actor, actor->bIsHidden);
		}
		
		// showing hidden appli-icons only
		if (myTaskbarParam.bHideVisibleApplis && myTaskbarParam.bShowAppli)  // on insere/detache l'icone selon la visibilite de la fenetre, avec une animation.
		{
			if (actor->bIsHidden)  // se cache => on insere son icone.
			{
				cd_message (" => se cache");
				pParentDock = cairo_dock_insert_appli_in_dock (icon, g_pMainDock, CAIRO_DOCK_ANIMATE_ICON);
				if (pParentDock != NULL)
				{
					if (g_bUseOpenGL && myTaskbarParam.iMinimizedWindowRenderType == 2)  // quand on est passe dans ce cas tout a l'heure l'icone n'etait pas encore dans son dock.
						cairo_dock_draw_hidden_appli_icon (icon, CAIRO_CONTAINER (pParentDock), TRUE);
					gtk_widget_queue_draw (pParentDock->container.pWidget);
				}
			}
			else  // se montre => on detache l'icone.
			{
				cd_message (" => re-apparait");
				cairo_dock_trigger_icon_removal_from_dock (icon);
			}
		}
		else if (myTaskbarParam.fVisibleAppliAlpha != 0)  // transparence
		{
			icon->fAlpha = 1;  // on triche un peu.
			if (pParentDock != NULL)
				cairo_dock_redraw_icon (icon);
		}
		
		// miniature (on le fait apres l'avoir inseree/detachee, car comme ca dans le cas ou on l'enleve du dock apres l'avoir deminimisee, l'icone est marquee comme en cours de suppression, et donc on ne recharge pas son icone. Sinon l'image change pendant la transition, ce qui est pas top. Comme ca ne change pas la taille de l'icone dans le dock, on peut faire ca apres l'avoir inseree.
		if (myTaskbarParam.iMinimizedWindowRenderType == 1 && (pParentDock != NULL || myTaskbarParam.bHideVisibleApplis))
		{
			// on redessine avec ou sans la miniature, suivant le nouvel etat.
			cairo_dock_load_icon_image (icon, CAIRO_CONTAINER (pParentDock));
			if (pParentDock)
			{
				cairo_dock_redraw_icon (icon);
				if (pParentDock->iRefCount != 0)  // on prevoit le redessin de l'icone pointant sur le sous-dock.
				{
					cairo_dock_trigger_redraw_subdock_content (pParentDock);
				}
			}
		}
	}
	
	return GLDI_NOTIFICATION_LET_PASS;
}

static gboolean _on_window_class_changed (G_GNUC_UNUSED gpointer data, GldiWindowActor *actor, G_GNUC_UNUSED const gchar *cOldClass, G_GNUC_UNUSED const gchar *cOldWmClass)
{
	Icon *icon = _get_appli_icon (actor);
	if (icon == NULL)
		return GLDI_NOTIFICATION_LET_PASS;
	
	// remove the icon from the dock, and then from its class
	CairoDock *pParentDock = NULL;
	if (icon->cParentDockName != NULL)  // if in a dock, detach it
		pParentDock = cairo_dock_detach_appli (icon);
	else  // else if inhibited, detach from the inhibitor
		cairo_dock_detach_Xid_from_inhibitors (actor, icon->cClass);
	cairo_dock_remove_appli_from_class (icon);
	
	// set the new class
	g_free (icon->cClass);
	icon->cClass = g_strdup (actor->cClass);
	g_free (icon->cWmClass);
	icon->cWmClass = g_strdup (actor->cWmClass);
	cairo_dock_add_appli_icon_to_class (icon);
	
	// re-insert the icon
	pParentDock = cairo_dock_insert_appli_in_dock (icon, g_pMainDock, ! CAIRO_DOCK_ANIMATE_ICON);
	if (pParentDock != NULL)
		gtk_widget_queue_draw (pParentDock->container.pWidget);
	
	// reload the icon
	g_strfreev (icon->pMimeTypes);
	icon->pMimeTypes = g_strdupv ((gchar**)cairo_dock_get_class_mimetypes (icon->cClass));
	g_free (icon->cCommand);
	icon->cCommand = g_strdup (cairo_dock_get_class_command (icon->cClass));
	cairo_dock_load_icon_image (icon, CAIRO_CONTAINER (pParentDock));
	
	return GLDI_NOTIFICATION_LET_PASS;
}

static void _hide_show_appli_icons_on_other_desktops (GldiWindowActor *pAppli, Icon *icon, CairoDock *pMainDock)
{
	if (! myTaskbarParam.bHideVisibleApplis || pAppli->bIsHidden)
	{
		cd_debug ("%s (%p)", __func__, pAppli);
		CairoDock *pParentDock = NULL;
		if (gldi_window_is_on_current_desktop (pAppli))
		{
			cd_debug (" => est sur le bureau actuel.");
			if (icon->cParentDockName == NULL)
			{
				pParentDock = cairo_dock_insert_appli_in_dock (icon, pMainDock, ! CAIRO_DOCK_ANIMATE_ICON);
			}
		}
		else
		{
			cd_debug (" => n'est pas sur le bureau actuel.");
			if (icon->cParentDockName != NULL)  // if in a dock, detach it
				pParentDock = cairo_dock_detach_appli (icon);
			else  // else if inhibited, detach from the inhibitor
				cairo_dock_detach_Xid_from_inhibitors (icon->pAppli, icon->cClass);
		}
		if (pParentDock != NULL)
			gtk_widget_queue_draw (pParentDock->container.pWidget);
	}
}

static gboolean _on_window_desktop_changed (G_GNUC_UNUSED gpointer data, GldiWindowActor *actor)
{
	Icon *icon = _get_appli_icon (actor);
	if (icon == NULL)
		return GLDI_NOTIFICATION_LET_PASS;
	
	// applis du bureau courant seulement.
	if (myTaskbarParam.bAppliOnCurrentDesktopOnly && myTaskbarParam.bShowAppli)
	{
		_hide_show_appli_icons_on_other_desktops (actor, icon, g_pMainDock);  // si elle vient sur notre bureau, elle n'est pas forcement sur le meme viewport, donc il faut le verifier.
	}
	
	return GLDI_NOTIFICATION_LET_PASS;
}

static gboolean _on_desktop_changed (G_GNUC_UNUSED gpointer data)
{
	// applis du bureau courant seulement.
	if (myTaskbarParam.bAppliOnCurrentDesktopOnly && myTaskbarParam.bShowAppli)
	{
		g_hash_table_foreach (s_hXWindowTable, (GHFunc) _hide_show_appli_icons_on_other_desktops, g_pMainDock);
	}
	
	return GLDI_NOTIFICATION_LET_PASS;
}

static gboolean _on_active_window_changed (G_GNUC_UNUSED gpointer data, GldiWindowActor *actor)
{
	// on gere son animation et son indicateur.
	Icon *icon = _get_appli_icon (actor);
	CairoDock *pParentDock = NULL;
	if (CAIRO_DOCK_IS_APPLI (icon))
	{
		if (icon->bIsDemandingAttention)  // force the stop demanding attention, as it can happen (for some reason) that the attention state doesn't change when the appli takes the focus.
			cairo_dock_appli_stops_demanding_attention (icon);
		
		pParentDock = gldi_dock_get (icon->cParentDockName);
		if (pParentDock == NULL)  // elle est soit inhibee, soit pas dans un dock.
		{
			cairo_dock_update_activity_on_inhibitors (icon->cClass, actor);
		}
		else
		{
			cairo_dock_animate_icon_on_active (icon, pParentDock);
		}
	}
	
	// on enleve l'indicateur sur la precedente appli active.
	Icon *pLastActiveIcon = _get_appli_icon (s_pCurrentActiveWindow);
	if (CAIRO_DOCK_IS_APPLI (pLastActiveIcon))
	{
		CairoDock *pLastActiveParentDock = gldi_dock_get (pLastActiveIcon->cParentDockName);
		if (pLastActiveParentDock == NULL)  // elle est soit inhibee, soit pas dans un dock.
		{
			cairo_dock_update_inactivity_on_inhibitors (pLastActiveIcon->cClass, s_pCurrentActiveWindow);
		}
		else
		{
			cairo_dock_redraw_icon (pLastActiveIcon);
			if (pLastActiveParentDock->iRefCount != 0)  // l'icone est dans un sous-dock, comme l'indicateur est aussi dessine sur l'icone pointant sur ce sous-dock, il faut la redessiner sans l'indicateur.
			{
				CairoDock *pMainDock = NULL;
				Icon *pPointingIcon = cairo_dock_search_icon_pointing_on_dock (pLastActiveParentDock, &pMainDock);
				if (pPointingIcon && pMainDock)
				{
					cairo_dock_redraw_icon (pPointingIcon);
				}
			}
		}
	}
	s_pCurrentActiveWindow = actor;
	
	return GLDI_NOTIFICATION_LET_PASS;
}


  ///////////////////////////
 // Applis manager : core //
///////////////////////////

static void cairo_dock_register_appli (Icon *icon)
{
	if (CAIRO_DOCK_IS_APPLI (icon))
	{
		cd_debug ("%s (%p ; %s)", __func__, icon->pAppli, icon->cName);
		// add to table
		g_hash_table_insert (s_hXWindowTable, icon->pAppli, icon);
		
		// add to class
		cairo_dock_add_appli_icon_to_class (icon);
	}
}

static void cairo_dock_unregister_appli (Icon *icon)
{
	if (CAIRO_DOCK_IS_APPLI (icon))
	{
		cd_debug ("%s (%p ; %s)", __func__, icon->pAppli, icon->cName);
		// remove from table
		g_hash_table_remove (s_hXWindowTable, icon->pAppli);
		
		// remove from class
		cairo_dock_remove_appli_from_class (icon);  // n'efface pas sa classe (on peut en avoir besoin encore).
		cairo_dock_detach_Xid_from_inhibitors (icon->pAppli, icon->cClass);
		
		// unset the appli
		gldi_icon_unset_appli (icon);
	}
}

static void _create_appli_icon (GldiWindowActor *actor, CairoDock *pDock)
{
	Icon *pIcon = cairo_dock_create_icon_from_window (actor);
	if (pIcon != NULL)
	{
		if (myTaskbarParam.bShowAppli && pDock)
		{
			cairo_dock_insert_appli_in_dock (pIcon, g_pMainDock, ! CAIRO_DOCK_ANIMATE_ICON);
		}
	}
}
void cairo_dock_start_applications_manager (CairoDock *pDock)
{
	g_return_if_fail (!s_bAppliManagerIsRunning);
	
	cairo_dock_set_overwrite_exceptions (myTaskbarParam.cOverwriteException);
	cairo_dock_set_group_exceptions (myTaskbarParam.cGroupException);
	
	// create an appli-icon for each window.
	gldi_windows_foreach (FALSE, (GFunc)_create_appli_icon, pDock);  // ordered by creation date; this allows us to set the correct age to the icon, which is constant. On the next updates, the z-order (which is dynamic) will be set.
	
	s_bAppliManagerIsRunning = TRUE;
}

static gboolean _remove_one_appli (G_GNUC_UNUSED GldiWindowActor *pAppli, Icon *pIcon, G_GNUC_UNUSED gpointer data)
{
	if (pIcon == NULL)
		return TRUE;
	if (pIcon->pAppli == NULL)
	{
		g_free (pIcon);
		return TRUE;
	}
	
	CairoDock *pDock = gldi_dock_get (pIcon->cParentDockName);
	if (pDock != NULL)
	{
		cairo_dock_detach_icon_from_dock (pIcon, pDock);
		if (! pDock->bIsMainDock)  // la taille du main dock est mis a jour 1 fois a la fin.
		{
			if (pDock->icons == NULL)  // le dock degage, le fake aussi.
			{
				CairoDock *pFakeClassParentDock = NULL;
				Icon *pFakeClassIcon = cairo_dock_search_icon_pointing_on_dock (pDock, &pFakeClassParentDock);
				if (CAIRO_DOCK_ICON_TYPE_IS_CLASS_CONTAINER (pFakeClassIcon)) // fake launcher
				{
					cd_debug ("on degage le fake qui pointe sur %s", pDock->cDockName);
					cairo_dock_detach_icon_from_dock (pFakeClassIcon, pFakeClassParentDock);
					gldi_object_unref (GLDI_OBJECT (pFakeClassIcon));
					if (! pFakeClassParentDock->bIsMainDock)
						cairo_dock_update_dock_size (pFakeClassParentDock);
				}
				gldi_object_unref (GLDI_OBJECT(pDock));
			}
		}
	}
	
	gldi_icon_unset_appli (pIcon);  // on ne veut pas passer dans le 'unregister'
	g_free (pIcon->cClass);  // ni la gestion de la classe.
	pIcon->cClass = NULL;
	gldi_object_unref (GLDI_OBJECT (pIcon));
	return TRUE;
}
static void _cairo_dock_stop_application_manager (void)
{
	s_bAppliManagerIsRunning = FALSE;
	
	cairo_dock_remove_all_applis_from_class_table ();  // enleve aussi les indicateurs.
	
	g_hash_table_foreach_remove (s_hXWindowTable, (GHRFunc) _remove_one_appli, NULL);  // libere toutes les icones d'appli.
}



  /////////////////////////////
 // Applis manager : access //
/////////////////////////////

GList *cairo_dock_get_current_applis_list (void)
{
	return g_hash_table_get_values (s_hXWindowTable);
}

Icon *cairo_dock_get_current_active_icon (void)
{
	GldiWindowActor *actor = gldi_windows_get_active ();
	return cairo_dock_get_appli_icon (actor);
}

Icon *cairo_dock_get_appli_icon (GldiWindowActor *actor)
{
	if (! actor)
		return NULL;
	return g_hash_table_lookup (s_hXWindowTable, actor);
}

static void _for_one_appli_icon (G_GNUC_UNUSED GldiWindowActor *actor, Icon *icon, gpointer *data)
{
	if (! CAIRO_DOCK_IS_APPLI (icon) || cairo_dock_icon_is_being_removed (icon))
		return ;
	CairoDockForeachIconFunc pFunction = data[0];
	gpointer pUserData = data[1];
	
	CairoDock *pParentDock = NULL;
	if (icon->cParentDockName != NULL)
		pParentDock = gldi_dock_get (icon->cParentDockName);
	else
		pParentDock = g_pMainDock;
	pFunction (icon, CAIRO_CONTAINER (pParentDock), pUserData);
}
void cairo_dock_foreach_appli_icon (CairoDockForeachIconFunc pFunction, gpointer pUserData)
{
	gpointer data[2] = {pFunction, pUserData};
	g_hash_table_foreach (s_hXWindowTable, (GHFunc) _for_one_appli_icon, data);
}

void cairo_dock_set_icons_geometry_for_window_manager (CairoDock *pDock)
{
	if (! s_bAppliManagerIsRunning)
		return ;
	//g_print ("%s (main:%d, ref:%d)\n", __func__, pDock->bIsMainDock, pDock->iRefCount);
	
	/*long *data = g_new0 (long, 1+6*g_list_length (pDock->icons));
	int i = 0;*/
	Icon *icon;
	GList *ic;
	for (ic = pDock->icons; ic != NULL; ic = ic->next)
	{
		icon = ic->data;
		if (CAIRO_DOCK_IS_APPLI (icon))
		{
			cairo_dock_set_one_icon_geometry_for_window_manager (icon, pDock);
			/*data[1+6*i+0] = 5;
			data[1+6*i+1] = icon->Xid;
			data[1+6*i+2] = pDock->container.iWindowPositionX + icon->fXAtRest;
			data[1+6*i+3] = 0;
			data[1+6*i+4] = icon->fWidth;
			data[1+6*i+5] = icon->fHeight;
			i ++;*/
		}
	}
	
	/*data[0] = i;
	Atom atom = XInternAtom (cairo_dock_get_Xdisplay(), "_KDE_WINDOW_PREVIEW", False);
	Window Xid = GDK_WINDOW_XID (pDock->container.pWidget->window);
	XChangeProperty(cairo_dock_get_Xdisplay(), Xid, atom, atom, 32, PropModeReplace, data, 1+6*i);*/
	
	if (pDock->bIsMainDock && myTaskbarParam.bHideVisibleApplis)  // on complete avec les applis pas dans le dock, pour que l'effet de minimisation pointe (a peu pres) au bon endroit quand on la minimisera.
	{
		g_hash_table_foreach (s_hXWindowTable, (GHFunc) cairo_dock_reserve_one_icon_geometry_for_window_manager, pDock);
	}
}


  ////////////////////////////
 // Applis manager : icons //
////////////////////////////

static void _load_appli (Icon *icon)
{
	if (cairo_dock_icon_is_being_removed (icon))
		return ;
	
	//\__________________ register the class to get its attributes, if it was not done yet.
	if (icon->cClass && !icon->pMimeTypes && !icon->cCommand)
	{
		gchar *cClass = cairo_dock_register_class_full (NULL, icon->cClass, icon->cWmClass);
		if (cClass != NULL)
		{
			g_free (cClass);
			icon->cCommand = g_strdup (cairo_dock_get_class_command (icon->cClass));
			icon->pMimeTypes = g_strdupv ((gchar**)cairo_dock_get_class_mimetypes (icon->cClass));
		}
	}
	
	//\__________________ then draw the icon
	int iWidth = cairo_dock_icon_get_allocated_width (icon);
	int iHeight = cairo_dock_icon_get_allocated_height (icon);
	cairo_surface_t *pPrevSurface = icon->image.pSurface;
	GLuint iPrevTexture = icon->image.iTexture;
	icon->image.pSurface = NULL;
	icon->image.iTexture = 0;
	
	// use the thumbnail in the case of a minimized window.
	if (myTaskbarParam.iMinimizedWindowRenderType == 1 && icon->pAppli->bIsHidden)
	{
		// create the thumbnail (window preview).
		if (g_bUseOpenGL)  // in OpenGL, we should be able to use the texture-from-pixmap mechanism
		{
			GLuint iTexture = gldi_window_get_texture (icon->pAppli);
			if (iTexture)
				cairo_dock_load_image_buffer_from_texture (&icon->image, iTexture, iWidth, iHeight);
		}
		if (icon->image.iTexture == 0)  // if not opengl or didn't work, get the content of the pixmap from the X server.
		{
			cairo_surface_t *pThumbnailSurface = gldi_window_get_thumbnail_surface (icon->pAppli, iWidth, iHeight);
			cairo_dock_load_image_buffer_from_surface (&icon->image, pThumbnailSurface, iWidth, iHeight);
		}
		// draw the previous image as an emblem.
		if (icon->image.iTexture != 0 && iPrevTexture != 0)
		{
			CairoDock *pParentDock = gldi_dock_get (icon->cParentDockName);
			cairo_dock_print_overlay_on_icon_from_texture (icon, CAIRO_CONTAINER (pParentDock), iPrevTexture, CAIRO_OVERLAY_LOWER_LEFT);
		}
		else if (icon->image.pSurface != NULL && pPrevSurface != NULL)
		{
			CairoDock *pParentDock = gldi_dock_get (icon->cParentDockName);
			cairo_dock_print_overlay_on_icon_from_surface (icon, CAIRO_CONTAINER (pParentDock), pPrevSurface, 0, 0, CAIRO_OVERLAY_LOWER_LEFT);
		}
	}
	
	// in other cases (or if the preview couldn't be used)
	if (icon->image.iTexture == 0 && icon->image.pSurface == NULL)
	{
		cairo_surface_t *pSurface = NULL;
		// or use the class icon
		if (myTaskbarParam.bOverWriteXIcons && ! cairo_dock_class_is_using_xicon (icon->cClass))
			pSurface = cairo_dock_create_surface_from_class (icon->cClass, iWidth, iHeight);
		// or use the X icon
		if (pSurface == NULL)
			pSurface = gldi_window_get_icon_surface (icon->pAppli, iWidth, iHeight);
		// or use a default image
		if (pSurface == NULL)  // some applis like xterm don't define any icon, set the default one.
		{
			cd_debug ("%s (%p) doesn't define any icon, we set the default one.", icon->cName, icon->pAppli);
			gchar *cIconPath = cairo_dock_search_image_s_path (CAIRO_DOCK_DEFAULT_APPLI_ICON_NAME);
			if (cIconPath == NULL)  // image non trouvee.
			{
				cIconPath = g_strdup (GLDI_SHARE_DATA_DIR"/icons/"CAIRO_DOCK_DEFAULT_APPLI_ICON_NAME);
			}
			pSurface = cairo_dock_create_surface_from_image_simple (cIconPath,
				iWidth,
				iHeight);
			g_free (cIconPath);
		}
		if (pSurface != NULL)
			cairo_dock_load_image_buffer_from_surface (&icon->image, pSurface, iWidth, iHeight);
	}
	
	// bent the icon in the case of a minimized window and if defined in the config.
	if (icon->pAppli->bIsHidden && myTaskbarParam.iMinimizedWindowRenderType == 2)
	{
		CairoDock *pParentDock = gldi_dock_get (icon->cParentDockName);
		if (pParentDock)
			cairo_dock_draw_hidden_appli_icon (icon, CAIRO_CONTAINER (pParentDock), FALSE);
	}
}

static void _show_appli_for_drop (Icon *pIcon)
{
	gldi_window_show (pIcon->pAppli);
}


  //////////////////
 /// GET CONFIG ///
//////////////////

static gboolean get_config (GKeyFile *pKeyFile, CairoTaskbarParam *pTaskBar)
{
	gboolean bFlushConfFileNeeded = FALSE;
	
	// comportement
	pTaskBar->bShowAppli = cairo_dock_get_boolean_key_value (pKeyFile, "TaskBar", "show applications", &bFlushConfFileNeeded, TRUE, "Applications", NULL);
	
	if (pTaskBar->bShowAppli)
	{
		pTaskBar->bAppliOnCurrentDesktopOnly = cairo_dock_get_boolean_key_value (pKeyFile, "TaskBar", "current desktop only", &bFlushConfFileNeeded, FALSE, "Applications", NULL);
		
		pTaskBar->bMixLauncherAppli = cairo_dock_get_boolean_key_value (pKeyFile, "TaskBar", "mix launcher appli", &bFlushConfFileNeeded, TRUE, NULL, NULL);
		
		pTaskBar->bGroupAppliByClass = cairo_dock_get_boolean_key_value (pKeyFile, "TaskBar", "group by class", &bFlushConfFileNeeded, TRUE, "Applications", NULL);
		pTaskBar->cGroupException = cairo_dock_get_string_key_value (pKeyFile, "TaskBar", "group exception", &bFlushConfFileNeeded, "pidgin;xchat", NULL, NULL);
		if (pTaskBar->cGroupException)
		{
			int i;
			for (i = 0; pTaskBar->cGroupException[i] != '\0'; i ++)  // on passe tout en minuscule.
				pTaskBar->cGroupException[i] = g_ascii_tolower (pTaskBar->cGroupException[i]);
		}
		
		pTaskBar->bHideVisibleApplis = cairo_dock_get_boolean_key_value (pKeyFile, "TaskBar", "hide visible", &bFlushConfFileNeeded, FALSE, "Applications", NULL);
		
		pTaskBar->iIconPlacement = cairo_dock_get_integer_key_value (pKeyFile, "TaskBar", "place icons", &bFlushConfFileNeeded, CAIRO_APPLI_AFTER_LAST_LAUNCHER, NULL, NULL);  // after the last launcher by default.
		pTaskBar->cRelativeIconName = cairo_dock_get_string_key_value (pKeyFile, "TaskBar", "relative icon", &bFlushConfFileNeeded, NULL, NULL, NULL);
		pTaskBar->bSeparateApplis = cairo_dock_get_boolean_key_value (pKeyFile, "TaskBar", "separate applis", &bFlushConfFileNeeded, TRUE, NULL, NULL);
		
		// representation
		pTaskBar->bOverWriteXIcons = cairo_dock_get_boolean_key_value (pKeyFile, "TaskBar", "overwrite xicon", &bFlushConfFileNeeded, TRUE, NULL, NULL);
		pTaskBar->cOverwriteException = cairo_dock_get_string_key_value (pKeyFile, "TaskBar", "overwrite exception", &bFlushConfFileNeeded, "pidgin;xchat", NULL, NULL);
		if (pTaskBar->cOverwriteException)
		{
			int i;
			for (i = 0; pTaskBar->cOverwriteException[i] != '\0'; i ++)
				pTaskBar->cOverwriteException[i] = g_ascii_tolower (pTaskBar->cOverwriteException[i]);
		}
		
		pTaskBar->iMinimizedWindowRenderType = cairo_dock_get_integer_key_value (pKeyFile, "TaskBar", "minimized", &bFlushConfFileNeeded, -1, NULL, NULL);
		if (pTaskBar->iMinimizedWindowRenderType == -1)  // anciens parametres.
		{
			gboolean bShowThumbnail = g_key_file_get_boolean (pKeyFile, "TaskBar", "window thumbnail", NULL);
			if (bShowThumbnail)
				pTaskBar->iMinimizedWindowRenderType = 1;
			else
				pTaskBar->iMinimizedWindowRenderType = 0;
			g_key_file_set_integer (pKeyFile, "TaskBar", "minimized", pTaskBar->iMinimizedWindowRenderType);
		}
		
		/**if (pTaskBar->iMinimizedWindowRenderType == 1 && ! cairo_dock_xcomposite_is_available ())
		{
			cd_warning ("Sorry but either your X server does not have the XComposite extension, or your version of Cairo-Dock was not built with the support of XComposite.\n You can't have window thumbnails in the dock");
			pTaskBar->iMinimizedWindowRenderType = 0;
		}
		if (pTaskBar->iMinimizedWindowRenderType == 0)*/
			pTaskBar->fVisibleAppliAlpha = MIN (.6, cairo_dock_get_double_key_value (pKeyFile, "TaskBar", "visibility alpha", &bFlushConfFileNeeded, .35, "Applications", NULL));
		
		pTaskBar->iAppliMaxNameLength = cairo_dock_get_integer_key_value (pKeyFile, "TaskBar", "max name length", &bFlushConfFileNeeded, 25, "Applications", NULL);
		
		
		// interaction
		pTaskBar->iActionOnMiddleClick = cairo_dock_get_integer_key_value (pKeyFile, "TaskBar", "action on middle click", &bFlushConfFileNeeded, 1, NULL, NULL);
		pTaskBar->bMinimizeOnClick = cairo_dock_get_boolean_key_value (pKeyFile, "TaskBar", "minimize on click", &bFlushConfFileNeeded, TRUE, "Applications", NULL);
		
		pTaskBar->bPresentClassOnClick = cairo_dock_get_boolean_key_value (pKeyFile, "TaskBar", "present class on click", &bFlushConfFileNeeded, TRUE, NULL, NULL);
		
		pTaskBar->bDemandsAttentionWithDialog = cairo_dock_get_boolean_key_value (pKeyFile, "TaskBar", "demands attention with dialog", &bFlushConfFileNeeded, TRUE, "Applications", NULL);
		pTaskBar->iDialogDuration = cairo_dock_get_integer_key_value (pKeyFile, "TaskBar", "duration", &bFlushConfFileNeeded, 2, NULL, NULL);
		pTaskBar->cAnimationOnDemandsAttention = cairo_dock_get_string_key_value (pKeyFile, "TaskBar", "animation on demands attention", &bFlushConfFileNeeded, "fire", NULL, NULL);
		gchar *cForceDemandsAttention = cairo_dock_get_string_key_value (pKeyFile, "TaskBar", "force demands attention", &bFlushConfFileNeeded, "pidgin;xchat", NULL, NULL);
		if (cForceDemandsAttention != NULL)
		{
			pTaskBar->cForceDemandsAttention = g_ascii_strdown (cForceDemandsAttention, -1);
			g_free (cForceDemandsAttention);
		}
		
		pTaskBar->cAnimationOnActiveWindow = cairo_dock_get_string_key_value (pKeyFile, "TaskBar", "animation on active window", &bFlushConfFileNeeded, "wobbly", NULL, NULL);
	}
	return bFlushConfFileNeeded;
}


  ////////////////////
 /// RESET CONFIG ///
////////////////////

static void reset_config (CairoTaskbarParam *pTaskBar)
{
	g_free (pTaskBar->cAnimationOnActiveWindow);
	g_free (pTaskBar->cAnimationOnDemandsAttention);
	g_free (pTaskBar->cOverwriteException);
	g_free (pTaskBar->cGroupException);
	g_free (pTaskBar->cForceDemandsAttention);
	g_free (pTaskBar->cRelativeIconName);
}

  ////////////
 /// LOAD ///
////////////

/*
static void load (void)
{
	
}
*/

  //////////////
 /// RELOAD ///
//////////////

static void reload (CairoTaskbarParam *pPrevTaskBar, CairoTaskbarParam *pTaskBar)
{
	CairoDock *pDock = g_pMainDock;
	
	if (pPrevTaskBar->bGroupAppliByClass != pTaskBar->bGroupAppliByClass
		|| pPrevTaskBar->bHideVisibleApplis != pTaskBar->bHideVisibleApplis
		|| pPrevTaskBar->bAppliOnCurrentDesktopOnly != pTaskBar->bAppliOnCurrentDesktopOnly
		|| pPrevTaskBar->bMixLauncherAppli != pTaskBar->bMixLauncherAppli
		|| pPrevTaskBar->bOverWriteXIcons != pTaskBar->bOverWriteXIcons
		|| pPrevTaskBar->iMinimizedWindowRenderType != pTaskBar->iMinimizedWindowRenderType
		|| pPrevTaskBar->iAppliMaxNameLength != pTaskBar->iAppliMaxNameLength
		|| cairo_dock_strings_differ (pPrevTaskBar->cGroupException, pTaskBar->cGroupException)
		|| cairo_dock_strings_differ (pPrevTaskBar->cOverwriteException, pTaskBar->cOverwriteException)
		|| pPrevTaskBar->bShowAppli != pTaskBar->bShowAppli
		|| pPrevTaskBar->iIconPlacement != pTaskBar->iIconPlacement
		|| pPrevTaskBar->bSeparateApplis != pTaskBar->bSeparateApplis
		|| cairo_dock_strings_differ (pPrevTaskBar->cRelativeIconName, pTaskBar->cRelativeIconName))
	{
		_cairo_dock_stop_application_manager ();
		
		cairo_dock_start_applications_manager (pDock);
		
		cairo_dock_calculate_dock_icons (pDock);
		gtk_widget_queue_draw (pDock->container.pWidget);  // le 'gdk_window_move_resize' ci-dessous ne provoquera pas le redessin si la taille n'a pas change.
		
		cairo_dock_move_resize_dock (pDock);
	}
	else
	{
		gtk_widget_queue_draw (pDock->container.pWidget);  // pour le fVisibleAlpha
	}
}


  //////////////
 /// UNLOAD ///
//////////////

static gboolean _remove_appli (G_GNUC_UNUSED GldiWindowActor *actor, Icon *pIcon, G_GNUC_UNUSED gpointer data)
{
	if (pIcon == NULL)
		return TRUE;
	if (pIcon->pAppli == NULL)
	{
		g_free (pIcon);
		return TRUE;
	}
	
	/// TODO here ?...
	///cairo_dock_set_xicon_geometry (pIcon->Xid, 0, 0, 0, 0);  // since we'll not detach the icons one by one, we do it here.
	
	// make it an invalid appli
	gldi_icon_unset_appli (pIcon);  // we don't want to go into the 'unregister'
	g_free (pIcon->cClass);  // nor the class manager, since we reseted it beforehand.
	pIcon->cClass = NULL;
	
	// if not inside a dock, free it, else it will be freeed with the dock.
	if (pIcon->cParentDockName == NULL)  // not in a dock.
	{
		gldi_object_unref (GLDI_OBJECT (pIcon));
	}
	
	return TRUE;
}
static void unload (void)
{
	// empty the class table.
	cairo_dock_reset_class_table ();
	
	// empty the applis table.
	g_hash_table_foreach_remove (s_hXWindowTable, (GHRFunc) _remove_appli, NULL);
	
	s_bAppliManagerIsRunning = FALSE;
}


  ////////////
 /// INIT ///
////////////

static void init (void)
{
	s_hXWindowTable = g_hash_table_new_full (g_direct_hash,
		g_direct_equal,
		NULL,  // window actor
		NULL);  // appli-icon
	
	cairo_dock_initialize_class_manager ();
	
	gldi_object_register_notification (&myWindowsMgr,
		NOTIFICATION_WINDOW_CREATED,
		(GldiNotificationFunc) _on_window_created,
		GLDI_RUN_FIRST, NULL);
	gldi_object_register_notification (&myWindowsMgr,
		NOTIFICATION_WINDOW_DESTROYED,
		(GldiNotificationFunc) _on_window_destroyed,
		GLDI_RUN_FIRST, NULL);
	gldi_object_register_notification (&myWindowsMgr,
		NOTIFICATION_WINDOW_NAME_CHANGED,
		(GldiNotificationFunc) _on_window_name_changed,
		GLDI_RUN_FIRST, NULL);
	gldi_object_register_notification (&myWindowsMgr,
		NOTIFICATION_WINDOW_ICON_CHANGED,
		(GldiNotificationFunc) _on_window_icon_changed,
		GLDI_RUN_FIRST, NULL);
	gldi_object_register_notification (&myWindowsMgr,
		NOTIFICATION_WINDOW_ATTENTION_CHANGED,
		(GldiNotificationFunc) _on_window_attention_changed,
		GLDI_RUN_FIRST, NULL);
	gldi_object_register_notification (&myWindowsMgr,
		NOTIFICATION_WINDOW_SIZE_POSITION_CHANGED,
		(GldiNotificationFunc) _on_window_size_position_changed,
		GLDI_RUN_FIRST, NULL);
	gldi_object_register_notification (&myWindowsMgr,
		NOTIFICATION_WINDOW_STATE_CHANGED,
		(GldiNotificationFunc) _on_window_state_changed,
		GLDI_RUN_FIRST, NULL);
	gldi_object_register_notification (&myWindowsMgr,
		NOTIFICATION_WINDOW_CLASS_CHANGED,
		(GldiNotificationFunc) _on_window_class_changed,
		GLDI_RUN_FIRST, NULL);
	gldi_object_register_notification (&myWindowsMgr,
		NOTIFICATION_WINDOW_DESKTOP_CHANGED,
		(GldiNotificationFunc) _on_window_desktop_changed,
		GLDI_RUN_FIRST, NULL);
	gldi_object_register_notification (&myDesktopMgr,
		NOTIFICATION_DESKTOP_CHANGED,
		(GldiNotificationFunc) _on_desktop_changed,
		GLDI_RUN_FIRST, NULL);
	gldi_object_register_notification (&myWindowsMgr,
		NOTIFICATION_WINDOW_ACTIVATED,
		(GldiNotificationFunc) _on_active_window_changed,
		GLDI_RUN_FIRST, NULL);
}


  ///////////////
 /// MANAGER ///
///////////////

static void init_object (GldiObject *obj, gpointer attr)
{
	Icon *icon = (Icon*)obj;
	GldiWindowActor *actor = (GldiWindowActor*)attr;
	
	icon->iGroup = CAIRO_DOCK_APPLI;
	icon->fOrder = CAIRO_DOCK_LAST_ORDER;
	gldi_icon_set_appli (icon, actor);
	
	icon->cName = g_strdup (actor->cName ? actor->cName : actor->cClass);
	icon->cClass = g_strdup (actor->cClass);  // we'll register the class during the loading of the icon, since it can take some time, and we don't really need the class params right now.
	
	icon->iface.load_image           = _load_appli;
	icon->iface.action_on_drag_hover = _show_appli_for_drop;
	
	icon->bHasIndicator = myIndicatorsParam.bDrawIndicatorOnAppli;
	if (myTaskbarParam.bSeparateApplis)
		icon->iGroup = CAIRO_DOCK_APPLI;
	else
		icon->iGroup = CAIRO_DOCK_LAUNCHER;
	
	//\____________ register it.
	cairo_dock_register_appli (icon);
}

static void reset_object (GldiObject *obj)
{
	Icon *pIcon = (Icon*)obj;
	cairo_dock_unregister_appli (pIcon);
}

void gldi_register_applications_manager (void)
{
	// Manager
	memset (&myTaskbarMgr, 0, sizeof (CairoTaskbarManager));
	myTaskbarMgr.mgr.cModuleName    = "Taskbar";
	myTaskbarMgr.mgr.init           = init;
	myTaskbarMgr.mgr.load           = NULL;  // the manager is started after the launchers&applets have been created, to avoid unecessary computations.
	myTaskbarMgr.mgr.unload         = unload;
	myTaskbarMgr.mgr.reload         = (GldiManagerReloadFunc)reload;
	myTaskbarMgr.mgr.get_config     = (GldiManagerGetConfigFunc)get_config;
	myTaskbarMgr.mgr.reset_config   = (GldiManagerResetConfigFunc)reset_config;
	myTaskbarMgr.mgr.init_object    = init_object;
	myTaskbarMgr.mgr.reset_object   = reset_object;
	myTaskbarMgr.mgr.iObjectSize    = sizeof (Icon);
	// Config
	memset (&myTaskbarParam, 0, sizeof (CairoTaskbarParam));
	myTaskbarMgr.mgr.pConfig = (GldiManagerConfigPtr)&myTaskbarParam;
	myTaskbarMgr.mgr.iSizeOfConfig = sizeof (CairoTaskbarParam);
	// data
	myTaskbarMgr.mgr.pData = (GldiManagerDataPtr)NULL;
	myTaskbarMgr.mgr.iSizeOfData = 0;
	// signals
	gldi_object_install_notifications (GLDI_OBJECT (&myTaskbarMgr), NB_NOTIFICATIONS_TASKBAR);
	gldi_object_set_manager (GLDI_OBJECT (&myTaskbarMgr), GLDI_MANAGER (&myIconsMgr));
	// register
	gldi_register_manager (GLDI_MANAGER(&myTaskbarMgr));
}