Example #1
0
/**
 * shell_global_create_root_pixmap_actor:
 * @global: a #ShellGlobal
 *
 * Creates an actor showing the root window pixmap.
 *
 * Return value: (transfer none): a #ClutterActor with the root window pixmap.
 *               The actor is floating, hence (transfer none).
 */
ClutterActor *
shell_global_create_root_pixmap_actor (ShellGlobal *global)
{
  GdkWindow *window;
  ClutterActor *stage;
  ClutterColor stage_color;

  /* The actor created is actually a ClutterClone of global->root_pixmap. */

  if (global->root_pixmap == NULL)
    {
      global->root_pixmap = clutter_glx_texture_pixmap_new ();

      clutter_texture_set_repeat (CLUTTER_TEXTURE (global->root_pixmap),
                                  TRUE, TRUE);

      /* The low and medium quality filters give nearest-neighbor resizing. */
      clutter_texture_set_filter_quality (CLUTTER_TEXTURE (global->root_pixmap),
                                          CLUTTER_TEXTURE_QUALITY_HIGH);

      /* Initialize to the stage color, since that's what will be seen
       * in the main view if there's no actual background window.
       */
      stage = mutter_plugin_get_stage (global->plugin);
      clutter_stage_get_color (CLUTTER_STAGE (stage), &stage_color);
      clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (global->root_pixmap),
                                         /* ClutterColor has the same layout
                                          * as one pixel of RGB(A) data.
                                          */
                                         (const guchar *)&stage_color, FALSE,
                                         /* w, h, rowstride, bpp, flags */
                                         1, 1, 3, 3, 0, NULL);

      /* We can only clone an actor within a stage, so we hide the source
       * texture then add it to the stage */
      clutter_actor_hide (global->root_pixmap);
      clutter_container_add_actor (CLUTTER_CONTAINER (stage),
                                   global->root_pixmap);

      /* This really should never happen; but just in case... */
      g_signal_connect (global->root_pixmap, "destroy",
                        G_CALLBACK (root_pixmap_destroy), global);

      /* Metacity handles changes to some root window properties in its global
       * event filter, though not _XROOTPMAP_ID. For all root window property
       * changes, the global filter returns GDK_FILTER_CONTINUE, so our
       * window specific filter will be called after the global one.
       *
       * Because Metacity is already handling root window property updates,
       * we don't have to worry about adding the PropertyChange mask to the
       * root window to get PropertyNotify events.
       */
      window = gdk_get_default_root_window ();
      gdk_window_add_filter (window, root_window_filter, global);

      update_root_window_pixmap (global);
    }

  return clutter_clone_new (global->root_pixmap);
}
Example #2
0
int main(int argc, char *argv[])
{
    ClutterActor *stage;
    WebKitWebView *web_view;
    
    ClutterConstraint *width_binding;
    ClutterConstraint *height_binding;
    ClutterConstraint *web_view_height_binding;
    
    gfloat stageWidth, stageHeight;
    ClutterActorBox stageAllocation;
    
    ClutterLayoutManager  *mainLayout;
    ClutterActor          *mainLayoutContainer;
    ClutterLayoutManager  *toolbarLayout;
    ClutterActor          *toolbarContainer;
    ClutterLayoutManager  *toolbarBinLayout;
    ClutterActor          *toolbarBinContainer;
    ClutterActor          *toolbarBgr;
    ClutterActor          *statusBar;
    ClutterActor *backFwdBtns;
    ClutterActor *backBtn;
    ClutterActor *fwdBtn;
    ClutterActor *uriGroup;
    ClutterActor *uriBgr;
    ClutterActor *uriText;
    ClutterActor *spacer;
    
    GError *error = NULL;
    
    ClutterColor whiteColor = { 255, 255, 255, 255 };
    ClutterColor blackColor = { 0, 0, 0, 255 };
    ClutterColor grayColor =  { 200, 200, 200, 255 };
    ClutterColor transparentColor = { 0, 0, 0, 0 };
    
    gchar *toolbarBgrPath = clutter_launcher_file_path("toolbar_bgr.png");
    gchar *backBtnPath = clutter_launcher_file_path("back_btn.png");
    gchar *fwdBtnPath = clutter_launcher_file_path("fwd_btn.png");
    
    g_thread_init(NULL);
    clutter_threads_init();
    
    clutter_init(&argc, &argv);
    
    stage = clutter_stage_get_default();
    clutter_actor_set_size(stage, 1024, 768);
    clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color);
    g_signal_connect (stage, "destroy", G_CALLBACK(clutter_main_quit), NULL);
    
    /* make the stage resizable */
    clutter_stage_set_user_resizable(CLUTTER_STAGE(stage), TRUE);
    
    clutter_actor_show(stage);
    
    mainLayout = clutter_box_layout_new();
    clutter_box_layout_set_vertical(CLUTTER_BOX_LAYOUT(mainLayout), TRUE);
    
    
    clutter_actor_get_allocation_box(stage, &stageAllocation);
    stageWidth = stageAllocation.x2 - stageAllocation.x1;
    stageHeight = stageAllocation.y2 - stageAllocation.y1;
    
    web_view = WEBKIT_WEB_VIEW(webkit_web_view_new((guint)stageWidth, (guint)stageHeight - (toolbarHeight + statusBarHeight)));
    g_object_set(web_view, "reactive", TRUE, NULL);
    
    mainLayoutContainer = clutter_box_new(mainLayout);
    clutter_actor_set_size(mainLayoutContainer, stageWidth, stageHeight);
    
    width_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_WIDTH, 0);
    height_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_HEIGHT, 0);
/*    web_view_height_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_HEIGHT, -(toolbarHeight + statusBarHeight));
  */  
    clutter_actor_add_constraint(mainLayoutContainer, width_binding);
    clutter_actor_add_constraint(mainLayoutContainer, height_binding);
/*    clutter_actor_add_constraint(CLUTTER_ACTOR(web_view), web_view_height_binding);
  */  
    toolbarBinLayout = clutter_bin_layout_new(CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_CENTER);
    toolbarBinContainer = clutter_box_new(toolbarBinLayout);
    
    toolbarBgr = clutter_texture_new_from_file(toolbarBgrPath, &error);
    if (toolbarBgr == NULL) {
      fprintf(stderr, "Can't load file: %s. Aborting...\n", toolbarBgrPath);
      exit(1);
    }
    clutter_actor_set_height(toolbarBgr, toolbarHeight);
    clutter_texture_set_repeat(CLUTTER_TEXTURE(toolbarBgr), TRUE, FALSE);
    clutter_box_pack(CLUTTER_BOX(toolbarBinContainer), toolbarBgr, NULL, NULL);
    
    toolbarLayout = clutter_box_layout_new();
    clutter_box_layout_set_vertical(CLUTTER_BOX_LAYOUT(toolbarLayout), FALSE);
    clutter_box_layout_set_spacing(CLUTTER_BOX_LAYOUT(toolbarLayout), 16);
    toolbarContainer = clutter_box_new(toolbarLayout);
    
    spacer = clutter_rectangle_new_with_color(&transparentColor);
    clutter_actor_set_size(spacer, 1, 1);
    clutter_box_pack(CLUTTER_BOX(toolbarContainer), spacer, NULL, NULL);
    
    backFwdBtns = clutter_group_new();
    
    backBtn = clutter_texture_new_from_file(backBtnPath, &error);
    if (backBtn == NULL) {
      fprintf(stderr, "Can't load file: %s. Aborting...\n", backBtnPath);
      exit(1);
    }
    clutter_actor_set_reactive(backBtn, TRUE);
    /* connect the release event */
    g_signal_connect (backBtn,
                      "button-release-event",
                      G_CALLBACK (on_back_release_cb),
                      web_view);
    
    fwdBtn = clutter_texture_new_from_file(fwdBtnPath, &error);
    if (fwdBtn == NULL) {
      fprintf(stderr, "Can't load file: %s. Aborting...\n", fwdBtnPath);
      exit(1);
    }
    clutter_actor_set_reactive(fwdBtn, TRUE);
    /* connect the release event */
    g_signal_connect (fwdBtn,
                      "button-release-event",
                      G_CALLBACK (on_fwd_release_cb),
                      web_view);
    
    clutter_actor_set_position(fwdBtn, 
                               clutter_actor_get_width(backBtn), 0);
    clutter_container_add(CLUTTER_CONTAINER(backFwdBtns), backBtn, fwdBtn, NULL);
    clutter_box_pack(CLUTTER_BOX(toolbarContainer), backFwdBtns, NULL, NULL);
    
    uriGroup = clutter_group_new();
    
    uriBgr = clutter_rectangle_new_with_color(&whiteColor);
    clutter_rectangle_set_border_color(CLUTTER_RECTANGLE(uriBgr), &blackColor);
    clutter_rectangle_set_border_width(CLUTTER_RECTANGLE(uriBgr), 1);
    clutter_actor_set_size(uriBgr, 400, 25);
    
    uriText = clutter_text_new_full("Helvetica 11px", "http://www.google.com", &blackColor);
    clutter_text_set_editable(CLUTTER_TEXT(uriText), TRUE);
    clutter_text_set_single_line_mode(CLUTTER_TEXT(uriText), TRUE);
    clutter_actor_set_position(uriText, 5, 7);
    clutter_actor_set_size(uriText, 390, 17);
    clutter_actor_set_reactive(uriText, TRUE);
    g_signal_connect(uriText, "activate", G_CALLBACK(on_uri_activate_cb), web_view);
    
    clutter_container_add(CLUTTER_CONTAINER(uriGroup), uriBgr, uriText, NULL);
    clutter_box_pack(CLUTTER_BOX(toolbarContainer), uriGroup, NULL, NULL);
    
    clutter_box_pack(CLUTTER_BOX(toolbarBinContainer), toolbarContainer, NULL, NULL);
    
    clutter_box_pack(CLUTTER_BOX(mainLayoutContainer), toolbarBinContainer, 
                     "y-align", CLUTTER_BOX_ALIGNMENT_START, NULL);
    clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), toolbarBinContainer, TRUE);
    clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), toolbarBinContainer, TRUE, FALSE);
    
    statusBar = clutter_rectangle_new_with_color(&grayColor);
    clutter_actor_set_height(statusBar, statusBarHeight);
    
    clutter_box_pack(CLUTTER_BOX(mainLayoutContainer), statusBar, 
                     "y-align", CLUTTER_BOX_ALIGNMENT_END, NULL);
    clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), statusBar, TRUE);
    clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), statusBar, TRUE, FALSE);
    
    clutter_box_pack_after(CLUTTER_BOX(mainLayoutContainer), CLUTTER_ACTOR(web_view), toolbarBinContainer, 
                           "y-align", CLUTTER_BOX_ALIGNMENT_START, NULL);
    clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), CLUTTER_ACTOR(web_view), TRUE);
    clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), CLUTTER_ACTOR(web_view), TRUE, TRUE);

    clutter_container_add(CLUTTER_CONTAINER(stage), mainLayoutContainer, NULL);
    
    g_signal_connect(web_view, "webkit-load-finished", G_CALLBACK(load_finished_cb), web_view);
    g_signal_connect(web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view);
    /*    g_signal_connect(stage, "delete-event", G_CALLBACK(delete_cb), web_view);*/
    g_signal_connect(web_view, "notify::uri", G_CALLBACK(notify_uri_cb), uriText);
    
    gchar *uri = (gchar*) (argc > 1 ? argv[1] : "http://www.google.com/");
    gchar *fileURL = filenameToURL(uri);

    webkit_web_view_load_uri(web_view, fileURL ? fileURL : uri);
    printf("%s\n", fileURL ? fileURL : uri);
    g_free(fileURL);
        
    g_timeout_add_full(G_PRIORITY_DEFAULT, 3000, timeout_cb, web_view, 0);
    
    clutter_threads_enter ();
    clutter_main();
    clutter_threads_leave ();
    
    return EXIT_SUCCESS;
}
Example #3
0
File: main.c Project: hannenz/zebra
static void on_gesture_end(ClutterGestureAction *action, ClutterActor *stage, gpointer data) {
	ClutterActor *new_actor, *texture, *actor;
	gfloat x, y, w, h;
	GError *error = NULL;
	GdkColor color;
	guint16 alpha;
	gint iw = 125;
	gint ih = 126;
	gboolean repeat_x = FALSE;
	gboolean repeat_y = TRUE;
	guint bgr;


	new_actor = tmpRect;

	gtk_color_button_get_color(GTK_COLOR_BUTTON(app.colorpicker), &color);
	alpha = gtk_color_button_get_alpha(GTK_COLOR_BUTTON(app.colorpicker));
	ClutterColor col =  {
		CLAMP(((color.red / 65535.0) * 255), 0, 255),
		CLAMP(((color.green / 65535.0) * 255), 0, 255),
		CLAMP(((color.blue / 65535.0) * 255), 0, 255),
		CLAMP(((alpha / 65535.0) * 255), 0, 255),

	};

	clutter_rectangle_set_color(CLUTTER_RECTANGLE(new_actor), &col);
	clutter_rectangle_set_border_width(CLUTTER_RECTANGLE(new_actor), 0);
	tmpRect = NULL;


	clutter_actor_get_position(new_actor, &x, &y);
	clutter_actor_get_size(new_actor, &w, &h);

	if (background_image_file != NULL){

		texture = clutter_texture_new_from_file(background_image_file, &error);
		if (error != NULL){
			g_print("Loading image failed\n");
			g_error_free(error);
		}
		clutter_actor_set_position(texture, x, y);
		clutter_actor_set_size(texture, w, h);
		clutter_actor_add_child(stage, texture);
		clutter_actor_show(texture);

		bgr = gtk_combo_box_get_active(GTK_COMBO_BOX(app.background_repeat_select));
		switch (bgr){
			case 0:
				repeat_x = repeat_y = FALSE;
				break;
			case 1:
				repeat_x = TRUE; repeat_y = FALSE;
				break;
			case 2:
				repeat_x = FALSE; repeat_y = TRUE;
				break;
			case 3:
				repeat_x = repeat_y = TRUE;
				break;
		}
		clutter_texture_get_base_size(CLUTTER_TEXTURE(texture), &iw, &ih);
		clutter_actor_set_clip(texture, 0, 0, repeat_x ? w : iw, repeat_y ? h : ih);
		clutter_texture_set_sync_size(CLUTTER_TEXTURE(texture), TRUE);
		clutter_texture_set_repeat(CLUTTER_TEXTURE(texture), TRUE, TRUE);
		clutter_texture_set_keep_aspect_ratio(CLUTTER_TEXTURE(texture), TRUE);
		actor = texture;
		clutter_actor_destroy(new_actor);
	}
	else {
		actor = new_actor;
	}
	tool = TOOL_SELECT;
	clutter_actor_add_action(actor, clutter_drag_action_new());
	clutter_actor_set_reactive(actor, TRUE);
	actors = g_list_append(actors, actor);
	GdkWindow *gdk_window;
	gdk_window = gtk_widget_get_window(app.stage);
	gdk_window_set_cursor(gdk_window, NULL);
}