/* Set focus to actor */ static void _xfdashboard_viewpad_focusable_set_focus(XfdashboardFocusable *inFocusable) { XfdashboardViewpad *self; XfdashboardViewpadPrivate *priv; XfdashboardFocusableInterface *selfIface; XfdashboardFocusableInterface *parentIface; g_return_if_fail(XFDASHBOARD_IS_FOCUSABLE(inFocusable)); g_return_if_fail(XFDASHBOARD_IS_VIEWPAD(inFocusable)); self=XFDASHBOARD_VIEWPAD(inFocusable); priv=self->priv; /* Viewpad is just a proxy for the current active view. * So check if current active view is focusable and call its * virtual function. */ if(priv->activeView && XFDASHBOARD_IS_FOCUSABLE(priv->activeView)) { /* Call virtual function of view to set focus */ xfdashboard_focusable_set_focus(XFDASHBOARD_FOCUSABLE(priv->activeView)); /* Call parent class interface function of this actor */ selfIface=XFDASHBOARD_FOCUSABLE_GET_IFACE(inFocusable); parentIface=g_type_interface_peek_parent(selfIface); if(parentIface && parentIface->set_focus) { parentIface->set_focus(inFocusable); } } }
/* Set focus to a registered focusable actor */ void xfdashboard_focus_manager_set_focus(XfdashboardFocusManager *self, XfdashboardFocusable *inFocusable) { XfdashboardFocusManagerPrivate *priv; XfdashboardFocusable *oldFocusable; g_return_if_fail(XFDASHBOARD_IS_FOCUS_MANAGER(self)); g_return_if_fail(XFDASHBOARD_IS_FOCUSABLE(inFocusable)); priv=self->priv; oldFocusable=NULL; /* Check if focusable actor is really registered */ if(g_list_find(priv->registeredFocusables, inFocusable)==NULL) { g_warning(_("Trying to focus an unregistered focusable actor")); return; } /* Check if new focusable actor can be focussed. If it cannot be focussed * move focus to next focusable actor. If no focusable actor can be found * do not change focus at all. */ if(!xfdashboard_focusable_can_focus(inFocusable)) { XfdashboardFocusable *newFocusable; newFocusable=xfdashboard_focus_manager_get_next_focusable(self, inFocusable); if(!newFocusable) { g_debug("Requested focusable actor '%s' cannot be focus but no other focusable actor was found", G_OBJECT_TYPE_NAME(inFocusable)); return; } g_debug("Requested focusable actor '%s' cannot be focused - moving focus to '%s'", G_OBJECT_TYPE_NAME(inFocusable), newFocusable ? G_OBJECT_TYPE_NAME(newFocusable) : "<nothing>"); inFocusable=newFocusable; } /* Do nothing if current focused actor and new one are the same */ oldFocusable=priv->currentFocus; if(oldFocusable==inFocusable) { g_debug("Current focused actor and new one are the same so do nothing."); return; } /* Unset focus at current focused actor */ if(priv->currentFocus) { xfdashboard_focusable_unset_focus(priv->currentFocus); priv->currentFocus=NULL; } /* Set focus to new focusable actor */ priv->currentFocus=inFocusable; xfdashboard_focusable_set_focus(priv->currentFocus); g_debug("Moved focus from '%s' to '%s'", oldFocusable ? G_OBJECT_TYPE_NAME(oldFocusable) : "<nothing>", G_OBJECT_TYPE_NAME(priv->currentFocus)); /* Emit signal for changed focus */ g_signal_emit(self, XfdashboardFocusManagerSignals[SIGNAL_CHANGED], 0, oldFocusable, priv->currentFocus); }