static gboolean sagarmatha_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 gboolean shell_stack_navigate_focus (StWidget *widget, ClutterActor *from, GtkDirectionType direction) { ClutterActor *top_actor; /* 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; if (CLUTTER_ACTOR_IS_MAPPED (CLUTTER_ACTOR (widget))) { clutter_actor_grab_key_focus (CLUTTER_ACTOR (widget)); return TRUE; } else { return FALSE; } } top_actor = clutter_actor_get_last_child (CLUTTER_ACTOR (widget)); if (ST_IS_WIDGET (top_actor)) return st_widget_navigate_focus (ST_WIDGET (top_actor), from, direction, FALSE); else return FALSE; }
static void mx_menu_show (ClutterActor *actor) { ClutterAnimation *animation = NULL; ClutterStage *stage; /* set reactive and opacity, since these may have been set by the fade-out * animation (e.g. from captured_event_handler or button_release_cb) */ if ((animation = clutter_actor_get_animation (actor))) { clutter_animation_completed (animation); } clutter_actor_set_reactive (actor, TRUE); clutter_actor_set_opacity (actor, 0xff); /* chain up to run show after re-setting properties above */ CLUTTER_ACTOR_CLASS (mx_menu_parent_class)->show (actor); clutter_actor_grab_key_focus (actor); stage = (ClutterStage*) clutter_actor_get_stage (actor); mx_focus_manager_push_focus (mx_focus_manager_get_for_stage (stage), MX_FOCUSABLE (actor)); }
static void mpl_entry_focus_in (ClutterActor *actor) { MplEntryPrivate *priv = MPL_ENTRY (actor)->priv; clutter_actor_grab_key_focus (priv->entry); }
static void make_ui (ClutterActor *stage) { ClutterActor *editable = NULL; ClutterActor *rectangle = NULL; ClutterActor *label = NULL; ClutterColor color_stage = { 0x00, 0x00, 0x00, 0xff }; ClutterColor color_text = { 0xff, 0x00, 0x00, 0xff }; ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 }; ClutterColor color_label = { 0x00, 0xff, 0x55, 0xff }; ClutterColor color_rect = { 0x00, 0xff, 0xff, 0x55 }; ClutterGeometry editable_geom = {150, 50, 100, 75}; ClutterActor *full_entry = NULL; ClutterActor *cloned_entry = NULL; clutter_stage_set_color (CLUTTER_STAGE (stage), &color_stage); clutter_actor_set_size (stage, WIDTH, HEIGHT); label = clutter_text_new_full ("Sans Bold 32px", "Entry", &color_label); clutter_actor_set_position (label, 0, 50); /* editable */ editable = clutter_text_new_full ("Sans Bold 32px", "ddd", &color_text); clutter_actor_set_position (editable, 150, 50); clutter_text_set_editable (CLUTTER_TEXT (editable), TRUE); clutter_text_set_selectable (CLUTTER_TEXT (editable), TRUE); clutter_text_set_selection_color (CLUTTER_TEXT (editable), &color_sel); clutter_actor_grab_key_focus (editable); clutter_actor_set_reactive (editable, TRUE); /* rectangle: to create a entry "feeling" */ rectangle = clutter_rectangle_new_with_color (&color_rect); clutter_actor_set_geometry (rectangle, &editable_geom); full_entry = clutter_group_new (); clutter_actor_set_position (full_entry, 0, 50); clutter_actor_set_size (full_entry, 100, 75); clutter_group_add (CLUTTER_GROUP (full_entry), label); clutter_group_add (CLUTTER_GROUP (full_entry), editable); clutter_group_add (CLUTTER_GROUP (full_entry), rectangle); clutter_actor_show_all (full_entry); clutter_actor_set_scale (full_entry, 2, 1); clutter_group_add (CLUTTER_GROUP (stage), full_entry); /* Cloning! */ cloned_entry = clutter_clone_new (full_entry); clutter_actor_set_position (cloned_entry, 50, 200); clutter_actor_set_scale (cloned_entry, 1, 2); clutter_actor_show_all (cloned_entry); clutter_actor_set_reactive (cloned_entry, TRUE); clutter_group_add (CLUTTER_GROUP (stage), cloned_entry); }
static void st_entry_key_focus_in (ClutterActor *actor) { StEntryPrivate *priv = ST_ENTRY_PRIV (actor); /* We never want key focus. The ClutterText should be given first pass for all key events */ clutter_actor_grab_key_focus (priv->entry); }
static MxFocusable* mx_button_accept_focus (MxFocusable *focusable, MxFocusHint hint) { mx_stylable_style_pseudo_class_add (MX_STYLABLE (focusable), "focus"); clutter_actor_grab_key_focus (CLUTTER_ACTOR (focusable)); return focusable; }
static MxFocusable* mex_content_tile_accept_focus (MxFocusable *focusable, MxFocusHint hint) { clutter_actor_grab_key_focus (CLUTTER_ACTOR (focusable)); g_signal_emit (focusable, signals[FOCUS_IN], 0); return focusable; }
static MxFocusable * mnb_launcher_button_accept_focus (MxFocusable *focusable, MxFocusHint hint) { clutter_ungrab_pointer (); clutter_actor_grab_key_focus (CLUTTER_ACTOR (focusable)); mx_stylable_set_style_pseudo_class (MX_STYLABLE (focusable), "hover"); return focusable; }
/* MxFocusableIface */ static MxFocusable* mex_content_box_accept_focus (MxFocusable *focusable, MxFocusHint hint) { MexContentBoxPrivate *priv = MEX_CONTENT_BOX (focusable)->priv; MxFocusable *focus = MX_FOCUSABLE (priv->tile); clutter_actor_grab_key_focus (CLUTTER_ACTOR (focusable)); return mx_focusable_accept_focus (focus, hint); }
static MxFocusable* mx_toggle_accept_focus (MxFocusable *focusable, MxFocusHint hint) { MxTogglePrivate *priv = MX_TOGGLE (focusable)->priv; mx_stylable_style_pseudo_class_add (MX_STYLABLE (focusable), "focus"); mx_stylable_style_pseudo_class_add (MX_STYLABLE (priv->handle), "focus"); clutter_actor_grab_key_focus (CLUTTER_ACTOR (focusable)); return focusable; }
static void make_ui (ClutterActor *stage) { gint i = 0; ClutterActor *editable = NULL; ClutterActor *rectangle = NULL; ClutterActor *label = NULL; ClutterColor color_stage = { 0x00, 0x00, 0x00, 0xff }; ClutterColor color_text = { 0xff, 0x00, 0x00, 0xff }; ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 }; ClutterColor color_label = { 0x00, 0xff, 0x55, 0xff }; ClutterColor color_rect = { 0x00, 0xff, 0xff, 0x55 }; ClutterGeometry label_geom = {0, 50, -1, -1}; ClutterGeometry editable_geom = {150, 50, 500, 75}; clutter_stage_set_color (CLUTTER_STAGE (stage), &color_stage); clutter_actor_set_size (stage, WIDTH, HEIGHT); for (i = 0; i < NUM_ENTRIES; i++) { /* label */ label = clutter_text_new_full ("Sans Bold 32px", "Entry", &color_label); clutter_actor_set_geometry (label, &label_geom); /* editable */ editable = clutter_text_new_full ("Sans Bold 32px", "ddd", &color_text); clutter_actor_set_geometry (editable, &editable_geom); clutter_text_set_editable (CLUTTER_TEXT (editable), TRUE); clutter_text_set_selectable (CLUTTER_TEXT (editable), TRUE); clutter_text_set_selection_color (CLUTTER_TEXT (editable), &color_sel); clutter_actor_grab_key_focus (editable); clutter_actor_set_reactive (editable, TRUE); /* rectangle: to create a entry "feeling" */ rectangle = clutter_rectangle_new_with_color (&color_rect); clutter_actor_set_geometry (rectangle, &editable_geom); clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); clutter_container_add_actor (CLUTTER_CONTAINER (stage), editable); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rectangle); label_geom.y += HEIGHT_STEP; editable_geom.y += HEIGHT_STEP; } }
static MxFocusable* mex_content_tile_accept_focus (MxFocusable *focusable, MxFocusHint hint) { MexContentTilePrivate *priv = MEX_CONTENT_TILE (focusable)->priv; clutter_actor_grab_key_focus (CLUTTER_ACTOR (focusable)); priv->start_video_preview = g_timeout_add_seconds (1, (GSourceFunc)_start_video_preview, MEX_CONTENT_TILE (focusable)); g_signal_emit (focusable, signals[FOCUS_IN], 0); return focusable; }
/* probably not really needed but making sure the is_pressed state is * consistent */ static gboolean mnb_launcher_button_key_press_event (ClutterActor *actor, ClutterKeyEvent *event) { if (event->keyval == CLUTTER_KEY_Return || event->keyval == CLUTTER_KEY_KP_Enter || event->keyval == CLUTTER_KEY_ISO_Enter) { MnbLauncherButton *self = MNB_LAUNCHER_BUTTON (actor); self->priv->is_pressed = TRUE; clutter_actor_grab_key_focus (actor); return TRUE; } return FALSE; }
static void mx_menu_show (ClutterActor *actor) { ClutterStage *stage; clutter_actor_set_reactive (actor, TRUE); clutter_actor_set_opacity (actor, 0xff); /* chain up to run show after re-setting properties above */ CLUTTER_ACTOR_CLASS (mx_menu_parent_class)->show (actor); clutter_actor_grab_key_focus (actor); stage = (ClutterStage*) clutter_actor_get_stage (actor); mx_focus_manager_push_focus (mx_focus_manager_get_for_stage (stage), MX_FOCUSABLE (actor)); }
gboolean meta_switcher_show(MetaSwitcher* self) { MetaSwitcherPrivate* priv = self->priv; int screen_width, screen_height; MetaScreen* screen = meta_plugin_get_screen(priv->plugin); priv->workspace = meta_screen_get_active_workspace(screen); meta_screen_get_size(screen, &screen_width, &screen_height); meta_switcher_present_list(self); if (priv->apps == NULL || priv->apps->len == 0) goto _end; _capture_desktop(self); clutter_content_invalidate(clutter_actor_get_content(priv->top)); ClutterActor* stage = meta_get_stage_for_screen(screen); clutter_actor_insert_child_above(stage, priv->top, NULL); clutter_actor_show(priv->top); if (!meta_plugin_begin_modal(priv->plugin, 0, clutter_get_current_event_time())) { if (!meta_plugin_begin_modal(priv->plugin, META_MODAL_POINTER_ALREADY_GRABBED, clutter_get_current_event_time())) { g_warning("can not be modal"); goto _end; } } meta_disable_unredirect_for_screen(screen); priv->modaled = TRUE; priv->previous_focused = clutter_stage_get_key_focus(CLUTTER_STAGE(stage)); if (priv->previous_focused == stage) priv->previous_focused = NULL; clutter_stage_set_key_focus(CLUTTER_STAGE(stage), priv->top); clutter_actor_grab_key_focus(priv->top); return TRUE; _end: clutter_actor_hide(priv->top); return FALSE; }
static gboolean st_bin_navigate_focus (StWidget *widget, ClutterActor *from, GtkDirectionType direction) { StBinPrivate *priv = ST_BIN (widget)->priv; ClutterActor *bin_actor = CLUTTER_ACTOR (widget); if (st_widget_get_can_focus (widget)) { if (from && clutter_actor_contains (bin_actor, from)) return FALSE; clutter_actor_grab_key_focus (bin_actor); return TRUE; } else if (priv->child && ST_IS_WIDGET (priv->child)) return st_widget_navigate_focus (ST_WIDGET (priv->child), from, direction, FALSE); else return FALSE; }
static gboolean st_entry_navigate_focus (StWidget *widget, ClutterActor *from, GtkDirectionType direction) { StEntryPrivate *priv = ST_ENTRY_PRIV (widget); /* This is basically the same as st_widget_real_navigate_focus(), * except that widget is behaving as a proxy for priv->entry (which * isn't an StWidget and so has no can-focus flag of its own). */ if (from == priv->entry) return FALSE; else if (st_widget_get_can_focus (widget)) { clutter_actor_grab_key_focus (priv->entry); return TRUE; } else return FALSE; }
void moses_overview_show(MosesOverview* self, gboolean all_windows) { MosesOverviewPrivate* priv = self->priv; MetaRectangle geom; MetaScreen* screen = meta_plugin_get_screen(priv->plugin); int focused_monitor = meta_screen_get_current_monitor(screen); meta_screen_get_monitor_geometry(screen, focused_monitor, &geom); // FIXME: overview is as big as the current monitor, // need to take care multiple monitors ClutterActor* stage = meta_get_stage_for_screen(screen); ClutterActor* top = CLUTTER_ACTOR(self); clutter_actor_set_size(top, geom.width, geom.height); clutter_actor_insert_child_above(stage, top, NULL); moses_overview_setup(self); priv->previous_focused = clutter_stage_get_key_focus(CLUTTER_STAGE(stage)); if (!meta_plugin_begin_modal(priv->plugin, 0, clutter_get_current_event_time())) { g_warning("can not be modal"); goto _end; } meta_disable_unredirect_for_screen(screen); clutter_actor_show(top); clutter_stage_set_key_focus(CLUTTER_STAGE(stage), top); clutter_actor_grab_key_focus(top); priv->modaled = TRUE; g_idle_add((GSourceFunc)on_idle, self); return; _end: clutter_actor_destroy(CLUTTER_ACTOR(self)); }
G_MODULE_EXPORT gint test_text_field_main (gint argc, gchar **argv) { ClutterActor *stage; ClutterActor *box, *label, *entry; ClutterLayoutManager *table; PangoAttrList *entry_attrs; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return EXIT_FAILURE; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Text Fields"); clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); table = clutter_table_layout_new (); clutter_table_layout_set_column_spacing (CLUTTER_TABLE_LAYOUT (table), 6); clutter_table_layout_set_row_spacing (CLUTTER_TABLE_LAYOUT (table), 6); box = clutter_actor_new (); clutter_actor_set_layout_manager (box, table); clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_WIDTH, -24.0)); clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_HEIGHT, -24.0)); clutter_actor_set_position (box, 12, 12); clutter_actor_add_child (stage, box); label = create_label (CLUTTER_COLOR_White, "<b>Input field:</b>"); g_object_set (label, "min-width", 150.0, NULL); clutter_actor_add_child (box, label); clutter_layout_manager_child_set (table, CLUTTER_CONTAINER (box), label, "row", 0, "column", 0, "x-expand", FALSE, "y-expand", FALSE, NULL); entry_attrs = pango_attr_list_new (); pango_attr_list_insert (entry_attrs, pango_attr_underline_new (PANGO_UNDERLINE_ERROR)); pango_attr_list_insert (entry_attrs, pango_attr_underline_color_new (65535, 0, 0)); entry = create_entry (CLUTTER_COLOR_Black, "somme misspeeled textt", entry_attrs, 0, 0); clutter_actor_add_child (box, entry); clutter_layout_manager_child_set (table, CLUTTER_CONTAINER (box), entry, "row", 0, "column", 1, "x-expand", TRUE, "x-fill", TRUE, "y-expand", FALSE, NULL); clutter_actor_grab_key_focus (entry); label = create_label (CLUTTER_COLOR_White, "<b>A very long password field:</b>"); clutter_actor_add_child (box, label); clutter_layout_manager_child_set (table, CLUTTER_CONTAINER (box), label, "row", 1, "column", 0, "x-expand", FALSE, "y-expand", FALSE, NULL); entry = create_entry (CLUTTER_COLOR_Black, "password", NULL, '*', 8); clutter_actor_add_child (box, entry); clutter_layout_manager_child_set (table, CLUTTER_CONTAINER (box), entry, "row", 1, "column", 1, "x-expand", TRUE, "x-fill", TRUE, "y-expand", FALSE, NULL); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
static gboolean st_container_navigate_focus (StWidget *widget, ClutterActor *from, GtkDirectionType direction) { StContainer *container = ST_CONTAINER (widget); ClutterActor *container_actor, *focus_child; GList *children, *l; container_actor = CLUTTER_ACTOR (widget); if (from == container_actor) return FALSE; /* Figure out if @from is a descendant of @container, and if so, * set @focus_child to the immediate child of @container that * contains (or *is*) @from. */ focus_child = from; while (focus_child && clutter_actor_get_parent (focus_child) != container_actor) focus_child = clutter_actor_get_parent (focus_child); if (st_widget_get_can_focus (widget)) { if (!focus_child) { /* Accept focus from outside */ clutter_actor_grab_key_focus (container_actor); return TRUE; } else { /* Yield focus from within: since @container itself is * focusable we don't allow the focus to be navigated * within @container. */ return FALSE; } } /* See if we can navigate within @focus_child */ if (focus_child && ST_IS_WIDGET (focus_child)) { if (st_widget_navigate_focus (ST_WIDGET (focus_child), from, direction, FALSE)) return TRUE; } /* At this point we know that we want to navigate focus to one of * @container's immediate children; the next one after @focus_child, * or the first one if @focus_child is %NULL. (With "next" and * "first" being determined by @direction.) */ children = st_container_get_focus_chain (container); if (direction == GTK_DIR_TAB_FORWARD || direction == GTK_DIR_TAB_BACKWARD) { if (direction == GTK_DIR_TAB_BACKWARD) children = g_list_reverse (children); if (focus_child) { /* Remove focus_child and any earlier children */ while (children && children->data != focus_child) children = g_list_delete_link (children, children); if (children) children = g_list_delete_link (children, children); } } else /* direction is an arrow key, not tab */ { StContainerChildSortData sort_data; /* Compute the allocation box of the previous focused actor, in * @container's coordinate space. If there was no previous focus, * use the coordinates of the appropriate edge of @container. * * Note that all of this code assumes the actors are not * transformed (or at most, they are all scaled by the same * amount). If @container or any of its children is rotated, or * any child is inconsistently scaled, then the focus chain will * probably be unpredictable. */ if (focus_child) { clutter_actor_get_allocation_box (focus_child, &sort_data.box); } else { clutter_actor_get_allocation_box (CLUTTER_ACTOR (container), &sort_data.box); switch (direction) { case GTK_DIR_UP: sort_data.box.y1 = sort_data.box.y2; break; case GTK_DIR_DOWN: sort_data.box.y2 = sort_data.box.y1; break; case GTK_DIR_LEFT: sort_data.box.x1 = sort_data.box.x2; break; case GTK_DIR_RIGHT: sort_data.box.x2 = sort_data.box.x1; break; default: g_warn_if_reached (); } } sort_data.direction = direction; if (focus_child) children = filter_by_position (children, &sort_data.box, direction); if (children) children = g_list_sort_with_data (children, sort_by_position, &sort_data); } /* Now try each child in turn */ for (l = children; l; l = l->next) { if (ST_IS_WIDGET (l->data)) { if (st_widget_navigate_focus (l->data, from, direction, FALSE)) { g_list_free (children); return TRUE; } } } g_list_free (children); return FALSE; }
static void make_ui (ClutterActor *stage) { ClutterActor *button = NULL; clutter_stage_set_title (CLUTTER_STAGE (stage), "Cally - AtkEditable Test"); clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_White); clutter_actor_set_size (stage, WIDTH, HEIGHT); /* text */ text_actor = clutter_text_new_full ("Sans Bold 32px", "Lorem ipsum dolor sit amet", CLUTTER_COLOR_Red); clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_actor); /* text_editable */ text_editable_actor = clutter_text_new_full ("Sans Bold 32px", "consectetur adipisicing elit", CLUTTER_COLOR_Red); clutter_actor_set_position (text_editable_actor, 0, 100); clutter_text_set_editable (CLUTTER_TEXT (text_editable_actor), TRUE); clutter_text_set_selectable (CLUTTER_TEXT (text_editable_actor), TRUE); clutter_text_set_selection_color (CLUTTER_TEXT (text_editable_actor), CLUTTER_COLOR_Green); clutter_text_set_activatable (CLUTTER_TEXT (text_editable_actor), TRUE); clutter_text_set_line_wrap (CLUTTER_TEXT (text_editable_actor), TRUE); clutter_actor_grab_key_focus (text_editable_actor); clutter_actor_set_reactive (text_editable_actor, TRUE); clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_editable_actor); g_signal_connect (text_editable_actor, "activate", G_CALLBACK (activate_cb), NULL); /* test buttons */ button = _create_button ("Set"); clutter_actor_set_position (button, 100, 200); g_signal_connect_after (button, "button-press-event", G_CALLBACK (set_text_press_cb), NULL); clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); button = _create_button ("Delete"); clutter_actor_set_position (button, 100, 250); g_signal_connect_after (button, "button-press-event", G_CALLBACK (delete_text_press_cb), NULL); clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); button = _create_button ("Insert"); clutter_actor_set_position (button, 100, 300); g_signal_connect_after (button, "button-press-event", G_CALLBACK (insert_text_press_cb), NULL); clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); button = _create_button ("Activate/Deactivate"); clutter_actor_set_position (button, 100, 350); g_signal_connect_after (button, "button-press-event", G_CALLBACK (activate_deactivate_press_cb), NULL); clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); button = _create_button ("Cursor position"); clutter_actor_set_position (button, 100, 450); g_signal_connect_after (button, "button-press-event", G_CALLBACK (print_cursor_position_press_cb), NULL); clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); }