x11: change event translator interface

Make the event translator return a new event, instead of
filling in a half-constructed one.

Update the two implementation in GdkX11Display and
GdkDeviceManagerXI2.
This commit is contained in:
Matthias Clasen 2020-02-15 12:09:31 -05:00
parent 15501afdbb
commit 79b4510c6d
4 changed files with 215 additions and 305 deletions

View File

@ -114,10 +114,9 @@ static void gdk_x11_device_manager_xi2_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static gboolean gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
GdkDisplay *display,
GdkEvent *event,
const XEvent *xevent);
static GdkEvent * gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
GdkDisplay *display,
const XEvent *xevent);
static GdkEventMask gdk_x11_device_manager_xi2_get_handled_events (GdkEventTranslator *translator);
static void gdk_x11_device_manager_xi2_select_surface_events (GdkEventTranslator *translator,
Window window,
@ -1463,38 +1462,39 @@ _gdk_device_manager_xi2_handle_focus (GdkSurface *surface,
}
}
static gboolean
static GdkEvent *
gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
GdkDisplay *display,
GdkEvent *event,
const XEvent *xevent)
{
GdkX11DeviceManagerXI2 *device_manager;
const XGenericEventCookie *cookie;
GdkDevice *device, *source_device;
gboolean return_val = TRUE;
GdkSurface *surface;
GdkX11Surface *impl;
int scale;
XIEvent *ev;
GdkEvent *event;
event = NULL;
device_manager = (GdkX11DeviceManagerXI2 *) translator;
cookie = &xevent->xcookie;
if (xevent->type != GenericEvent ||
cookie->extension != device_manager->opcode)
return FALSE;
return event;
ev = (XIEvent *) cookie->data;
if (!ev)
return FALSE;
return NULL;
if (!get_event_surface (translator, ev, &surface))
return FALSE;
return NULL;
if (surface && GDK_SURFACE_DESTROYED (surface))
return FALSE;
return NULL;
scale = 1;
if (surface)
@ -1507,7 +1507,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
ev->evtype == XI_ButtonRelease)
{
if (_gdk_x11_moveresize_handle_event (xevent))
return FALSE;
return NULL;
}
switch (ev->evtype)
@ -1515,17 +1515,14 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
case XI_HierarchyChanged:
handle_hierarchy_changed (device_manager,
(XIHierarchyEvent *) ev);
return_val = FALSE;
break;
case XI_DeviceChanged:
handle_device_changed (device_manager,
(XIDeviceChangedEvent *) ev);
return_val = FALSE;
break;
case XI_PropertyEvent:
handle_property_change (device_manager,
(XIPropertyEvent *) ev);
return_val = FALSE;
break;
case XI_KeyPress:
case XI_KeyRelease:
@ -1533,6 +1530,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
GdkKeymap *keymap = gdk_display_get_keymap (display);
GdkModifierType consumed, state;
guint keyval;
GDK_DISPLAY_NOTE (display, EVENTS,
g_message ("key %s:\twindow %ld\n"
@ -1545,38 +1543,39 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
xev->sourceid,
xev->detail));
event->any.type = xev->evtype == XI_KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
event->any.surface = surface;
event->key.time = xev->time;
event->key.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
event->key.group = xev->group.effective;
event->key.hardware_keycode = xev->detail;
gdk_event_set_scancode (event, xev->detail);
event->key.is_modifier = gdk_x11_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->deviceid));
gdk_event_set_device (event, device);
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
event->key.keyval = GDK_KEY_VoidSymbol;
keyval = GDK_KEY_VoidSymbol;
gdk_keymap_translate_keyboard_state (keymap,
event->key.hardware_keycode,
event->key.state,
event->key.group,
&event->key.keyval,
xev->detail,
state,
xev->group.effective,
&keyval,
NULL, NULL, &consumed);
state = event->key.state & ~consumed;
state &= ~consumed;
_gdk_x11_keymap_add_virt_mods (keymap, &state);
event->key.state |= state;
event = gdk_event_key_new (xev->evtype == XI_KeyPress
? GDK_KEY_PRESS
: GDK_KEY_RELEASE,
surface,
device,
source_device,
xev->time,
state,
keyval,
xev->detail,
xev->detail,
xev->group.effective,
gdk_x11_keymap_key_is_modifier (keymap, xev->detail));
if (ev->evtype == XI_KeyPress)
set_user_time (event);
@ -1616,76 +1615,78 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
else if (ev->evtype == XI_ButtonPress &&
(xev->detail >= 4 && xev->detail <= 7))
{
GdkScrollDirection direction;
/* Button presses of button 4-7 are scroll events */
event->any.type = GDK_SCROLL;
if (xev->detail == 4)
event->scroll.direction = GDK_SCROLL_UP;
direction = GDK_SCROLL_UP;
else if (xev->detail == 5)
event->scroll.direction = GDK_SCROLL_DOWN;
direction = GDK_SCROLL_DOWN;
else if (xev->detail == 6)
event->scroll.direction = GDK_SCROLL_LEFT;
direction = GDK_SCROLL_LEFT;
else
event->scroll.direction = GDK_SCROLL_RIGHT;
event->any.surface = surface;
event->scroll.time = xev->time;
event->scroll.x = (gdouble) xev->event_x / scale;
event->scroll.y = (gdouble) xev->event_y / scale;
event->scroll.delta_x = 0;
event->scroll.delta_y = 0;
direction = GDK_SCROLL_RIGHT;
device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->deviceid));
gdk_event_set_device (event, device);
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
event->scroll.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
event = gdk_event_discrete_scroll_new (surface,
device,
source_device,
NULL,
xev->time,
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
direction,
FALSE);
}
else
{
event->any.type = (ev->evtype == XI_ButtonPress) ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE;
event->any.surface = surface;
event->button.time = xev->time;
event->button.x = (gdouble) xev->event_x / scale;
event->button.y = (gdouble) xev->event_y / scale;
double x, y;
double *axes;
device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->deviceid));
gdk_event_set_device (event, device);
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
gdk_event_set_device_tool (event, source_device->last_tool);
event->button.axes = translate_axes (device,
event->button.x,
event->button.y,
event->any.surface,
&xev->valuators);
axes = translate_axes (device,
event->button.x,
event->button.y,
event->any.surface,
&xev->valuators);
if (gdk_device_get_mode (device) == GDK_MODE_SURFACE)
{
/* Update event coordinates from axes */
gdk_device_get_axis (device, event->button.axes, GDK_AXIS_X, &event->button.x);
gdk_device_get_axis (device, event->button.axes, GDK_AXIS_Y, &event->button.y);
gdk_device_get_axis (device, event->button.axes, GDK_AXIS_X, &x);
gdk_device_get_axis (device, event->button.axes, GDK_AXIS_Y, &y);
}
else
{
x = (double) xev->event_x / scale;
y = (double) xev->event_y / scale;
}
event->button.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
event->button.button = xev->detail;
event = gdk_event_button_new (ev->evtype == XI_ButtonPress
? GDK_BUTTON_PRESS
: GDK_BUTTON_RELEASE,
surface,
device,
source_device,
source_device->last_tool,
xev->time,
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
xev->detail,
x, y,
axes);
}
if (return_val == FALSE)
break;
gdk_event_set_display (event, display);
if (ev->evtype == XI_ButtonPress)
set_user_time (event);
@ -1697,6 +1698,9 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
gdouble delta_x, delta_y;
double x, y;
double *axes;
#ifdef XINPUT_2_2
if (xev->flags & XIPointerEmulated)
return FALSE;
@ -1719,56 +1723,50 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
scroll_valuators_changed (GDK_X11_DEVICE_XI2 (source_device),
&xev->valuators, &delta_x, &delta_y))
{
event->any.type = GDK_SCROLL;
event->scroll.direction = GDK_SCROLL_SMOOTH;
if (delta_x == 0.0 && delta_y == 0.0)
event->scroll.is_stop = TRUE;
GDK_DISPLAY_NOTE (display, EVENTS,
g_message ("smooth scroll: \n\tdevice: %u\n\tsource device: %u\n\twindow %ld\n\tdeltas: %f %f",
xev->deviceid, xev->sourceid,
xev->event, delta_x, delta_y));
event->any.surface = surface;
event->scroll.time = xev->time;
event->scroll.x = (gdouble) xev->event_x / scale;
event->scroll.y = (gdouble) xev->event_y / scale;
event->scroll.delta_x = delta_x;
event->scroll.delta_y = delta_y;
gdk_event_set_device (event, device);
gdk_event_set_source_device (event, source_device);
event->scroll.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
event = gdk_event_scroll_new (surface,
device,
source_device,
NULL,
xev->time,
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
delta_x,
delta_y,
delta_x == 0.0 && delta_y == 0.0);
break;
}
event->any.type = GDK_MOTION_NOTIFY;
event->any.surface = surface;
event->motion.time = xev->time;
event->motion.x = (gdouble) xev->event_x / scale;
event->motion.y = (gdouble) xev->event_y / scale;
gdk_event_set_device (event, device);
gdk_event_set_source_device (event, source_device);
gdk_event_set_device_tool (event, source_device->last_tool);
event->motion.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
event->motion.axes = translate_axes (device,
event->motion.x,
event->motion.y,
event->any.surface,
&xev->valuators);
axes = translate_axes (device,
event->motion.x,
event->motion.y,
event->any.surface,
&xev->valuators);
if (gdk_device_get_mode (device) == GDK_MODE_SURFACE)
{
/* Update event coordinates from axes */
gdk_device_get_axis (device, event->motion.axes, GDK_AXIS_X, &event->motion.x);
gdk_device_get_axis (device, event->motion.axes, GDK_AXIS_Y, &event->motion.y);
gdk_device_get_axis (device, event->motion.axes, GDK_AXIS_X, &x);
gdk_device_get_axis (device, event->motion.axes, GDK_AXIS_Y, &y);
}
else
{
x = (double) xev->event_x / scale;
y = (double) xev->event_y / scale;
}
event = gdk_event_motion_new (surface,
device,
source_device,
source_device->last_tool,
xev->time,
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
x, y,
axes);
}
break;
@ -1777,6 +1775,10 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
case XI_TouchEnd:
{
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
GdkModifierType state;
double x, y;
double *axes;
GDK_DISPLAY_NOTE (display, EVENTS,
g_message ("touch %s:\twindow %ld\n\ttouch id: %u\n\tpointer emulating: %s",
@ -1785,54 +1787,45 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
xev->detail,
xev->flags & XITouchEmulatingPointer ? "true" : "false"));
if (ev->evtype == XI_TouchBegin)
event->any.type = GDK_TOUCH_BEGIN;
else if (ev->evtype == XI_TouchEnd)
event->any.type = GDK_TOUCH_END;
event->any.surface = surface;
event->touch.time = xev->time;
event->touch.x = (gdouble) xev->event_x / scale;
event->touch.y = (gdouble) xev->event_y / scale;
device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->deviceid));
gdk_event_set_device (event, device);
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
event->touch.axes = translate_axes (device,
event->touch.x,
event->touch.y,
event->any.surface,
&xev->valuators);
state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
if (ev->evtype == XI_TouchBegin)
state |= GDK_BUTTON1_MASK;
axes = translate_axes (device,
event->touch.x,
event->touch.y,
event->any.surface,
&xev->valuators);
if (gdk_device_get_mode (device) == GDK_MODE_SURFACE)
{
/* Update event coordinates from axes */
gdk_device_get_axis (device, event->touch.axes, GDK_AXIS_X, &event->touch.x);
gdk_device_get_axis (device, event->touch.axes, GDK_AXIS_Y, &event->touch.y);
gdk_device_get_axis (device, event->touch.axes, GDK_AXIS_X, &x);
gdk_device_get_axis (device, event->touch.axes, GDK_AXIS_Y, &y);
}
event->touch.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
if (ev->evtype == XI_TouchBegin)
event->touch.state |= GDK_BUTTON1_MASK;
event->touch.sequence = GUINT_TO_POINTER (xev->detail);
if (xev->flags & XITouchEmulatingPointer)
else
{
event->touch.emulating_pointer = TRUE;
gdk_event_set_pointer_emulated (event, TRUE);
x = (double) xev->event_x / scale;
y = (double) xev->event_y / scale;
}
if (return_val == FALSE)
break;
gdk_event_set_display (event, display);
event = gdk_event_touch_new (ev->evtype == XI_TouchBegin
? GDK_TOUCH_BEGIN
: GDK_TOUCH_END,
GUINT_TO_POINTER (xev->detail),
surface,
device,
source_device,
xev->time,
state,
x, y,
axes,
xev->flags & XITouchEmulatingPointer);
if (ev->evtype == XI_TouchBegin)
set_user_time (event);
@ -1842,6 +1835,10 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
case XI_TouchUpdate:
{
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
GdkModifierType state;
double x, y;
double *axes;
GDK_DISPLAY_NOTE (display, EVENTS,
g_message ("touch update:\twindow %ld\n\ttouch id: %u\n\tpointer emulating: %s",
@ -1849,43 +1846,43 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
xev->detail,
xev->flags & XITouchEmulatingPointer ? "true" : "false"));
event->any.surface = surface;
event->touch.sequence = GUINT_TO_POINTER (xev->detail);
event->any.type = GDK_TOUCH_UPDATE;
event->touch.time = xev->time;
event->touch.x = (gdouble) xev->event_x / scale;
event->touch.y = (gdouble) xev->event_y / scale;
device = g_hash_table_lookup (device_manager->id_table,
GINT_TO_POINTER (xev->deviceid));
gdk_event_set_device (event, device);
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
event->touch.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
state |= GDK_BUTTON1_MASK;
event->touch.state |= GDK_BUTTON1_MASK;
if (xev->flags & XITouchEmulatingPointer)
{
event->touch.emulating_pointer = TRUE;
gdk_event_set_pointer_emulated (event, TRUE);
}
event->touch.axes = translate_axes (device,
event->touch.x,
event->touch.y,
event->any.surface,
&xev->valuators);
axes = translate_axes (device,
event->touch.x,
event->touch.y,
event->any.surface,
&xev->valuators);
if (gdk_device_get_mode (device) == GDK_MODE_SURFACE)
{
/* Update event coordinates from axes */
gdk_device_get_axis (device, event->touch.axes, GDK_AXIS_X, &event->touch.x);
gdk_device_get_axis (device, event->touch.axes, GDK_AXIS_Y, &event->touch.y);
gdk_device_get_axis (device, event->touch.axes, GDK_AXIS_X, &x);
gdk_device_get_axis (device, event->touch.axes, GDK_AXIS_Y, &y);
}
else
{
x = (double) xev->event_x / scale;
y = (double) xev->event_y / scale;
}
event = gdk_event_touch_new (GDK_TOUCH_UPDATE,
GUINT_TO_POINTER (xev->detail),
surface,
device,
source_device,
xev->time,
state,
x, y,
axes,
xev->flags & XITouchEmulatingPointer);
}
break;
#endif /* XINPUT_2_2 */
@ -1904,23 +1901,11 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
xev->deviceid, xev->sourceid,
xev->detail, xev->mode));
event->any.type = (ev->evtype == XI_Enter) ? GDK_ENTER_NOTIFY : GDK_LEAVE_NOTIFY;
event->crossing.x = (gdouble) xev->event_x / scale;
event->crossing.y = (gdouble) xev->event_y / scale;
event->crossing.time = xev->time;
event->crossing.focus = xev->focus;
event->any.surface = surface;
event->crossing.child_surface = gdk_x11_surface_lookup_for_display (display, xev->child);
device = g_hash_table_lookup (device_manager->id_table,
GINT_TO_POINTER (xev->deviceid));
gdk_event_set_device (event, device);
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
if (ev->evtype == XI_Enter &&
xev->detail != XINotifyInferior && xev->mode != XINotifyPassiveUngrab &&
@ -1941,9 +1926,19 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
}
}
event->crossing.mode = translate_crossing_mode (xev->mode);
event->crossing.detail = translate_notify_type (xev->detail);
event->crossing.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
event = gdk_event_crossing_new (ev->evtype == XI_Enter
? GDK_ENTER_NOTIFY
: GDK_LEAVE_NOTIFY,
surface,
device,
source_device,
xev->time,
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
(double) xev->event_x / scale,
(double) xev->event_y / scale,
translate_crossing_mode (xev->mode),
translate_notify_type (xev->detail));
}
break;
case XI_FocusIn:
@ -1967,35 +1962,13 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
xev->detail,
xev->mode);
}
return_val = FALSE;
}
break;
default:
return_val = FALSE;
break;
}
event->any.send_event = cookie->send_event;
if (return_val)
{
if (event->any.surface)
g_object_ref (event->any.surface);
if (((event->any.type == GDK_ENTER_NOTIFY) ||
(event->any.type == GDK_LEAVE_NOTIFY)) &&
(event->crossing.child_surface != NULL))
g_object_ref (event->crossing.child_surface);
}
else
{
/* Mark this event as having no resources to be freed */
event->any.surface = NULL;
event->any.type = GDK_NOTHING;
}
return return_val;
return event;
}
static GdkEventMask

View File

@ -106,10 +106,9 @@ static void gdk_x11_display_finalize (GObject *object);
static void gdk_x11_display_event_translator_init (GdkEventTranslatorIface *iface);
static gboolean gdk_x11_display_translate_event (GdkEventTranslator *translator,
GdkDisplay *display,
GdkEvent *event,
const XEvent *xevent);
static GdkEvent * gdk_x11_display_translate_event (GdkEventTranslator *translator,
GdkDisplay *display,
const XEvent *xevent);
static void gdk_internal_connection_watch (Display *display,
XPointer arg,
@ -630,10 +629,9 @@ get_event_xwindow (const XEvent *xevent)
return xwindow;
}
static gboolean
static GdkEvent *
gdk_x11_display_translate_event (GdkEventTranslator *translator,
GdkDisplay *display,
GdkEvent *event,
const XEvent *xevent)
{
Window xwindow;
@ -643,7 +641,9 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
GdkX11Screen *x11_screen = NULL;
GdkToplevelX11 *toplevel = NULL;
GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
gboolean return_val;
GdkEvent *event;
event = NULL;
/* Find the GdkSurface that this event relates to. If that's
* not the same as the surface that the event was sent to,
@ -665,7 +665,7 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
* and ShmCompletion for pixmaps
*/
if (!GDK_IS_SURFACE (surface))
return FALSE;
return NULL;
x11_screen = GDK_SURFACE_SCREEN (surface);
toplevel = _gdk_x11_surface_get_toplevel (surface);
@ -674,16 +674,10 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
g_object_ref (surface);
}
event->any.surface = surface;
event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
if (surface && GDK_SURFACE_DESTROYED (surface))
{
if (xevent->type != DestroyNotify)
{
return_val = FALSE;
goto done;
}
goto done;
}
if (xevent->type == DestroyNotify && !is_substructure)
@ -700,7 +694,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
/* careful, reentrancy */
_gdk_x11_screen_window_manager_changed (x11_screen);
return_val = FALSE;
goto done;
}
}
@ -712,15 +705,12 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
* received.
*/
return_val = TRUE;
switch (xevent->type)
{
case KeymapNotify:
GDK_DISPLAY_NOTE (display, EVENTS, g_message ("keymap notify"));
/* Not currently handled */
return_val = FALSE;
break;
case Expose:
@ -732,10 +722,7 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
event->any.send_event ? " (send)" : ""));
if (surface == NULL)
{
return_val = FALSE;
break;
}
break;
{
GdkRectangle expose_rect;
@ -751,7 +738,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
expose_rect.height = y2 - expose_rect.y;
gdk_surface_invalidate_rect (surface, &expose_rect);
return_val = FALSE;
}
break;
@ -766,10 +752,7 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
xevent->xgraphicsexpose.drawable));
if (surface == NULL)
{
return_val = FALSE;
break;
}
break;
expose_rect.x = xevent->xgraphicsexpose.x / surface_impl->surface_scale;
expose_rect.y = xevent->xgraphicsexpose.y / surface_impl->surface_scale;
@ -781,7 +764,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
expose_rect.height = y2 - expose_rect.y;
gdk_surface_invalidate_rect (surface, &expose_rect);
return_val = FALSE;
}
break;
@ -807,7 +789,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
}
#endif /* G_ENABLE_DEBUG */
/* not handled */
return_val = FALSE;
break;
case CreateNotify:
@ -831,17 +812,11 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
if (!is_substructure)
{
/* handle destroy like delete */
event->any.type = GDK_DELETE;
event->any.surface = surface;
return_val = surface && !GDK_SURFACE_DESTROYED (surface);
event = gdk_event_delete_new (surface);
if (surface && GDK_SURFACE_XID (surface) != x11_screen->xroot_window)
gdk_surface_destroy_notify (surface);
}
else
return_val = FALSE;
break;
@ -887,8 +862,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
gdk_profiler_add_markf (g_get_monotonic_time (), 0, "unmapped window", "0x%lx", GDK_SURFACE_XID (surface));
}
return_val = FALSE;
break;
case MapNotify:
@ -914,8 +887,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
}
}
return_val = FALSE;
break;
case ReparentNotify:
@ -928,7 +899,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
xevent->xreparent.override_redirect));
/* Not currently handled */
return_val = FALSE;
break;
case ConfigureNotify:
@ -957,15 +927,14 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
}
#endif
if (!surface ||
xevent->xconfigure.event != xevent->xconfigure.window)
return_val = FALSE;
else
{
event->any.type = GDK_CONFIGURE;
event->any.surface = surface;
event->configure.width = (xevent->xconfigure.width + surface_impl->surface_scale - 1) / surface_impl->surface_scale;
event->configure.height = (xevent->xconfigure.height + surface_impl->surface_scale - 1) / surface_impl->surface_scale;
if (surface &&
xevent->xconfigure.event == xevent->xconfigure.window)
{
int x, y;
event = gdk_event_configure_new (surface,
(xevent->xconfigure.width + surface_impl->surface_scale - 1) / surface_impl->surface_scale,
(xevent->xconfigure.height + surface_impl->surface_scale - 1) / surface_impl->surface_scale);
if (!xevent->xconfigure.send_event &&
!xevent->xconfigure.override_redirect &&
@ -975,6 +944,7 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
gint ty = 0;
Window child_window = 0;
x = y = 0;
gdk_x11_display_error_trap_push (display);
if (XTranslateCoordinates (GDK_SURFACE_XDISPLAY (surface),
GDK_SURFACE_XID (surface),
@ -983,22 +953,22 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
&tx, &ty,
&child_window))
{
event->configure.x = tx / surface_impl->surface_scale;
event->configure.y = ty / surface_impl->surface_scale;
x = tx / surface_impl->surface_scale;
y = ty / surface_impl->surface_scale;
}
gdk_x11_display_error_trap_pop_ignored (display);
}
else
{
event->configure.x = xevent->xconfigure.x / surface_impl->surface_scale;
event->configure.y = xevent->xconfigure.y / surface_impl->surface_scale;
x = xevent->xconfigure.x / surface_impl->surface_scale;
y = xevent->xconfigure.y / surface_impl->surface_scale;
}
if (!is_substructure)
{
int new_abs_x, new_abs_y;
new_abs_x = event->configure.x;
new_abs_y = event->configure.y;
new_abs_x = x;
new_abs_y = y;
surface_impl->abs_x = new_abs_x;
surface_impl->abs_y = new_abs_y;
@ -1047,10 +1017,7 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
"\""));
if (surface == NULL)
{
return_val = FALSE;
break;
}
break;
/* We compare with the serial of the last time we mapped the
* window to avoid refetching properties that we set ourselves
@ -1067,8 +1034,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_GTK_EDGE_CONSTRAINTS"))
gdk_check_edge_constraints_changed (surface);
}
return_val = FALSE;
break;
case ColormapNotify:
@ -1077,7 +1042,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
xevent->xcolormap.window));
/* Not currently handled */
return_val = FALSE;
break;
case ClientMessage:
@ -1086,7 +1050,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
xevent->xclient.window));
/* Not currently handled */
return_val = FALSE;
break;
case MappingNotify:
@ -1097,7 +1060,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
*/
XRefreshKeyboardMapping ((XMappingEvent *) xevent);
_gdk_x11_keymap_keys_changed (display);
return_val = FALSE;
break;
default:
@ -1120,8 +1082,6 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
case XkbNewKeyboardNotify:
case XkbMapNotify:
_gdk_x11_keymap_keys_changed (display);
return_val = FALSE;
break;
case XkbStateNotify:
@ -1131,28 +1091,14 @@ gdk_x11_display_translate_event (GdkEventTranslator *translator,
break;
}
}
else
#endif
return_val = FALSE;
}
done:
if (return_val)
{
if (event->any.surface)
g_object_ref (event->any.surface);
}
else
{
/* Mark this event as having no resources to be freed */
event->any.surface = NULL;
event->any.type = GDK_NOTHING;
}
if (surface)
g_object_unref (surface);
return return_val;
return event;
}
static GdkFrameTimings *

View File

@ -36,7 +36,6 @@ _gdk_x11_event_translator_translate (GdkEventTranslator *translator,
const XEvent *xevent)
{
GdkEventTranslatorIface *iface;
GdkEvent *event;
g_return_val_if_fail (GDK_IS_EVENT_TRANSLATOR (translator), NULL);
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
@ -46,14 +45,7 @@ _gdk_x11_event_translator_translate (GdkEventTranslator *translator,
if (!iface->translate_event)
return NULL;
event = gdk_event_new (GDK_NOTHING);
if ((iface->translate_event) (translator, display, event, xevent))
return event;
g_object_unref (event);
return NULL;
return (iface->translate_event) (translator, display, xevent);
}
GdkEventMask

View File

@ -38,10 +38,9 @@ struct _GdkEventTranslatorIface
GTypeInterface iface;
/* VMethods */
gboolean (* translate_event) (GdkEventTranslator *translator,
GdkDisplay *display,
GdkEvent *event,
const XEvent *xevent);
GdkEvent * (* translate_event) (GdkEventTranslator *translator,
GdkDisplay *display,
const XEvent *xevent);
GdkEventMask (* get_handled_events) (GdkEventTranslator *translator);
void (* select_surface_events) (GdkEventTranslator *translator,