1
0
Fork 0

Store the motion event deliver flag in ClutterStage

Once upon a time, the land of Clutter had a stage singleton. It was
created automatically at initialization time and stayed around even
after the main loop was terminated. The singleton was content in
being all there was. There also was a global API to handle the
configuration of the stage singleton that would affect the behaviour
on other classes, signals and properties.

Then, an evil wizard came along and locked the stage singleton in his
black tower, and twisted it until it was possible to create new stages.
These new stages were pesky, and didn't have the same semantics of the
singleton: they didn't stay around when closed, or terminate the main
loop on delete events.

The evil wizard also started moving all the stage-related API from the
global context into class-specific methods.

Finally, the evil wizard cast a spell, and the stage singleton was
demoted to creation on demand - and until somebody called the
clutter_stage_get_default() function, the singleton remained in a limbo
of NULL pointers and undefined memory areas.

There was a last bit - literally - of information still held by the
global API; a tiny, little flag that disabled per-actor motion events.
The evil wizard added private accessors for it, and stored it inside the
stage private structure, in preparation for a deprecation that would
come in a future development cycle.

The evil wizard looked down upon the land of Clutter from the height of
his black tower; the lay of the land had been reshaped into a crucible
of potential, and the last dregs of the original force of creation were
either molted into new, useful shapes, or blasted away by the sheer fury
of his will.

All was good.
This commit is contained in:
Emmanuele Bassi 2011-02-18 17:19:04 +00:00
parent 7500b77b2b
commit bc548dc862
3 changed files with 53 additions and 7 deletions

View file

@ -109,6 +109,7 @@
#include "clutter-master-clock.h"
#include "clutter-private.h"
#include "clutter-profile.h"
#include "clutter-stage-manager.h"
#include "clutter-stage-private.h"
#include "clutter-version.h" /* For flavour define */
@ -264,9 +265,28 @@ clutter_redraw (ClutterStage *stage)
void
clutter_set_motion_events_enabled (gboolean enable)
{
ClutterMainContext *context = _clutter_context_get_default ();
ClutterStageManager *stage_manager;
ClutterMainContext *context;
const GSList *l;
enable = !!enable;
context = _clutter_context_get_default ();
if (context->motion_events_per_actor == enable)
return;
/* store the flag for later query and for newly created stages */
context->motion_events_per_actor = enable;
/* propagate the change to all stages */
stage_manager = clutter_stage_manager_get_default ();
for (l = clutter_stage_manager_peek_stages (stage_manager);
l != NULL;
l = l->next)
{
_clutter_stage_set_motion_events_enabled (l->data, enable);
}
}
/**
@ -2355,10 +2375,8 @@ _clutter_process_event_details (ClutterActor *stage,
break;
case CLUTTER_MOTION:
/* Only stage gets motion events if clutter_set_motion_events is TRUE,
* and the event is not a synthetic event with source set.
*/
if (!context->motion_events_per_actor &&
/* only the stage gets motion events if they are enabled */
if (!_clutter_stage_get_motion_events_enabled (CLUTTER_STAGE (stage)) &&
event->any.source == NULL)
{
/* Only stage gets motion events */
@ -2368,13 +2386,15 @@ _clutter_process_event_details (ClutterActor *stage,
if (context->pointer_grab_actor != NULL)
{
clutter_actor_event (context->pointer_grab_actor,
event, FALSE);
event,
FALSE);
break;
}
else if (device != NULL && device->pointer_grab_actor != NULL)
{
clutter_actor_event (device->pointer_grab_actor,
event, FALSE);
event,
FALSE);
break;
}

View file

@ -90,6 +90,10 @@ void _clutter_stage_remove_device (ClutterStage *stage,
gboolean _clutter_stage_has_device (ClutterStage *stage,
ClutterInputDevice *device);
void _clutter_stage_set_motion_events_enabled (ClutterStage *stage,
gboolean enabled);
gboolean _clutter_stage_get_motion_events_enabled (ClutterStage *stage);
G_END_DECLS
#endif /* __CLUTTER_STAGE_PRIVATE_H__ */

View file

@ -157,6 +157,7 @@ struct _ClutterStagePrivate
guint dirty_projection : 1;
guint have_valid_pick_buffer : 1;
guint accept_focus : 1;
guint motion_events_enabled : 1;
};
enum
@ -1636,6 +1637,7 @@ clutter_stage_init (ClutterStage *self)
priv->use_fog = FALSE;
priv->throttle_motion_events = TRUE;
priv->min_size_changed = FALSE;
priv->motion_events_enabled = clutter_get_motion_events_enabled ();
priv->color = default_stage_color;
@ -3465,3 +3467,23 @@ _clutter_stage_has_device (ClutterStage *stage,
return g_hash_table_lookup (priv->devices, device) != NULL;
}
void
_clutter_stage_set_motion_events_enabled (ClutterStage *stage,
gboolean enabled)
{
ClutterStagePrivate *priv = stage->priv;
enabled = !!enabled;
if (priv->motion_events_enabled != enabled)
{
priv->motion_events_enabled = enabled;
}
}
gboolean
_clutter_stage_get_motion_events_enabled (ClutterStage *stage)
{
return stage->priv->motion_events_enabled;
}