ShellStack: make this an StWidget
Base ShellStack on StContainer rather than ClutterGroup, so that it has StWidget-y features (and so we don't have to "cheat" in shell_stack_allocate()). Implement navigate_focus() to only ever pass focus into the top-most child, since doing otherwise would be surprising. https://bugzilla.gnome.org/show_bug.cgi?id=646934
This commit is contained in:
parent
caade78e79
commit
9ae8d90be4
@ -18,35 +18,50 @@
|
|||||||
|
|
||||||
G_DEFINE_TYPE (ShellStack,
|
G_DEFINE_TYPE (ShellStack,
|
||||||
shell_stack,
|
shell_stack,
|
||||||
CLUTTER_TYPE_GROUP);
|
ST_TYPE_CONTAINER);
|
||||||
|
|
||||||
|
static void
|
||||||
|
shell_stack_paint (ClutterActor *actor)
|
||||||
|
{
|
||||||
|
CLUTTER_ACTOR_CLASS (shell_stack_parent_class)->paint (actor);
|
||||||
|
|
||||||
|
clutter_container_foreach (CLUTTER_CONTAINER (actor),
|
||||||
|
CLUTTER_CALLBACK (clutter_actor_paint),
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
shell_stack_pick (ClutterActor *actor,
|
||||||
|
const ClutterColor *pick)
|
||||||
|
{
|
||||||
|
/* Chain up so we get a bounding box painted (if we are reactive) */
|
||||||
|
CLUTTER_ACTOR_CLASS (shell_stack_parent_class)->pick (actor, pick);
|
||||||
|
|
||||||
|
clutter_container_foreach (CLUTTER_CONTAINER (actor),
|
||||||
|
CLUTTER_CALLBACK (clutter_actor_paint),
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shell_stack_allocate (ClutterActor *self,
|
shell_stack_allocate (ClutterActor *self,
|
||||||
const ClutterActorBox *box,
|
const ClutterActorBox *box,
|
||||||
ClutterAllocationFlags flags)
|
ClutterAllocationFlags flags)
|
||||||
{
|
{
|
||||||
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
||||||
|
ClutterActorBox content_box;
|
||||||
GList *children, *iter;
|
GList *children, *iter;
|
||||||
float width, height;
|
|
||||||
|
|
||||||
width = box->x2 - box->x1;
|
CLUTTER_ACTOR_CLASS (shell_stack_parent_class)->allocate (self, box, flags);
|
||||||
height = box->y2 - box->y1;
|
|
||||||
|
|
||||||
/* Chain up directly to ClutterActor to set actor->allocation. We explicitly skip our parent class
|
st_theme_node_get_content_box (theme_node, box, &content_box);
|
||||||
* ClutterGroup here because we want to override the allocate function. */
|
|
||||||
(CLUTTER_ACTOR_CLASS (g_type_class_peek (clutter_actor_get_type ())))->allocate (self, box, flags);
|
|
||||||
|
|
||||||
children = clutter_container_get_children (CLUTTER_CONTAINER (self));
|
children = st_container_get_children_list (ST_CONTAINER (self));
|
||||||
for (iter = children; iter; iter = iter->next)
|
for (iter = children; iter; iter = iter->next)
|
||||||
{
|
{
|
||||||
ClutterActor *actor = CLUTTER_ACTOR (iter->data);
|
ClutterActor *actor = CLUTTER_ACTOR (iter->data);
|
||||||
ClutterActorBox child_box;
|
ClutterActorBox child_box = content_box;
|
||||||
child_box.x1 = 0;
|
|
||||||
child_box.x2 = width;
|
|
||||||
child_box.y1 = 0;
|
|
||||||
child_box.y2 = height;
|
|
||||||
clutter_actor_allocate (actor, &child_box, flags);
|
clutter_actor_allocate (actor, &child_box, flags);
|
||||||
}
|
}
|
||||||
g_list_free (children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -56,12 +71,15 @@ shell_stack_get_preferred_height (ClutterActor *actor,
|
|||||||
gfloat *natural_height_p)
|
gfloat *natural_height_p)
|
||||||
{
|
{
|
||||||
ShellStack *stack = SHELL_STACK (actor);
|
ShellStack *stack = SHELL_STACK (actor);
|
||||||
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
||||||
gboolean first = TRUE;
|
gboolean first = TRUE;
|
||||||
float min = 0, natural = 0;
|
float min = 0, natural = 0;
|
||||||
GList *children;
|
GList *children;
|
||||||
GList *iter;
|
GList *iter;
|
||||||
|
|
||||||
children = clutter_container_get_children (CLUTTER_CONTAINER (stack));
|
st_theme_node_adjust_for_width (theme_node, &for_width);
|
||||||
|
|
||||||
|
children = st_container_get_children_list (ST_CONTAINER (stack));
|
||||||
|
|
||||||
for (iter = children; iter; iter = iter->next)
|
for (iter = children; iter; iter = iter->next)
|
||||||
{
|
{
|
||||||
@ -95,7 +113,7 @@ shell_stack_get_preferred_height (ClutterActor *actor,
|
|||||||
if (natural_height_p)
|
if (natural_height_p)
|
||||||
*natural_height_p = natural;
|
*natural_height_p = natural;
|
||||||
|
|
||||||
g_list_free (children);
|
st_theme_node_adjust_preferred_height (theme_node, min_height_p, natural_height_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -105,12 +123,15 @@ shell_stack_get_preferred_width (ClutterActor *actor,
|
|||||||
gfloat *natural_width_p)
|
gfloat *natural_width_p)
|
||||||
{
|
{
|
||||||
ShellStack *stack = SHELL_STACK (actor);
|
ShellStack *stack = SHELL_STACK (actor);
|
||||||
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
||||||
gboolean first = TRUE;
|
gboolean first = TRUE;
|
||||||
float min = 0, natural = 0;
|
float min = 0, natural = 0;
|
||||||
GList *iter;
|
GList *iter;
|
||||||
GList *children;
|
GList *children;
|
||||||
|
|
||||||
children = clutter_container_get_children (CLUTTER_CONTAINER (stack));
|
st_theme_node_adjust_for_height (theme_node, &for_height);
|
||||||
|
|
||||||
|
children = st_container_get_children_list (ST_CONTAINER (stack));
|
||||||
|
|
||||||
for (iter = children; iter; iter = iter->next)
|
for (iter = children; iter; iter = iter->next)
|
||||||
{
|
{
|
||||||
@ -143,17 +164,55 @@ shell_stack_get_preferred_width (ClutterActor *actor,
|
|||||||
|
|
||||||
if (natural_width_p)
|
if (natural_width_p)
|
||||||
*natural_width_p = natural;
|
*natural_width_p = natural;
|
||||||
g_list_free (children);
|
|
||||||
|
st_theme_node_adjust_preferred_width (theme_node, min_width_p, natural_width_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
shell_stack_navigate_focus (StWidget *widget,
|
||||||
|
ClutterActor *from,
|
||||||
|
GtkDirectionType direction)
|
||||||
|
{
|
||||||
|
ClutterActor *top_actor;
|
||||||
|
GList *children;
|
||||||
|
|
||||||
|
/* If the stack is itself focusable, then focus into or out of
|
||||||
|
* it, as appropriate.
|
||||||
|
*/
|
||||||
|
if (st_widget_get_can_focus (widget))
|
||||||
|
{
|
||||||
|
if (from && clutter_actor_contains (CLUTTER_ACTOR (widget), from))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
clutter_actor_grab_key_focus (CLUTTER_ACTOR (widget));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, navigate into its top-most child only */
|
||||||
|
children = st_container_get_children_list (ST_CONTAINER (widget));
|
||||||
|
if (!children)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
top_actor = g_list_last (children)->data;
|
||||||
|
if (ST_IS_WIDGET (top_actor))
|
||||||
|
return st_widget_navigate_focus (ST_WIDGET (top_actor), from, direction, FALSE);
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shell_stack_class_init (ShellStackClass *klass)
|
shell_stack_class_init (ShellStackClass *klass)
|
||||||
{
|
{
|
||||||
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
||||||
|
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
|
||||||
|
|
||||||
|
actor_class->paint = shell_stack_paint;
|
||||||
|
actor_class->pick = shell_stack_pick;
|
||||||
actor_class->get_preferred_width = shell_stack_get_preferred_width;
|
actor_class->get_preferred_width = shell_stack_get_preferred_width;
|
||||||
actor_class->get_preferred_height = shell_stack_get_preferred_height;
|
actor_class->get_preferred_height = shell_stack_get_preferred_height;
|
||||||
actor_class->allocate = shell_stack_allocate;
|
actor_class->allocate = shell_stack_allocate;
|
||||||
|
|
||||||
|
widget_class->navigate_focus = shell_stack_navigate_focus;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#ifndef __SHELL_STACK_H__
|
#ifndef __SHELL_STACK_H__
|
||||||
#define __SHELL_STACK_H__
|
#define __SHELL_STACK_H__
|
||||||
|
|
||||||
#include <clutter/clutter.h>
|
#include "st.h"
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#define SHELL_TYPE_STACK (shell_stack_get_type ())
|
#define SHELL_TYPE_STACK (shell_stack_get_type ())
|
||||||
@ -19,14 +19,14 @@ typedef struct _ShellStackPrivate ShellStackPrivate;
|
|||||||
|
|
||||||
struct _ShellStack
|
struct _ShellStack
|
||||||
{
|
{
|
||||||
ClutterGroup parent;
|
StContainer parent;
|
||||||
|
|
||||||
ShellStackPrivate *priv;
|
ShellStackPrivate *priv;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _ShellStackClass
|
struct _ShellStackClass
|
||||||
{
|
{
|
||||||
ClutterGroupClass parent_class;
|
StContainerClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType shell_stack_get_type (void) G_GNUC_CONST;
|
GType shell_stack_get_type (void) G_GNUC_CONST;
|
||||||
|
Loading…
Reference in New Issue
Block a user