예제 #1
0
G_MODULE_EXPORT int
test_pixmap_main (int argc, char **argv)
{
  GOptionContext      *context;
  Display	      *xdpy;
  int		       screen;
  ClutterActor        *group = NULL, *label, *stage, *tex;
  Pixmap               pixmap;
  const ClutterColor   gry = { 0x99, 0x99, 0x99, 0xFF };
  Window               win_remote;
  guint		       w, h, d;
  GC		       gc;
  ClutterTimeline     *timeline;
  ClutterAlpha	      *alpha;
  ClutterBehaviour    *depth_behavior;
  int		       i;
  int                  row_height;

#ifdef CLUTTER_WINDOWING_X11
  clutter_set_windowing_backend (CLUTTER_WINDOWING_X11);
#endif

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

#ifdef CLUTTER_WINDOWING_X11
  if (!clutter_check_windowing_backend (CLUTTER_WINDOWING_X11))
    g_error ("test-pixmap requires the X11 Clutter backend.");
#endif

  xdpy = clutter_x11_get_default_display ();
  XSynchronize (xdpy, True);

  context = g_option_context_new (" - test-pixmap options");
  g_option_context_add_main_entries (context, g_options, NULL);
  g_option_context_parse (context, &argc, &argv, NULL);

  pixmap = create_pixmap (&w, &h, &d);

  screen = DefaultScreen(xdpy);
  win_remote = XCreateSimpleWindow (xdpy, DefaultRootWindow(xdpy),
				    0, 0, 200, 200,
				    0,
				    WhitePixel(xdpy, screen),
				    WhitePixel(xdpy, screen));

  XMapWindow (xdpy, win_remote);

  stage = clutter_stage_new ();
  clutter_actor_set_position (stage, 0, 150);
  clutter_actor_set_background_color (stage, &gry);
  clutter_stage_set_title (CLUTTER_STAGE (stage), "X11 Texture from Pixmap");
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  timeline = clutter_timeline_new (5000);
  g_signal_connect (timeline,
                    "completed", G_CALLBACK (timeline_completed),
                    NULL);

  alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);
  depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 400);

  if (!disable_x11)
    {
      group = clutter_group_new ();
      clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
      label = clutter_text_new_with_text ("fixed",
                                          "ClutterX11Texture (Window)");
      clutter_container_add_actor (CLUTTER_CONTAINER (group), label);
      tex = clutter_x11_texture_pixmap_new_with_window (win_remote);
      clutter_container_add_actor (CLUTTER_CONTAINER (group), tex);
      clutter_actor_set_position (tex, 0, 20);
      clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex),
                                                TRUE);
      clutter_texture_set_filter_quality (CLUTTER_TEXTURE (tex),
                                          CLUTTER_TEXTURE_QUALITY_HIGH);
      clutter_actor_set_position (group, 0, 0);
      if (!disable_animation)
        clutter_behaviour_apply (depth_behavior, group);
    }

  if (group)
    row_height = clutter_actor_get_height (group);
  else
    row_height = 0;

  /* NB: We only draw on the window after being redirected, so we dont
   * have to worry about handling expose events... */
  gc = XCreateGC (xdpy, win_remote, 0, NULL);
  XSetForeground (xdpy, gc, BlackPixel (xdpy, screen));
  XSetLineAttributes(xdpy, gc, 5, LineSolid, CapButt, JoinMiter);

  for (i = 0; i < 10; i++)
    XDrawLine (xdpy, win_remote, gc, 0+i*20, 0, 10+i*20+i, 200);


  group = clutter_group_new ();
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
  label = clutter_text_new_with_text ("fixed", "ClutterX11Texture (Pixmap)");
  clutter_container_add_actor (CLUTTER_CONTAINER (group), label);
  tex = clutter_x11_texture_pixmap_new_with_pixmap (pixmap);
  clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex),
                                            TRUE);
  clutter_container_add_actor (CLUTTER_CONTAINER (group), tex);
  clutter_actor_set_position (tex, 0, 20);
  clutter_texture_set_filter_quality (CLUTTER_TEXTURE (tex),
				      CLUTTER_TEXTURE_QUALITY_HIGH);
  /* oddly, the actor's size is 0 until it is realized, even though
     pixmap-height is set */
  clutter_actor_set_position (group, 0, row_height);
  if (!disable_animation)
    clutter_behaviour_apply (depth_behavior, group);


  g_signal_connect (stage, "key-release-event",
                    G_CALLBACK (stage_key_release_cb), (gpointer)pixmap);
  g_signal_connect (stage, "button-press-event",
                    G_CALLBACK (stage_button_press_cb), (gpointer)pixmap);

  clutter_actor_show (stage);

  if (!disable_animation)
    clutter_timeline_start (timeline);

  clutter_threads_add_timeout (1000, draw_arc, GUINT_TO_POINTER (pixmap));

  clutter_main ();

  return EXIT_SUCCESS;
}
예제 #2
0
파일: main.c 프로젝트: mchalupa/mutter
/**
 * meta_init: (skip)
 *
 * Initialize mutter. Call this after meta_get_option_context() and
 * meta_plugin_manager_set_plugin_type(), and before meta_run().
 */
void
meta_init (void)
{
  struct sigaction act;
  sigset_t empty_mask;

  sigemptyset (&empty_mask);
  act.sa_handler = SIG_IGN;
  act.sa_mask    = empty_mask;
  act.sa_flags   = 0;
  if (sigaction (SIGPIPE,  &act, NULL) < 0)
    g_printerr ("Failed to register SIGPIPE handler: %s\n",
                g_strerror (errno));
#ifdef SIGXFSZ
  if (sigaction (SIGXFSZ,  &act, NULL) < 0)
    g_printerr ("Failed to register SIGXFSZ handler: %s\n",
                g_strerror (errno));
#endif

  g_unix_signal_add (SIGTERM, on_sigterm, NULL);

  if (g_getenv ("MUTTER_VERBOSE"))
    meta_set_verbose (TRUE);
  if (g_getenv ("MUTTER_DEBUG"))
    meta_set_debugging (TRUE);

#if defined(CLUTTER_WINDOWING_EGL) && defined(HAVE_NATIVE_BACKEND)
  if (opt_display_server)
    clutter_set_windowing_backend (CLUTTER_WINDOWING_EGL);
  else
#endif
    clutter_set_windowing_backend (CLUTTER_WINDOWING_X11);

#ifdef HAVE_WAYLAND
  meta_set_is_wayland_compositor (opt_wayland);
#endif

  if (g_get_home_dir ())
    if (chdir (g_get_home_dir ()) < 0)
      meta_warning ("Could not change to home directory %s.\n",
                    g_get_home_dir ());

  meta_print_self_identity ();

#ifdef HAVE_INTROSPECTION
  g_irepository_prepend_search_path (MUTTER_PKGLIBDIR);
#endif

#ifdef HAVE_WAYLAND
  if (meta_is_wayland_compositor ())
    meta_wayland_pre_clutter_init ();
#endif

  /* NB: When running as a hybrid wayland compositor we run our own headless X
   * server so the user can't control the X display to connect too. */
  if (!meta_is_wayland_compositor ())
    meta_select_display (opt_display_name);

  meta_clutter_init ();

#ifdef HAVE_WAYLAND
  /* Bring up Wayland. This also launches Xwayland and sets DISPLAY as well... */
  if (meta_is_wayland_compositor ())
    meta_wayland_init ();
#endif

  meta_set_syncing (opt_sync || (g_getenv ("MUTTER_SYNC") != NULL));

  if (opt_replace_wm)
    meta_set_replace_current_wm (TRUE);

  if (opt_save_file && opt_client_id)
    meta_fatal ("Can't specify both SM save file and SM client id\n");

  meta_main_loop = g_main_loop_new (NULL, FALSE);

  meta_ui_init ();

  meta_restart_init ();
}
예제 #3
0
/* Main entry point */
int main(int argc, char **argv)
{
	XfdashboardApplication		*app=NULL;
	gint						status;

#ifdef ENABLE_NLS
	/* Set up localization */
	xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
#endif

#if !GLIB_CHECK_VERSION(2, 36, 0)
	/* Initialize GObject type system */
	g_type_init();
#endif

#if CLUTTER_CHECK_VERSION(1, 16, 0)
	/* Enforce X11 backend in Clutter. This function must be called before any
	 * other Clutter API function.
	 */
	clutter_set_windowing_backend("x11");
#endif

	/* Tell clutter to try to initialize an RGBA visual */
	clutter_x11_set_use_argb_visual(TRUE);

	/* Initialize GTK+ and Clutter */
	gtk_init(&argc, &argv);
	if(!clutter_init(&argc, &argv))
	{
		g_error(_("Initializing clutter failed!"));
		return(1);
	}

	/* Notify that application has started and main loop will be entered */
	gdk_notify_startup_complete();

	/* Start application as primary or remote instace */
	app=xfdashboard_application_get_default();
	if(!app)
	{
		g_warning(_("Failed to create application instance"));
		return(XFDASHBOARD_APPLICATION_ERROR_FAILED);
	}

	status=g_application_run(G_APPLICATION(app), argc, argv);
	if(status==XFDASHBOARD_APPLICATION_ERROR_RESTART &&
		g_application_get_is_remote(G_APPLICATION(app)))
	{
		/* Wait for existing primary instance to quit */
		if(_restart(app))
		{
			g_debug("Reached clean state to restart application");

			/* Destroy remote instance application object for restart */
			g_object_unref(app);
			app=NULL;

			/* Create new application instance which should become
			 * the new primary instance.
			 */
			app=xfdashboard_application_get_default();
			if(!app)
			{
				g_warning(_("Failed to create application instance"));
				return(XFDASHBOARD_APPLICATION_ERROR_FAILED);
			}

			g_debug("Starting new primary instance");
			status=g_application_run(G_APPLICATION(app), argc, argv);
		}
			else
			{
				g_warning(_("Could not restart application because existing instance seems still to be running."));
			}
	}

	/* Clean up, release allocated resources */
	g_object_unref(app);

	return(status);
}
예제 #4
0
파일: main.c 프로젝트: kelsieflynn/mutter
/**
 * meta_init: (skip)
 *
 * Initialize mutter. Call this after meta_get_option_context() and
 * meta_plugin_manager_set_plugin_type(), and before meta_run().
 */
void
meta_init (void)
{
  struct sigaction act;
  sigset_t empty_mask;
  ClutterSettings *clutter_settings;

  sigemptyset (&empty_mask);
  act.sa_handler = SIG_IGN;
  act.sa_mask    = empty_mask;
  act.sa_flags   = 0;
  if (sigaction (SIGPIPE,  &act, NULL) < 0)
    g_printerr ("Failed to register SIGPIPE handler: %s\n",
                g_strerror (errno));
#ifdef SIGXFSZ
  if (sigaction (SIGXFSZ,  &act, NULL) < 0)
    g_printerr ("Failed to register SIGXFSZ handler: %s\n",
                g_strerror (errno));
#endif

  g_unix_signal_add (SIGTERM, on_sigterm, NULL);

  if (g_getenv ("MUTTER_VERBOSE"))
    meta_set_verbose (TRUE);
  if (g_getenv ("MUTTER_DEBUG"))
    meta_set_debugging (TRUE);

#if defined(CLUTTER_WINDOWING_EGL) && defined(HAVE_NATIVE_BACKEND)
  if (opt_display_server)
    clutter_set_windowing_backend (CLUTTER_WINDOWING_EGL);
#endif

  meta_set_is_wayland_compositor (opt_wayland);

  if (g_get_home_dir ())
    if (chdir (g_get_home_dir ()) < 0)
      meta_warning ("Could not change to home directory %s.\n",
                    g_get_home_dir ());

  meta_print_self_identity ();

#ifdef HAVE_INTROSPECTION
  g_irepository_prepend_search_path (MUTTER_PKGLIBDIR);
#endif

  if (meta_is_wayland_compositor ())
    {
      /* NB: When running as a hybrid wayland compositor we run our own headless X
       * server so the user can't control the X display to connect too. */
      meta_wayland_init ();
    }
  else
    meta_select_display (opt_display_name);

  meta_set_syncing (opt_sync || (g_getenv ("MUTTER_SYNC") != NULL));

  if (opt_replace_wm)
    meta_set_replace_current_wm (TRUE);

  if (opt_save_file && opt_client_id)
    meta_fatal ("Can't specify both SM save file and SM client id\n");

  meta_main_loop = g_main_loop_new (NULL, FALSE);

  meta_ui_init ();

  /* If we are running with wayland then we don't wait until we have
   * an X connection before initializing clutter we instead initialize
   * it earlier since we need to initialize the GL driver so the driver
   * can register any needed wayland extensions. */
  if (!meta_is_wayland_compositor ())
    {
      /*
       * Clutter can only be initialized after the UI.
       */
      meta_clutter_init ();
    }

  meta_restart_init ();

  /*
   * XXX: We cannot handle high dpi scaling yet, so fix the scale to 1
   * for now.
   */
  clutter_settings = clutter_settings_get_default ();
  g_object_set (clutter_settings, "window-scaling-factor", 1, NULL);
}
예제 #5
0
void
clutter_try_set_windowing_backend (const char *backend_type)
{
  if (allowed_backends == NULL)
    clutter_set_windowing_backend (backend_type);
}
예제 #6
0
파일: snappy.c 프로젝트: GNOME/snappy
/*            snappy's main function             */
int
main (int argc, char *argv[])
{
  UserInterface *ui = NULL;
  GstEngine *engine = NULL;
  ClutterActor *video_texture;
  ClutterGstVideoSink *sink;

  gboolean ok, blind = FALSE, fullscreen = FALSE, hide = FALSE, loop = FALSE;
  gboolean secret = FALSE, tags = FALSE;
  gint ret = 0;
  gchar *uri = NULL;
  gchar *suburi = NULL;
  GList *uri_list;
  GOptionContext *context;
  gchar *data_dir;

  ClutterInitError ci_err;

#ifdef ENABLE_DBUS
  SnappyMP *mp_obj = NULL;
#endif

  context = g_option_context_new ("<media file> - Play movie files");

  clutter_set_windowing_backend (CLUTTER_WINDOWING_X11);
  ci_err = gtk_clutter_init (&argc, &argv);
  if (ci_err != CLUTTER_INIT_SUCCESS)
    goto quit;

  /* Try to find the path for our resources in case snappy was relocated */
  data_dir = g_strdup (SNAPPY_DATA_DIR);
  if (!g_file_test (data_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
    gchar *root_dir;

#ifdef G_OS_WIN32
    root_dir = g_win32_get_package_installation_directory_of_module (NULL);
#elif !defined(G_OS_UNIX)
    gchar *exec_path;
    gchar *bin_dir;

    exec_path = g_file_read_link ("/proc/self/exe", NULL);
    bin_dir = g_path_get_dirname (exec_path);
    root_dir = g_build_filename (bin_dir, "..", NULL);
    g_free (exec_path);
    g_free (bin_dir);
#else
    root_dir = NULL;
#endif
    if (root_dir != NULL) {
      data_dir = g_build_filename (root_dir, "share", "snappy", NULL);
      g_free (root_dir);
    }
  }

  /* Process command arguments */
  uri_list = process_args (argc, argv, &blind, &fullscreen, &hide,
      &loop, &secret, &suburi, &tags, context);

  gst_init (&argc, &argv);
  clutter_gst_init (NULL, NULL);

  /* User Interface */
  ui = g_new (UserInterface, 1);
  ui->uri_list = uri_list;
  ui->blind = blind;
  ui->fullscreen = fullscreen;
  ui->hide = hide;
  ui->tags = tags;
  ui->data_dir = data_dir;
  interface_init (ui);

  /* Gstreamer engine */
  engine = g_new (GstEngine, 1);
  sink = clutter_gst_video_sink_new ();
  if (sink == NULL) {
    g_print ("ERROR: Failed to create clutter-gst sink element\n");
    return FALSE;
  }
  video_texture = g_object_new (CLUTTER_TYPE_ACTOR, "content",
      g_object_new (CLUTTER_GST_TYPE_CONTENT, "sink", sink, NULL),
      "name", "texture", NULL);

  ok = engine_init (engine, sink);
  if (!ok)
    goto quit;

  engine->secret = secret;
  engine->loop = loop;

  ui->engine = engine;
  ui->texture = video_texture;

  gst_bus_add_watch (engine->bus, bus_call, ui);
  gst_object_unref (engine->bus);

  /* Get uri to load */
  if (uri_list) {
    uri = g_list_first (uri_list)->data;
    /* based on video filename we can guess subtitle file (.srt files only) */
    if (NULL == suburi) {
      gchar suburi_path_guessing[1024]; //buffer
      gchar *uri_no_extension = strip_filename_extension (uri);

      sprintf (suburi_path_guessing, "%s.srt", uri_no_extension);
      /* subtitle file exists, defaults for it */
      if (g_file_test (g_filename_from_uri (suburi_path_guessing, NULL, NULL),
              G_FILE_TEST_EXISTS))
        suburi = suburi_path_guessing;
    }
  }

  /* Load engine and start interface */
  engine_load_uri (engine, uri);
  interface_start (ui, uri);

  /* Load subtitle file if available */
  if (suburi != NULL) {
    suburi = clean_uri (suburi);
    set_subtitle_uri (engine, suburi);
  }

  /* Start playing if we have a URI to play */
  if (uri) {
    change_state (engine, "Paused");
    change_state (engine, "Playing");
  }
#ifdef ENABLE_DBUS
  /* Start MPRIS Dbus object */
  mp_obj = g_new (SnappyMP, 1);
  mp_obj->engine = engine;
  mp_obj->ui = ui;
  load_dlna (mp_obj);
#endif

  /* Main loop */
  gtk_main ();

  /* Close snappy */
  close_down (ui, engine);
#ifdef ENABLE_DBUS
  close_dlna (mp_obj);
#endif

quit:
  g_list_free (uri_list);
  g_option_context_free (context);

  return ret;
}