ctx = clutter_context_get_default ();
/* compute the numbers we'll store in the components */
- red = (id >> (ctx->fb_g_mask_used+ctx->fb_b_mask_used))
+ red = (id >> (ctx->fb_g_mask_used+ctx->fb_b_mask_used))
& (0xff >> (8-ctx->fb_r_mask_used));
green = (id >> ctx->fb_b_mask_used) & (0xff >> (8-ctx->fb_g_mask_used));
blue = (id) & (0xff >> (8-ctx->fb_b_mask_used));
/* shift left bits a bit and add one, this circumvents
* at least some potential rounding errors in GL/GLES
- * driver / hw implementation.
+ * driver / hw implementation.
*/
if (ctx->fb_r_mask_used != ctx->fb_r_mask)
red = red * 2 + 1;
if (ctx->fb_b_mask_used != ctx->fb_b_mask)
blue = blue * 2 + 1;
- /* shift up to be full 8bit values */
+ /* shift up to be full 8bit values */
red = (red << (8 - ctx->fb_r_mask)) | (0xff >> (ctx->fb_r_mask + 1));
green = (green << (8 - ctx->fb_g_mask)) | (0xff >> (ctx->fb_g_mask + 1));
blue = (blue << (8 - ctx->fb_b_mask)) | (0xff >> (ctx->fb_b_mask + 1));
col->alpha = 0xff;
}
-guint
-_clutter_pixel_to_id (guchar pixel[4])
+guint
+_clutter_pixel_to_id (guchar pixel[4])
{
ClutterMainContext *ctx;
gint red, green, blue;
/* divide potentially by two if 'fuzzy' */
red = red >> (ctx->fb_r_mask - ctx->fb_r_mask_used);
green = green >> (ctx->fb_g_mask - ctx->fb_g_mask_used);
- blue = blue >> (ctx->fb_b_mask - ctx->fb_b_mask_used);
+ blue = blue >> (ctx->fb_b_mask - ctx->fb_b_mask_used);
/* combine the correct per component values into the final id */
- id = blue + (green << ctx->fb_b_mask_used)
+ id = blue + (green << ctx->fb_b_mask_used)
+ (red << (ctx->fb_b_mask_used + ctx->fb_g_mask_used));
-
+
return id;
}
GLint viewport[4];
ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
guint32 id;
-
+
context = clutter_context_get_default ();
_clutter_backend_ensure_context (context->backend, stage);
if (G_UNLIKELY(!ClutterCntx))
{
ClutterMainContext *ctx;
- gdouble resolution;
ClutterCntx = ctx = g_new0 (ClutterMainContext, 1);
ctx->backend = g_object_new (_clutter_backend_impl_get_type (), NULL);
ctx->timer = g_timer_new ();
g_timer_start (ctx->timer);
#endif
-
- ctx->font_map = PANGO_CLUTTER_FONT_MAP (pango_clutter_font_map_new ());
-
- resolution = clutter_backend_get_resolution (ctx->backend);
- pango_clutter_font_map_set_resolution (ctx->font_map, resolution);
-
- pango_clutter_font_map_set_use_mipmapping (ctx->font_map, TRUE);
}
return ClutterCntx;
{
ClutterMainContext *ctx;
ClutterActor *stage;
+ gdouble resolution;
+ ClutterBackend *backend;
/* Note, creates backend if not already existing, though parse args will
* have likely created it
*/
ctx = clutter_context_get_default ();
+ backend = ctx->backend;
+
+ if (!ctx->options_parsed)
+ {
+ g_set_error (error, CLUTTER_INIT_ERROR,
+ CLUTTER_INIT_ERROR_INTERNAL,
+ "When using clutter_get_option_group_without_init() "
+ "you must parse options before calling clutter_init()");
+
+ return CLUTTER_INIT_ERROR_INTERNAL;
+ }
+
+ /*
+ * Call backend post parse hooks.
+ */
+ if (CLUTTER_BACKEND_GET_CLASS (backend)->post_parse)
+ if (!CLUTTER_BACKEND_GET_CLASS (backend)->post_parse (backend, error))
+ return CLUTTER_INIT_ERROR_BACKEND;
+
+ /*
+ * Resolution requires display to be open, so can only be queried after
+ * the post_parse hooks run.
+ */
+ ctx->font_map = PANGO_CLUTTER_FONT_MAP (pango_clutter_font_map_new ());
+
+ resolution = clutter_backend_get_resolution (ctx->backend);
+ pango_clutter_font_map_set_resolution (ctx->font_map, resolution);
+
+ pango_clutter_font_map_set_use_mipmapping (ctx->font_map, TRUE);
/* Stage will give us a GL Context etc */
stage = clutter_stage_get_default ();
return CLUTTER_INIT_ERROR_INTERNAL;
}
- /* Now we can safely assume we have a valid GL context and can
+ /* Now we can safely assume we have a valid GL context and can
* start issueing cogl commands
*/
clutter_stage_set_title (CLUTTER_STAGE (stage), g_get_prgname ());
clutter_is_initialized = TRUE;
+ ctx->is_initialized = TRUE;
return CLUTTER_INIT_SUCCESS;
}
if (clutter_is_initialized)
return TRUE;
-
+
if (setlocale (LC_ALL, "") == NULL)
g_warning ("Locale not supported by C library.\n"
"Using the fallback 'C' locale.");
{
ClutterMainContext *clutter_context;
ClutterBackend *backend;
- gboolean retval = FALSE;
if (clutter_is_initialized)
return TRUE;
}
clutter_context->frame_rate = clutter_default_fps;
+ clutter_context->options_parsed = TRUE;
- if (CLUTTER_BACKEND_GET_CLASS (backend)->post_parse)
- retval = CLUTTER_BACKEND_GET_CLASS (backend)->post_parse (backend, error);
- else
- retval = TRUE;
-
- if (retval)
- clutter_init_real (error);
+ /*
+ * If not asked to defer display setup, call clutter_init_real(),
+ * which in turn calls the backend post parse hooks.
+ */
+ if (!clutter_context->defer_display_setup)
+ return clutter_init_real (error);
- return retval;
+ return TRUE;
}
/**
ClutterMainContext *context;
GOptionGroup *group;
+ clutter_base_init ();
+
context = clutter_context_get_default ();
group = g_option_group_new ("clutter",
}
/**
+ * clutter_get_option_group_without_init:
+ *
+ * Returns a #GOptionGroup for the command line arguments recognized
+ * by Clutter. You should add this group to your #GOptionContext with
+ * g_option_context_add_group(), if you are using g_option_context_parse()
+ * to parse your commandline arguments. Unlike clutter_get_option_group(),
+ * calling g_option_context_parse() with the #GOptionGroup returned by this
+ * function requires a subsequent explicit call to clutter_init(); use this
+ * function when needing to set foreign display connection with
+ * clutter_x11_set_display(), or with gtk_clutter_init().
+ *
+ * Return value: a #GOptionGroup for the commandline arguments
+ * recognized by Clutter
+ *
+ * Since: 0.8.2
+ */
+GOptionGroup *
+clutter_get_option_group_without_init (void)
+{
+ ClutterMainContext *context;
+ GOptionGroup *group;
+
+ clutter_base_init ();
+
+ context = clutter_context_get_default ();
+ context->defer_display_setup = TRUE;
+
+ group = clutter_get_option_group ();
+
+ return group;
+}
+
+/**
* clutter_init_with_args:
* @argc: a pointer to the number of command line arguments
* @argv: a pointer to the array of command line arguments
GOptionContext *context;
GOptionGroup *group;
gboolean res;
+ ClutterMainContext *ctx;
if (clutter_is_initialized)
return CLUTTER_INIT_SUCCESS;
clutter_base_init ();
- if (argc && *argc > 0 && *argv)
- g_set_prgname ((*argv)[0]);
+ ctx = clutter_context_get_default ();
- group = clutter_get_option_group ();
- context = g_option_context_new (parameter_string);
+ if (!ctx->defer_display_setup)
+ {
+ if (argc && *argc > 0 && *argv)
+ g_set_prgname ((*argv)[0]);
- g_option_context_add_group (context, group);
+ group = clutter_get_option_group ();
+ context = g_option_context_new (parameter_string);
- if (entries)
- g_option_context_add_main_entries (context, entries, translation_domain);
+ g_option_context_add_group (context, group);
- res = g_option_context_parse (context, argc, argv, error);
- g_option_context_free (context);
+ if (entries)
+ g_option_context_add_main_entries (context, entries, translation_domain);
- /* if res is FALSE, the error is filled for
- * us by g_option_context_parse()
- */
- if (!res)
- {
- /* if there has been an error in the initialization, the
- * error id will be preserved inside the GError code
+ res = g_option_context_parse (context, argc, argv, error);
+ g_option_context_free (context);
+
+ /* if res is FALSE, the error is filled for
+ * us by g_option_context_parse()
*/
- if (error && *error)
- return (*error)->code;
- else
- return CLUTTER_INIT_ERROR_INTERNAL;
- }
+ if (!res)
+ {
+ /* if there has been an error in the initialization, the
+ * error id will be preserved inside the GError code
+ */
+ if (error && *error)
+ return (*error)->code;
+ else
+ return CLUTTER_INIT_ERROR_INTERNAL;
+ }
- return CLUTTER_INIT_SUCCESS;
+ return CLUTTER_INIT_SUCCESS;
+ }
+ else
+ return clutter_init_real (error);
}
static gboolean
if (!g_option_context_parse (option_context, argc, argv, &error))
{
if (error)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
ret = FALSE;
}
clutter_init (int *argc,
char ***argv)
{
+ ClutterMainContext *ctx;
+ GError *error = NULL;
+
if (clutter_is_initialized)
return CLUTTER_INIT_SUCCESS;
clutter_base_init ();
- if (argc && *argc > 0 && *argv)
- g_set_prgname ((*argv)[0]);
+ ctx = clutter_context_get_default ();
- /* parse_args will trigger backend creation and things like
- * DISPLAY connection etc.
- */
- if (clutter_parse_args (argc, argv) == FALSE)
+ if (!ctx->defer_display_setup)
{
- CLUTTER_NOTE (MISC, "failed to parse arguments.");
- return CLUTTER_INIT_ERROR_INTERNAL;
- }
+ if (argc && *argc > 0 && *argv)
+ g_set_prgname ((*argv)[0]);
- return CLUTTER_INIT_SUCCESS;
+ /* parse_args will trigger backend creation and things like
+ * DISPLAY connection etc.
+ */
+ if (clutter_parse_args (argc, argv) == FALSE)
+ {
+ CLUTTER_NOTE (MISC, "failed to parse arguments.");
+ return CLUTTER_INIT_ERROR_INTERNAL;
+ }
+
+ return CLUTTER_INIT_SUCCESS;
+ }
+ else
+ return clutter_init_real (&error);
}
gboolean
}
/* store time and position for this click for comparison with
- * next event
+ * next event
*/
previous_time = event->button.time;
previous_x = event->button.x;
if (last_actor && last_actor != motion_current_actor)
{
- g_signal_handlers_disconnect_by_func
+ g_signal_handlers_disconnect_by_func
(last_actor,
G_CALLBACK (unset_motion_last_actor),
event->motion.device);
else
clutter_actor_destroy (stage);
}
-
+
break;
case CLUTTER_KEY_PRESS:
/* global grabs */
if (context->pointer_grab_actor != NULL)
{
- clutter_actor_event (context->pointer_grab_actor,
+ clutter_actor_event (context->pointer_grab_actor,
event, FALSE);
break;
}
else if (device != NULL && device->pointer_grab_actor != NULL)
{
- clutter_actor_event (device->pointer_grab_actor,
+ clutter_actor_event (device->pointer_grab_actor,
event, FALSE);
break;
}
{
ClutterInputDevice *dev = (ClutterInputDevice *)data;
ClutterMainContext *context;
-
+
context = clutter_context_get_default ();
if (dev)
* renderer. This will free up some memory and GL texture
* resources. The cache will be automatically refilled as more text is
* drawn.
- *
+ *
* Since: 0.8
*/
void
if (font_map)
return pango_clutter_font_map_get_use_mipmapping (font_map);
- return FALSE;
+ return FALSE;
}
/**
context = clutter_context_get_default ();
- for (item = context->input_devices;
- item != NULL;
+ for (item = context->input_devices;
+ item != NULL;
item = item->next)
{
device = item->data;
int num_events;
#endif
ClutterX11InputDeviceType type; /* FIXME: generic to ClutterInputDevice? */
-};
+};
#ifdef USE_XINPUT
void _clutter_x11_register_xinput ();
if (clutter_synchronise)
XSynchronize (backend_x11->xdpy, True);
-
+
XInternAtoms (backend_x11->xdpy,
(char **) atom_names, n_atom_names,
False, atoms);
void
clutter_x11_set_display (Display *xdpy)
{
- if (backend_singleton && backend_singleton->xdpy)
+ ClutterMainContext *ctx = clutter_context_get_default ();
+
+ if (ctx->is_initialized)
{
g_critical ("Display connection already exists. You can only call "
"clutter_x11_set_display() once before clutter_init()\n");
void
clutter_x11_enable_xinput ()
{
- if (backend_singleton != NULL)
+ ClutterMainContext *ctx = clutter_context_get_default ();
+
+ if (ctx->is_initialized)
{
g_warning ("clutter_x11_enable_xinput should "
"be called before clutter_init");
- return;
+ return;
}
_enable_xinput = TRUE;
void
clutter_x11_disable_event_retrieval (void)
{
- if (backend_singleton != NULL)
+ ClutterMainContext *ctx = clutter_context_get_default ();
+
+ if (ctx->is_initialized)
{
g_warning ("clutter_x11_disable_event_retrieval should "
"be called before clutter_init");
- return;
+ return;
}
_no_xevent_retrieval = TRUE;
#ifdef USE_XINPUT
-void
+void
_clutter_x11_register_xinput ()
{
XDeviceInfo *xdevices = NULL;
gint num_events = 0;
gint i = 0, j = 0;
gboolean have_an_xpointer = FALSE;
-
+
ClutterBackendX11 *x11b;
ClutterX11XInputDevice *device = NULL;
return;
}
- for (i = 0; i < num_devices; i++)
+ for (i = 0; i < num_devices; i++)
{
num_events = 0;
info = xdevices + i;
- CLUTTER_NOTE (BACKEND, "Considering %li with type %d",
+ CLUTTER_NOTE (BACKEND, "Considering %li with type %d",
info->id, info->use);
/* Only want 'raw' devices themselves not virtual ones */
break;
}
- CLUTTER_NOTE (BACKEND, "Registering XINPUT device with XID: %li",
+ CLUTTER_NOTE (BACKEND, "Registering XINPUT device with XID: %li",
xdevice->device_id);
/* We must go through all the classes supported by this device and
#if 0
/* We do not do XInput keyboard events yet, since it is broken */
case KeyClass:
- DeviceKeyPress (xdevice,
- x11b->event_types [CLUTTER_X11_XINPUT_KEY_PRESS_EVENT],
+ DeviceKeyPress (xdevice,
+ x11b->event_types [CLUTTER_X11_XINPUT_KEY_PRESS_EVENT],
device->xevent_list [num_events]);
num_events++;
- DeviceKeyRelease (xdevice,
- x11b->event_types [CLUTTER_X11_XINPUT_KEY_RELEASE_EVENT],
+ DeviceKeyRelease (xdevice,
+ x11b->event_types [CLUTTER_X11_XINPUT_KEY_RELEASE_EVENT],
device->xevent_list [num_events]);
num_events++;
break;
#endif
case ButtonClass:
- DeviceButtonPress (xdevice,
- x11b->event_types [CLUTTER_X11_XINPUT_BUTTON_PRESS_EVENT],
+ DeviceButtonPress (xdevice,
+ x11b->event_types [CLUTTER_X11_XINPUT_BUTTON_PRESS_EVENT],
device->xevent_list [num_events]);
num_events++;
- DeviceButtonRelease (xdevice,
- x11b->event_types [CLUTTER_X11_XINPUT_BUTTON_RELEASE_EVENT],
+ DeviceButtonRelease (xdevice,
+ x11b->event_types [CLUTTER_X11_XINPUT_BUTTON_RELEASE_EVENT],
device->xevent_list [num_events]);
num_events++;
break;
case ValuatorClass:
- DeviceMotionNotify (xdevice,
- x11b->event_types [CLUTTER_X11_XINPUT_MOTION_NOTIFY_EVENT],
+ DeviceMotionNotify (xdevice,
+ x11b->event_types [CLUTTER_X11_XINPUT_MOTION_NOTIFY_EVENT],
device->xevent_list [num_events]);
num_events++;
break;
return;
}
- for (list_it = context->input_devices;
- list_it != NULL;
+ for (list_it = context->input_devices;
+ list_it != NULL;
list_it = list_it->next)
{
device = (ClutterX11XInputDevice *)list_it->data;
- XSelectExtensionEvent (backend_singleton->xdpy,
+ XSelectExtensionEvent (backend_singleton->xdpy,
xwin,
- device->xevent_list,
+ device->xevent_list,
device->num_events);
}
}
return NULL;
}
- for (list_it = context->input_devices;
- list_it != NULL;
+ for (list_it = context->input_devices;
+ list_it != NULL;
list_it = list_it->next)
{
device = (ClutterX11XInputDevice *)list_it->data;
/**
* clutter_x11_has_xinput:
- *
+ *
* Gets whether Clutter has XInput support.
*
* Return value: %TRUE if Clutter was compiled with XInput support
if (XCompositeQueryExtension (dpy, &event, &error))
{
int major = 0, minor = 0;
- if (XCompositeQueryVersion (dpy, &major, &minor))
+ if (XCompositeQueryVersion (dpy, &major, &minor))
{
- if (major >= 0 && minor >= 3)
+ if (major >= 0 && minor >= 3)
have_composite = TRUE;
}
}