mirror of
https://github.com/brl/mutter.git
synced 2024-11-23 00:20:42 -05:00
device-manager-xi2: Clamp coordinates of events to the stage coordinates
The X server can sometimes send us coordinates in the negatives or above our window in extreme cases. Ensure that the user never sees this.
This commit is contained in:
parent
1de024b5fa
commit
98e03fc03f
@ -642,6 +642,17 @@ translate_axes (ClutterInputDevice *device,
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
translate_coords (ClutterStageX11 *stage_x11,
|
||||||
|
gdouble event_x,
|
||||||
|
gdouble event_y,
|
||||||
|
gfloat *x_out,
|
||||||
|
gfloat *y_out)
|
||||||
|
{
|
||||||
|
*x_out = CLAMP (event_x, 0, stage_x11->xwin_width) / stage_x11->scale_factor;
|
||||||
|
*y_out = CLAMP (event_y, 0, stage_x11->xwin_height) / stage_x11->scale_factor;
|
||||||
|
}
|
||||||
|
|
||||||
static gdouble
|
static gdouble
|
||||||
scroll_valuators_changed (ClutterInputDevice *device,
|
scroll_valuators_changed (ClutterInputDevice *device,
|
||||||
XIValuatorState *valuators,
|
XIValuatorState *valuators,
|
||||||
@ -744,7 +755,6 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
|
|||||||
XGenericEventCookie *cookie;
|
XGenericEventCookie *cookie;
|
||||||
XIEvent *xi_event;
|
XIEvent *xi_event;
|
||||||
XEvent *xevent;
|
XEvent *xevent;
|
||||||
int window_scale;
|
|
||||||
|
|
||||||
backend_x11 = CLUTTER_BACKEND_X11 (clutter_get_default_backend ());
|
backend_x11 = CLUTTER_BACKEND_X11 (clutter_get_default_backend ());
|
||||||
|
|
||||||
@ -773,11 +783,6 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
|
|||||||
|
|
||||||
event->any.stage = stage;
|
event->any.stage = stage;
|
||||||
|
|
||||||
if (stage_x11 != NULL)
|
|
||||||
window_scale = stage_x11->scale_factor;
|
|
||||||
else
|
|
||||||
window_scale = 1;
|
|
||||||
|
|
||||||
switch (xi_event->evtype)
|
switch (xi_event->evtype)
|
||||||
{
|
{
|
||||||
case XI_HierarchyChanged:
|
case XI_HierarchyChanged:
|
||||||
@ -932,8 +937,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
|
|||||||
event->scroll.stage = stage;
|
event->scroll.stage = stage;
|
||||||
|
|
||||||
event->scroll.time = xev->time;
|
event->scroll.time = xev->time;
|
||||||
event->scroll.x = xev->event_x / window_scale;
|
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->scroll.x, &event->scroll.y);
|
||||||
event->scroll.y = xev->event_y / window_scale;
|
|
||||||
_clutter_input_device_xi2_translate_state (event,
|
_clutter_input_device_xi2_translate_state (event,
|
||||||
&xev->mods,
|
&xev->mods,
|
||||||
&xev->buttons,
|
&xev->buttons,
|
||||||
@ -979,8 +983,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
|
|||||||
event->button.stage = stage;
|
event->button.stage = stage;
|
||||||
|
|
||||||
event->button.time = xev->time;
|
event->button.time = xev->time;
|
||||||
event->button.x = xev->event_x / window_scale;
|
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->button.x, &event->button.y);
|
||||||
event->button.y = xev->event_y / window_scale;
|
|
||||||
event->button.button = xev->detail;
|
event->button.button = xev->detail;
|
||||||
_clutter_input_device_xi2_translate_state (event,
|
_clutter_input_device_xi2_translate_state (event,
|
||||||
&xev->mods,
|
&xev->mods,
|
||||||
@ -1061,8 +1064,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
|
|||||||
|
|
||||||
event->scroll.stage = stage;
|
event->scroll.stage = stage;
|
||||||
event->scroll.time = xev->time;
|
event->scroll.time = xev->time;
|
||||||
event->scroll.x = xev->event_x / window_scale;
|
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->scroll.x, &event->scroll.y);
|
||||||
event->scroll.y = xev->event_y / window_scale;
|
|
||||||
_clutter_input_device_xi2_translate_state (event,
|
_clutter_input_device_xi2_translate_state (event,
|
||||||
&xev->mods,
|
&xev->mods,
|
||||||
&xev->buttons,
|
&xev->buttons,
|
||||||
@ -1090,8 +1092,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
|
|||||||
event->motion.stage = stage;
|
event->motion.stage = stage;
|
||||||
|
|
||||||
event->motion.time = xev->time;
|
event->motion.time = xev->time;
|
||||||
event->motion.x = xev->event_x / window_scale;
|
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->motion.x, &event->motion.y);
|
||||||
event->motion.y = xev->event_y / window_scale;
|
|
||||||
_clutter_input_device_xi2_translate_state (event,
|
_clutter_input_device_xi2_translate_state (event,
|
||||||
&xev->mods,
|
&xev->mods,
|
||||||
&xev->buttons,
|
&xev->buttons,
|
||||||
@ -1141,8 +1142,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
|
|||||||
|
|
||||||
event->touch.stage = stage;
|
event->touch.stage = stage;
|
||||||
event->touch.time = xev->time;
|
event->touch.time = xev->time;
|
||||||
event->touch.x = xev->event_x / window_scale;
|
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->touch.x, &event->touch.y);
|
||||||
event->touch.y = xev->event_y / window_scale;
|
|
||||||
_clutter_input_device_xi2_translate_state (event,
|
_clutter_input_device_xi2_translate_state (event,
|
||||||
&xev->mods,
|
&xev->mods,
|
||||||
&xev->buttons,
|
&xev->buttons,
|
||||||
@ -1196,8 +1196,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
|
|||||||
event->touch.stage = stage;
|
event->touch.stage = stage;
|
||||||
event->touch.time = xev->time;
|
event->touch.time = xev->time;
|
||||||
event->touch.sequence = GUINT_TO_POINTER (xev->detail);
|
event->touch.sequence = GUINT_TO_POINTER (xev->detail);
|
||||||
event->touch.x = xev->event_x / window_scale;
|
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->touch.x, &event->touch.y);
|
||||||
event->touch.y = xev->event_y / window_scale;
|
|
||||||
|
|
||||||
clutter_event_set_source_device (event, source_device);
|
clutter_event_set_source_device (event, source_device);
|
||||||
|
|
||||||
@ -1253,8 +1252,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
|
|||||||
event->crossing.related = NULL;
|
event->crossing.related = NULL;
|
||||||
|
|
||||||
event->crossing.time = xev->time;
|
event->crossing.time = xev->time;
|
||||||
event->crossing.x = xev->event_x / window_scale;
|
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->crossing.x, &event->crossing.y);
|
||||||
event->crossing.y = xev->event_y / window_scale;
|
|
||||||
|
|
||||||
_clutter_input_device_set_stage (device, stage);
|
_clutter_input_device_set_stage (device, stage);
|
||||||
}
|
}
|
||||||
@ -1277,8 +1275,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
|
|||||||
event->crossing.related = NULL;
|
event->crossing.related = NULL;
|
||||||
|
|
||||||
event->crossing.time = xev->time;
|
event->crossing.time = xev->time;
|
||||||
event->crossing.x = xev->event_x / window_scale;
|
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->crossing.x, &event->crossing.y);
|
||||||
event->crossing.y = xev->event_y / window_scale;
|
|
||||||
|
|
||||||
_clutter_input_device_set_stage (device, NULL);
|
_clutter_input_device_set_stage (device, NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user