From 4a3ad9c3af2db9bb805b7abae018f6531087d1ac Mon Sep 17 00:00:00 2001 From: Adel Gadllah Date: Mon, 3 Mar 2014 11:36:11 +0100 Subject: [PATCH] DeviceManagerXi2: Cache the client pointer Currently clutter_device_manager_xi2_get_core_device always does a round trip to query the client. So avoid that by caching the client pointer and only update it when the xi devices change. https://bugzilla.gnome.org/show_bug.cgi?id=725561 --- clutter/x11/clutter-device-manager-xi2.c | 35 +++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/clutter/x11/clutter-device-manager-xi2.c b/clutter/x11/clutter-device-manager-xi2.c index d508026dd..b00cddb90 100644 --- a/clutter/x11/clutter-device-manager-xi2.c +++ b/clutter/x11/clutter-device-manager-xi2.c @@ -222,6 +222,21 @@ is_touch_device (XIAnyClassInfo **classes, return FALSE; } +static void +update_client_pointer (ClutterDeviceManagerXI2 *manager_xi2) +{ + ClutterBackendX11 *backend_x11; + int device_id; + + backend_x11 = + CLUTTER_BACKEND_X11 (_clutter_device_manager_get_backend (CLUTTER_DEVICE_MANAGER (manager_xi2))); + + XIGetClientPointer (backend_x11->xdpy, None, &device_id); + + manager_xi2->client_pointer = g_hash_table_lookup (manager_xi2->devices_by_id, + GINT_TO_POINTER (device_id)); +} + static ClutterInputDevice * create_device (ClutterDeviceManagerXI2 *manager_xi2, ClutterBackendX11 *backend_x11, @@ -792,6 +807,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator, XIHierarchyEvent *xev = (XIHierarchyEvent *) xi_event; translate_hierarchy_event (backend_x11, manager_xi2, xev); + update_client_pointer (manager_xi2); } retval = CLUTTER_TRANSLATE_REMOVE; break; @@ -815,6 +831,8 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator, if (source_device) _clutter_input_device_reset_scroll_info (source_device); + + update_client_pointer (manager_xi2); } retval = CLUTTER_TRANSLATE_REMOVE; break; @@ -1356,25 +1374,14 @@ clutter_device_manager_xi2_get_core_device (ClutterDeviceManager *manager, ClutterInputDeviceType device_type) { ClutterDeviceManagerXI2 *manager_xi2 = CLUTTER_DEVICE_MANAGER_XI2 (manager); - ClutterBackendX11 *backend_x11; - ClutterInputDevice *device; - int device_id; - - backend_x11 = - CLUTTER_BACKEND_X11 (_clutter_device_manager_get_backend (manager)); - - XIGetClientPointer (backend_x11->xdpy, None, &device_id); - - device = g_hash_table_lookup (manager_xi2->devices_by_id, - GINT_TO_POINTER (device_id)); switch (device_type) { case CLUTTER_POINTER_DEVICE: - return device; + return manager_xi2->client_pointer; case CLUTTER_KEYBOARD_DEVICE: - return clutter_input_device_get_associated_device (device); + return clutter_input_device_get_associated_device (manager_xi2->client_pointer); default: break; @@ -1477,6 +1484,8 @@ clutter_device_manager_xi2_constructed (GObject *gobject) clutter_x11_get_root_window (), &event_mask); + update_client_pointer (manager_xi2); + if (G_OBJECT_CLASS (clutter_device_manager_xi2_parent_class)->constructed) G_OBJECT_CLASS (clutter_device_manager_xi2_parent_class)->constructed (gobject); }