| 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-app.h" |
| 25 |
#include "applet-draw.h" |
| 26 |
#include "applet-struct.h" |
| 27 |
#include "applet-init.h" |
| 28 |
|
| 29 |
|
| 30 |
CD_APPLET_DEFINE_BEGIN (N_("Global Menu"), |
| 31 |
3, 0, 0, |
| 32 |
CAIRO_DOCK_CATEGORY_APPLET_DESKTOP, |
| 33 |
N_("This applet allows you to control the current active window:\n" |
| 34 |
" close, minimize, maximize, and display the application menu." |
| 35 |
"To display the menu, applications have to support this feature, which is the case on Ubuntu by default.\n" |
| 36 |
"You can bind a shortkey to this action."), |
| 37 |
"Fabounet") |
| 38 |
CD_APPLET_DEFINE_COMMON_APPLET_INTERFACE |
| 39 |
CD_APPLET_ALLOW_EMPTY_TITLE |
| 40 |
CD_APPLET_DEFINE_END |
| 41 |
|
| 42 |
static gboolean _reversed_buttons_order (void) |
| 43 |
{ // TRUE: on the left (close, min, max) || FALSE: on the right (min, max, close) |
| 44 |
if (myConfig.iButtonsOrder == CD_GM_BUTTON_ORDER_AUTO |
| 45 |
&& ((myDock && (int) myIcon->fXAtRest < (myDock->container.iWidth / 2)) |
| 46 |
|| (myDesklet && myDesklet->container.iWindowPositionX < (g_desktopGeometry.Xscreen.width / 2)))) |
| 47 |
return TRUE; |
| 48 |
return (myConfig.iButtonsOrder == CD_GM_BUTTON_ORDER_LEFT); |
| 49 |
} |
| 50 |
|
| 51 |
//\___________ 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). |
| 52 |
CD_APPLET_INIT_BEGIN |
| 53 |
if (myDesklet) |
| 54 |
{ |
| 55 |
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); // set a desklet renderer. |
| 56 |
} |
| 57 |
|
| 58 |
gldi_object_register_notification (&myWindowObjectMgr, |
| 59 |
NOTIFICATION_WINDOW_ACTIVATED, |
| 60 |
(GldiNotificationFunc) cd_app_menu_on_active_window_changed, |
| 61 |
GLDI_RUN_AFTER, myApplet); |
| 62 |
gldi_object_register_notification (&myWindowObjectMgr, |
| 63 |
NOTIFICATION_WINDOW_STATE_CHANGED, |
| 64 |
(GldiNotificationFunc) cd_app_menu_on_state_changed, |
| 65 |
GLDI_RUN_AFTER, myApplet); |
| 66 |
gldi_object_register_notification (&myWindowObjectMgr, |
| 67 |
NOTIFICATION_WINDOW_NAME_CHANGED, |
| 68 |
(GldiNotificationFunc) cd_app_menu_on_name_changed, |
| 69 |
GLDI_RUN_AFTER, myApplet); |
| 70 |
gldi_object_register_notification (&myWindowObjectMgr, |
| 71 |
NOTIFICATION_WINDOW_CREATED, |
| 72 |
(GldiNotificationFunc) cd_app_menu_on_new_appli, |
| 73 |
GLDI_RUN_AFTER, myApplet); |
| 74 |
|
| 75 |
gldi_object_register_notification (myContainer, |
| 76 |
NOTIFICATION_MOUSE_MOVED, |
| 77 |
(GldiNotificationFunc) on_mouse_moved, |
| 78 |
GLDI_RUN_AFTER, myApplet); |
| 79 |
gldi_object_register_notification (myContainer, |
| 80 |
NOTIFICATION_UPDATE_SLOW, |
| 81 |
(GldiNotificationFunc) cd_app_menu_on_update_container, |
| 82 |
GLDI_RUN_AFTER, myApplet); |
| 83 |
|
| 84 |
// start ! |
| 85 |
myData.iNbButtons = myConfig.bDisplayControls * 3 + 1; // we display the icon even if we don't provide the menu. |
| 86 |
cd_app_menu_start (); |
| 87 |
|
| 88 |
if (myConfig.bDisplayControls) // no animation on mouse hover if the buttons are displayed, it's hard to click |
| 89 |
{ |
| 90 |
CD_APPLET_SET_STATIC_ICON; |
| 91 |
myData.bReversedButtonsOrder = _reversed_buttons_order (); |
| 92 |
/** => TODO? check if the position of the icon has changed? |
| 93 |
* => if we use the 'auto' position, this position of the icon seems to |
| 94 |
* not be correct if we call this function here... we can check if |
| 95 |
* something has changed with CD_APPLET_RELOAD but the order doesn't |
| 96 |
* change if the icon has been moved in the same dock (it works if the |
| 97 |
* container has changed). Do we have to register to this notifications? |
| 98 |
* => NOTIFICATION_ICON_MOVED |
| 99 |
*/ |
| 100 |
} |
| 101 |
|
| 102 |
// mouse events |
| 103 |
CD_APPLET_REGISTER_FOR_CLICK_EVENT; |
| 104 |
CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT; |
| 105 |
CD_APPLET_REGISTER_FOR_DOUBLE_CLICK_EVENT; |
| 106 |
// CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT; |
| 107 |
CD_APPLET_REGISTER_FOR_SCROLL_EVENT; |
| 108 |
|
| 109 |
// keyboard events |
| 110 |
if (myConfig.bDisplayMenu) |
| 111 |
myData.pKeyBinding = CD_APPLET_BIND_KEY (myConfig.cShortkey, |
| 112 |
D_("Show/hide the current application menu"), |
| 113 |
"Configuration", "shortkey", |
| 114 |
(CDBindkeyHandler) cd_app_menu_on_keybinding_pull); |
| 115 |
CD_APPLET_INIT_END |
| 116 |
|
| 117 |
|
| 118 |
//\___________ 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. |
| 119 |
CD_APPLET_STOP_BEGIN |
| 120 |
gldi_object_remove_notification (&myWindowObjectMgr, |
| 121 |
NOTIFICATION_WINDOW_ACTIVATED, |
| 122 |
(GldiNotificationFunc) cd_app_menu_on_active_window_changed, myApplet); |
| 123 |
gldi_object_remove_notification (&myWindowObjectMgr, |
| 124 |
NOTIFICATION_WINDOW_STATE_CHANGED, |
| 125 |
(GldiNotificationFunc) cd_app_menu_on_state_changed, myApplet); |
| 126 |
gldi_object_remove_notification (&myWindowObjectMgr, |
| 127 |
NOTIFICATION_WINDOW_NAME_CHANGED, |
| 128 |
(GldiNotificationFunc) cd_app_menu_on_name_changed, myApplet); |
| 129 |
gldi_object_remove_notification (&myWindowObjectMgr, |
| 130 |
NOTIFICATION_WINDOW_CREATED, |
| 131 |
(GldiNotificationFunc) cd_app_menu_on_new_appli, myApplet); |
| 132 |
|
| 133 |
gldi_object_remove_notification (myContainer, |
| 134 |
NOTIFICATION_MOUSE_MOVED, |
| 135 |
(GldiNotificationFunc) on_mouse_moved, myApplet); |
| 136 |
gldi_object_remove_notification (myContainer, |
| 137 |
NOTIFICATION_UPDATE_SLOW, |
| 138 |
(GldiNotificationFunc) cd_app_menu_on_update_container, myApplet); |
| 139 |
|
| 140 |
cd_app_menu_stop (); |
| 141 |
|
| 142 |
// mouse events |
| 143 |
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT; |
| 144 |
CD_APPLET_UNREGISTER_FOR_DOUBLE_CLICK_EVENT; |
| 145 |
CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT; |
| 146 |
// CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT; |
| 147 |
CD_APPLET_UNREGISTER_FOR_SCROLL_EVENT; |
| 148 |
|
| 149 |
// keyboard events |
| 150 |
if (myConfig.bDisplayMenu) |
| 151 |
gldi_object_unref (GLDI_OBJECT(myData.pKeyBinding)); |
| 152 |
CD_APPLET_STOP_END |
| 153 |
|
| 154 |
|
| 155 |
//\___________ 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. |
| 156 |
CD_APPLET_RELOAD_BEGIN |
| 157 |
// if they are loaded, reload the controls icons. |
| 158 |
cd_app_menu_load_button_images (); |
| 159 |
cd_app_menu_default_image (); |
| 160 |
|
| 161 |
if (CD_APPLET_MY_CONFIG_CHANGED) |
| 162 |
{ |
| 163 |
if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED) // we are now in a desklet, set a renderer. |
| 164 |
{ |
| 165 |
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); |
| 166 |
} |
| 167 |
|
| 168 |
if (CD_APPLET_MY_OLD_CONTAINER != myContainer) |
| 169 |
{ |
| 170 |
gldi_object_remove_notification (CD_APPLET_MY_OLD_CONTAINER, |
| 171 |
NOTIFICATION_MOUSE_MOVED, |
| 172 |
(GldiNotificationFunc) on_mouse_moved, myApplet); |
| 173 |
gldi_object_remove_notification (CD_APPLET_MY_OLD_CONTAINER, |
| 174 |
NOTIFICATION_UPDATE_SLOW, |
| 175 |
(GldiNotificationFunc) cd_app_menu_on_update_container, myApplet); |
| 176 |
|
| 177 |
gldi_object_register_notification (myContainer, |
| 178 |
NOTIFICATION_MOUSE_MOVED, |
| 179 |
(GldiNotificationFunc) on_mouse_moved, |
| 180 |
GLDI_RUN_AFTER, myApplet); |
| 181 |
gldi_object_register_notification (myContainer, |
| 182 |
NOTIFICATION_UPDATE_SLOW, |
| 183 |
(GldiNotificationFunc) cd_app_menu_on_update_container, |
| 184 |
GLDI_RUN_AFTER, myApplet); |
| 185 |
} |
| 186 |
|
| 187 |
// windows borders |
| 188 |
cd_app_menu_set_windows_borders (!myConfig.bDisplayControls); |
| 189 |
|
| 190 |
// registrar |
| 191 |
if (myConfig.bDisplayMenu && !myData.pProxyRegistrar) |
| 192 |
cd_app_detect_registrar (); |
| 193 |
else if (! myConfig.bDisplayMenu) // even if myData.pProxyRegistrar is NULL, we have to cancel the detection |
| 194 |
cd_app_disconnect_from_registrar (); |
| 195 |
|
| 196 |
// to update any param that could have changed, simply re-set the current window. |
| 197 |
myData.iNbButtons = myConfig.bDisplayControls * 3 + 1; |
| 198 |
myData.iAnimIterMin = myData.iAnimIterMax = myData.iAnimIterClose = 0; |
| 199 |
myData.bButtonAnimating = FALSE; |
| 200 |
GldiWindowActor *pActiveWindow = myData.pCurrentWindow; |
| 201 |
myData.pCurrentWindow = NULL; |
| 202 |
cd_app_menu_set_current_window (pActiveWindow); |
| 203 |
|
| 204 |
// shortkey |
| 205 |
if (myConfig.bDisplayMenu) |
| 206 |
{ |
| 207 |
if (myData.pKeyBinding) |
| 208 |
gldi_shortkey_rebind (myData.pKeyBinding, myConfig.cShortkey, NULL); |
| 209 |
else |
| 210 |
myData.pKeyBinding = CD_APPLET_BIND_KEY (myConfig.cShortkey, |
| 211 |
D_("Show/hide the current application menu"), |
| 212 |
"Configuration", "shortkey", |
| 213 |
(CDBindkeyHandler) cd_app_menu_on_keybinding_pull); |
| 214 |
} |
| 215 |
else if (myData.pKeyBinding) |
| 216 |
{ |
| 217 |
gldi_object_unref (GLDI_OBJECT(myData.pKeyBinding)); |
| 218 |
} |
| 219 |
|
| 220 |
cairo_dock_set_icon_static (myIcon, myConfig.bDisplayControls); |
| 221 |
} |
| 222 |
|
| 223 |
if (myConfig.bDisplayControls) |
| 224 |
{ |
| 225 |
myData.bReversedButtonsOrder = _reversed_buttons_order (); |
| 226 |
cd_app_menu_resize (); |
| 227 |
} |
| 228 |
|
| 229 |
CD_APPLET_RELOAD_END |