/* 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); }
/* Handle key event (it is either key-press or key-release) by focusable actor * which has the focus or by specified actor. */ gboolean xfdashboard_focus_manager_handle_key_event(XfdashboardFocusManager *self, const ClutterEvent *inEvent, XfdashboardFocusable *inFocusable) { XfdashboardFocusManagerPrivate *priv; g_return_val_if_fail(XFDASHBOARD_IS_FOCUS_MANAGER(self), CLUTTER_EVENT_PROPAGATE); g_return_val_if_fail(inEvent, CLUTTER_EVENT_PROPAGATE); g_return_val_if_fail(clutter_event_type(inEvent)==CLUTTER_KEY_PRESS || clutter_event_type(inEvent)==CLUTTER_KEY_RELEASE, CLUTTER_EVENT_PROPAGATE); g_return_val_if_fail(!inFocusable || XFDASHBOARD_IS_FOCUSABLE(inFocusable), CLUTTER_EVENT_PROPAGATE); priv=self->priv; /* If no focusable actor was specified then use current focused actor */ if(!inFocusable) { inFocusable=priv->currentFocus; /* If still no focusable actor is available we cannot handle event * so let the others try it by propagating event. */ if(!inFocusable) return(CLUTTER_EVENT_PROPAGATE); } /* Synthesize event for specified focusable actor */ if(inFocusable) { XfdashboardBindingsPool *bindings; const XfdashboardBinding *binding; gboolean eventStatus; /* Take reference on ourselve and the focusable actor to keep them alive when handling event */ g_object_ref(self); g_object_ref(inFocusable); /* Lookup action for event and emit action if a binding was found * for this event. */ eventStatus=CLUTTER_EVENT_PROPAGATE; bindings=xfdashboard_bindings_pool_get_default(); binding=xfdashboard_bindings_pool_find_for_event(bindings, CLUTTER_ACTOR(inFocusable), inEvent); if(binding) { const gchar *target; const gchar *action; GSList *targetFocusables; GSList *iter; GSignalQuery signalData={ 0, }; /* Get action of binding */ action=xfdashboard_binding_get_action(binding); /* Build up list of targets which is either the requested focusable actor, * the current focused actor or focusable actors of a specific type */ targetFocusables=NULL; target=xfdashboard_binding_get_target(binding); if(target) { /* Target class name is specified so build up a list of targets */ targetFocusables=_xfdashboard_focus_manager_get_targets_for_binding(self, binding); } else { /* No target class name was specified so add requested focusable * actor to list of target. */ targetFocusables=g_slist_append(targetFocusables, g_object_ref(inFocusable)); } g_debug("Target list for action '%s' has %d actors", action, g_slist_length(targetFocusables)); /* Emit action of binding to each actor in target list just build up */ for(iter=targetFocusables; iter; iter=g_slist_next(iter)) { GObject *targetObject; guint signalID; /* Get target to emit action signal at */ targetObject=G_OBJECT(iter->data); /* Check if target provides action requested as signal */ signalID=g_signal_lookup(action, G_OBJECT_TYPE(targetObject)); if(!signalID) { g_warning(_("Object type %s does not provide action '%s'"), G_OBJECT_TYPE_NAME(targetObject), action); continue; } /* Query signal for detailed data */ g_signal_query(signalID, &signalData); /* Check if signal is an action signal */ if(!(signalData.signal_flags & G_SIGNAL_ACTION)) { g_warning(_("Action '%s' at object type %s is not an action signal."), action, G_OBJECT_TYPE_NAME(targetObject)); continue; } #if DEBUG /* In debug mode also check if signal has right signature * to be able to handle this action properly. */ if(signalID) { GType returnValueType=G_TYPE_BOOLEAN; GType parameterTypes[]={ XFDASHBOARD_TYPE_FOCUSABLE, G_TYPE_STRING, CLUTTER_TYPE_EVENT }; guint parameterCount; guint i; /* Check if signal wants the right type of return value */ if(signalData.return_type!=returnValueType) { g_critical(_("Action '%s' at object type %s wants return value of type %s but expected is %s."), action, G_OBJECT_TYPE_NAME(targetObject), g_type_name(signalData.return_type), g_type_name(returnValueType)); } /* Check if signals wants the right number and types of parameters */ parameterCount=sizeof(parameterTypes)/sizeof(GType); if(signalData.n_params!=parameterCount) { g_critical(_("Action '%s' at object type %s wants %u parameters but expected are %u."), action, G_OBJECT_TYPE_NAME(targetObject), signalData.n_params, parameterCount); } for(i=0; i<(parameterCount<signalData.n_params ? parameterCount : signalData.n_params); i++) { if(signalData.param_types[i]!=parameterTypes[i]) { g_critical(_("Action '%s' at object type %s wants type %s at parameter %u but type %s is expected."), action, G_OBJECT_TYPE_NAME(targetObject), g_type_name(signalData.param_types[i]), i+1, g_type_name(parameterTypes[i])); } } } #endif /* Emit action signal at target */ g_debug("Emitting action signal '%s' at focusable actor %s", action, G_OBJECT_TYPE_NAME(targetObject)); g_signal_emit_by_name(targetObject, action, inFocusable, action, inEvent, &eventStatus); g_debug("Action signal '%s' was %s by focusable actor %s", action, eventStatus==CLUTTER_EVENT_STOP ? "handled" : "not handled", G_OBJECT_TYPE_NAME(targetObject)); } /* Release allocated resources */ g_slist_free_full(targetFocusables, g_object_unref); } g_object_unref(bindings); /* Release reference on ourselve and the focusable actor to took to keep them alive */ g_object_unref(inFocusable); g_object_unref(self); if(eventStatus==CLUTTER_EVENT_STOP) return(CLUTTER_EVENT_STOP); } /* Event was not handled so synthesize event to specified focusable actor */ return(clutter_actor_event(CLUTTER_ACTOR(inFocusable), inEvent, FALSE)); }