| 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 |
#include <string.h> |
| 22 |
|
| 23 |
#include <gdk/gdkx.h> |
| 24 |
#include <gdk/gdkkeysyms.h> |
| 25 |
|
| 26 |
#include "applet-struct.h" |
| 27 |
#include "applet-draw.h" |
| 28 |
#include "applet-icon-finder.h" |
| 29 |
#include "applet-search.h" |
| 30 |
#include "applet-session.h" |
| 31 |
#include "applet-listing.h" |
| 32 |
#include "applet-notifications.h" |
| 33 |
|
| 34 |
gboolean cd_do_render (gpointer pUserData, GldiContainer *pContainer, cairo_t *pCairoContext) |
| 35 |
{ |
| 36 |
g_return_val_if_fail (!cd_do_session_is_off (), GLDI_NOTIFICATION_LET_PASS); |
| 37 |
|
| 38 |
if (pCairoContext != NULL) |
| 39 |
{ |
| 40 |
cd_do_render_cairo (g_pMainDock, pCairoContext); |
| 41 |
} |
| 42 |
else |
| 43 |
{ |
| 44 |
cd_do_render_opengl (g_pMainDock); |
| 45 |
} |
| 46 |
|
| 47 |
return GLDI_NOTIFICATION_LET_PASS; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
gboolean cd_do_update_container (gpointer pUserData, GldiContainer *pContainer, gboolean *bContinueAnimation) |
| 52 |
{ |
| 53 |
g_return_val_if_fail (!cd_do_session_is_off (), GLDI_NOTIFICATION_LET_PASS); |
| 54 |
|
| 55 |
int iDeltaT = cairo_dock_get_animation_delta_t (pContainer); |
| 56 |
if (cd_do_session_is_closing ()) |
| 57 |
{ |
| 58 |
//\___________________ animation de fermeture de la session (disparition des lettres ou du prompt). |
| 59 |
myData.iCloseTime -= iDeltaT; |
| 60 |
if (myData.iCloseTime <= 0) |
| 61 |
cd_do_exit_session (); |
| 62 |
else |
| 63 |
*bContinueAnimation = TRUE; |
| 64 |
cairo_dock_redraw_container (pContainer); |
| 65 |
} |
| 66 |
else if (cd_do_session_is_running ()) |
| 67 |
{ |
| 68 |
if (myData.pCharList == NULL) |
| 69 |
{ |
| 70 |
//\___________________ animation du prompt. |
| 71 |
if (myData.iPromptAnimationCount > -1) |
| 72 |
{ |
| 73 |
myData.iPromptAnimationCount ++; |
| 74 |
*bContinueAnimation = TRUE; |
| 75 |
} |
| 76 |
} |
| 77 |
else |
| 78 |
{ |
| 79 |
//\___________________ animation des caracteres : deplacement vers la gauche/droite et apparition. |
| 80 |
myData.iAppearanceTime -= iDeltaT; |
| 81 |
if (myData.iAppearanceTime < 0) |
| 82 |
myData.iAppearanceTime = 0; |
| 83 |
else |
| 84 |
*bContinueAnimation = TRUE; |
| 85 |
|
| 86 |
double f = (double) myData.iAppearanceTime / myConfig.iAppearanceDuration; |
| 87 |
CDChar *pChar; |
| 88 |
GList *c; |
| 89 |
for (c = myData.pCharList; c != NULL; c = c->next) |
| 90 |
{ |
| 91 |
pChar = c->data; |
| 92 |
pChar->iCurrentX = f * pChar->iInitialX + (1-f) * pChar->iFinalX; |
| 93 |
pChar->iCurrentY = f * pChar->iInitialY + (1-f) * pChar->iFinalY; |
| 94 |
|
| 95 |
if (pChar->fRotationAngle != 0) |
| 96 |
{ |
| 97 |
pChar->fRotationAngle -= 10.; // 360. * iDeltaT / myConfig.iAppearanceDuration; |
| 98 |
if (pChar->fRotationAngle < 0) |
| 99 |
pChar->fRotationAngle = 0; |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
//\___________________ animation du decalage des icones d'appli correspondantes. |
| 105 |
if (myData.iMatchingGlideCount != 0) |
| 106 |
{ |
| 107 |
myData.iMatchingGlideCount --; |
| 108 |
double f = (double) myData.iMatchingGlideCount / 10; |
| 109 |
myData.iCurrentMatchingOffset = myData.iPreviousMatchingOffset * f + myData.iMatchingAimPoint * (1 - f); |
| 110 |
} |
| 111 |
|
| 112 |
cairo_dock_redraw_container (pContainer); |
| 113 |
} |
| 114 |
|
| 115 |
return GLDI_NOTIFICATION_LET_PASS; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
/*gboolean cd_do_enter_container (gpointer pUserData, GldiContainer *pContainer, gboolean *bStartAnimation) |
| 120 |
{ |
| 121 |
if (myData.sCurrentText == NULL || myData.bIgnoreIconState) |
| 122 |
return GLDI_NOTIFICATION_LET_PASS; |
| 123 |
|
| 124 |
cd_do_close_session (); |
| 125 |
|
| 126 |
*bStartAnimation = TRUE; |
| 127 |
return GLDI_NOTIFICATION_LET_PASS; |
| 128 |
}*/ |
| 129 |
|
| 130 |
|
| 131 |
static void _check_dock_is_active (gchar *cDockName, CairoDock *pDock, gboolean *data) |
| 132 |
{ |
| 133 |
if (gldi_container_is_active (CAIRO_CONTAINER (pDock))) |
| 134 |
*data = TRUE; |
| 135 |
} |
| 136 |
gboolean cd_do_check_active_dock (gpointer pUserData, GldiWindowActor *actor) |
| 137 |
{ |
| 138 |
g_return_val_if_fail (cd_do_session_is_running (), GLDI_NOTIFICATION_LET_PASS); |
| 139 |
|
| 140 |
if (myData.sCurrentText == NULL) |
| 141 |
return GLDI_NOTIFICATION_LET_PASS; |
| 142 |
|
| 143 |
gboolean bDockIsActive = FALSE; |
| 144 |
gldi_docks_foreach ((GHFunc) _check_dock_is_active, &bDockIsActive); |
| 145 |
|
| 146 |
if (! bDockIsActive) |
| 147 |
{ |
| 148 |
gtk_window_present (GTK_WINDOW (g_pMainDock->container.pWidget)); |
| 149 |
} |
| 150 |
return GLDI_NOTIFICATION_LET_PASS; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
gboolean cd_do_key_pressed (gpointer pUserData, GldiContainer *pContainer, guint iKeyVal, guint iModifierType, const gchar *string) |
| 155 |
{ |
| 156 |
g_return_val_if_fail (cd_do_session_is_running (), GLDI_NOTIFICATION_LET_PASS); |
| 157 |
|
| 158 |
if (myData.sCurrentText == NULL) |
| 159 |
return GLDI_NOTIFICATION_LET_PASS; |
| 160 |
|
| 161 |
const gchar *cKeyName = gdk_keyval_name (iKeyVal); |
| 162 |
guint32 iUnicodeChar = gdk_keyval_to_unicode (iKeyVal); |
| 163 |
cd_debug ("+ cKeyName : %s (%c, %s)", cKeyName, iUnicodeChar, string); |
| 164 |
|
| 165 |
if (iKeyVal == GDK_KEY_Escape) // on clot la session. |
| 166 |
{ |
| 167 |
cd_do_close_session (); |
| 168 |
} |
| 169 |
else if (iKeyVal == GDK_KEY_space && myData.iNbValidCaracters == 0) // pas d'espace en debut de chaine. |
| 170 |
{ |
| 171 |
// on rejette. |
| 172 |
} |
| 173 |
else if (iKeyVal >= GDK_KEY_Shift_L && iKeyVal <= GDK_KEY_Hyper_R) // on n'ecrit pas les modificateurs. |
| 174 |
{ |
| 175 |
// on rejette. |
| 176 |
} |
| 177 |
else if (iKeyVal == GDK_KEY_BackSpace) // on efface la derniere lettre. |
| 178 |
{ |
| 179 |
if (myData.iNbValidCaracters > 0) |
| 180 |
{ |
| 181 |
cd_debug ("on efface la derniere lettre de %s %d/%d", myData.sCurrentText->str, myData.iNbValidCaracters, myData.sCurrentText->len); |
| 182 |
if (myData.iNbValidCaracters == myData.sCurrentText->len) // pas de completion en cours => on efface la derniere lettre tapee. |
| 183 |
myData.iNbValidCaracters --; |
| 184 |
|
| 185 |
// on efface les lettres precedentes jusqu'a la derniere position validee. |
| 186 |
cd_do_delete_invalid_caracters (); |
| 187 |
|
| 188 |
// on relance la recherche. |
| 189 |
if (myData.pListingHistory == NULL) // recherche principale. |
| 190 |
{ |
| 191 |
g_list_free (myData.pMatchingIcons); |
| 192 |
myData.pMatchingIcons = NULL; |
| 193 |
cd_do_search_matching_icons (); |
| 194 |
if (myData.pMatchingIcons == NULL && myData.sCurrentText->len > 0) // on n'a trouve aucun programme, on cherche des entrees. |
| 195 |
{ |
| 196 |
if (myData.iSidLoadExternAppliIdle != 0) |
| 197 |
{ |
| 198 |
g_source_remove (myData.iSidLoadExternAppliIdle); |
| 199 |
myData.iSidLoadExternAppliIdle = 0; |
| 200 |
} |
| 201 |
cd_do_launch_all_backends (); |
| 202 |
} |
| 203 |
else // on a trouve au moins un programme, on cache le listing des fichiers. |
| 204 |
{ |
| 205 |
|
| 206 |
cd_do_hide_listing (); |
| 207 |
} |
| 208 |
} |
| 209 |
else // sous-recherche => on filtre. |
| 210 |
{ |
| 211 |
cd_do_filter_current_listing (); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
// on repositionne les caracteres et on anime tout ca. |
| 216 |
cd_do_launch_appearance_animation (); |
| 217 |
} |
| 218 |
} |
| 219 |
else if (iKeyVal == GDK_KEY_Tab) // completion. |
| 220 |
{ |
| 221 |
if (myData.iNbValidCaracters > 0) |
| 222 |
{ |
| 223 |
gboolean bPrevious = iModifierType & GDK_SHIFT_MASK; |
| 224 |
if (myData.pMatchingIcons != NULL) |
| 225 |
{ |
| 226 |
cd_do_select_previous_next_matching_icon (!bPrevious); |
| 227 |
} |
| 228 |
else |
| 229 |
{ |
| 230 |
// faire un truc ?... |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
else if (iKeyVal == GDK_KEY_Return) |
| 235 |
{ |
| 236 |
cd_debug ("Enter (%s)", myData.cSearchText); |
| 237 |
if (myData.pMatchingIcons != NULL) // on a une appli a lancer. |
| 238 |
{ |
| 239 |
Icon *pIcon = (myData.pCurrentMatchingElement ? myData.pCurrentMatchingElement->data : myData.pMatchingIcons->data); |
| 240 |
cairo_dock_launch_command (pIcon->cCommand); |
| 241 |
} |
| 242 |
else if (myData.pListing && myData.pListing->pCurrentEntry) // pas d'appli mais une entree => on l'execute. |
| 243 |
{ |
| 244 |
CDEntry *pEntry = myData.pListing->pCurrentEntry->data; |
| 245 |
cd_debug ("on valide l'entree '%s ; %s'", pEntry->cName, pEntry->cPath); |
| 246 |
if (pEntry->execute) |
| 247 |
pEntry->execute (pEntry); |
| 248 |
else |
| 249 |
return GLDI_NOTIFICATION_INTERCEPT; |
| 250 |
} |
| 251 |
else if (myData.iNbValidCaracters > 0) // pas d'entree mais du texte => on l'execute tel quel. |
| 252 |
{ |
| 253 |
cd_debug ("on execute '%s'", myData.sCurrentText->str); |
| 254 |
cairo_dock_launch_command (myData.sCurrentText->str); |
| 255 |
} |
| 256 |
|
| 257 |
if (!(iModifierType & GDK_CONTROL_MASK) && !(iModifierType & GDK_MOD1_MASK) && !(iModifierType & GDK_SHIFT_MASK)) |
| 258 |
cd_do_close_session (); |
| 259 |
} |
| 260 |
else if (iKeyVal == GDK_KEY_Left || iKeyVal == GDK_KEY_Right || iKeyVal == GDK_KEY_Up || iKeyVal == GDK_KEY_Down) |
| 261 |
{ |
| 262 |
if (myData.pMatchingIcons != NULL) |
| 263 |
{ |
| 264 |
cd_do_select_previous_next_matching_icon (iKeyVal == GDK_KEY_Right || iKeyVal == GDK_KEY_Down); |
| 265 |
} |
| 266 |
else if (myData.pListing != NULL && myData.pListing->pEntries != NULL) |
| 267 |
{ |
| 268 |
if (iKeyVal == GDK_KEY_Down) |
| 269 |
{ |
| 270 |
cd_do_select_prev_next_entry_in_listing (TRUE); // next |
| 271 |
} |
| 272 |
else if (iKeyVal == GDK_KEY_Up) |
| 273 |
{ |
| 274 |
cd_do_select_prev_next_entry_in_listing (FALSE); // previous |
| 275 |
} |
| 276 |
else if (iKeyVal == GDK_KEY_Right) |
| 277 |
{ |
| 278 |
cd_do_show_current_sub_listing (); |
| 279 |
} |
| 280 |
else if (iKeyVal == GDK_KEY_Left) |
| 281 |
{ |
| 282 |
cd_do_show_previous_listing (); |
| 283 |
} |
| 284 |
} |
| 285 |
} |
| 286 |
else if (iKeyVal == GDK_KEY_Page_Down || iKeyVal == GDK_KEY_Page_Up || iKeyVal == GDK_KEY_Home || iKeyVal == GDK_KEY_End) |
| 287 |
{ |
| 288 |
if (myData.pListing != NULL) |
| 289 |
{ |
| 290 |
if (iKeyVal == GDK_KEY_Page_Down || iKeyVal == GDK_KEY_Page_Up) |
| 291 |
cd_do_select_prev_next_page_in_listing (iKeyVal == GDK_KEY_Page_Down); // TRUE <=> next page |
| 292 |
else |
| 293 |
cd_do_select_last_first_entry_in_listing (iKeyVal == GDK_KEY_End); // TRUE <=> last entry. |
| 294 |
} |
| 295 |
} |
| 296 |
else if (iKeyVal >= GDK_KEY_F1 && iKeyVal <= GDK_KEY_F9) |
| 297 |
{ |
| 298 |
if (myData.pListing != NULL && gldi_container_is_visible (CAIRO_CONTAINER (myData.pListing))) |
| 299 |
{ |
| 300 |
cd_debug ("modification du filtre : option n°%d", iKeyVal - GDK_KEY_F1); |
| 301 |
cd_do_activate_filter_option (iKeyVal - GDK_KEY_F1); |
| 302 |
cairo_dock_redraw_container (CAIRO_CONTAINER (myData.pListing)); |
| 303 |
} |
| 304 |
} |
| 305 |
else if (string) /// utiliser l'unichar ... |
| 306 |
{ |
| 307 |
cd_debug ("string:'%s'", string); |
| 308 |
guint iNbNewChar = 0; |
| 309 |
if ((iModifierType & GDK_CONTROL_MASK) && iUnicodeChar == 'v') // CTRL+v |
| 310 |
{ |
| 311 |
cd_debug ("CTRL+v\n"); |
| 312 |
GtkClipboard *pClipBoard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); |
| 313 |
gchar *cText = gtk_clipboard_wait_for_text (pClipBoard); // la main loop s'execute pendant ce temps. |
| 314 |
if (cText != NULL) |
| 315 |
{ |
| 316 |
cd_debug ("clipboard : '%s'", cText); |
| 317 |
iNbNewChar = strlen (cText); /// penser a l'UTF-8 ... |
| 318 |
gchar *str = strchr (cText, '\r'); |
| 319 |
if (str) |
| 320 |
*str = '\0'; |
| 321 |
str = strchr (cText, '\n'); |
| 322 |
if (str) |
| 323 |
*str = '\0'; |
| 324 |
g_string_append (myData.sCurrentText, cText); |
| 325 |
cd_do_load_pending_caracters (); |
| 326 |
cd_do_launch_appearance_animation (); |
| 327 |
myData.iNbValidCaracters = myData.sCurrentText->len; // cela valide le texte colle ainsi que les lettres precedemment ajoutee par completion. |
| 328 |
} |
| 329 |
} |
| 330 |
else // on rajoute la lettre au mot |
| 331 |
{ |
| 332 |
iNbNewChar = 1; |
| 333 |
g_string_append_c (myData.sCurrentText, *string); |
| 334 |
myData.iNbValidCaracters = myData.sCurrentText->len; // l'utilisateur valide la nouvelle lettre ainsi que celles precedemment ajoutee par completion. |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
// on cherche la liste des icones qui correspondent. |
| 339 |
if (myData.pListingHistory == NULL) |
| 340 |
{ |
| 341 |
//if (! (myData.bFoundNothing || (myData.pListing && myData.pListing->pEntries))) // on n'est pas deja dans une recherche de fichiers |
| 342 |
if (myData.iNbValidCaracters == iNbNewChar || myData.pMatchingIcons != NULL) // 1er ajout de lettre ou precedente recherche d'icones fructueuse => on remet ca. |
| 343 |
{ |
| 344 |
cd_do_search_matching_icons (); |
| 345 |
} |
| 346 |
|
| 347 |
// si on n'a trouve aucun lanceur, on lance la recherche dans les backends. |
| 348 |
if (myData.pMatchingIcons == NULL) |
| 349 |
{ |
| 350 |
cd_do_launch_all_backends (); |
| 351 |
} |
| 352 |
} |
| 353 |
else |
| 354 |
{ |
| 355 |
cd_do_filter_current_listing (); |
| 356 |
} |
| 357 |
|
| 358 |
// on rajoute une surface/texture pour la/les nouvelle(s) lettre(s). |
| 359 |
myData.iNbValidCaracters -= iNbNewChar; // le nouveau caractere n'est pas encore charge. |
| 360 |
cd_do_load_pending_caracters (); |
| 361 |
myData.iNbValidCaracters += iNbNewChar; |
| 362 |
|
| 363 |
// on repositionne les caracteres et on anime tout ca. |
| 364 |
cd_do_launch_appearance_animation (); |
| 365 |
} |
| 366 |
|
| 367 |
return GLDI_NOTIFICATION_INTERCEPT; |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
void cd_do_on_shortkey_search (const char *keystring, gpointer data) |
| 372 |
{ |
| 373 |
if (! cd_do_session_is_running ()) |
| 374 |
{ |
| 375 |
cd_do_open_session (); |
| 376 |
} |
| 377 |
else |
| 378 |
{ |
| 379 |
cd_do_close_session (); |
| 380 |
} |
| 381 |
} |