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 #include "stdlib.h"
21 
22 #include "applet-config.h"
23 #include "applet-notifications.h"
24 #include "applet-struct.h"
25 #include "applet-init.h"
26 
27 
28 CD_APPLET_DEFINITION (N_("showDesktop"),
29 	2, 2, 0,
30 	CAIRO_DOCK_CATEGORY_APPLET_DESKTOP,
31 	N_("This applet adds an icon to show your desktop,\n"
32 	" and also : the desklets, the Widget Layer, or all the desktops at once.\n"
33 	"It can also be used to quickly change the screen's resolution from the right-click menu.\n"
34 	"Left-click to show/hide the desktop,\n"
35 	"Middle-click to show/hide either the desktop, the desklets, the Widget Layer, or all the desktops at once."),
36 	"Rom1 (Romain PEROL) &amp; Fabounet (Fabrice Rey)")
37 
38 
39 static const gchar *s_cShortkeyDescription[CD_NB_ACTIONS] = {"Show desktop", "Show the desklets", "Show desktop and desklets", "Show the Widget Layer", "Expose all the desktops"};  // same names as in the config file, so no need to add N_()
40 
_show_desktop_for_drop(Icon * pIcon)41 static void _show_desktop_for_drop (Icon *pIcon)
42 {
43 	gldi_desktop_show_hide (! myData.bDesktopVisible);
44 }
45 //\___________ 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).
46 CD_APPLET_INIT_BEGIN
47 	if (myDesklet)
48 	{
49 		CD_APPLET_SET_DESKLET_RENDERER ("Simple");
50 	}
51 
52 	CD_APPLET_REGISTER_FOR_CLICK_EVENT;
53 	CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
54 	CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
55 	gldi_object_register_notification (&myDesktopMgr,
56 		NOTIFICATION_DESKTOP_VISIBILITY_CHANGED,
57 		(GldiNotificationFunc) on_show_desktop,
58 		GLDI_RUN_AFTER, myApplet);
59 
60 	myIcon->iface.action_on_drag_hover = _show_desktop_for_drop;
61 
62 	myData.bDesktopVisible = gldi_desktop_is_visible ();
63 	if ((myData.bDesktopVisible || myData.bDeskletsVisible) && myConfig.cVisibleImage)
64 		CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cVisibleImage);
65 	else
66 		CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;
67 
68 	myData.cKeyBinding = CD_APPLET_BIND_KEY (myConfig.cShortcut,
69 		D_(s_cShortkeyDescription[myConfig.iActionOnMiddleClick]),
70 		"Configuration", "shortkey",
71 		(CDBindkeyHandler) on_keybinding_pull);
72 CD_APPLET_INIT_END
73 
74 
75 //\___________ 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.
76 CD_APPLET_STOP_BEGIN
77 	CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
78 	CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
79 	CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
80 	gldi_object_remove_notification (&myDesktopMgr,
81 		NOTIFICATION_DESKTOP_VISIBILITY_CHANGED,
82 		(GldiNotificationFunc) on_show_desktop, myApplet);
83 
84 	gldi_object_unref (GLDI_OBJECT(myData.cKeyBinding));
85 	if (myData.pLastActiveWindow)
86 		gldi_object_unref (GLDI_OBJECT(myData.pLastActiveWindow));
87 CD_APPLET_STOP_END
88 
89 
90 //\___________ 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.
91 CD_APPLET_RELOAD_BEGIN
92 	if (CD_APPLET_MY_CONFIG_CHANGED)
93 	{
94 		if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED)  // we are now in a desklet, set a renderer.
95 		{
96 			CD_APPLET_SET_DESKLET_RENDERER ("Simple");
97 		}
98 
99 		if ((myData.bDesktopVisible || myData.bDeskletsVisible) && myConfig.cVisibleImage)
100 			CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cVisibleImage);
101 		else
102 			CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;
103 
104 		gldi_shortkey_rebind (myData.cKeyBinding, myConfig.cShortcut, D_(s_cShortkeyDescription[myConfig.iActionOnMiddleClick]));
105 	}
106 CD_APPLET_RELOAD_END
107