41
41
static void _load_bg_image (void)
43
if (myData.pBackgroundSurface != NULL)
45
cairo_surface_destroy (myData.pBackgroundSurface);
46
myData.pBackgroundSurface = NULL;
48
if (myData.iBackgroundTexture != 0)
50
_cairo_dock_delete_texture (myData.iBackgroundTexture);
51
myData.iBackgroundTexture = 0;
54
if (myConfig.cBackgroundImage != NULL)
56
myData.pBackgroundSurface = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (myConfig.cBackgroundImage);
58
myData.iBackgroundTexture = cairo_dock_create_texture_from_surface (myData.pBackgroundSurface);
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,
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)
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);
63
62
CD_APPLET_INIT_BEGIN
66
65
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); // set a desklet renderer.
69
myConfig.textDescription.iSize = (int) myIcon->fHeight * myConfig.fTextRatio;
68
myConfig.textDescription.iSize = (int) myIcon->iImageHeight * myConfig.fTextRatio;
71
70
CD_APPLET_REGISTER_FOR_CLICK_EVENT;
72
71
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
77
76
CAIRO_DOCK_RUN_AFTER,
80
myData.pKeyBinding = CD_APPLET_BIND_KEY (myConfig.cShortkey,
81
D_("Switch keyboard language"),
82
"Configuration", "shortkey",
83
(CDBindkeyHandler) cd_xkbd_on_keybinding_pull);
82
87
myData.iCurrentGroup = -1; // pour forcer le redessin.
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);*/
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);
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,
105
102
CD_APPLET_REMOVE_TRANSITION_ON_MY_ICON;
104
cd_keybinder_unbind (myData.pKeyBinding);
106
105
CD_APPLET_STOP_END
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;
113
112
if (CD_APPLET_MY_CONFIG_CHANGED)
121
120
_load_bg_image ();
123
122
myData.iCurrentGroup = -1; // pour forcer le redessin.
123
if (!myConfig.bShowKbdIndicator) // no more indicators
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;
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);
134
cd_keybinder_rebind (myData.pKeyBinding, myConfig.cShortkey, NULL);