device-manager-x11: Ignore events if no source device is set
There might be some inconsistent event for which we don't have a known source device. In the current state we don't handle them and we could crash when getting the current device tool. So, add an utility function that retrieves the source device for an event that warns if no device is found, and use this for Motion, Key and Button events. In case we don't have a valid source in such case, just return early instead of trying to generate invalid clutter events. https://gitlab.gnome.org/GNOME/mutter/merge_requests/823
This commit is contained in:
parent
4af4b79123
commit
427670cc63
@ -1291,6 +1291,22 @@ handle_raw_event (MetaDeviceManagerX11 *manager_xi2,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ClutterInputDevice *
|
||||||
|
get_source_device_checked (MetaDeviceManagerX11 *manager_xi2,
|
||||||
|
XIDeviceEvent *xev)
|
||||||
|
{
|
||||||
|
ClutterInputDevice *source_device;
|
||||||
|
|
||||||
|
source_device = g_hash_table_lookup (manager_xi2->devices_by_id,
|
||||||
|
GINT_TO_POINTER (xev->sourceid));
|
||||||
|
|
||||||
|
if (!source_device)
|
||||||
|
g_warning ("Impossible to get the source device with id %d for event of "
|
||||||
|
"type %d", xev->sourceid, xev->evtype);
|
||||||
|
|
||||||
|
return source_device;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
meta_device_manager_x11_translate_event (MetaDeviceManagerX11 *manager_xi2,
|
meta_device_manager_x11_translate_event (MetaDeviceManagerX11 *manager_xi2,
|
||||||
XEvent *xevent,
|
XEvent *xevent,
|
||||||
@ -1379,6 +1395,10 @@ meta_device_manager_x11_translate_event (MetaDeviceManagerX11 *manager_xi2,
|
|||||||
char buffer[7] = { 0, };
|
char buffer[7] = { 0, };
|
||||||
gunichar n;
|
gunichar n;
|
||||||
|
|
||||||
|
source_device = get_source_device_checked (manager_xi2, xev);
|
||||||
|
if (!source_device)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
event->key.type = event->type = (xev->evtype == XI_KeyPress)
|
event->key.type = event->type = (xev->evtype == XI_KeyPress)
|
||||||
? CLUTTER_KEY_PRESS
|
? CLUTTER_KEY_PRESS
|
||||||
: CLUTTER_KEY_RELEASE;
|
: CLUTTER_KEY_RELEASE;
|
||||||
@ -1413,8 +1433,6 @@ meta_device_manager_x11_translate_event (MetaDeviceManagerX11 *manager_xi2,
|
|||||||
event_x11->caps_lock_set =
|
event_x11->caps_lock_set =
|
||||||
clutter_keymap_get_caps_lock_state (CLUTTER_KEYMAP (keymap_x11));
|
clutter_keymap_get_caps_lock_state (CLUTTER_KEYMAP (keymap_x11));
|
||||||
|
|
||||||
source_device = g_hash_table_lookup (manager_xi2->devices_by_id,
|
|
||||||
GINT_TO_POINTER (xev->sourceid));
|
|
||||||
clutter_event_set_source_device (event, source_device);
|
clutter_event_set_source_device (event, source_device);
|
||||||
|
|
||||||
device = g_hash_table_lookup (manager_xi2->devices_by_id,
|
device = g_hash_table_lookup (manager_xi2->devices_by_id,
|
||||||
@ -1458,8 +1476,10 @@ meta_device_manager_x11_translate_event (MetaDeviceManagerX11 *manager_xi2,
|
|||||||
{
|
{
|
||||||
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
|
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
|
||||||
|
|
||||||
source_device = g_hash_table_lookup (manager_xi2->devices_by_id,
|
source_device = get_source_device_checked (manager_xi2, xev);
|
||||||
GINT_TO_POINTER (xev->sourceid));
|
if (!source_device)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
device = g_hash_table_lookup (manager_xi2->devices_by_id,
|
device = g_hash_table_lookup (manager_xi2->devices_by_id,
|
||||||
GINT_TO_POINTER (xev->deviceid));
|
GINT_TO_POINTER (xev->deviceid));
|
||||||
|
|
||||||
@ -1626,7 +1646,7 @@ meta_device_manager_x11_translate_event (MetaDeviceManagerX11 *manager_xi2,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source_device != NULL && device->stage != NULL)
|
if (device->stage != NULL)
|
||||||
_clutter_input_device_set_stage (source_device, device->stage);
|
_clutter_input_device_set_stage (source_device, device->stage);
|
||||||
|
|
||||||
if (xev->flags & XIPointerEmulated)
|
if (xev->flags & XIPointerEmulated)
|
||||||
@ -1644,8 +1664,10 @@ meta_device_manager_x11_translate_event (MetaDeviceManagerX11 *manager_xi2,
|
|||||||
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
|
XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
|
||||||
double delta_x, delta_y;
|
double delta_x, delta_y;
|
||||||
|
|
||||||
source_device = g_hash_table_lookup (manager_xi2->devices_by_id,
|
source_device = get_source_device_checked (manager_xi2, xev);
|
||||||
GINT_TO_POINTER (xev->sourceid));
|
if (!source_device)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
device = g_hash_table_lookup (manager_xi2->devices_by_id,
|
device = g_hash_table_lookup (manager_xi2->devices_by_id,
|
||||||
GINT_TO_POINTER (xev->deviceid));
|
GINT_TO_POINTER (xev->deviceid));
|
||||||
|
|
||||||
@ -1716,7 +1738,7 @@ meta_device_manager_x11_translate_event (MetaDeviceManagerX11 *manager_xi2,
|
|||||||
event->motion.y,
|
event->motion.y,
|
||||||
&xev->valuators);
|
&xev->valuators);
|
||||||
|
|
||||||
if (source_device != NULL && device->stage != NULL)
|
if (device->stage != NULL)
|
||||||
_clutter_input_device_set_stage (source_device, device->stage);
|
_clutter_input_device_set_stage (source_device, device->stage);
|
||||||
|
|
||||||
if (xev->flags & XIPointerEmulated)
|
if (xev->flags & XIPointerEmulated)
|
||||||
|
Loading…
Reference in New Issue
Block a user