| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
#include <string.h> |
| 22 |
|
| 23 |
#include "applet-struct.h" |
| 24 |
#include "applet-animation.h" |
| 25 |
#include "applet-notifications.h" |
| 26 |
|
| 27 |
#define PENGUIN_NB_MESSAGES 13 |
| 28 |
static const gchar *s_pMessage[PENGUIN_NB_MESSAGES] = { |
| 29 |
N_("Hey, I'm here!"), |
| 30 |
N_("Sorry but I'm busy right now."), |
| 31 |
N_("I don't have time to play with you, I have to dig and mine all these icons."), |
| 32 |
N_("Your dock is so messy! Let me clean it."), |
| 33 |
N_("Admit my superiority on you as a penguin!"), |
| 34 |
N_("Wait, do you want to kill me?!"), |
| 35 |
N_("Do you know how painful it is to be clicked on??"), |
| 36 |
N_("It's my dock now, mwahahaha!"), |
| 37 |
N_("I want to be a pirate!"), |
| 38 |
N_("You shall not pass!"), |
| 39 |
N_("I'm your father!"), |
| 40 |
N_("- Gee, Brain, what do you want to do tonight?\n- The same thing we do every night, Pinky : try to take over the Dock!"), |
| 41 |
N_("For Aiur!")}; |
| 42 |
|
| 43 |
|
| 44 |
CD_APPLET_ON_CLICK_PROTO |
| 45 |
{ |
| 46 |
PenguinAnimation *pAnimation = penguin_get_current_animation (); |
| 47 |
if (penguin_is_resting (pAnimation)) |
| 48 |
return GLDI_NOTIFICATION_LET_PASS; |
| 49 |
|
| 50 |
if ((myConfig.bFree && pClickedContainer == myContainer && myDock->container.iMouseX > (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->container.iMouseX < (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->container.iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->container.iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon)) |
| 51 |
{ |
| 52 |
myData.iCurrentPositionY = (myConfig.bFree ? myDocksParam.iDockLineWidth : 0); |
| 53 |
PenguinAnimation *pAnimation = penguin_get_current_animation (); |
| 54 |
int iNewAnimation; |
| 55 |
int iRandom = g_random_int_range (0, 4); |
| 56 |
if (iRandom == 0) |
| 57 |
iNewAnimation = penguin_choose_go_up_animation (myApplet); |
| 58 |
else |
| 59 |
iNewAnimation = penguin_choose_next_animation (myApplet, pAnimation); |
| 60 |
penguin_set_new_animation (myApplet, iNewAnimation); |
| 61 |
|
| 62 |
cairo_dock_redraw_container (myContainer); |
| 63 |
|
| 64 |
gldi_icon_stop_animation (pClickedIcon); |
| 65 |
CD_APPLET_ON_CLICK_END |
| 66 |
|
| 67 |
|
| 68 |
static void _start_xpenguins (GtkMenuItem *menu_item, gpointer *data) |
| 69 |
{ |
| 70 |
cairo_dock_launch_command ("xpenguins"); |
| 71 |
} |
| 72 |
static void _stop_xpenguins (GtkMenuItem *menu_item, gpointer *data) |
| 73 |
{ |
| 74 |
cairo_dock_launch_command ("xpenguins-stop"); |
| 75 |
} |
| 76 |
static void _keep_quiet (GtkMenuItem *menu_item, GldiModuleInstance *myApplet) |
| 77 |
{ |
| 78 |
|
| 79 |
if (myData.iSidRestartDelayed != 0) |
| 80 |
{ |
| 81 |
g_source_remove (myData.iSidRestartDelayed); |
| 82 |
myData.iSidRestartDelayed = 0; |
| 83 |
} |
| 84 |
gldi_object_remove_notification (myContainer, NOTIFICATION_UPDATE_SLOW, (GldiNotificationFunc) penguin_update_container, myApplet); |
| 85 |
gldi_object_remove_notification (myIcon, NOTIFICATION_UPDATE_ICON_SLOW, (GldiNotificationFunc) penguin_update_icon, myApplet); |
| 86 |
|
| 87 |
|
| 88 |
int iNewAnimation = penguin_choose_resting_animation (myApplet); |
| 89 |
penguin_set_new_animation (myApplet, iNewAnimation); |
| 90 |
myData.iCurrentPositionY = (myConfig.bFree ? myDocksParam.iDockLineWidth : 0); |
| 91 |
if (myConfig.bFree) |
| 92 |
{ |
| 93 |
penguin_move_in_dock (myApplet); |
| 94 |
} |
| 95 |
else |
| 96 |
{ |
| 97 |
penguin_move_in_icon (myApplet); |
| 98 |
} |
| 99 |
} |
| 100 |
static void _wake_up (GtkMenuItem *menu_item, GldiModuleInstance *myApplet) |
| 101 |
{ |
| 102 |
penguin_start_animating (myApplet); |
| 103 |
} |
| 104 |
gboolean on_build_container_menu (GldiModuleInstance *myApplet, Icon *pClickedIcon, GldiContainer *pClickedContainer, GtkWidget *pAppletMenu, gboolean *bDiscardMenu) |
| 105 |
{ |
| 106 |
PenguinAnimation *pAnimation = penguin_get_current_animation (); |
| 107 |
if(pAnimation == NULL) |
| 108 |
CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS); |
| 109 |
|
| 110 |
if ((myConfig.bFree && pClickedContainer == myContainer && myDock->container.iMouseX > (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->container.iMouseX < (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->container.iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->container.iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon)) |
| 111 |
{ |
| 112 |
if (pClickedIcon != myIcon) |
| 113 |
{ |
| 114 |
gldi_object_notify (myContainer, NOTIFICATION_BUILD_CONTAINER_MENU, myIcon, myContainer, pAppletMenu, bDiscardMenu); |
| 115 |
gldi_object_notify (myContainer, NOTIFICATION_BUILD_ICON_MENU, myIcon, myContainer, pAppletMenu); |
| 116 |
return GLDI_NOTIFICATION_INTERCEPT; |
| 117 |
} |
| 118 |
} |
| 119 |
return GLDI_NOTIFICATION_LET_PASS; |
| 120 |
} |
| 121 |
|
| 122 |
static gboolean s_bXPenguinsChecked = FALSE, s_bHasXPenguins = FALSE; |
| 123 |
|
| 124 |
CD_APPLET_ON_BUILD_MENU_BEGIN |
| 125 |
PenguinAnimation *pAnimation = penguin_get_current_animation (); |
| 126 |
if(pAnimation == NULL) |
| 127 |
CD_APPLET_LEAVE (GLDI_NOTIFICATION_LET_PASS); |
| 128 |
|
| 129 |
if ((myConfig.bFree && pClickedContainer == myContainer && myDock->container.iMouseX > (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->container.iMouseX < (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->container.iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->container.iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon)) |
| 130 |
{ |
| 131 |
if (pClickedIcon != myIcon) |
| 132 |
{ |
| 133 |
return GLDI_NOTIFICATION_INTERCEPT; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
if (penguin_is_resting (pAnimation)) |
| 138 |
{ |
| 139 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Wake up"), MY_APPLET_SHARE_DATA_DIR"/icon.png", _wake_up, CD_APPLET_MY_MENU); |
| 140 |
} |
| 141 |
else |
| 142 |
{ |
| 143 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Keep quiet"), MY_APPLET_SHARE_DATA_DIR"/icon.png",_keep_quiet, CD_APPLET_MY_MENU); |
| 144 |
} |
| 145 |
|
| 146 |
if (! s_bXPenguinsChecked) |
| 147 |
{ |
| 148 |
s_bXPenguinsChecked = TRUE; |
| 149 |
gchar *cResult = cairo_dock_launch_command_sync ("which xpenguins"); |
| 150 |
if (cResult != NULL && *cResult == '/') |
| 151 |
s_bHasXPenguins = TRUE; |
| 152 |
|
| 153 |
g_free (cResult); |
| 154 |
} |
| 155 |
|
| 156 |
if (s_bHasXPenguins) |
| 157 |
{ |
| 158 |
CD_APPLET_ADD_IN_MENU(D_("Start XPenguins"), _start_xpenguins, CD_APPLET_MY_MENU); |
| 159 |
CD_APPLET_ADD_IN_MENU(D_("Stop XPenguins"), _stop_xpenguins, CD_APPLET_MY_MENU); |
| 160 |
} |
| 161 |
CD_APPLET_ON_BUILD_MENU_END |
| 162 |
|
| 163 |
|
| 164 |
gboolean CD_APPLET_ON_MIDDLE_CLICK_FUNC (GldiModuleInstance *myApplet, Icon *pClickedIcon, GldiContainer *pClickedContainer) |
| 165 |
{ |
| 166 |
PenguinAnimation *pAnimation = penguin_get_current_animation (); |
| 167 |
if(pAnimation == NULL) |
| 168 |
return GLDI_NOTIFICATION_LET_PASS; |
| 169 |
|
| 170 |
if ((myConfig.bFree && pClickedContainer == myContainer && myDock->container.iMouseX > (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX && myDock->container.iMouseX < (myDock->container.iWidth - myDock->fFlatDockWidth) / 2 + myData.iCurrentPositionX + pAnimation->iFrameWidth && myDock->container.iMouseY > myContainer->iHeight - myData.iCurrentPositionY - pAnimation->iFrameHeight && myDock->container.iMouseY < myContainer->iHeight - myData.iCurrentPositionY) || (! myConfig.bFree && pClickedIcon == myIcon)) |
| 171 |
{ |
| 172 |
if (myData.pDialog != NULL) |
| 173 |
{ |
| 174 |
gldi_object_unref (GLDI_OBJECT(myData.pDialog)); |
| 175 |
myData.pDialog = NULL; |
| 176 |
} |
| 177 |
PenguinAnimation *pAnimation = penguin_get_current_animation (); |
| 178 |
if (penguin_is_resting (pAnimation)) |
| 179 |
{ |
| 180 |
Icon *pIcon = cairo_dock_get_pointed_icon (myDock->icons); |
| 181 |
if (pIcon != NULL) |
| 182 |
myData.pDialog = gldi_dialog_show_temporary (D_("Zzzzz"), pIcon, myContainer, 2000); |
| 183 |
else |
| 184 |
myData.pDialog = gldi_dialog_show_general_message (D_("Zzzzz"), 2000); |
| 185 |
} |
| 186 |
else if (! pAnimation->bEnding && myData.iSidRestartDelayed == 0) |
| 187 |
{ |
| 188 |
int iRandom = g_random_int_range (0, 5); |
| 189 |
if (iRandom == 0) |
| 190 |
{ |
| 191 |
int iNewAnimation = penguin_choose_ending_animation (myApplet); |
| 192 |
penguin_set_new_animation (myApplet, iNewAnimation); |
| 193 |
} |
| 194 |
else if (iRandom == 1 && ! myConfig.bFree) |
| 195 |
{ |
| 196 |
CD_APPLET_ANIMATE_MY_ICON ("bounce", 3); |
| 197 |
myData.pDialog = gldi_dialog_show_temporary ("Olll����� !", myIcon, myContainer, 2500); |
| 198 |
} |
| 199 |
else |
| 200 |
{ |
| 201 |
iRandom = g_random_int_range (0, PENGUIN_NB_MESSAGES); |
| 202 |
Icon *pIcon = cairo_dock_get_pointed_icon (myDock->icons); |
| 203 |
const gchar *cMessage = D_(s_pMessage[iRandom]); |
| 204 |
int iDuration = 2000 + 25 * g_utf8_strlen (cMessage, -1); |
| 205 |
if (pIcon != NULL) |
| 206 |
myData.pDialog = gldi_dialog_show_temporary (cMessage, pIcon, myContainer, iDuration); |
| 207 |
else |
| 208 |
myData.pDialog = gldi_dialog_show_general_message (cMessage, iDuration); |
| 209 |
} |
| 210 |
} |
| 211 |
CD_APPLET_ON_MIDDLE_CLICK_END |
| 212 |
|
| 213 |
|
| 214 |
gboolean cd_on_dock_destroyed (GldiModuleInstance *myApplet, CairoDock *pDock) |
| 215 |
{ |
| 216 |
gldi_object_delete (GLDI_OBJECT(myApplet)); |
| 217 |
return GLDI_NOTIFICATION_LET_PASS; |
| 218 |
} |