]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkdevice.c
Add GdkFrameHistory and GdkFrameTimings, handle _NET_WM_FRAME_TIMINGS
[~andy/gtk] / gdk / gdkdevice.c
index a9119233c0748cf222aa466f5b2fd8d4d5e6667c..3147d9e6a0a5be5e9f6ef08946942b03bd7b90ac 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -32,7 +30,8 @@
  * @Title: GdkDevice
  * @See_also: #GdkDeviceManager
  *
- * The #GdkDevice object represents a single input device.
+ * The #GdkDevice object represents a single input device, such
+ * as a keyboard, a mouse, a touchpad, etc.
  *
  * See the #GdkDeviceManager documentation for more information
  * about the various kinds of master and slave devices, and their
@@ -48,7 +47,6 @@ struct _GdkAxisInfo
 
   gdouble min_axis;
   gdouble max_axis;
-
   gdouble min_value;
   gdouble max_value;
   gdouble resolution;
@@ -273,7 +271,9 @@ gdk_device_dispose (GObject *object)
 
   if (device->associated)
     {
-      _gdk_device_set_associated_device (device->associated, NULL);
+      if (device->type == GDK_DEVICE_TYPE_MASTER)
+        _gdk_device_set_associated_device (device->associated, NULL);
+
       g_object_unref (device->associated);
       device->associated = NULL;
     }
@@ -377,14 +377,17 @@ gdk_device_get_property (GObject    *object,
 }
 
 /**
- * gdk_device_get_state:
+ * gdk_device_get_state: (skip)
  * @device: a #GdkDevice.
  * @window: a #GdkWindow.
  * @axes: an array of doubles to store the values of the axes of @device in,
  * or %NULL.
  * @mask: location to store the modifiers, or %NULL.
  *
- * Gets the current state of a pointer device relative to @window.
+ * Gets the current state of a pointer device relative to @window. As a slave
+ * device coordinates are those of its master pointer, This
+ * function may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE,
+ * unless there is an ongoing grab on them, see gdk_device_grab().
  */
 void
 gdk_device_get_state (GdkDevice       *device,
@@ -395,6 +398,8 @@ gdk_device_get_state (GdkDevice       *device,
   g_return_if_fail (GDK_IS_DEVICE (device));
   g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
   g_return_if_fail (GDK_IS_WINDOW (window));
+  g_return_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE ||
+                    gdk_display_device_is_grabbed (gdk_device_get_display (device), device));
 
   if (GDK_DEVICE_GET_CLASS (device)->get_state)
     GDK_DEVICE_GET_CLASS (device)->get_state (device, window, axes, mask);
@@ -408,7 +413,10 @@ gdk_device_get_state (GdkDevice       *device,
  * @x: (out) (allow-none): location to store root window X coordinate of @device, or %NULL.
  * @y: (out) (allow-none): location to store root window Y coordinate of @device, or %NULL.
  *
- * Gets the current location of @device.
+ * Gets the current location of @device. As a slave device
+ * coordinates are those of its master pointer, This function
+ * may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE,
+ * unless there is an ongoing grab on them, see gdk_device_grab().
  *
  * Since: 3.0
  **/
@@ -427,6 +435,10 @@ gdk_device_get_position (GdkDevice        *device,
   g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
 
   display = gdk_device_get_display (device);
+
+  g_return_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE ||
+                    gdk_display_device_is_grabbed (display, device));
+
   default_screen = gdk_display_get_default_screen (display);
 
   _gdk_device_query_state (device,
@@ -454,6 +466,10 @@ gdk_device_get_position (GdkDevice        *device,
  * Obtains the window underneath @device, returning the location of the device in @win_x and @win_y. Returns
  * %NULL if the window tree under @device is not known to GDK (for example, belongs to another application).
  *
+ * As a slave device coordinates are those of its master pointer, This
+ * function may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE,
+ * unless there is an ongoing grab on them, see gdk_device_grab().
+ *
  * Returns: (transfer none): the #GdkWindow under the device position, or %NULL.
  *
  * Since: 3.0
@@ -468,6 +484,8 @@ gdk_device_get_window_at_position (GdkDevice  *device,
 
   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
   g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
+  g_return_val_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE ||
+                        gdk_display_device_is_grabbed (gdk_device_get_display (device), device), NULL);
 
   window = _gdk_device_window_at_position (device, &tmp_x, &tmp_y, NULL, FALSE);
 
@@ -493,7 +511,7 @@ gdk_device_get_window_at_position (GdkDevice  *device,
 }
 
 /**
- * gdk_device_get_history:
+ * gdk_device_get_history: (skip)
  * @device: a #GdkDevice
  * @window: the window with respect to which which the event coordinates will be reported
  * @start: starting timestamp for range of events to return
@@ -697,8 +715,8 @@ gdk_device_get_n_keys (GdkDevice *device)
  * gdk_device_get_key:
  * @device: a #GdkDevice.
  * @index_: the index of the macro button to get.
- * @keyval: return value for the keyval.
- * @modifiers: return value for modifiers.
+ * @keyval: (out): return value for the keyval.
+ * @modifiers: (out): return value for modifiers.
  *
  * If @index_ has a valid keyval, this function will return %TRUE
  * and fill in @keyval and @modifiers with the keyval settings.
@@ -921,7 +939,7 @@ GList *
 gdk_device_list_slave_devices (GdkDevice *device)
 {
   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
-  g_return_val_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER, NULL);
+  g_return_val_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER, NULL);
 
   return g_list_copy (device->slaves);
 }
@@ -1024,9 +1042,9 @@ gdk_device_list_axes (GdkDevice *device)
 }
 
 /**
- * gdk_device_get_axis_value:
+ * gdk_device_get_axis_value: (skip)
  * @device: a pointer #GdkDevice.
- * @axes: pointer to an array of axes
+ * @axes: (array): pointer to an array of axes
  * @axis_label: #GdkAtom with the axis label.
  * @value: location to store the found value.
  *
@@ -1071,11 +1089,11 @@ gdk_device_get_axis_value (GdkDevice *device,
 }
 
 /**
- * gdk_device_get_axis:
+ * gdk_device_get_axis: (skip)
  * @device: a #GdkDevice
- * @axes: pointer to an array of axes
+ * @axes: (array): pointer to an array of axes
  * @use: the use to look for
- * @value: location to store the found value.
+ * @value: (out): location to store the found value.
  *
  * Interprets an array of double as axis values for a given device,
  * and locates the value in the array for a given axis use.
@@ -1149,7 +1167,7 @@ get_native_grab_event_mask (GdkEventMask grab_mask)
  *                @event_mask. In either mode, unreported events are discarded.
  * @event_mask: specifies the event mask, which is used in accordance with
  *              @owner_events.
- * @cursor: the cursor to display while the grab is active if the device is
+ * @cursor: (allow-none): the cursor to display while the grab is active if the device is
  *          a pointer. If this is %NULL then the normal cursors are used for
  *          @window and its descendants, and the cursor for @window is used
  *          elsewhere.
@@ -1196,10 +1214,7 @@ gdk_device_grab (GdkDevice        *device,
   g_return_val_if_fail (GDK_IS_DEVICE (device), GDK_GRAB_SUCCESS);
   g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_GRAB_SUCCESS);
 
-  if (_gdk_native_windows)
-    native = window;
-  else
-    native = gdk_window_get_toplevel (window);
+  native = gdk_window_get_toplevel (window);
 
   while (native->window_type == GDK_WINDOW_OFFSCREEN)
     {
@@ -1354,6 +1369,29 @@ _gdk_device_add_axis (GdkDevice   *device,
   return pos;
 }
 
+void
+_gdk_device_get_axis_info (GdkDevice   *device,
+                          guint        index_,
+                          GdkAtom      *label_atom,
+                          GdkAxisUse   *use,
+                          gdouble      *min_value,
+                          gdouble      *max_value,
+                          gdouble      *resolution)
+{
+  GdkAxisInfo *info;
+
+  g_return_if_fail (GDK_IS_DEVICE (device));
+  g_return_if_fail (index_ < device->axes->len);
+
+  info = &g_array_index (device->axes, GdkAxisInfo, index_);
+
+  *label_atom = info->label;
+  *use = info->use;
+  *min_value = info->min_value;
+  *max_value = info->max_value;
+  *resolution = info->resolution;
+}
+
 void
 _gdk_device_set_keys (GdkDevice *device,
                       guint      num_keys)
@@ -1383,16 +1421,6 @@ find_axis_info (GArray     *array,
   return NULL;
 }
 
-GdkAxisUse
-_gdk_device_get_axis_use (GdkDevice *device,
-                          guint      index_)
-{
-  GdkAxisInfo info;
-
-  info = g_array_index (device->axes, GdkAxisInfo, index_);
-  return info.use;
-}
-
 gboolean
 _gdk_device_translate_window_coord (GdkDevice *device,
                                     GdkWindow *window,
@@ -1583,7 +1611,7 @@ _gdk_device_translate_axis (GdkDevice *device,
   return TRUE;
 }
 
-gboolean
+void
 _gdk_device_query_state (GdkDevice        *device,
                          GdkWindow        *window,
                          GdkWindow       **root_window,
@@ -1594,15 +1622,15 @@ _gdk_device_query_state (GdkDevice        *device,
                          gint             *win_y,
                          GdkModifierType  *mask)
 {
-  return GDK_DEVICE_GET_CLASS (device)->query_state (device,
-                                                     window,
-                                                     root_window,
-                                                     child_window,
-                                                     root_x,
-                                                     root_y,
-                                                     win_x,
-                                                     win_y,
-                                                     mask);
+  GDK_DEVICE_GET_CLASS (device)->query_state (device,
+                                              window,
+                                              root_window,
+                                              child_window,
+                                              root_x,
+                                              root_y,
+                                              win_x,
+                                              win_y,
+                                              mask);
 }
 
 GdkWindow *