[clutter] device-manager: select/unselect device events as device change



commit 032870dcccd116045c8bed641ab894c229299c82
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Apr 24 10:21:25 2012 -0400

    device-manager: select/unselect device events as device change
    
    When a device is added or changes, select/unselect events from X
    accordingly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=673644

 clutter/x11/clutter-device-manager-xi2.c |   13 +++++++++++
 clutter/x11/clutter-stage-x11.c          |   34 ++++++++++++++++++++++++++++++
 clutter/x11/clutter-stage-x11.h          |    3 ++
 3 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/clutter/x11/clutter-device-manager-xi2.c b/clutter/x11/clutter-device-manager-xi2.c
index 64f9eed..681c690 100644
--- a/clutter/x11/clutter-device-manager-xi2.c
+++ b/clutter/x11/clutter-device-manager-xi2.c
@@ -425,6 +425,7 @@ translate_hierarchy_event (ClutterBackendX11       *backend_x11,
           ClutterInputDevice *master, *slave;
           XIDeviceInfo *info;
           int n_devices;
+          gboolean send_changed = FALSE;
 
           CLUTTER_NOTE (EVENT, "Hierarchy event: slave %s",
                         (ev->info[i].flags & XISlaveAttached)
@@ -440,6 +441,8 @@ translate_hierarchy_event (ClutterBackendX11       *backend_x11,
             {
               _clutter_input_device_remove_slave (master, slave);
               _clutter_input_device_set_associated_device (slave, NULL);
+
+              send_changed = TRUE;
             }
 
           /* and attach the slave to the new master if needed */
@@ -453,8 +456,18 @@ translate_hierarchy_event (ClutterBackendX11       *backend_x11,
               _clutter_input_device_set_associated_device (slave, master);
               _clutter_input_device_add_slave (master, slave);
 
+              send_changed = TRUE;
               XIFreeDeviceInfo (info);
             }
+
+          if (send_changed)
+            {
+              ClutterStage *stage = _clutter_input_device_get_stage (master);
+              if (stage != NULL)
+                _clutter_stage_x11_events_device_changed (CLUTTER_STAGE_X11 (_clutter_stage_get_window (stage)), 
+                                                          master,
+                                                          CLUTTER_DEVICE_MANAGER (manager_xi2));
+            }
         }
     }
 }
diff --git a/clutter/x11/clutter-stage-x11.c b/clutter/x11/clutter-stage-x11.c
index c02b751..45a6fa2 100644
--- a/clutter/x11/clutter-stage-x11.c
+++ b/clutter/x11/clutter-stage-x11.c
@@ -538,6 +538,37 @@ clutter_stage_x11_set_fullscreen (ClutterStageWindow *stage_window,
    * queue a relayout etc. */
 }
 
+void
+_clutter_stage_x11_events_device_changed (ClutterStageX11 *stage_x11,
+                                          ClutterInputDevice *device,
+                                          ClutterDeviceManager *device_manager)
+{
+  ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
+  int event_flags = 0;
+
+  if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_FLOATING)
+    event_flags = CLUTTER_STAGE_X11_EVENT_MASK;
+
+  _clutter_device_manager_select_stage_events (device_manager,
+                                               stage_cogl->wrapper,
+                                               event_flags);
+}
+
+static void
+stage_events_device_added (ClutterDeviceManager *device_manager,
+                           ClutterInputDevice *device,
+                           gpointer user_data)
+{
+  ClutterStageWindow *stage_window = user_data;
+  ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window);
+  int event_flags = CLUTTER_STAGE_X11_EVENT_MASK;
+
+  if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_FLOATING)
+    _clutter_device_manager_select_stage_events (device_manager,
+                                                 stage_cogl->wrapper,
+                                                 event_flags);
+}
+
 static gboolean
 clutter_stage_x11_realize (ClutterStageWindow *stage_window)
 {
@@ -625,6 +656,9 @@ clutter_stage_x11_realize (ClutterStageWindow *stage_window)
                                                stage_cogl->wrapper,
                                                event_flags);
 
+  g_signal_connect (device_manager, "device-added",
+                    G_CALLBACK (stage_events_device_added), stage_window);
+
   clutter_stage_x11_fix_window_size (stage_x11,
                                      stage_x11->xwin_width,
                                      stage_x11->xwin_height);
diff --git a/clutter/x11/clutter-stage-x11.h b/clutter/x11/clutter-stage-x11.h
index 61ff15f..7e0b244 100644
--- a/clutter/x11/clutter-stage-x11.h
+++ b/clutter/x11/clutter-stage-x11.h
@@ -92,6 +92,9 @@ GType _clutter_stage_x11_get_type (void) G_GNUC_CONST;
 void  _clutter_stage_x11_update_foreign_event_mask (CoglOnscreen *onscreen,
                                                     guint32 event_mask,
                                                     void *user_data);
+void  _clutter_stage_x11_events_device_changed (ClutterStageX11 *stage_x11,
+                                                ClutterInputDevice *device,
+                                                ClutterDeviceManager *device_manager);
 
 /* Private to subclasses */
 void            _clutter_stage_x11_set_user_time                (ClutterStageX11 *stage_x11,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]