Skip to content
Snippets Groups Projects
Commit 6207e530 authored by Justin Kim's avatar Justin Kim
Browse files

roller: Refactoring captured_event


Overriding `captured_event` isn't neccessary. Above all,
it can be achieved by handling the specialized events,
such as button-press-event, button-release-event, and touch-event.

Reviewed-by: default avatarFrédéric Dalleau <frederic.dalleau@collabora.com>
Signed-off-by: default avatarJustin Kim <justin.kim@collabora.com>
Differential Revision: https://phabricator.apertis.org/D5481
parent b128f26f
No related branches found
No related tags found
No related merge requests found
......@@ -1314,139 +1314,162 @@ finalize (GObject *object)
}
static gboolean
actor_captured_event (ClutterActor *actor,
ClutterEvent *event)
release_event (ClutterActor *actor,
gfloat x,
gfloat y)
{
LightwoodRoller *self = LIGHTWOOD_ROLLER (actor);
LightwoodRollerPrivate *priv = lightwood_roller_get_instance_private (self);
ClutterActor *stage, *child_actor;
gint row;
gboolean value;
gfloat event_x = 0.0, event_y = 0.0;
ClutterActor *stage;
ClutterActor *child_actor;
gboolean unfocused;
gint row;
/* Grab the X and Y coordinate from the event. */
switch (event->type)
{
case CLUTTER_BUTTON_PRESS:
case CLUTTER_BUTTON_RELEASE: {
ClutterButtonEvent *button_event = (ClutterButtonEvent *) event;
LightwoodRoller *self = LIGHTWOOD_ROLLER (actor);
LightwoodRollerPrivate *priv = lightwood_roller_get_instance_private (self);
event_x = button_event->x;
event_y = button_event->y;
g_debug ("%s: button-release/touch-end: "
"bLongPressEnable: %d, "
"press_timestamp: %" G_GINT64_FORMAT ", "
"bFlag: %d, "
"x: %f, y: %f, "
"rollover_enabled: %d",
G_STRFUNC, priv->bLongPressEnable,
priv->press_timestamp,
priv->bFlag, x, y,
priv->rollover_enabled);
if (!priv->bLongPressEnable)
{
/* Consider we were panning, so don't focus or activate items */
if (g_get_monotonic_time () - priv->press_timestamp > 250000)
return CLUTTER_EVENT_STOP;
break;
}
case CLUTTER_TOUCH_BEGIN:
case CLUTTER_TOUCH_END: {
ClutterTouchEvent *touch_event = (ClutterTouchEvent *) event;
priv->press_timestamp = 0;
}
event_x = touch_event->x;
event_y = touch_event->y;
// making sure press and release event occurs in the widget.
if (!priv->bFlag)
{
return CLUTTER_EVENT_STOP;
}
break;
}
}
priv->bFlag = FALSE;
/* Handle the events. */
switch (event->type)
{
case CLUTTER_BUTTON_PRESS:
case CLUTTER_TOUCH_BEGIN:
{
g_debug ("%s: button-press/touch-begin: "
"bLongPressEnable: %d, "
"press_timestamp: %" G_GINT64_FORMAT ", "
"bFlag: %d, "
"x: %f, y: %f, "
"rollover_enabled: %d",
G_STRFUNC, priv->bLongPressEnable,
priv->press_timestamp,
priv->bFlag, event_x, event_y,
priv->rollover_enabled);
if(!priv->bLongPressEnable)
{
priv->press_timestamp = g_get_monotonic_time ();
}
priv->bFlag = TRUE;
}
/* Ignore event, and if we are still moving, MxKineticScrollView will stop */
return FALSE;
case CLUTTER_BUTTON_RELEASE:
case CLUTTER_TOUCH_END:
g_debug ("%s: button-release/touch-end: "
"bLongPressEnable: %d, "
"press_timestamp: %" G_GINT64_FORMAT ", "
"bFlag: %d, "
"x: %f, y: %f, "
"rollover_enabled: %d",
G_STRFUNC, priv->bLongPressEnable,
priv->press_timestamp,
priv->bFlag, event_x, event_y,
priv->rollover_enabled);
if(!priv->bLongPressEnable)
{
/* Consider we were panning, so don't focus or activate items */
if (g_get_monotonic_time () - priv->press_timestamp > 250000)
return TRUE;
priv->press_timestamp = 0;
}
// making sure press and release event ocuurs in the widget.
if(!priv->bFlag)
{
return TRUE;
}
priv->bFlag = FALSE;
stage = clutter_actor_get_stage (actor);
child_actor = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage),
CLUTTER_PICK_REACTIVE,
event_x,
event_y);
row = LIGHTWOOD_ROLLER_GET_CLASS (actor)->get_row_from_item (LIGHTWOOD_ROLLER (actor),
child_actor);
g_debug ("%s: child_actor: %p, row: %i",
G_STRFUNC, child_actor, row);
if (row < 0)
return FALSE;
/* If rollover is disabled allow item selection without briging the item to mid of roller */
if(priv->rollover_enabled == FALSE)
{
return FALSE;
}
/* Roller Animation Issue */
value = focus_row (LIGHTWOOD_ROLLER (actor), row, TRUE, FALSE, -1, -1, -1);
g_debug ("%s: value: %d", G_STRFUNC, value);
return value;
case CLUTTER_TOUCH_CANCEL:
priv->bFlag = FALSE;
case CLUTTER_NOTHING:
case CLUTTER_KEY_PRESS:
case CLUTTER_KEY_RELEASE:
case CLUTTER_MOTION:
case CLUTTER_ENTER:
case CLUTTER_LEAVE:
case CLUTTER_SCROLL:
case CLUTTER_STAGE_STATE:
case CLUTTER_DESTROY_NOTIFY:
case CLUTTER_CLIENT_MESSAGE:
case CLUTTER_DELETE:
case CLUTTER_TOUCH_UPDATE:
case CLUTTER_EVENT_LAST:
default:
return FALSE;
}
stage = clutter_actor_get_stage (actor);
child_actor = clutter_stage_get_actor_at_pos (
CLUTTER_STAGE (stage),
CLUTTER_PICK_REACTIVE,
x, y);
row = LIGHTWOOD_ROLLER_GET_CLASS (actor)->get_row_from_item (
LIGHTWOOD_ROLLER (actor),
child_actor);
g_debug ("%s: child_actor: %p, row: %i",
G_STRFUNC, child_actor, row);
if (row < 0)
return CLUTTER_EVENT_PROPAGATE;
/* If rollover is disabled allow item selection without briging the item to mid of roller */
if (priv->rollover_enabled == FALSE)
{
return CLUTTER_EVENT_PROPAGATE;
}
/* Roller Animation Issue */
unfocused = focus_row (self, row, TRUE, FALSE, -1, -1, -1);
/* If the row isn't in the middle of window,
* it assumes that the event is about scrolling up and down */
if (unfocused)
{
return CLUTTER_EVENT_PROPAGATE;
}
/* when row returned is 0 or the max value in the model,
* then it is always first row in the roller */
if (row == 0 || row == thornbury_model_get_n_rows (priv->model))
row = 0;
if (priv->glow == TRUE)
{
lightwood_roller_set_glow_row (LIGHTWOOD_ROLLER (actor), row);
}
g_debug ("ROLLER:ITEM_ACTIVATED");
g_signal_emit (self, signals[ITEM_ACTIVATED], 0, row);
return CLUTTER_EVENT_STOP;
}
static gboolean
lightwood_roller_button_release_event (ClutterActor *actor,
ClutterButtonEvent *event)
{
return release_event (actor, event->x, event->y);
}
static gboolean
press_event (ClutterActor *actor,
gfloat x,
gfloat y)
{
LightwoodRoller *self = LIGHTWOOD_ROLLER (actor);
LightwoodRollerPrivate *priv = lightwood_roller_get_instance_private (self);
g_debug ("%s: button-press/touch-begin: "
"bLongPressEnable: %d, "
"press_timestamp: %" G_GINT64_FORMAT ", "
"bFlag: %d, "
"x: %f, y: %f, "
"rollover_enabled: %d",
G_STRFUNC, priv->bLongPressEnable,
priv->press_timestamp,
priv->bFlag, x, y,
priv->rollover_enabled);
if (!priv->bLongPressEnable)
{
priv->press_timestamp = g_get_monotonic_time ();
}
priv->bFlag = TRUE;
return CLUTTER_EVENT_PROPAGATE;
}
static gboolean
lightwood_roller_touch_event (ClutterActor *actor,
ClutterTouchEvent *event)
{
LightwoodRoller *self = LIGHTWOOD_ROLLER (actor);
LightwoodRollerPrivate *priv = lightwood_roller_get_instance_private (self);
if (event->type == CLUTTER_TOUCH_BEGIN)
{
return press_event (actor, event->x, event->y);
}
if (event->type == CLUTTER_TOUCH_END)
{
return release_event (actor, event->x, event->y);
}
if (event->type == CLUTTER_TOUCH_CANCEL)
{
priv->bFlag = FALSE;
g_debug ("%s: touch event is cancelled.", G_STRFUNC);
}
return CLUTTER_EVENT_PROPAGATE;
}
static gboolean
lightwood_roller_button_press_event (ClutterActor *actor,
ClutterButtonEvent *event)
{
return press_event (actor, event->x, event->y);
}
static void
......@@ -1557,68 +1580,6 @@ lightwood_roller_set_glow_row (LightwoodRoller *roller,
g_slist_free (items);
}
static gboolean
event_cb (ClutterActor *actor,
ClutterButtonEvent *event,
gpointer user_data)
{
LightwoodRoller *self = LIGHTWOOD_ROLLER (actor);
LightwoodRollerPrivate *priv = lightwood_roller_get_instance_private (self);
switch(event->type)
{
case CLUTTER_BUTTON_RELEASE:
case CLUTTER_TOUCH_END:
{
ClutterActor *stage, *child_actor;
stage = clutter_actor_get_stage (actor);
child_actor = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage),
CLUTTER_PICK_REACTIVE,
event->x, event->y);
if (child_actor != NULL)
{
gint row = LIGHTWOOD_ROLLER_GET_CLASS (actor)->get_row_from_item (LIGHTWOOD_ROLLER (actor),
child_actor);
/* when row returned is 0 or the max value in the model,
then it is always first row in the roller */
if(row == 0 || row == thornbury_model_get_n_rows(priv->model))
row = 0;
/* row = -1 should not be given to applications */
if(row != -1)
{
if(priv->glow == TRUE)
lightwood_roller_set_glow_row (LIGHTWOOD_ROLLER (actor), row);
g_debug ("ROLLER:ITEM_ACTIVATED");
g_signal_emit (actor, signals[ITEM_ACTIVATED], 0, row);
}
return TRUE;
}
}
case CLUTTER_NOTHING:
case CLUTTER_KEY_PRESS:
case CLUTTER_KEY_RELEASE:
case CLUTTER_MOTION:
case CLUTTER_ENTER:
case CLUTTER_LEAVE:
case CLUTTER_BUTTON_PRESS:
case CLUTTER_SCROLL:
case CLUTTER_STAGE_STATE:
case CLUTTER_DESTROY_NOTIFY:
case CLUTTER_CLIENT_MESSAGE:
case CLUTTER_DELETE:
case CLUTTER_TOUCH_BEGIN:
case CLUTTER_TOUCH_UPDATE:
case CLUTTER_TOUCH_CANCEL:
case CLUTTER_EVENT_LAST:
default:
return FALSE;
}
}
static void
lightwood_roller_class_init (LightwoodRollerClass *klass)
{
......@@ -1634,8 +1595,10 @@ lightwood_roller_class_init (LightwoodRollerClass *klass)
actor_class->paint = actor_paint;
actor_class->pick = actor_pick;
actor_class->allocate = actor_allocate;
actor_class->captured_event = actor_captured_event;
actor_class->parent_set = actor_parent_set;
actor_class->button_press_event = lightwood_roller_button_press_event;
actor_class->button_release_event = lightwood_roller_button_release_event;
actor_class->touch_event = lightwood_roller_touch_event;
pspec = g_param_spec_boolean ("roll-over",
"Roll over",
......@@ -1864,11 +1827,6 @@ lightwood_roller_init (LightwoodRoller *self)
"interpolation-completed",
G_CALLBACK (interpolation_completed_cb),
self);
g_signal_connect (G_OBJECT (self), "button-release-event",
G_CALLBACK (event_cb), NULL);
g_signal_connect (G_OBJECT (self), "touch-event",
G_CALLBACK (event_cb), NULL);
}
/* Private LightwoodRoller implementation */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment