static void _xfdashboard_live_workspace_get_preferred_width(ClutterActor *self, gfloat inForHeight, gfloat *outMinWidth, gfloat *outNaturalWidth) { XfdashboardLiveWorkspacePrivate *priv=XFDASHBOARD_LIVE_WORKSPACE(self)->priv; gfloat minWidth, naturalWidth; gfloat childWidth, childHeight; minWidth=naturalWidth=0.0f; /* Determine size of workspace if available (should usually be the largest actor) */ if(priv->workspace) { childWidth=(gfloat)xfdashboard_window_tracker_workspace_get_width(priv->workspace); childHeight=(gfloat)xfdashboard_window_tracker_workspace_get_height(priv->workspace); if(inForHeight<0.0f) naturalWidth=childWidth; else naturalWidth=(childWidth/childHeight)*inForHeight; } /* Store sizes computed */ if(outMinWidth) *outMinWidth=minWidth; if(outNaturalWidth) *outNaturalWidth=naturalWidth; }
/* Find live workspace actor for native workspace */ static XfdashboardLiveWorkspace* _xfdashboard_workspace_selector_find_actor_for_workspace(XfdashboardWorkspaceSelector *self, XfdashboardWindowTrackerWorkspace *inWorkspace) { ClutterActorIter iter; ClutterActor *child; XfdashboardLiveWorkspace *liveWorkspace; g_return_val_if_fail(XFDASHBOARD_IS_WORKSPACE_SELECTOR(self), NULL); g_return_val_if_fail(XFDASHBOARD_IS_WINDOW_TRACKER_WORKSPACE(inWorkspace), NULL); /* Iterate through workspace actor and lookup the one handling requesting workspace */ clutter_actor_iter_init(&iter, CLUTTER_ACTOR(self)); while(clutter_actor_iter_next(&iter, &child)) { if(XFDASHBOARD_IS_LIVE_WORKSPACE(child)) { liveWorkspace=XFDASHBOARD_LIVE_WORKSPACE(child); if(xfdashboard_live_workspace_get_workspace(liveWorkspace)==inWorkspace) { return(liveWorkspace); } } } return(NULL); }
/* Window stacking has changed */ static void _xfdashboard_live_workspace_on_window_stacking_changed(XfdashboardLiveWorkspace *self, gpointer inUserData) { XfdashboardLiveWorkspacePrivate *priv=XFDASHBOARD_LIVE_WORKSPACE(self)->priv; GList *windows; XfdashboardWindowTrackerWindow *window; ClutterActor *actor; g_return_if_fail(XFDASHBOARD_IS_LIVE_WORKSPACE(self)); priv=self->priv; /* Get stacked order of windows */ windows=xfdashboard_window_tracker_get_windows_stacked(priv->windowTracker); /* Iterate through list of stacked window from beginning to end * and reinsert each window found to bottom of this actor */ for( ; windows; windows=g_list_next(windows)) { /* Get window and find corresponding actor */ window=XFDASHBOARD_WINDOW_TRACKER_WINDOW(windows->data); if(!window) continue; actor=_xfdashboard_live_workspace_find_by_window(self, window); if(!actor) continue; /* If we get here the window actor was found so move to bottom */ g_object_ref(actor); clutter_actor_remove_child(CLUTTER_ACTOR(self), actor); clutter_actor_insert_child_above(CLUTTER_ACTOR(self), actor, NULL); g_object_unref(actor); } }
/* Allocate position and size of actor and its children */ static void _xfdashboard_live_workspace_allocate(ClutterActor *self, const ClutterActorBox *inBox, ClutterAllocationFlags inFlags) { XfdashboardLiveWorkspacePrivate *priv=XFDASHBOARD_LIVE_WORKSPACE(self)->priv; gfloat availableWidth, availableHeight; gfloat workspaceWidth, workspaceHeight; ClutterContent *content; XfdashboardWindowTrackerWindow *window; gint x, y, w, h; ClutterActor *child; ClutterActorIter iter; ClutterActorBox childAllocation={ 0, }; /* Chain up to store the allocation of the actor */ CLUTTER_ACTOR_CLASS(xfdashboard_live_workspace_parent_class)->allocate(self, inBox, inFlags); /* If we handle no workspace to not set allocation of children */ if(!priv->workspace) return; /* Get size of workspace and this allocation as it is needed * to calculate translated position and size */ clutter_actor_box_get_size(inBox, &availableWidth, &availableHeight); workspaceWidth=(gfloat)xfdashboard_window_tracker_workspace_get_width(priv->workspace); workspaceHeight=(gfloat)xfdashboard_window_tracker_workspace_get_height(priv->workspace); /* Iterate through window actors, calculate translated allocation of * position and size to available size of this actor */ clutter_actor_iter_init(&iter, self); while(clutter_actor_iter_next(&iter, &child)) { /* Get window actor */ if(!CLUTTER_IS_ACTOR(child)) continue; /* Get associated window */ content=clutter_actor_get_content(child); if(!content || !XFDASHBOARD_IS_WINDOW_CONTENT(content)) continue; window=xfdashboard_window_content_get_window(XFDASHBOARD_WINDOW_CONTENT(content)); if(!window) continue; /* Get real size of child */ xfdashboard_window_tracker_window_get_position_size(window, &x, &y, &w, &h); /* Calculate translated position and size of child */ childAllocation.x1=ceil((x/workspaceWidth)*availableWidth); childAllocation.y1=ceil((y/workspaceHeight)*availableHeight); childAllocation.x2=childAllocation.x1+ceil((w/workspaceWidth)*availableWidth); childAllocation.y2=childAllocation.y1+ceil((h/workspaceHeight)*availableHeight); /* Set allocation of child */ clutter_actor_allocate(child, &childAllocation, inFlags); } }
/* A live workspace was clicked */ static void _xfdashboard_workspace_selector_on_workspace_clicked(XfdashboardWorkspaceSelector *self, gpointer inUserData) { XfdashboardLiveWorkspace *liveWorkspace; g_return_if_fail(XFDASHBOARD_IS_WORKSPACE_SELECTOR(self)); g_return_if_fail(XFDASHBOARD_IS_LIVE_WORKSPACE(inUserData)); liveWorkspace=XFDASHBOARD_LIVE_WORKSPACE(inUserData); /* Active workspace */ xfdashboard_window_tracker_workspace_activate(xfdashboard_live_workspace_get_workspace(liveWorkspace)); /* Quit application */ xfdashboard_application_quit(); }
/* Activate selection */ static gboolean _xfdashboard_workspace_selector_focusable_activate_selection(XfdashboardFocusable *inFocusable, ClutterActor *inSelection) { XfdashboardWorkspaceSelector *self; XfdashboardLiveWorkspace *actor; XfdashboardWindowTrackerWorkspace *workspace; g_return_val_if_fail(XFDASHBOARD_IS_FOCUSABLE(inFocusable), FALSE); g_return_val_if_fail(XFDASHBOARD_IS_WORKSPACE_SELECTOR(inFocusable), FALSE); g_return_val_if_fail(XFDASHBOARD_IS_LIVE_WORKSPACE(inSelection), FALSE); self=XFDASHBOARD_WORKSPACE_SELECTOR(inFocusable); actor=XFDASHBOARD_LIVE_WORKSPACE(inSelection); workspace=NULL; /* Check that selection is a child of this actor */ if(!xfdashboard_actor_contains_child_deep(CLUTTER_ACTOR(self), inSelection)) { ClutterActor *parent; parent=clutter_actor_get_parent(inSelection); g_warning(_("%s is a child of %s and cannot be selected at %s"), G_OBJECT_TYPE_NAME(inSelection), parent ? G_OBJECT_TYPE_NAME(parent) : "<nil>", G_OBJECT_TYPE_NAME(self)); } /* Get workspace of new selection and set new selection*/ workspace=xfdashboard_live_workspace_get_workspace(actor); if(workspace) { /* Activate workspace */ xfdashboard_window_tracker_workspace_activate(workspace); /* Quit application */ xfdashboard_application_quit(); /* Activation was successful */ return(TRUE); } /* Activation was unsuccessful if we get here */ g_warning(_("Could not determine workspace of %s to set selection at %s"), G_OBJECT_TYPE_NAME(actor), G_OBJECT_TYPE_NAME(self)); return(FALSE); }
static void _xfdashboard_live_workspace_get_property(GObject *inObject, guint inPropID, GValue *outValue, GParamSpec *inSpec) { XfdashboardLiveWorkspace *self=XFDASHBOARD_LIVE_WORKSPACE(inObject); switch(inPropID) { case PROP_WORKSPACE: g_value_set_object(outValue, self->priv->workspace); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(inObject, inPropID, inSpec); break; } }
/* Dispose this object */ static void _xfdashboard_live_workspace_dispose(GObject *inObject) { XfdashboardLiveWorkspace *self=XFDASHBOARD_LIVE_WORKSPACE(inObject); XfdashboardLiveWorkspacePrivate *priv=self->priv; /* Dispose allocated resources */ if(priv->windowTracker) { g_signal_handlers_disconnect_by_data(priv->windowTracker, self); g_object_unref(priv->windowTracker); priv->windowTracker=NULL; } if(priv->workspace) { g_signal_handlers_disconnect_by_data(priv->workspace, self); priv->workspace=NULL; } /* Call parent's class dispose method */ G_OBJECT_CLASS(xfdashboard_live_workspace_parent_class)->dispose(inObject); }
/* Find requested selection target depending of current selection */ static ClutterActor* _xfdashboard_workspace_selector_focusable_find_selection(XfdashboardFocusable *inFocusable, ClutterActor *inSelection, XfdashboardSelectionTarget inDirection) { XfdashboardWorkspaceSelector *self; XfdashboardWorkspaceSelectorPrivate *priv; XfdashboardLiveWorkspace *selection; ClutterActor *newSelection; g_return_val_if_fail(XFDASHBOARD_IS_FOCUSABLE(inFocusable), NULL); g_return_val_if_fail(XFDASHBOARD_IS_WORKSPACE_SELECTOR(inFocusable), NULL); g_return_val_if_fail(!inSelection || XFDASHBOARD_IS_LIVE_WORKSPACE(inSelection), NULL); self=XFDASHBOARD_WORKSPACE_SELECTOR(inFocusable); priv=self->priv; newSelection=NULL; selection=NULL; /* Find actor for current active workspace which is also the current selection */ if(priv->activeWorkspace) { selection=_xfdashboard_workspace_selector_find_actor_for_workspace(self, priv->activeWorkspace); } if(!selection) return(NULL); /* If there is nothing selected return currently determined actor which is * the current active workspace. */ if(!inSelection) { g_debug("No selection at %s, so select first child %s for direction %u", G_OBJECT_TYPE_NAME(self), selection ? G_OBJECT_TYPE_NAME(selection) : "<nil>", inDirection); return(CLUTTER_ACTOR(selection)); } /* Check that selection is a child of this actor otherwise return NULL */ if(!xfdashboard_actor_contains_child_deep(CLUTTER_ACTOR(self), inSelection)) { ClutterActor *parent; parent=clutter_actor_get_parent(inSelection); g_warning(_("Cannot lookup selection target at %s because %s is a child of %s"), G_OBJECT_TYPE_NAME(self), G_OBJECT_TYPE_NAME(inSelection), parent ? G_OBJECT_TYPE_NAME(parent) : "<nil>"); return(NULL); } /* Find target selection */ switch(inDirection) { case XFDASHBOARD_SELECTION_TARGET_LEFT: if(priv->orientation==CLUTTER_ORIENTATION_HORIZONTAL) { newSelection=clutter_actor_get_previous_sibling(CLUTTER_ACTOR(selection)); } break; case XFDASHBOARD_SELECTION_TARGET_UP: if(priv->orientation==CLUTTER_ORIENTATION_VERTICAL) { newSelection=clutter_actor_get_previous_sibling(CLUTTER_ACTOR(selection)); } break; case XFDASHBOARD_SELECTION_TARGET_RIGHT: if(priv->orientation==CLUTTER_ORIENTATION_HORIZONTAL) { newSelection=clutter_actor_get_next_sibling(CLUTTER_ACTOR(selection)); } break; case XFDASHBOARD_SELECTION_TARGET_DOWN: if(priv->orientation==CLUTTER_ORIENTATION_VERTICAL) { newSelection=clutter_actor_get_next_sibling(CLUTTER_ACTOR(selection)); } break; case XFDASHBOARD_SELECTION_TARGET_FIRST: case XFDASHBOARD_SELECTION_TARGET_PAGE_UP: case XFDASHBOARD_SELECTION_TARGET_PAGE_LEFT: if(inDirection==XFDASHBOARD_SELECTION_TARGET_FIRST || (inDirection==XFDASHBOARD_SELECTION_TARGET_PAGE_UP && priv->orientation==CLUTTER_ORIENTATION_VERTICAL) || (inDirection==XFDASHBOARD_SELECTION_TARGET_PAGE_LEFT && priv->orientation==CLUTTER_ORIENTATION_HORIZONTAL)) { newSelection=clutter_actor_get_first_child(CLUTTER_ACTOR(self)); } break; case XFDASHBOARD_SELECTION_TARGET_LAST: case XFDASHBOARD_SELECTION_TARGET_PAGE_DOWN: case XFDASHBOARD_SELECTION_TARGET_PAGE_RIGHT: if(inDirection==XFDASHBOARD_SELECTION_TARGET_LAST || (inDirection==XFDASHBOARD_SELECTION_TARGET_PAGE_DOWN && priv->orientation==CLUTTER_ORIENTATION_VERTICAL) || (inDirection==XFDASHBOARD_SELECTION_TARGET_PAGE_RIGHT && priv->orientation==CLUTTER_ORIENTATION_HORIZONTAL)) { newSelection=clutter_actor_get_last_child(CLUTTER_ACTOR(self)); } break; case XFDASHBOARD_SELECTION_TARGET_NEXT: newSelection=clutter_actor_get_next_sibling(CLUTTER_ACTOR(selection)); if(!newSelection) newSelection=clutter_actor_get_previous_sibling(CLUTTER_ACTOR(selection)); break; default: { gchar *valueName; valueName=xfdashboard_get_enum_value_name(XFDASHBOARD_TYPE_SELECTION_TARGET, inDirection); g_critical(_("Focusable object %s does not handle selection direction of type %s."), G_OBJECT_TYPE_NAME(self), valueName); g_free(valueName); } break; } /* If new selection could be found override current selection with it */ if(newSelection && XFDASHBOARD_IS_LIVE_WORKSPACE(newSelection)) { selection=XFDASHBOARD_LIVE_WORKSPACE(newSelection); } /* Return new selection found */ g_debug("Selecting %s at %s for current selection %s in direction %u", selection ? G_OBJECT_TYPE_NAME(selection) : "<nil>", G_OBJECT_TYPE_NAME(self), inSelection ? G_OBJECT_TYPE_NAME(inSelection) : "<nil>", inDirection); return(CLUTTER_ACTOR(selection)); }