/* Switch to requested view */ static void _xfdashboard_application_switch_to_view(XfdashboardApplication *self, const gchar *inInternalViewName) { GSList *stages, *iter; g_return_if_fail(XFDASHBOARD_IS_APPLICATION(self)); /* If no view name was specified then do nothing and return immediately */ if(!inInternalViewName || !inInternalViewName[0]) { g_debug("No view to switch to specified"); return; } /* Iterate through list of stages and set specified view at stage */ g_debug("Trying to switch to view '%s'", inInternalViewName); stages=clutter_stage_manager_list_stages(clutter_stage_manager_get_default()); for(iter=stages; iter; iter=g_slist_next(iter)) { /* Tell stage to switch view */ if(XFDASHBOARD_IS_STAGE(iter->data)) { xfdashboard_stage_set_switch_to_view(XFDASHBOARD_STAGE(iter->data), inInternalViewName); } } }
/* Callback function for xfdashboard_traverse_actor() to find stage interface * used in xfdashboard_notify(). */ static gboolean _xfdashboard_notify_traverse_callback(ClutterActor *inActor, gpointer inUserData) { XfdashboardStage **outStageInterface; XfdashboardWindowTrackerMonitor *stageMonitor; g_return_val_if_fail(CLUTTER_IS_ACTOR(inActor), XFDASHBOARD_TRAVERSAL_CONTINUE); g_return_val_if_fail(inUserData, XFDASHBOARD_TRAVERSAL_CONTINUE); outStageInterface=(XfdashboardStage**)inUserData; /* If actor currently traverse is a stage interface then store * the actor in user-data and stop further traversal. */ if(XFDASHBOARD_IS_STAGE_INTERFACE(inActor)) { stageMonitor=xfdashboard_stage_interface_get_monitor(XFDASHBOARD_STAGE_INTERFACE(inActor)); if(xfdashboard_window_tracker_monitor_is_primary(stageMonitor)) { *outStageInterface=XFDASHBOARD_STAGE(clutter_actor_get_stage(inActor)); return(XFDASHBOARD_TRAVERSAL_STOP); } } /* If we get here a stage interface was not found so continue traversal */ return(XFDASHBOARD_TRAVERSAL_CONTINUE); }
/** * xfdashboard_get_global_stage_of_actor: * @inActor: The #ClutterActor for which to find the global stage * * Gets the main #XfdashboardStage where @inActor belongs to. * * Return value: (transfer none): The #XfdashboardStage found * or %NULL if none was found. */ XfdashboardStage* xfdashboard_get_global_stage_of_actor(ClutterActor *inActor) { ClutterActor *parent; g_return_val_if_fail(CLUTTER_IS_ACTOR(inActor), NULL); /* Iterate through parents and return first XfdashboardStage * found. That's the main global and all monitors spanning * stage where the requested actor belongs to. */ parent=clutter_actor_get_parent(inActor); while(parent) { /* Check if current iterated parent is a XfdashboardStage. * If it is return it. */ if(XFDASHBOARD_IS_STAGE(parent)) return(XFDASHBOARD_STAGE(parent)); /* Continue with next parent */ parent=clutter_actor_get_parent(parent); } /* If we get here we did not find the global stage the actor * belongs to, so return NULL. */ return(NULL); }
/** * xfdashboard_notify: * @inSender: The sending #ClutterActor or %NULL * @inIconName: The icon name to display in notification or %NULL * @inFormat: A standard printf() format string for notification text * @...: The parameters to insert into the format string * * Shows a notification with the formatted text as specified in @inFormat * and the parameters at the monitor where the sending actor @inSender * is placed on. * * If @inSender is NULL the primary monitor is used. * * If @inIconName is NULL no icon will be shown in notification. */ void xfdashboard_notify(ClutterActor *inSender, const gchar *inIconName, const gchar *inFormat, ...) { XfdashboardStage *stage; va_list args; gchar *text; g_return_if_fail(inSender==NULL || CLUTTER_IS_ACTOR(inSender)); stage=NULL; /* Build text to display */ va_start(args, inFormat); text=g_strdup_vprintf(inFormat, args); va_end(args); /* Get stage of sending actor if available */ if(inSender) stage=XFDASHBOARD_STAGE(clutter_actor_get_stage(inSender)); /* No sending actor specified or no stage found so get default stage */ if(!stage) { XfdashboardCssSelector *selector; /* Traverse through actors to find stage */ selector=xfdashboard_css_selector_new_from_string("XfdashboardStageInterface"); xfdashboard_traverse_actor(NULL, selector, _xfdashboard_notify_traverse_callback, &stage); g_object_unref(selector); /* If we still do not have found a stage to show notification * stop further processing and show notification text as a critical * warning in addition to the critical warning that we could not * find any stage. */ if(!stage) { g_critical(_("Could find any stage to show notification: %s"), text); } } /* Show notification on stage (if any found) */ if(stage) xfdashboard_stage_show_notification(stage, inIconName, text); /* Release allocated resources */ g_free(text); }
/* Perform full initialization of this application instance */ static gboolean _xfdashboard_application_initialize_full(XfdashboardApplication *self, XfdashboardStage **outStage) { XfdashboardApplicationPrivate *priv; GError *error; ClutterActor *stage; #if !GARCON_CHECK_VERSION(0,3,0) const gchar *desktop; #endif g_return_val_if_fail(XFDASHBOARD_IS_APPLICATION(self), FALSE); g_return_val_if_fail(outStage==NULL || *outStage==NULL, FALSE); priv=self->priv; error=NULL; /* Initialize garcon for current desktop environment */ #if !GARCON_CHECK_VERSION(0,3,0) desktop=g_getenv("XDG_CURRENT_DESKTOP"); if(G_LIKELY(desktop==NULL)) { /* If we could not determine current desktop environment * assume Xfce as this application is developed for this DE. */ desktop="XFCE"; } /* If desktop enviroment was found but has no name * set NULL to get all menu items shown. */ else if(*desktop==0) desktop=NULL; garcon_set_environment(desktop); #else garcon_set_environment_xdg(GARCON_ENVIRONMENT_XFCE); #endif /* Setup the session management */ priv->sessionManagementClient=xfce_sm_client_get(); xfce_sm_client_set_priority(priv->sessionManagementClient, XFCE_SM_CLIENT_PRIORITY_DEFAULT); xfce_sm_client_set_restart_style(priv->sessionManagementClient, XFCE_SM_CLIENT_RESTART_IMMEDIATELY); g_signal_connect_swapped(priv->sessionManagementClient, "quit", G_CALLBACK(_xfdashboard_application_on_session_quit), self); if(!xfce_sm_client_connect(priv->sessionManagementClient, &error)) { g_warning("Failed to connect to session manager: %s", (error && error->message) ? error->message : _("unknown error")); g_clear_error(&error); } /* Initialize xfconf */ if(!xfconf_init(&error)) { g_critical(_("Could not initialize xfconf: %s"), (error && error->message) ? error->message : _("unknown error")); if(error) g_error_free(error); return(FALSE); } priv->xfconfChannel=xfconf_channel_get(XFDASHBOARD_XFCONF_CHANNEL); /* Set up keyboard and pointer bindings */ priv->bindings=xfdashboard_bindings_pool_get_default(); if(!priv->bindings) { g_critical(_("Could not initialize bindings")); return(FALSE); } if(!xfdashboard_bindings_pool_load(priv->bindings, &error)) { g_critical(_("Could not load bindings: %s"), (error && error->message) ? error->message : _("unknown error")); if(error!=NULL) g_error_free(error); return(FALSE); } /* Set up application database */ priv->appDatabase=xfdashboard_application_database_get_default(); if(!priv->appDatabase) { g_critical(_("Could not initialize application database")); return(FALSE); } if(!xfdashboard_application_database_load(priv->appDatabase, &error)) { g_critical(_("Could not load application database: %s"), (error && error->message) ? error->message : _("unknown error")); if(error!=NULL) g_error_free(error); return(FALSE); } /* Set up application tracker */ priv->appTracker=xfdashboard_application_tracker_get_default(); if(!priv->appTracker) { g_critical(_("Could not initialize application tracker")); return(FALSE); } /* Set up and load theme */ priv->xfconfThemeChangedSignalID=xfconf_g_property_bind(priv->xfconfChannel, THEME_NAME_XFCONF_PROP, G_TYPE_STRING, self, "theme-name"); if(!priv->xfconfThemeChangedSignalID) { g_warning(_("Could not create binding between xfconf property and local resource for theme change notification.")); } /* Set up default theme in Xfcond if property in channel does not exist * because it indicates first start. */ if(!xfconf_channel_has_property(priv->xfconfChannel, THEME_NAME_XFCONF_PROP)) { xfconf_channel_set_string(priv->xfconfChannel, THEME_NAME_XFCONF_PROP, DEFAULT_THEME_NAME); } /* At this time the theme must have been loaded, either because we * set the default theme name because of missing theme property in * xfconf channel or the value of xfconf channel property has been read * and set when setting up binding (between xfconf property and local property) * what caused a call to function to set theme name in this object * and also caused a reload of theme. * So if no theme object is set in this object then loading theme has * failed and we have to return FALSE. */ if(!priv->theme) return(FALSE); /* Register built-in views (order of registration is important) */ priv->viewManager=xfdashboard_view_manager_get_default(); xfdashboard_view_manager_register(priv->viewManager, XFDASHBOARD_TYPE_WINDOWS_VIEW); xfdashboard_view_manager_register(priv->viewManager, XFDASHBOARD_TYPE_APPLICATIONS_VIEW); xfdashboard_view_manager_register(priv->viewManager, XFDASHBOARD_TYPE_SEARCH_VIEW); /* Register built-in search providers */ priv->searchManager=xfdashboard_search_manager_get_default(); xfdashboard_search_manager_register(priv->searchManager, XFDASHBOARD_TYPE_APPLICATIONS_SEARCH_PROVIDER); /* Create single-instance of focus manager to keep it alive while * application is running. */ priv->focusManager=xfdashboard_focus_manager_get_default(); /* Create stage containing all monitors */ stage=xfdashboard_stage_new(); g_signal_connect_swapped(stage, "delete-event", G_CALLBACK(_xfdashboard_application_on_delete_stage), self); /* Emit signal 'theme-changed' to get current theme loaded at each stage created */ g_signal_emit(self, XfdashboardApplicationSignals[SIGNAL_THEME_CHANGED], 0, priv->theme); /* Set return results */ if(outStage) *outStage=XFDASHBOARD_STAGE(stage); /* Initialization was successful so return TRUE */ #ifdef DEBUG xfdashboard_notify(NULL, NULL, _("Welcome to %s (%s)!"), PACKAGE_NAME, PACKAGE_VERSION); #else xfdashboard_notify(NULL, NULL, _("Welcome to %s!"), PACKAGE_NAME); #endif return(TRUE); }
/** * xfdashboard_notify: * @inSender: The sending #ClutterActor or %NULL * @inIconName: The icon name to display in notification or %NULL * @inFormat: A standard printf() format string for notification text * @...: The parameters to insert into the format string * * Shows a notification with the formatted text as specified in @inFormat * and the parameters at the monitor where the sending actor @inSender * is placed on. * * If @inSender is NULL the primary monitor is used. * * If @inIconName is NULL no icon will be shown in notification. */ void xfdashboard_notify(ClutterActor *inSender, const gchar *inIconName, const gchar *inFormat, ...) { XfdashboardStage *stage; ClutterStageManager *stageManager; va_list args; gchar *text; g_return_if_fail(inSender==NULL || CLUTTER_IS_ACTOR(inSender)); stage=NULL; /* Build text to display */ va_start(args, inFormat); text=g_strdup_vprintf(inFormat, args); va_end(args); /* Get stage of sending actor if available */ if(inSender) stage=XFDASHBOARD_STAGE(clutter_actor_get_stage(inSender)); /* No sending actor specified or no stage found so get default stage */ if(!stage) { const GSList *stages; const GSList *stagesIter; ClutterActorIter interfaceIter; ClutterActor *child; XfdashboardWindowTrackerMonitor *stageMonitor; /* Get stage manager to iterate through stages to find the one * for primary monitor or at least the first stage. */ stageManager=clutter_stage_manager_get_default(); /* Find stage for primary monitor and if we cannot find it * use first stage. */ if(stageManager && CLUTTER_IS_STAGE_MANAGER(stageManager)) { /* Get list of all stages */ stages=clutter_stage_manager_peek_stages(stageManager); /* Iterate through list of all stage and lookup the one for * primary monitor. */ for(stagesIter=stages; stagesIter && !stage; stagesIter=stagesIter->next) { /* Skip this stage if it is not a XfdashboardStage */ if(!XFDASHBOARD_IS_STAGE(stagesIter->data)) continue; /* Iterate through stage's children and lookup stage interfaces */ clutter_actor_iter_init(&interfaceIter, CLUTTER_ACTOR(stagesIter->data)); while(clutter_actor_iter_next(&interfaceIter, &child)) { if(XFDASHBOARD_IS_STAGE_INTERFACE(child)) { stageMonitor=xfdashboard_stage_interface_get_monitor(XFDASHBOARD_STAGE_INTERFACE(child)); if(xfdashboard_window_tracker_monitor_is_primary(stageMonitor)) { stage=XFDASHBOARD_STAGE(clutter_actor_get_stage(child)); } } } } /* If we did not get stage for primary monitor use first stage */ if(!stage && stages) { stage=XFDASHBOARD_STAGE(stages->data); } } /* If we still do not have found a stage to show notification * stop further processing and show notification text as a critical * warning in addition to the critical warning that we could not * find any stage. */ if(!stage) { g_critical(_("Could find any stage to show notification: %s"), text); } } /* Show notification on stage (if any found) */ if(stage) xfdashboard_stage_show_notification(stage, inIconName, text); /* Release allocated resources */ g_free(text); }