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 "applet-config.h" 21 #include "applet-notifications.h" 22 #include "applet-struct.h" 23 #include "applet-menu.h" 24 #include "applet-recent.h" 25 #include "applet-init.h" 26 27 28 CD_APPLET_DEFINE_BEGIN ("GMenu", 29 2, 0, 0, 30 CAIRO_DOCK_CATEGORY_APPLET_DESKTOP, 31 N_("Displays the common Applications menu and the Recently used files.\n" 32 "It is compatible with any XDG compliant menu (Gnome, XFCE, KDE, ...)\n" 33 "Middle-click to open a dialog to quickly launch any command (you can set up a shortkey for it, like ALT+F2)\n" 34 "You can also set up a shortkey to pop up the menu (like ALT+F1)"), 35 "Fabounet (Fabrice Rey)") 36 CD_APPLET_DEFINE_COMMON_APPLET_INTERFACE 37 CD_APPLET_REDEFINE_TITLE (N_("Applications Menu")) 38 CD_APPLET_DEFINE_END 39 40 41 //\___________ 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). 42 CD_APPLET_INIT_BEGIN 43 if (myDesklet) 44 { 45 CD_APPLET_SET_DESKLET_RENDERER ("Simple"); // set a desklet renderer. 46 } 47 48 CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE; // set the default icon if none is specified in conf. 49 50 myData.iPanelDefaultMenuIconSize = cairo_dock_search_icon_size (GTK_ICON_SIZE_LARGE_TOOLBAR); 51 52 cd_menu_start (); 53 54 myData.iShowQuit = myConfig.iShowQuit; 55 myData.bLoadSettingsMenu = myConfig.bLoadSettingsMenu; 56 57 CD_APPLET_REGISTER_FOR_CLICK_EVENT; 58 CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT; 59 CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT; 60 61 // keyboard events 62 myData.cKeyBinding = CD_APPLET_BIND_KEY (myConfig.cMenuShortkey, 63 D_("Show/hide the Applications menu"), 64 "Configuration", "menu shortkey", 65 (CDBindkeyHandler) cd_menu_on_shortkey_menu); 66 67 myData.cKeyBindingQuickLaunch = CD_APPLET_BIND_KEY (myConfig.cQuickLaunchShortkey, 68 D_("Show/hide the quick-launch dialog"), 69 "Configuration", "quick launch shortkey", 70 (CDBindkeyHandler) cd_menu_on_shortkey_quick_launch); 71 CD_APPLET_INIT_END 72 73 74 //\___________ 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. 75 CD_APPLET_STOP_BEGIN 76 CD_APPLET_UNREGISTER_FOR_CLICK_EVENT; 77 CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT; 78 CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT; 79 80 // keyboard events 81 gldi_object_unref (GLDI_OBJECT(myData.cKeyBinding)); 82 gldi_object_unref (GLDI_OBJECT(myData.cKeyBindingQuickLaunch)); 83 84 CD_APPLET_STOP_END 85 86 87 //\___________ 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. 88 CD_APPLET_RELOAD_BEGIN 89 if (CD_APPLET_MY_CONFIG_CHANGED) 90 { 91 if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED) // we are now in a desklet, set a renderer. 92 { 93 CD_APPLET_SET_DESKLET_RENDERER ("Simple"); 94 } 95 96 CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE; // set the default icon if none is specified in conf. 97 98 gldi_shortkey_rebind (myData.cKeyBinding, myConfig.cMenuShortkey, NULL); 99 gldi_shortkey_rebind (myData.cKeyBindingQuickLaunch, myConfig.cQuickLaunchShortkey, NULL); 100 101 // on reset ce qu'il faut. 102 if (myData.pMenu != NULL 103 && (myConfig.iShowQuit != myData.iShowQuit 104 || myConfig.bLoadSettingsMenu != myData.bLoadSettingsMenu)) 105 { 106 cd_menu_stop (); // this is not very optimized but well... 107 } 108 myData.iShowQuit = myConfig.iShowQuit; 109 myData.bLoadSettingsMenu = myConfig.bLoadSettingsMenu; 110 111 // on reconstruit ce qu'il faut. 112 if (myData.pMenu == NULL) 113 { 114 cd_menu_start (); 115 } 116 else // menu deja existant, on rajoute/enleve les recents a la main. 117 { 118 if (! myConfig.bShowRecent) // on ne veut plus des recent items. 119 { 120 if (myData.pRecentMenuItem != NULL) 121 { 122 gtk_widget_destroy (myData.pRecentMenuItem); 123 myData.pRecentMenuItem = NULL; 124 } 125 } 126 else // on veut les recent items. 127 { 128 if (myData.pRecentMenuItem != NULL) // ils existent deja. 129 { 130 if (myData.iNbRecentItems != myConfig.iNbRecentItems) // rebuild the recent sub-menu 131 { 132 GtkWidget *pRecentMenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (myData.pRecentMenuItem)); 133 gtk_widget_destroy (pRecentMenu); 134 cd_menu_append_recent_to_menu (myData.pMenu, myApplet); 135 } 136 } 137 else // il faut les construire. 138 { 139 cd_menu_append_recent_to_menu (myData.pMenu, myApplet); 140 } 141 } 142 } 143 } // no need to do anything if the icons theme changes, because the gtk-images are loaded with a GIcon (idem for the Recent sub-menu) 144 CD_APPLET_RELOAD_END 145