backends/native: Port to new event constructors

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3153>
This commit is contained in:
Carlos Garnacho 2023-08-03 12:17:00 +02:00
parent c341bf5af9
commit 2e8d839708
4 changed files with 305 additions and 296 deletions

View File

@ -713,6 +713,7 @@ meta_seat_impl_notify_key_in_impl (MetaSeatImpl *seat_impl,
gboolean update_keys) gboolean update_keys)
{ {
ClutterEvent *event = NULL; ClutterEvent *event = NULL;
ClutterEventFlags flags = CLUTTER_EVENT_NONE;
enum xkb_state_component changed_state; enum xkb_state_component changed_state;
uint32_t keycode; uint32_t keycode;
@ -730,13 +731,6 @@ meta_seat_impl_notify_key_in_impl (MetaSeatImpl *seat_impl,
} }
} }
event = meta_key_event_new_from_evdev (device,
seat_impl->core_keyboard,
seat_impl->xkb,
seat_impl->button_state,
us2ms (time_us), key, state);
event->key.evdev_code = key;
keycode = meta_xkb_evdev_to_keycode (key); keycode = meta_xkb_evdev_to_keycode (key);
/* We must be careful and not pass multiple releases to xkb, otherwise it gets /* We must be careful and not pass multiple releases to xkb, otherwise it gets
@ -749,9 +743,16 @@ meta_seat_impl_notify_key_in_impl (MetaSeatImpl *seat_impl,
else else
{ {
changed_state = 0; changed_state = 0;
clutter_event_set_flags (event, CLUTTER_EVENT_FLAG_REPEATED); flags = CLUTTER_EVENT_FLAG_REPEATED;
} }
event = meta_key_event_new_from_evdev (device,
seat_impl->core_keyboard,
flags,
seat_impl->xkb,
seat_impl->button_state,
time_us, key, state);
if (!meta_input_device_native_process_kbd_a11y_event_in_impl (seat_impl->core_keyboard, if (!meta_input_device_native_process_kbd_a11y_event_in_impl (seat_impl->core_keyboard,
event)) event))
queue_event (seat_impl, event); queue_event (seat_impl, event);
@ -822,30 +823,18 @@ meta_seat_impl_notify_key_in_impl (MetaSeatImpl *seat_impl,
} }
} }
static ClutterEvent * static void
new_absolute_motion_event (MetaSeatImpl *seat_impl, constrain_coordinates (MetaSeatImpl *seat_impl,
ClutterInputDevice *input_device, ClutterInputDevice *input_device,
uint64_t time_us, uint64_t time_us,
float x, float x,
float y, float y,
double *axes) float *x_out,
float *y_out)
{ {
ClutterEvent *event; if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE)
event = clutter_event_new (CLUTTER_MOTION);
if (clutter_input_device_get_device_type (input_device) != CLUTTER_TABLET_DEVICE)
{ {
meta_seat_impl_constrain_pointer (seat_impl, /* Viewport may be unset during startup */
seat_impl->core_pointer,
time_us,
seat_impl->pointer_x,
seat_impl->pointer_y,
&x, &y);
}
else
{
/* This may happen early at startup */
if (seat_impl->viewports) if (seat_impl->viewports)
{ {
meta_input_device_native_translate_coordinates_in_impl (input_device, meta_input_device_native_translate_coordinates_in_impl (input_device,
@ -854,45 +843,46 @@ new_absolute_motion_event (MetaSeatImpl *seat_impl,
&y); &y);
} }
} }
else
{
meta_seat_impl_constrain_pointer (seat_impl,
seat_impl->core_pointer,
time_us,
seat_impl->pointer_x,
seat_impl->pointer_y,
&x, &y);
}
event->motion.time_us = time_us; if (x_out)
event->motion.time = us2ms (time_us); *x_out = x;
meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state); if (y_out)
event->motion.x = x; *y_out = y;
event->motion.y = y; }
event->motion.axes = axes; static void
clutter_event_set_device (event, seat_impl->core_pointer); update_device_coords_in_impl (MetaSeatImpl *seat_impl,
clutter_event_set_source_device (event, input_device); ClutterInputDevice *input_device,
graphene_point_t coords)
{
MetaInputDeviceNative *device_native;
g_rw_lock_writer_lock (&seat_impl->state_lock); g_rw_lock_writer_lock (&seat_impl->state_lock);
if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE) if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE)
{ {
MetaInputDeviceNative *device_native = device_native = META_INPUT_DEVICE_NATIVE (input_device);
META_INPUT_DEVICE_NATIVE (input_device);
clutter_event_set_device_tool (event, device_native->last_tool);
clutter_event_set_device (event, input_device);
meta_input_device_native_set_coords_in_impl (META_INPUT_DEVICE_NATIVE (input_device),
x, y);
} }
else else
{ {
clutter_event_set_device (event, seat_impl->core_pointer); device_native = META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer);
meta_input_device_native_set_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer), seat_impl->pointer_x = coords.x;
x, y); seat_impl->pointer_y = coords.y;
} }
if (clutter_input_device_get_device_type (input_device) != CLUTTER_TABLET_DEVICE) meta_input_device_native_set_coords_in_impl (device_native,
{ coords.x, coords.y);
seat_impl->pointer_x = x;
seat_impl->pointer_y = y;
}
g_rw_lock_writer_unlock (&seat_impl->state_lock); g_rw_lock_writer_unlock (&seat_impl->state_lock);
return event;
} }
void void
@ -904,38 +894,63 @@ meta_seat_impl_notify_relative_motion_in_impl (MetaSeatImpl *seat_impl,
float dx_unaccel, float dx_unaccel,
float dy_unaccel) float dy_unaccel)
{ {
MetaInputDeviceNative *device_native =
META_INPUT_DEVICE_NATIVE (input_device);
ClutterEvent *event; ClutterEvent *event;
float old_x, old_y; ClutterModifierType modifiers;
float x, y, cur_x, cur_y;
double dx_constrained, dy_constrained; double dx_constrained, dy_constrained;
if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE)
{
meta_input_device_native_get_coords_in_impl (device_native,
&cur_x, &cur_y);
}
else
{
meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer),
&cur_x, &cur_y);
}
meta_seat_impl_filter_relative_motion (seat_impl, meta_seat_impl_filter_relative_motion (seat_impl,
input_device, input_device,
seat_impl->pointer_x, cur_x,
seat_impl->pointer_y, cur_y,
&dx, &dx,
&dy); &dy);
old_x = seat_impl->pointer_x; constrain_coordinates (seat_impl, input_device,
old_y = seat_impl->pointer_y; time_us,
event = new_absolute_motion_event (seat_impl, input_device, cur_x + dx,
time_us, cur_y + dy,
old_x + dx, &x, &y);
old_y + dy,
NULL);
dx_constrained = event->motion.x - old_x;
dy_constrained = event->motion.y - old_y;
event->motion.flags |= CLUTTER_EVENT_FLAG_RELATIVE_MOTION; modifiers =
event->motion.dx = dx; xkb_state_serialize_mods (seat_impl->xkb, XKB_STATE_MODS_EFFECTIVE) |
event->motion.dy = dy; seat_impl->button_state;
event->motion.dx_unaccel = dx_unaccel;
event->motion.dy_unaccel = dy_unaccel; dx_constrained = x - cur_x;
event->motion.dx_constrained = dx_constrained; dy_constrained = y - cur_y;
event->motion.dy_constrained = dy_constrained;
update_device_coords_in_impl (seat_impl, input_device,
GRAPHENE_POINT_INIT (x, y));
g_signal_emit (seat_impl, signals[POINTER_POSITION_CHANGED_IN_IMPL], 0, g_signal_emit (seat_impl, signals[POINTER_POSITION_CHANGED_IN_IMPL], 0,
&GRAPHENE_POINT_INIT (seat_impl->pointer_x, &GRAPHENE_POINT_INIT (x, y));
seat_impl->pointer_y));
event =
clutter_event_motion_new (CLUTTER_EVENT_FLAG_RELATIVE_MOTION,
time_us,
input_device,
NULL,
modifiers,
GRAPHENE_POINT_INIT (x, y),
GRAPHENE_POINT_INIT (dx, dy),
GRAPHENE_POINT_INIT (dx_unaccel,
dy_unaccel),
GRAPHENE_POINT_INIT (dx_constrained,
dy_constrained),
NULL);
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -948,14 +963,35 @@ meta_seat_impl_notify_absolute_motion_in_impl (MetaSeatImpl *seat_impl,
float y, float y,
double *axes) double *axes)
{ {
MetaInputDeviceNative *device_native =
META_INPUT_DEVICE_NATIVE (input_device);
ClutterModifierType modifiers;
ClutterEvent *event; ClutterEvent *event;
event = new_absolute_motion_event (seat_impl, input_device, time_us, x, y, axes); constrain_coordinates (seat_impl, input_device, time_us, x, y, &x, &y);
update_device_coords_in_impl (seat_impl, input_device,
GRAPHENE_POINT_INIT (x, y));
modifiers =
xkb_state_serialize_mods (seat_impl->xkb, XKB_STATE_MODS_EFFECTIVE) |
seat_impl->button_state;
g_signal_emit (seat_impl, signals[POINTER_POSITION_CHANGED_IN_IMPL], 0, g_signal_emit (seat_impl, signals[POINTER_POSITION_CHANGED_IN_IMPL], 0,
&GRAPHENE_POINT_INIT (seat_impl->pointer_x, &GRAPHENE_POINT_INIT (seat_impl->pointer_x,
seat_impl->pointer_y)); seat_impl->pointer_y));
event =
clutter_event_motion_new (CLUTTER_EVENT_NONE,
time_us,
input_device,
device_native->last_tool,
modifiers,
GRAPHENE_POINT_INIT (x, y),
GRAPHENE_POINT_INIT (0, 0),
GRAPHENE_POINT_INIT (0, 0),
GRAPHENE_POINT_INIT (0, 0),
axes);
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -968,7 +1004,9 @@ meta_seat_impl_notify_button_in_impl (MetaSeatImpl *seat_impl,
{ {
MetaInputDeviceNative *device_native = (MetaInputDeviceNative *) input_device; MetaInputDeviceNative *device_native = (MetaInputDeviceNative *) input_device;
ClutterEvent *event = NULL; ClutterEvent *event = NULL;
ClutterModifierType modifiers;
int button_nr; int button_nr;
float x, y;
static int maskmap[8] = static int maskmap[8] =
{ {
CLUTTER_BUTTON1_MASK, CLUTTER_BUTTON3_MASK, CLUTTER_BUTTON2_MASK, CLUTTER_BUTTON1_MASK, CLUTTER_BUTTON3_MASK, CLUTTER_BUTTON2_MASK,
@ -1026,11 +1064,6 @@ meta_seat_impl_notify_button_in_impl (MetaSeatImpl *seat_impl,
return; return;
} }
if (state)
event = clutter_event_new (CLUTTER_BUTTON_PRESS);
else
event = clutter_event_new (CLUTTER_BUTTON_RELEASE);
if (button_nr < G_N_ELEMENTS (maskmap)) if (button_nr < G_N_ELEMENTS (maskmap))
{ {
/* Update the modifiers */ /* Update the modifiers */
@ -1040,26 +1073,16 @@ meta_seat_impl_notify_button_in_impl (MetaSeatImpl *seat_impl,
seat_impl->button_state &= ~maskmap[button_nr - 1]; seat_impl->button_state &= ~maskmap[button_nr - 1];
} }
event->button.time = us2ms (time_us);
meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
event->button.button = button_nr;
if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE) if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE)
{ {
meta_input_device_native_get_coords_in_impl (device_native, meta_input_device_native_get_coords_in_impl (device_native, &x, &y);
&event->button.x,
&event->button.y);
} }
else else
{ {
meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer), meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer),
&event->button.x, &x, &y);
&event->button.y);
} }
clutter_event_set_device (event, seat_impl->core_pointer);
clutter_event_set_source_device (event, input_device);
if (device_native->last_tool) if (device_native->last_tool)
{ {
/* Apply the button event code as per the tool mapping */ /* Apply the button event code as per the tool mapping */
@ -1071,17 +1094,23 @@ meta_seat_impl_notify_button_in_impl (MetaSeatImpl *seat_impl,
button = mapped_button; button = mapped_button;
} }
event->button.evdev_code = button; modifiers =
xkb_state_serialize_mods (seat_impl->xkb, XKB_STATE_MODS_EFFECTIVE) |
seat_impl->button_state;
if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE) event =
{ clutter_event_button_new (state ?
clutter_event_set_device_tool (event, device_native->last_tool); CLUTTER_BUTTON_PRESS :
clutter_event_set_device (event, input_device); CLUTTER_BUTTON_RELEASE,
} CLUTTER_EVENT_NONE,
else time_us,
{ input_device,
clutter_event_set_device (event, seat_impl->core_pointer); device_native->last_tool,
} modifiers,
GRAPHENE_POINT_INIT (x, y),
button_nr,
button,
NULL);
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -1105,33 +1134,37 @@ notify_scroll (ClutterInputDevice *input_device,
{ {
MetaSeatImpl *seat_impl; MetaSeatImpl *seat_impl;
ClutterEvent *event = NULL; ClutterEvent *event = NULL;
ClutterModifierType modifiers;
double scroll_factor; double scroll_factor;
float x, y;
seat_impl = seat_impl_from_device (input_device); seat_impl = seat_impl_from_device (input_device);
event = clutter_event_new (CLUTTER_SCROLL);
event->scroll.time = us2ms (time_us);
meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
/* libinput pointer axis events are in pointer motion coordinate space. /* libinput pointer axis events are in pointer motion coordinate space.
* To convert to Xi2 discrete step coordinate space, multiply the factor * To convert to Xi2 discrete step coordinate space, multiply the factor
* 1/10. */ * 1/10. */
event->scroll.direction = CLUTTER_SCROLL_SMOOTH;
scroll_factor = 1.0 / DISCRETE_SCROLL_STEP; scroll_factor = 1.0 / DISCRETE_SCROLL_STEP;
clutter_event_set_scroll_delta (event,
scroll_factor * dx,
scroll_factor * dy);
event->scroll.x = seat_impl->pointer_x; x = seat_impl->pointer_x;
event->scroll.y = seat_impl->pointer_y; y = seat_impl->pointer_y;
clutter_event_set_device (event, seat_impl->core_pointer);
clutter_event_set_source_device (event, input_device);
event->scroll.scroll_source = scroll_source;
event->scroll.finish_flags = flags;
if (emulated) modifiers =
event->any.flags |= CLUTTER_EVENT_FLAG_POINTER_EMULATED; xkb_state_serialize_mods (seat_impl->xkb, XKB_STATE_MODS_EFFECTIVE) |
seat_impl->button_state;
event =
clutter_event_scroll_smooth_new (emulated ?
CLUTTER_EVENT_FLAG_POINTER_EMULATED :
CLUTTER_EVENT_NONE,
time_us,
input_device,
NULL,
modifiers,
GRAPHENE_POINT_INIT (x, y),
GRAPHENE_POINT_INIT (scroll_factor * dx,
scroll_factor * dy),
scroll_source,
flags);
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -1145,27 +1178,30 @@ notify_discrete_scroll (ClutterInputDevice *input_device,
{ {
MetaSeatImpl *seat_impl; MetaSeatImpl *seat_impl;
ClutterEvent *event = NULL; ClutterEvent *event = NULL;
ClutterModifierType modifiers;
float x, y;
if (direction == CLUTTER_SCROLL_SMOOTH) if (direction == CLUTTER_SCROLL_SMOOTH)
return; return;
seat_impl = seat_impl_from_device (input_device); seat_impl = seat_impl_from_device (input_device);
x = seat_impl->pointer_x;
y = seat_impl->pointer_y;
event = clutter_event_new (CLUTTER_SCROLL); modifiers =
xkb_state_serialize_mods (seat_impl->xkb, XKB_STATE_MODS_EFFECTIVE) |
seat_impl->button_state;
event->scroll.time = us2ms (time_us); event =
meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state); clutter_event_scroll_discrete_new (emulated ?
CLUTTER_EVENT_FLAG_POINTER_EMULATED :
event->scroll.direction = direction; CLUTTER_EVENT_NONE,
time_us,
event->scroll.x = seat_impl->pointer_x; input_device,
event->scroll.y = seat_impl->pointer_y; NULL,
clutter_event_set_device (event, seat_impl->core_pointer); modifiers,
clutter_event_set_source_device (event, input_device); GRAPHENE_POINT_INIT (x, y),
event->scroll.scroll_source = scroll_source; direction);
if (emulated)
event->any.flags |= CLUTTER_EVENT_FLAG_POINTER_EMULATED;
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -1336,23 +1372,28 @@ meta_seat_impl_notify_touch_event_in_impl (MetaSeatImpl *seat_impl,
double y) double y)
{ {
ClutterEvent *event = NULL; ClutterEvent *event = NULL;
ClutterEventSequence *sequence;
event = clutter_event_new (evtype); ClutterModifierType modifiers;
event->touch.time = us2ms (time_us);
event->touch.x = x;
event->touch.y = y;
/* "NULL" sequences are special cased in clutter */ /* "NULL" sequences are special cased in clutter */
event->touch.sequence = GINT_TO_POINTER (MAX (1, slot + 1)); sequence = GINT_TO_POINTER (MAX (1, slot + 1));
meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
modifiers =
xkb_state_serialize_mods (seat_impl->xkb, XKB_STATE_MODS_EFFECTIVE) |
seat_impl->button_state;
if (evtype == CLUTTER_TOUCH_BEGIN || if (evtype == CLUTTER_TOUCH_BEGIN ||
evtype == CLUTTER_TOUCH_UPDATE) evtype == CLUTTER_TOUCH_UPDATE)
event->touch.modifier_state |= CLUTTER_BUTTON1_MASK; modifiers |= CLUTTER_BUTTON1_MASK;
clutter_event_set_device (event, seat_impl->core_pointer); event =
clutter_event_set_source_device (event, input_device); clutter_event_touch_new (evtype,
CLUTTER_EVENT_NONE,
time_us,
input_device,
sequence,
modifiers,
GRAPHENE_POINT_INIT (x, y));
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -1596,16 +1637,13 @@ notify_absolute_motion_in_impl (ClutterInputDevice *input_device,
double *axes) double *axes)
{ {
MetaSeatImpl *seat_impl; MetaSeatImpl *seat_impl;
ClutterEvent *event;
seat_impl = seat_impl_from_device (input_device); seat_impl = seat_impl_from_device (input_device);
event = new_absolute_motion_event (seat_impl, input_device, time_us, x, y, axes); meta_seat_impl_notify_absolute_motion_in_impl (seat_impl,
input_device,
g_signal_emit (seat_impl, signals[POINTER_POSITION_CHANGED_IN_IMPL], 0, time_us,
&GRAPHENE_POINT_INIT (seat_impl->pointer_x, x, y,
seat_impl->pointer_y)); axes);
queue_event (seat_impl, event);
} }
static void static void
@ -1615,39 +1653,15 @@ notify_relative_tool_motion_in_impl (ClutterInputDevice *input_device,
float dy, float dy,
double *axes) double *axes)
{ {
MetaInputDeviceNative *device_native;
ClutterEvent *event;
MetaSeatImpl *seat_impl; MetaSeatImpl *seat_impl;
float old_x, old_y;
double dx_constrained, dy_constrained;
device_native = META_INPUT_DEVICE_NATIVE (input_device);
seat_impl = seat_impl_from_device (input_device); seat_impl = seat_impl_from_device (input_device);
meta_seat_impl_notify_relative_motion_in_impl (seat_impl,
meta_seat_impl_filter_relative_motion (seat_impl, input_device,
input_device, time_us,
device_native->pointer_x, dx, dy,
device_native->pointer_y, /* FIXME */
&dx, dx, dy);
&dy);
old_x = device_native->pointer_x;
old_y = device_native->pointer_y;
event = new_absolute_motion_event (seat_impl, input_device, time_us,
old_x + dx, old_y + dy, axes);
dx_constrained = event->motion.x - old_x;
dy_constrained = event->motion.y - old_y;
event->motion.flags |= CLUTTER_EVENT_FLAG_RELATIVE_MOTION;
event->motion.dx = dx;
event->motion.dy = dy;
event->motion.dx_constrained = dx_constrained;
event->motion.dy_constrained = dy_constrained;
queue_event (seat_impl, event);
} }
static void static void
@ -1664,29 +1678,23 @@ notify_pinch_gesture_event (ClutterInputDevice *input_device,
{ {
MetaSeatImpl *seat_impl; MetaSeatImpl *seat_impl;
ClutterEvent *event = NULL; ClutterEvent *event = NULL;
float x, y;
seat_impl = seat_impl_from_device (input_device); seat_impl = seat_impl_from_device (input_device);
event = clutter_event_new (CLUTTER_TOUCHPAD_PINCH);
meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer), meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer),
&event->touchpad_pinch.x, &x, &y);
&event->touchpad_pinch.y); event =
clutter_event_touchpad_pinch_new (CLUTTER_EVENT_NONE,
event->touchpad_pinch.phase = phase; time_us,
event->touchpad_pinch.time = us2ms (time_us); input_device,
event->touchpad_pinch.dx = dx; phase,
event->touchpad_pinch.dy = dy; n_fingers,
event->touchpad_pinch.dx_unaccel = dx_unaccel; GRAPHENE_POINT_INIT (x, y),
event->touchpad_pinch.dy_unaccel = dy_unaccel; GRAPHENE_POINT_INIT (dx, dy),
event->touchpad_pinch.angle_delta = angle_delta; GRAPHENE_POINT_INIT (dx_unaccel,
event->touchpad_pinch.scale = scale; dy_unaccel),
event->touchpad_pinch.n_fingers = n_fingers; angle_delta, scale);
meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
clutter_event_set_device (event, seat_impl->core_pointer);
clutter_event_set_source_device (event, input_device);
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -1703,27 +1711,22 @@ notify_swipe_gesture_event (ClutterInputDevice *input_device,
{ {
MetaSeatImpl *seat_impl; MetaSeatImpl *seat_impl;
ClutterEvent *event = NULL; ClutterEvent *event = NULL;
float x, y;
seat_impl = seat_impl_from_device (input_device); seat_impl = seat_impl_from_device (input_device);
event = clutter_event_new (CLUTTER_TOUCHPAD_SWIPE);
event->touchpad_swipe.phase = phase;
event->touchpad_swipe.time = us2ms (time_us);
meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer), meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer),
&event->touchpad_swipe.x, &x, &y);
&event->touchpad_swipe.y); event =
event->touchpad_swipe.dx = dx; clutter_event_touchpad_swipe_new (CLUTTER_EVENT_NONE,
event->touchpad_swipe.dy = dy; time_us,
event->touchpad_swipe.dx_unaccel = dx_unaccel; input_device,
event->touchpad_swipe.dy_unaccel = dy_unaccel; phase,
event->touchpad_swipe.n_fingers = n_fingers; n_fingers,
GRAPHENE_POINT_INIT (x, y),
meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state); GRAPHENE_POINT_INIT (dx, dy),
GRAPHENE_POINT_INIT (dx_unaccel,
clutter_event_set_device (event, seat_impl->core_pointer); dy_unaccel));
clutter_event_set_source_device (event, input_device);
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -1736,23 +1739,19 @@ notify_hold_gesture_event (ClutterInputDevice *input_device,
{ {
MetaSeatImpl *seat_impl; MetaSeatImpl *seat_impl;
ClutterEvent *event = NULL; ClutterEvent *event = NULL;
float x, y;
seat_impl = seat_impl_from_device (input_device); seat_impl = seat_impl_from_device (input_device);
event = clutter_event_new (CLUTTER_TOUCHPAD_HOLD);
event->touchpad_hold.phase = phase;
event->touchpad_hold.time = us2ms (time_us);
event->touchpad_hold.n_fingers = n_fingers;
meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer), meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer),
&event->touchpad_hold.x, &x, &y);
&event->touchpad_hold.y);
meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state); event = clutter_event_touchpad_hold_new (CLUTTER_EVENT_NONE,
time_us,
clutter_event_set_device (event, seat_impl->core_pointer); input_device,
clutter_event_set_source_device (event, input_device); phase,
n_fingers,
GRAPHENE_POINT_INIT (x, y));
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -1769,15 +1768,13 @@ notify_proximity (ClutterInputDevice *input_device,
device_native = META_INPUT_DEVICE_NATIVE (input_device); device_native = META_INPUT_DEVICE_NATIVE (input_device);
seat_impl = seat_impl_from_device (input_device); seat_impl = seat_impl_from_device (input_device);
if (in) event = clutter_event_proximity_new (in ?
event = clutter_event_new (CLUTTER_PROXIMITY_IN); CLUTTER_PROXIMITY_IN :
else CLUTTER_PROXIMITY_OUT,
event = clutter_event_new (CLUTTER_PROXIMITY_OUT); CLUTTER_EVENT_NONE,
time_us,
event->proximity.time = us2ms (time_us); input_device,
clutter_event_set_device_tool (event, device_native->last_tool); device_native->last_tool);
clutter_event_set_device (event, seat_impl->core_pointer);
clutter_event_set_source_device (event, input_device);
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -1795,17 +1792,15 @@ notify_pad_button (ClutterInputDevice *input_device,
seat_impl = seat_impl_from_device (input_device); seat_impl = seat_impl_from_device (input_device);
if (pressed) event = clutter_event_pad_button_new (pressed ?
event = clutter_event_new (CLUTTER_PAD_BUTTON_PRESS); CLUTTER_PAD_BUTTON_PRESS :
else CLUTTER_PAD_BUTTON_RELEASE,
event = clutter_event_new (CLUTTER_PAD_BUTTON_RELEASE); CLUTTER_EVENT_NONE,
time_us,
event->pad_button.button = button; input_device,
event->pad_button.group = mode_group; button,
event->pad_button.mode = mode; mode_group,
clutter_event_set_device (event, input_device); mode);
clutter_event_set_source_device (event, input_device);
clutter_event_set_time (event, us2ms (time_us));
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -1830,15 +1825,14 @@ notify_pad_strip (ClutterInputDevice *input_device,
else else
source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN; source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN;
event = clutter_event_new (CLUTTER_PAD_STRIP); event = clutter_event_pad_strip_new (CLUTTER_EVENT_NONE,
event->pad_strip.strip_source = source; time_us,
event->pad_strip.strip_number = strip_number; input_device,
event->pad_strip.value = value; source,
event->pad_strip.group = mode_group; strip_number,
event->pad_strip.mode = mode; mode_group,
clutter_event_set_device (event, input_device); value,
clutter_event_set_source_device (event, input_device); mode);
clutter_event_set_time (event, us2ms (time_us));
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -1863,15 +1857,14 @@ notify_pad_ring (ClutterInputDevice *input_device,
else else
source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN; source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN;
event = clutter_event_new (CLUTTER_PAD_RING); event = clutter_event_pad_ring_new (CLUTTER_EVENT_NONE,
event->pad_ring.ring_source = source; time_us,
event->pad_ring.ring_number = ring_number; input_device,
event->pad_ring.angle = angle; source,
event->pad_ring.group = mode_group; ring_number,
event->pad_ring.mode = mode; mode_group,
clutter_event_set_device (event, input_device); angle,
clutter_event_set_source_device (event, input_device); mode);
clutter_event_set_time (event, us2ms (time_us));
queue_event (seat_impl, event); queue_event (seat_impl, event);
} }
@ -2074,8 +2067,12 @@ process_base_event (MetaSeatImpl *seat_impl,
libinput_device = libinput_event_get_device (event); libinput_device = libinput_event_get_device (event);
device = evdev_add_device (seat_impl, libinput_device); device = evdev_add_device (seat_impl, libinput_device);
device_event = clutter_event_new (CLUTTER_DEVICE_ADDED); device_event =
clutter_event_set_device (device_event, device); clutter_event_device_notify_new (CLUTTER_DEVICE_ADDED,
CLUTTER_EVENT_NONE,
CLUTTER_CURRENT_TIME,
device);
meta_input_settings_add_device (input_settings, device); meta_input_settings_add_device (input_settings, device);
break; break;
@ -2083,8 +2080,11 @@ process_base_event (MetaSeatImpl *seat_impl,
libinput_device = libinput_event_get_device (event); libinput_device = libinput_event_get_device (event);
device = libinput_device_get_user_data (libinput_device); device = libinput_device_get_user_data (libinput_device);
device_event = clutter_event_new (CLUTTER_DEVICE_REMOVED); device_event =
clutter_event_set_device (device_event, device); clutter_event_device_notify_new (CLUTTER_DEVICE_REMOVED,
CLUTTER_EVENT_NONE,
CLUTTER_CURRENT_TIME,
device);
meta_input_settings_remove_device (input_settings, device); meta_input_settings_remove_device (input_settings, device);
evdev_remove_device (seat_impl, evdev_remove_device (seat_impl,
META_INPUT_DEVICE_NATIVE (device)); META_INPUT_DEVICE_NATIVE (device));

View File

@ -199,13 +199,14 @@ release_device_in_impl (GTask *task)
} }
} }
device_event = clutter_event_new (CLUTTER_DEVICE_REMOVED); device_event = clutter_event_device_notify_new (CLUTTER_DEVICE_REMOVED,
clutter_event_set_device (device_event, impl_state->device); CLUTTER_EVENT_NONE,
time_us,
impl_state->device);
_clutter_event_push (device_event, FALSE); _clutter_event_push (device_event, FALSE);
g_clear_object (&impl_state->device); g_clear_object (&impl_state->device);
g_task_return_boolean (task, TRUE); g_task_return_boolean (task, TRUE);
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
@ -1039,8 +1040,11 @@ meta_virtual_input_device_native_constructed (GObject *object)
device_type, device_type,
CLUTTER_INPUT_MODE_PHYSICAL); CLUTTER_INPUT_MODE_PHYSICAL);
device_event = clutter_event_new (CLUTTER_DEVICE_ADDED); device_event =
clutter_event_set_device (device_event, virtual_evdev->impl_state->device); clutter_event_device_notify_new (CLUTTER_DEVICE_ADDED,
CLUTTER_EVENT_NONE,
CLUTTER_CURRENT_TIME,
virtual_evdev->impl_state->device);
_clutter_event_push (device_event, FALSE); _clutter_event_push (device_event, FALSE);
} }

View File

@ -41,9 +41,10 @@
ClutterEvent * ClutterEvent *
meta_key_event_new_from_evdev (ClutterInputDevice *device, meta_key_event_new_from_evdev (ClutterInputDevice *device,
ClutterInputDevice *core_device, ClutterInputDevice *core_device,
ClutterEventFlags flags,
struct xkb_state *xkb_state, struct xkb_state *xkb_state,
uint32_t button_state, uint32_t button_state,
uint32_t _time, uint64_t time_us,
xkb_keycode_t key, xkb_keycode_t key,
uint32_t state) uint32_t state)
{ {
@ -51,13 +52,10 @@ meta_key_event_new_from_evdev (ClutterInputDevice *device,
xkb_keysym_t sym; xkb_keysym_t sym;
const xkb_keysym_t *syms; const xkb_keysym_t *syms;
char buffer[8]; char buffer[8];
gunichar unicode_value;
ClutterModifierType modifiers;
int n; int n;
if (state)
event = clutter_event_new (CLUTTER_KEY_PRESS);
else
event = clutter_event_new (CLUTTER_KEY_RELEASE);
/* We use a fixed offset of 8 because evdev starts KEY_* numbering from /* We use a fixed offset of 8 because evdev starts KEY_* numbering from
* 0, whereas X11's minimum keycode, for really stupid reasons, is 8. * 0, whereas X11's minimum keycode, for really stupid reasons, is 8.
* So the evdev XKB rules are based on the keycodes all being shifted * So the evdev XKB rules are based on the keycodes all being shifted
@ -70,27 +68,33 @@ meta_key_event_new_from_evdev (ClutterInputDevice *device,
else else
sym = XKB_KEY_NoSymbol; sym = XKB_KEY_NoSymbol;
event->key.time = _time; modifiers = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_EFFECTIVE) |
meta_xkb_translate_state (event, xkb_state, button_state); button_state;
event->key.hardware_keycode = key;
event->key.keyval = sym;
clutter_event_set_device (event, core_device);
clutter_event_set_source_device (event, device);
n = xkb_keysym_to_utf8 (sym, buffer, sizeof (buffer)); n = xkb_keysym_to_utf8 (sym, buffer, sizeof (buffer));
if (n == 0) if (n == 0)
{ {
/* not printable */ /* not printable */
event->key.unicode_value = (gunichar) '\0'; unicode_value = (gunichar) '\0';
} }
else else
{ {
event->key.unicode_value = g_utf8_get_char_validated (buffer, n); unicode_value = g_utf8_get_char_validated (buffer, n);
if (event->key.unicode_value == -1 || event->key.unicode_value == -2) if (unicode_value == -1 || unicode_value == -2)
event->key.unicode_value = (gunichar) '\0'; unicode_value = (gunichar) '\0';
} }
event = clutter_event_key_new (state ?
CLUTTER_KEY_PRESS : CLUTTER_KEY_RELEASE,
flags,
time_us,
device,
modifiers,
sym,
key - 8,
key,
unicode_value);
return event; return event;
} }

View File

@ -26,9 +26,10 @@
ClutterEvent * meta_key_event_new_from_evdev (ClutterInputDevice *device, ClutterEvent * meta_key_event_new_from_evdev (ClutterInputDevice *device,
ClutterInputDevice *core_keyboard, ClutterInputDevice *core_keyboard,
ClutterEventFlags flags,
struct xkb_state *xkb_state, struct xkb_state *xkb_state,
uint32_t button_state, uint32_t button_state,
uint32_t _time, uint64_t time_us,
uint32_t key, uint32_t key,
uint32_t state); uint32_t state);
void meta_xkb_translate_state (ClutterEvent *event, void meta_xkb_translate_state (ClutterEvent *event,