/* Unregister a focusable actor */ void xfdashboard_focus_manager_unregister(XfdashboardFocusManager *self, XfdashboardFocusable *inFocusable) { XfdashboardFocusManagerPrivate *priv; g_return_if_fail(XFDASHBOARD_IS_FOCUS_MANAGER(self)); g_return_if_fail(inFocusable); priv=self->priv; /* Unregister type if registered. * We do not need to check if the given actor is focusable or stylable * because it could not be registered if it is not. */ if(g_list_find(priv->registeredFocusables, inFocusable)!=NULL) { g_debug("Unregistering focusable %s", G_OBJECT_TYPE_NAME(inFocusable)); /* If we unregister the focusable actor which has the focus currently * move focus to next focusable actor first but check that we will not * reselect the focusable actor which should be unregistered. That can * happen because this actor is not yet removed from list of registered * focusable actor and is the only selectable one. But it needs to be * still in the list otherwise we could not find the next actor to * focus appropiately. */ if(inFocusable==priv->currentFocus) { XfdashboardFocusable *focusable; focusable=xfdashboard_focus_manager_get_next_focusable(self, priv->currentFocus); if(focusable && focusable!=priv->currentFocus) xfdashboard_focus_manager_set_focus(self, focusable); else { xfdashboard_focusable_unset_focus(priv->currentFocus); priv->currentFocus=NULL; } } /* Remove focusable actor from list of registered focusable actors */ priv->registeredFocusables=g_list_remove(priv->registeredFocusables, inFocusable); /* Disconnect from signals because we are not interested in this actor anymore */ g_signal_handlers_disconnect_by_func(inFocusable, G_CALLBACK(_xfdashboard_focus_manager_on_focusable_destroy), self); g_signal_handlers_disconnect_by_func(inFocusable, G_CALLBACK(_xfdashboard_focus_manager_on_focusable_hide), self); /* Emit signal */ g_signal_emit(self, XfdashboardFocusManagerSignals[SIGNAL_UNREGISTERED], 0, inFocusable); } }
/* Actor got key focus */ static void _xfdashboard_text_box_key_focus_in(ClutterActor *inActor) { XfdashboardTextBox *self=XFDASHBOARD_TEXT_BOX(inActor); XfdashboardTextBoxPrivate *priv=self->priv; ClutterStage *stage; XfdashboardFocusManager *focusManager; /* Push key focus forward to text box */ stage=CLUTTER_STAGE(clutter_actor_get_stage(inActor)); clutter_stage_set_key_focus(stage, priv->actorTextBox); /* Update focus in focus manager */ focusManager=xfdashboard_focus_manager_get_default(); xfdashboard_focus_manager_set_focus(focusManager, XFDASHBOARD_FOCUSABLE(self)); g_object_unref(focusManager); }
/* Action signal to move focus to previous focusable actor was emitted */ static gboolean _xfdashboard_focus_manager_move_focus_previous(XfdashboardFocusManager *self, XfdashboardFocusable *inSource, const gchar *inAction, ClutterEvent *inEvent) { XfdashboardFocusable *currentFocusable; XfdashboardFocusable *newFocusable; g_return_val_if_fail(XFDASHBOARD_IS_FOCUS_MANAGER(self), CLUTTER_EVENT_PROPAGATE); g_return_val_if_fail(inEvent, CLUTTER_EVENT_PROPAGATE); /* Get current focus */ currentFocusable=xfdashboard_focus_manager_get_focus(self); /* Get next focusable actor to focus */ newFocusable=xfdashboard_focus_manager_get_previous_focusable(self, currentFocusable); if(newFocusable) xfdashboard_focus_manager_set_focus(self, newFocusable); return(CLUTTER_EVENT_STOP); }
/* Action signal to close currently selected window was emitted */ static gboolean _xfdashboard_view_activate(XfdashboardView *self, XfdashboardFocusable *inSource, const gchar *inAction, ClutterEvent *inEvent) { XfdashboardViewPrivate *priv; XfdashboardViewpad *viewpad; XfdashboardFocusManager *focusManager; g_return_val_if_fail(XFDASHBOARD_IS_VIEW(self), CLUTTER_EVENT_PROPAGATE); priv=self->priv; /* Only enabled views can be activated */ if(!priv->isEnabled) return(CLUTTER_EVENT_STOP); /* Find viewpad which contains this view */ viewpad=_xfdashboard_view_find_viewpad(self); if(!viewpad) return(CLUTTER_EVENT_STOP); /* Activate view at viewpad if this view is not the active one */ if(xfdashboard_viewpad_get_active_view(viewpad)!=self) { xfdashboard_viewpad_set_active_view(viewpad, self); } /* Set focus to view if it has not the focus */ focusManager=xfdashboard_focus_manager_get_default(); if(XFDASHBOARD_IS_FOCUSABLE(self) && !xfdashboard_focus_manager_has_focus(focusManager, XFDASHBOARD_FOCUSABLE(self))) { xfdashboard_focus_manager_set_focus(focusManager, XFDASHBOARD_FOCUSABLE(self)); } g_object_unref(focusManager); /* Action handled */ return(CLUTTER_EVENT_STOP); }
/* A registered focusable actor is going to be hidden or unrealized */ static void _xfdashboard_focus_manager_on_focusable_hide(XfdashboardFocusManager *self, gpointer inUserData) { XfdashboardFocusManagerPrivate *priv; XfdashboardFocusable *focusable; XfdashboardFocusable *nextFocusable; g_return_if_fail(XFDASHBOARD_IS_FOCUS_MANAGER(self)); g_return_if_fail(XFDASHBOARD_IS_FOCUSABLE(inUserData)); priv=self->priv; focusable=XFDASHBOARD_FOCUSABLE(inUserData); /* Only move focus if hidden or unrealized focusable actor is the one * which has the focus currently. */ if(priv->currentFocus!=focusable) return; if(CLUTTER_ACTOR_IS_MAPPED(CLUTTER_ACTOR(focusable)) && CLUTTER_ACTOR_IS_REALIZED(CLUTTER_ACTOR(focusable)) && CLUTTER_ACTOR_IS_VISIBLE(CLUTTER_ACTOR(focusable))) { return; } /* Move focus to next focusable actor if this actor which has the current focus * is going to be unrealized or hidden. */ nextFocusable=xfdashboard_focus_manager_get_next_focusable(self, priv->currentFocus); if(nextFocusable && nextFocusable!=priv->currentFocus) xfdashboard_focus_manager_set_focus(self, nextFocusable); else { xfdashboard_focusable_unset_focus(priv->currentFocus); priv->currentFocus=NULL; } }