~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to show-mouse/src/applet-init.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
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.
 
11
*
 
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/>.
 
18
*/
 
19
 
 
20
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
 
 
29
#include "stdlib.h"
 
30
 
 
31
#include "applet-config.h"
 
32
#include "applet-notifications.h"
 
33
#include "applet-struct.h"
 
34
#include "applet-init.h"
 
35
 
 
36
 
 
37
CD_APPLET_PRE_INIT_BEGIN(N_("show mouse"),
 
38
        2, 0, 0,
 
39
        CAIRO_DOCK_CATEGORY_PLUG_IN,
 
40
        N_("This plug-in draw some animation around the cursor when it's inside a dock/desklet."),
 
41
        "Fabounet (Fabrice Rey)")
 
42
        if (! g_bUseOpenGL)
 
43
                return FALSE;
 
44
        CD_APPLET_DEFINE_COMMON_APPLET_INTERFACE
 
45
CD_APPLET_PRE_INIT_END
 
46
 
 
47
 
 
48
#define _cd_mouse_register_on_dock(...) \
 
49
        cairo_dock_register_notification (CAIRO_DOCK_ENTER_DOCK, (CairoDockNotificationFunc) cd_show_mouse_enter_container, CAIRO_DOCK_RUN_AFTER, NULL);\
 
50
        cairo_dock_register_notification (CAIRO_DOCK_UPDATE_DOCK, (CairoDockNotificationFunc) cd_show_mouse_update_container, CAIRO_DOCK_RUN_AFTER, NULL);\
 
51
        cairo_dock_register_notification (CAIRO_DOCK_RENDER_DOCK, (CairoDockNotificationFunc) cd_show_mouse_render, CAIRO_DOCK_RUN_AFTER, NULL);
 
52
 
 
53
#define _cd_mouse_register_on_desklet(...) \
 
54
        cairo_dock_register_notification (CAIRO_DOCK_ENTER_DESKLET, (CairoDockNotificationFunc) cd_show_mouse_enter_container, CAIRO_DOCK_RUN_AFTER, NULL);\
 
55
        cairo_dock_register_notification (CAIRO_DOCK_UPDATE_DESKLET, (CairoDockNotificationFunc) cd_show_mouse_update_container, CAIRO_DOCK_RUN_AFTER, NULL);\
 
56
        cairo_dock_register_notification (CAIRO_DOCK_RENDER_DESKLET, (CairoDockNotificationFunc) cd_show_mouse_render, CAIRO_DOCK_RUN_AFTER, NULL);
 
57
 
 
58
#define _cd_mouse_unregister_from_dock(...) \
 
59
        cairo_dock_remove_notification_func (CAIRO_DOCK_RENDER_DOCK, (CairoDockNotificationFunc) cd_show_mouse_render, NULL);\
 
60
        cairo_dock_remove_notification_func (CAIRO_DOCK_UPDATE_DOCK, (CairoDockNotificationFunc) cd_show_mouse_update_container, NULL);\
 
61
        cairo_dock_remove_notification_func (CAIRO_DOCK_ENTER_DOCK, (CairoDockNotificationFunc) cd_show_mouse_enter_container, NULL);
 
62
 
 
63
#define _cd_mouse_unregister_from_desklet(...) \
 
64
        cairo_dock_remove_notification_func (CAIRO_DOCK_RENDER_DESKLET, (CairoDockNotificationFunc) cd_show_mouse_render, NULL);\
 
65
        cairo_dock_remove_notification_func (CAIRO_DOCK_UPDATE_DESKLET, (CairoDockNotificationFunc) cd_show_mouse_update_container, NULL);\
 
66
        cairo_dock_remove_notification_func (CAIRO_DOCK_ENTER_DESKLET, (CairoDockNotificationFunc) cd_show_mouse_enter_container, NULL);
 
67
 
 
68
//\___________ Here is where you initiate your applet. myConfig is already set at this point, and also myIcon, myContainer, myDock, myDesklet (and myDrawContext if you're in dock mode). The macro CD_APPLET_MY_CONF_FILE and CD_APPLET_MY_KEY_FILE can give you access to the applet's conf-file and its corresponding key-file (also available during reload). If you're in desklet mode, myDrawContext is still NULL, and myIcon's buffers has not been filled, because you may not need them then (idem when reloading).
 
69
CD_APPLET_INIT_BEGIN
 
70
        if (! cairo_dock_reserve_data_slot (myApplet))
 
71
                return;
 
72
        
 
73
        if (myConfig.iContainerType & CD_SHOW_MOUSE_ON_DOCK)
 
74
        {
 
75
                _cd_mouse_register_on_dock ();
 
76
        }
 
77
        
 
78
        if (myConfig.iContainerType & CD_SHOW_MOUSE_ON_DESKLET)
 
79
        {
 
80
                _cd_mouse_register_on_desklet ();
 
81
        }
 
82
        myData.iContainerType = myConfig.iContainerType;
 
83
        
 
84
        cairo_dock_register_notification (CAIRO_DOCK_STOP_DOCK, (CairoDockNotificationFunc) cd_show_mouse_free_data, CAIRO_DOCK_RUN_AFTER, NULL);
 
85
        cairo_dock_register_notification (CAIRO_DOCK_STOP_DESKLET, (CairoDockNotificationFunc) cd_show_mouse_free_data, CAIRO_DOCK_RUN_AFTER, NULL);
 
86
CD_APPLET_INIT_END
 
87
 
 
88
 
 
89
//\___________ Here is where you stop your applet. myConfig and myData are still valid, but will be reseted to 0 at the end of the function. In the end, your applet will go back to its original state, as if it had never been activated.
 
90
static void _free_dock_data (gchar *cDockName, CairoDock *pDock, gpointer data)
 
91
{
 
92
        cd_show_mouse_free_data (data, CAIRO_CONTAINER (pDock));
 
93
}
 
94
static gboolean _free_desklet_data (CairoDesklet *pDesklet, CairoDockModuleInstance *pInstance, gpointer data)
 
95
{
 
96
        cd_show_mouse_free_data (data, CAIRO_CONTAINER (pDesklet));
 
97
        return FALSE;
 
98
}
 
99
CD_APPLET_STOP_BEGIN
 
100
        _cd_mouse_unregister_from_dock ();
 
101
        _cd_mouse_unregister_from_desklet ();
 
102
        cairo_dock_remove_notification_func (CAIRO_DOCK_STOP_DOCK, (CairoDockNotificationFunc) cd_show_mouse_free_data, NULL);
 
103
        cairo_dock_remove_notification_func (CAIRO_DOCK_STOP_DESKLET, (CairoDockNotificationFunc) cd_show_mouse_free_data, NULL);
 
104
        
 
105
        cairo_dock_foreach_docks (_free_dock_data, NULL);
 
106
        cairo_dock_foreach_desklet (_free_desklet_data, NULL);
 
107
CD_APPLET_STOP_END
 
108
 
 
109
 
 
110
//\___________ The reload occurs in 2 occasions : when the user changes the applet's config, and when the user reload the cairo-dock's config or modify the desklet's size. The macro CD_APPLET_MY_CONFIG_CHANGED can tell you this. myConfig has already been reloaded at this point if you're in the first case, myData is untouched. You also have the macro CD_APPLET_MY_CONTAINER_TYPE_CHANGED that can tell you if you switched from dock/desklet to desklet/dock mode.
 
111
CD_APPLET_RELOAD_BEGIN
 
112
        if (CD_APPLET_MY_CONFIG_CHANGED)
 
113
        {
 
114
                if (myConfig.iContainerType != myData.iContainerType)
 
115
                {
 
116
                        if ((myConfig.iContainerType & CD_SHOW_MOUSE_ON_DOCK) & ! (myData.iContainerType & CD_SHOW_MOUSE_ON_DOCK))
 
117
                        {
 
118
                                _cd_mouse_register_on_dock ();
 
119
                        }
 
120
                        if (! (myConfig.iContainerType & CD_SHOW_MOUSE_ON_DOCK) & (myData.iContainerType & CD_SHOW_MOUSE_ON_DOCK))
 
121
                        {
 
122
                                _cd_mouse_unregister_from_dock ();
 
123
                        }
 
124
                        if ((myConfig.iContainerType & CD_SHOW_MOUSE_ON_DESKLET) & ! (myData.iContainerType & CD_SHOW_MOUSE_ON_DESKLET))
 
125
                        {
 
126
                                _cd_mouse_register_on_desklet ();
 
127
                        }
 
128
                        if (! (myConfig.iContainerType & CD_SHOW_MOUSE_ON_DESKLET) & (myData.iContainerType & CD_SHOW_MOUSE_ON_DESKLET))
 
129
                        {
 
130
                                _cd_mouse_unregister_from_desklet ();
 
131
                        }
 
132
                        myData.iContainerType = myConfig.iContainerType;
 
133
                }
 
134
        }
 
135
CD_APPLET_RELOAD_END