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

« back to all changes in this revision

Viewing changes to keyboard-indicator/src/applet-init.c

Tags: upstream-3.0.0.0beta1
ImportĀ upstreamĀ versionĀ 3.0.0.0beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
static void _load_bg_image (void)
42
42
{
43
 
        if (myData.pBackgroundSurface != NULL)
44
 
        {
45
 
                cairo_surface_destroy (myData.pBackgroundSurface);
46
 
                myData.pBackgroundSurface = NULL;
47
 
        }
48
 
        if (myData.iBackgroundTexture != 0)
49
 
        {
50
 
                _cairo_dock_delete_texture (myData.iBackgroundTexture);
51
 
                myData.iBackgroundTexture = 0;
52
 
        }
53
 
        
54
 
        if (myConfig.cBackgroundImage != NULL)
55
 
        {
56
 
                myData.pBackgroundSurface = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (myConfig.cBackgroundImage);
57
 
                if (g_bUseOpenGL)
58
 
                        myData.iBackgroundTexture = cairo_dock_create_texture_from_surface (myData.pBackgroundSurface);
59
 
        }
 
43
        int iWidth, iHeight;
 
44
        CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
 
45
        cairo_dock_unload_image_buffer (&myData.bgImage);
 
46
        cairo_dock_load_image_buffer (&myData.bgImage,
 
47
                myConfig.cBackgroundImage,
 
48
                iWidth,
 
49
                iHeight,
 
50
                0);
60
51
}
61
52
 
62
53
//\___________ 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).
 
54
static gboolean _init (gpointer data)
 
55
{
 
56
        cd_debug ("INIT XKBD");
 
57
        g_return_val_if_fail (myApplet != NULL, FALSE);
 
58
        Window Xid = cairo_dock_get_current_active_window ();
 
59
        cd_xkbd_keyboard_state_changed (myApplet, &Xid);
 
60
        return FALSE;
 
61
}
63
62
CD_APPLET_INIT_BEGIN
64
63
        if (myDesklet)
65
64
        {
66
65
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");  // set a desklet renderer.
67
66
        }
68
67
        
69
 
        myConfig.textDescription.iSize = (int) myIcon->fHeight * myConfig.fTextRatio;
 
68
        myConfig.textDescription.iSize = (int) myIcon->iImageHeight * myConfig.fTextRatio;
70
69
        
71
70
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
72
71
        CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
77
76
                CAIRO_DOCK_RUN_AFTER,
78
77
                myApplet);
79
78
        
 
79
        // shortkey
 
80
        myData.pKeyBinding = CD_APPLET_BIND_KEY (myConfig.cShortkey,
 
81
                D_("Switch keyboard language"),
 
82
                "Configuration", "shortkey",
 
83
                (CDBindkeyHandler) cd_xkbd_on_keybinding_pull);
 
84
        
80
85
        _load_bg_image ();
81
86
        
82
87
        myData.iCurrentGroup = -1;  // pour forcer le redessin.
83
88
        
84
 
        /*Display *dsp = (Display*)cairo_dock_get_Xdisplay (); // const
85
 
        XklEngine *pEngine = xkl_engine_get_instance (dsp);
86
 
        xkl_engine_start_listen (pEngine, XKLL_MANAGE_WINDOW_STATES | XKLL_MANAGE_LAYOUTS);*/
87
 
        
88
 
        Window Xid = cairo_dock_get_current_active_window ();
89
 
        cd_xkbd_keyboard_state_changed (myApplet, &Xid);
 
89
        g_timeout_add_seconds (1, _init, NULL);
90
90
CD_APPLET_INIT_END
91
91
 
92
92
 
93
93
//\___________ 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.
94
94
CD_APPLET_STOP_BEGIN
95
 
        /*Display *dsp = (Display*)cairo_dock_get_Xdisplay (); // const
96
 
        XklEngine *pEngine = xkl_engine_get_instance (dsp);
97
 
        xkl_engine_stop_listen (pEngine, XKLL_MANAGE_WINDOW_STATES | XKLL_MANAGE_LAYOUTS);*/
98
95
        CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
99
96
        CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
100
97
        CD_APPLET_UNREGISTER_FOR_SCROLL_EVENT;
103
100
                (CairoDockNotificationFunc) cd_xkbd_keyboard_state_changed,
104
101
                myApplet);
105
102
        CD_APPLET_REMOVE_TRANSITION_ON_MY_ICON;
 
103
        
 
104
        cd_keybinder_unbind (myData.pKeyBinding);
106
105
CD_APPLET_STOP_END
107
106
 
108
107
 
109
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.
110
109
CD_APPLET_RELOAD_BEGIN
111
 
        myConfig.textDescription.iSize = (int) myIcon->fHeight * myConfig.fTextRatio;
 
110
        myConfig.textDescription.iSize = (int) myIcon->iImageHeight * myConfig.fTextRatio;
112
111
        
113
112
        if (CD_APPLET_MY_CONFIG_CHANGED)
114
113
        {
121
120
                _load_bg_image ();
122
121
                
123
122
                myData.iCurrentGroup = -1;  // pour forcer le redessin.
 
123
                if (!myConfig.bShowKbdIndicator)  // no more indicators
 
124
                {
 
125
                        CD_APPLET_REMOVE_OVERLAY_ON_MY_ICON (CAIRO_OVERLAY_UPPER_RIGHT);
 
126
                        CD_APPLET_REMOVE_OVERLAY_ON_MY_ICON (CAIRO_OVERLAY_UPPER_LEFT);
 
127
                        myData.iPreviousIndic = 0;
 
128
                }
124
129
                
125
130
                //\_____________ On declenche le redessin de l'icone.
126
131
                Window Xid = cairo_dock_get_current_active_window ();
127
132
                cd_xkbd_keyboard_state_changed (myApplet, &Xid);
 
133
                
 
134
                cd_keybinder_rebind (myData.pKeyBinding, myConfig.cShortkey, NULL);
128
135
        }
129
136
        else
130
137
        {