~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-updates

« back to all changes in this revision

Viewing changes to keyboard-indicator/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-xklavier.h"
 
33
#include "applet-notifications.h"
 
34
#include "applet-struct.h"
 
35
#include "applet-init.h"
 
36
 
 
37
 
 
38
CD_APPLET_DEFINITION (N_("keyboard indicator"),
 
39
        2, 0, 0,
 
40
        CAIRO_DOCK_CATEGORY_DESKTOP,
 
41
        N_("This applet lets you control the keyboard layout.\n\
 
42
        It can also display the current num and caps lock.\n\
 
43
        Left-click to switch to the next layout\n\
 
44
        Scroll up/down to select the previous/next layout\n\
 
45
        Right-click gives you access to the list of available layouts."),
 
46
        "Fabounet (Fabrice Rey)")
 
47
 
 
48
static void _load_bg_image (void)
 
49
{
 
50
        if (myData.pBackgroundSurface != NULL)
 
51
        {
 
52
                cairo_surface_destroy (myData.pBackgroundSurface);
 
53
                myData.pBackgroundSurface = NULL;
 
54
        }
 
55
        if (myData.iBackgroundTexture != 0)
 
56
        {
 
57
                _cairo_dock_delete_texture (myData.iBackgroundTexture);
 
58
                myData.iBackgroundTexture = 0;
 
59
        }
 
60
        
 
61
        if (myConfig.cBackgroundImage != NULL)
 
62
        {
 
63
                myData.pBackgroundSurface = CD_APPLET_LOAD_USER_SURFACE_FOR_MY_APPLET (myConfig.cBackgroundImage, (gchar *)NULL);
 
64
                if (g_bUseOpenGL)
 
65
                        myData.iBackgroundTexture = cairo_dock_create_texture_from_surface (myData.pBackgroundSurface);
 
66
        }
 
67
}
 
68
 
 
69
//\___________ 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).
 
70
CD_APPLET_INIT_BEGIN
 
71
        if (myDesklet)
 
72
        {
 
73
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");  // set a desklet renderer.
 
74
        }
 
75
        
 
76
        myConfig.textDescription.iSize = (int) myIcon->fHeight;
 
77
        
 
78
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
 
79
        CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
 
80
        CD_APPLET_REGISTER_FOR_SCROLL_EVENT;
 
81
        cairo_dock_register_notification (CAIRO_DOCK_KBD_STATE_CHANGED,
 
82
                (CairoDockNotificationFunc) cd_xkbd_keyboard_state_changed,
 
83
                CAIRO_DOCK_RUN_AFTER,
 
84
                myApplet);
 
85
        
 
86
        _load_bg_image ();
 
87
        
 
88
        myData.iCurrentGroup = -1;  // pour forcer le redessin.
 
89
        
 
90
        Window Xid = cairo_dock_get_current_active_window ();
 
91
        cd_xkbd_keyboard_state_changed (myApplet, &Xid);
 
92
        g_print (MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
 
93
CD_APPLET_INIT_END
 
94
 
 
95
 
 
96
//\___________ 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.
 
97
CD_APPLET_STOP_BEGIN
 
98
        CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
 
99
        CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
 
100
        CD_APPLET_UNREGISTER_FOR_SCROLL_EVENT;
 
101
        cairo_dock_remove_notification_func (CAIRO_DOCK_KBD_STATE_CHANGED,
 
102
                (CairoDockNotificationFunc) cd_xkbd_keyboard_state_changed,
 
103
                myApplet);
 
104
        CD_APPLET_REMOVE_TRANSITION_ON_MY_ICON;
 
105
CD_APPLET_STOP_END
 
106
 
 
107
 
 
108
//\___________ 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.
 
109
CD_APPLET_RELOAD_BEGIN
 
110
        if (myDesklet)
 
111
        {
 
112
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");  // set a desklet renderer.
 
113
        }
 
114
        
 
115
        myConfig.textDescription.iSize = (int) myIcon->fHeight;
 
116
        
 
117
        if (CD_APPLET_MY_CONFIG_CHANGED)
 
118
        {
 
119
                CD_APPLET_REMOVE_TRANSITION_ON_MY_ICON;  // prudence.
 
120
                _load_bg_image ();
 
121
                
 
122
                myData.iCurrentGroup = -1;  // pour forcer le redessin.
 
123
                
 
124
                //\_____________ On declenche le redessin de l'icone.
 
125
                Window Xid = cairo_dock_get_current_active_window ();
 
126
                cd_xkbd_keyboard_state_changed (myApplet, &Xid);
 
127
        }
 
128
CD_APPLET_RELOAD_END