* 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"
-#include "gdkdevice.h"
+#include <math.h>
#include "gdkdeviceprivate.h"
-#include "gdkintl.h"
+#include "gdkdisplayprivate.h"
#include "gdkinternals.h"
+#include "gdkintl.h"
+/**
+ * SECTION:gdkdevice
+ * @Short_description: Object representing an input device
+ * @Title: GdkDevice
+ * @See_also: #GdkDeviceManager
+ *
+ * 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
+ * relationships.
+ */
typedef struct _GdkAxisInfo GdkAxisInfo;
gdouble min_axis;
gdouble max_axis;
-
gdouble min_value;
gdouble max_value;
gdouble resolution;
};
-struct _GdkDevicePrivate
-{
- gchar *name;
- GdkInputSource source;
- GdkInputMode mode;
- gboolean has_cursor;
- gint num_keys;
- GdkDeviceKey *keys;
- GdkDeviceManager *device_manager;
- GdkDisplay *display;
- GdkDevice *associated;
- GdkDeviceType type;
- GArray *axes;
+enum {
+ CHANGED,
+ LAST_SIGNAL
};
+static guint signals [LAST_SIGNAL] = { 0 };
+
+
static void gdk_device_dispose (GObject *object);
static void gdk_device_set_property (GObject *object,
guint prop_id,
* Since: 3.0
*/
g_object_class_install_property (object_class,
- PROP_DISPLAY,
- g_param_spec_object ("display",
+ PROP_DISPLAY,
+ g_param_spec_object ("display",
P_("Device Display"),
P_("Display which the device belongs to"),
GDK_TYPE_DISPLAY,
* Since: 3.0
*/
g_object_class_install_property (object_class,
- PROP_DEVICE_MANAGER,
- g_param_spec_object ("device-manager",
+ PROP_DEVICE_MANAGER,
+ g_param_spec_object ("device-manager",
P_("Device manager"),
P_("Device manager which the device belongs to"),
GDK_TYPE_DEVICE_MANAGER,
* Since: 3.0
*/
g_object_class_install_property (object_class,
- PROP_NAME,
- g_param_spec_string ("name",
+ PROP_NAME,
+ g_param_spec_string ("name",
P_("Device name"),
P_("Device name"),
NULL,
* Since: 3.0
*/
g_object_class_install_property (object_class,
- PROP_ASSOCIATED_DEVICE,
- g_param_spec_object ("associated-device",
+ PROP_ASSOCIATED_DEVICE,
+ g_param_spec_object ("associated-device",
P_("Associated device"),
P_("Associated pointer or keyboard with this device"),
GDK_TYPE_DEVICE,
* Since: 3.0
*/
g_object_class_install_property (object_class,
- PROP_INPUT_SOURCE,
- g_param_spec_enum ("input-source",
+ PROP_INPUT_SOURCE,
+ g_param_spec_enum ("input-source",
P_("Input source"),
P_("Source type for the device"),
GDK_TYPE_INPUT_SOURCE,
*/
g_object_class_install_property (object_class,
PROP_INPUT_MODE,
- g_param_spec_enum ("input-mode",
+ g_param_spec_enum ("input-mode",
P_("Input mode for the device"),
P_("Input mode for the device"),
GDK_TYPE_INPUT_MODE,
* Since: 3.0
*/
g_object_class_install_property (object_class,
- PROP_HAS_CURSOR,
- g_param_spec_boolean ("has-cursor",
+ PROP_HAS_CURSOR,
+ g_param_spec_boolean ("has-cursor",
P_("Whether the device has a cursor"),
P_("Whether there is a visible cursor following device motion"),
FALSE,
* Since: 3.0
*/
g_object_class_install_property (object_class,
- PROP_N_AXES,
- g_param_spec_uint ("n-axes",
+ PROP_N_AXES,
+ g_param_spec_uint ("n-axes",
P_("Number of axes in the device"),
P_("Number of axes in the device"),
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
- g_type_class_add_private (object_class, sizeof (GdkDevicePrivate));
+ /**
+ * GdkDevice::changed:
+ * @device: the #GdkDevice that changed.
+ *
+ * The ::changed signal is emitted either when the #GdkDevice
+ * has changed the number of either axes or keys. For example
+ * In X this will normally happen when the slave device routing
+ * events through the master device changes (for example, user
+ * switches from the USB mouse to a tablet), in that case the
+ * master device will change to reflect the new slave device
+ * axes and keys.
+ */
+ signals[CHANGED] =
+ g_signal_new (g_intern_static_string ("changed"),
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
static void
gdk_device_init (GdkDevice *device)
{
- GdkDevicePrivate *priv;
-
- device->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (device,
- GDK_TYPE_DEVICE,
- GdkDevicePrivate);
-
- priv->axes = g_array_new (FALSE, TRUE, sizeof (GdkAxisInfo));
+ device->axes = g_array_new (FALSE, TRUE, sizeof (GdkAxisInfo));
}
static void
gdk_device_dispose (GObject *object)
{
- GdkDevicePrivate *priv;
- GdkDevice *device;
+ GdkDevice *device = GDK_DEVICE (object);
- device = GDK_DEVICE (object);
- priv = device->priv;
+ if (device->type == GDK_DEVICE_TYPE_SLAVE)
+ _gdk_device_remove_slave (device->associated, device);
- if (priv->associated)
+ if (device->associated)
{
- _gdk_device_set_associated_device (priv->associated, NULL);
- g_object_unref (priv->associated);
- priv->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;
}
- if (priv->axes)
+ if (device->axes)
{
- g_array_free (priv->axes, TRUE);
- priv->axes = NULL;
+ g_array_free (device->axes, TRUE);
+ device->axes = NULL;
}
- g_free (priv->name);
- g_free (priv->keys);
+ g_free (device->name);
+ g_free (device->keys);
- priv->name = NULL;
- priv->keys = NULL;
+ device->name = NULL;
+ device->keys = NULL;
G_OBJECT_CLASS (gdk_device_parent_class)->dispose (object);
}
GParamSpec *pspec)
{
GdkDevice *device = GDK_DEVICE (object);
- GdkDevicePrivate *priv = device->priv;
switch (prop_id)
{
case PROP_DISPLAY:
- priv->display = g_value_get_object (value);
+ device->display = g_value_get_object (value);
break;
case PROP_DEVICE_MANAGER:
- priv->device_manager = g_value_get_object (value);
+ device->manager = g_value_get_object (value);
break;
case PROP_NAME:
- if (priv->name)
- g_free (priv->name);
+ if (device->name)
+ g_free (device->name);
- priv->name = g_value_dup_string (value);
+ device->name = g_value_dup_string (value);
break;
case PROP_TYPE:
- priv->type = g_value_get_enum (value);
+ device->type = g_value_get_enum (value);
break;
case PROP_INPUT_SOURCE:
- priv->source = g_value_get_enum (value);
+ device->source = g_value_get_enum (value);
break;
case PROP_INPUT_MODE:
gdk_device_set_mode (device, g_value_get_enum (value));
break;
case PROP_HAS_CURSOR:
- priv->has_cursor = g_value_get_boolean (value);
+ device->has_cursor = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
GParamSpec *pspec)
{
GdkDevice *device = GDK_DEVICE (object);
- GdkDevicePrivate *priv = device->priv;
switch (prop_id)
{
case PROP_DISPLAY:
- g_value_set_object (value, priv->display);
+ g_value_set_object (value, device->display);
break;
case PROP_DEVICE_MANAGER:
- g_value_set_object (value, priv->device_manager);
+ g_value_set_object (value, device->manager);
break;
case PROP_ASSOCIATED_DEVICE:
- g_value_set_object (value, priv->associated);
+ g_value_set_object (value, device->associated);
break;
case PROP_NAME:
- g_value_set_string (value, priv->name);
+ g_value_set_string (value, device->name);
break;
case PROP_TYPE:
- g_value_set_enum (value, priv->type);
+ g_value_set_enum (value, device->type);
break;
case PROP_INPUT_SOURCE:
- g_value_set_enum (value, priv->source);
+ g_value_set_enum (value, device->source);
break;
case PROP_INPUT_MODE:
- g_value_set_enum (value, priv->mode);
+ g_value_set_enum (value, device->mode);
break;
case PROP_HAS_CURSOR:
- g_value_set_boolean (value, priv->has_cursor);
+ g_value_set_boolean (value, device->has_cursor);
break;
case PROP_N_AXES:
- g_value_set_uint (value, priv->axes->len);
+ g_value_set_uint (value, device->axes->len);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
/**
- * 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 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,
GdkModifierType *mask)
{
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);
}
/**
- * gdk_device_get_history:
+ * gdk_device_get_position:
+ * @device: pointer device to query status about.
+ * @screen: (out) (transfer none) (allow-none): location to store the #GdkScreen
+ * the @device is on, or %NULL.
+ * @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. 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
+ **/
+void
+gdk_device_get_position (GdkDevice *device,
+ GdkScreen **screen,
+ gint *x,
+ gint *y)
+{
+ GdkDisplay *display;
+ gint tmp_x, tmp_y;
+ GdkScreen *default_screen;
+ GdkWindow *root;
+
+ g_return_if_fail (GDK_IS_DEVICE (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,
+ gdk_screen_get_root_window (default_screen),
+ &root, NULL,
+ &tmp_x, &tmp_y,
+ NULL, NULL, NULL);
+
+ if (screen)
+ *screen = gdk_window_get_screen (root);
+ if (x)
+ *x = tmp_x;
+ if (y)
+ *y = tmp_y;
+}
+
+/**
+ * gdk_device_get_window_at_position:
+ * @device: pointer #GdkDevice to query info to.
+ * @win_x: (out) (allow-none): return location for the X coordinate of the device location,
+ * relative to the window origin, or %NULL.
+ * @win_y: (out) (allow-none): return location for the Y coordinate of the device location,
+ * relative to the window origin, or %NULL.
+ *
+ * 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
+ **/
+GdkWindow *
+gdk_device_get_window_at_position (GdkDevice *device,
+ gint *win_x,
+ gint *win_y)
+{
+ gint tmp_x, tmp_y;
+ GdkWindow *window;
+
+ 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);
+
+ /* This might need corrections, as the native window returned
+ may contain client side children */
+ if (window)
+ {
+ double xx, yy;
+
+ window = _gdk_window_find_descendant_at (window,
+ tmp_x, tmp_y,
+ &xx, &yy);
+ tmp_x = floor (xx + 0.5);
+ tmp_y = floor (yy + 0.5);
+ }
+
+ if (win_x)
+ *win_x = tmp_x;
+ if (win_y)
+ *win_y = tmp_y;
+
+ return window;
+}
+
+/**
+ * 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
* @stop: ending timestamp for the range of events to return
- * @events: (array length=n_events) (out) (transfer none): location to store a newly-allocated array of #GdkTimeCoord, or %NULL
+ * @events: (array length=n_events) (out) (transfer full): location to store a newly-allocated array of #GdkTimeCoord, or %NULL
* @n_events: location to store the length of @events, or %NULL
*
- * Obtains the motion history for a device; given a starting and
+ * Obtains the motion history for a pointer device; given a starting and
* ending timestamp, return all events in the motion history for
* the device in the given range of time. Some windowing systems
* do not support motion history, in which case, %FALSE will
gint *n_events)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
+ g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, FALSE);
g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
if (n_events)
for (i = 0; i < n_events; i++)
result[i] = g_malloc (sizeof (GdkTimeCoord) -
- sizeof (double) * (GDK_MAX_TIMECOORD_AXES - device->priv->axes->len));
+ sizeof (double) * (GDK_MAX_TIMECOORD_AXES - device->axes->len));
return result;
}
/**
- * gdk_device_free_history:
- * @events: (inout) (transfer none): an array of #GdkTimeCoord.
+ * gdk_device_free_history: (skip)
+ * @events: an array of #GdkTimeCoord.
* @n_events: the length of the array.
*
* Frees an array of #GdkTimeCoord that was returned by gdk_device_get_history().
{
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
- return device->priv->name;
+ return device->name;
}
/**
gdk_device_get_has_cursor (GdkDevice *device)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
+ g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, FALSE);
- return device->priv->has_cursor;
+ return device->has_cursor;
}
/**
{
g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
- return device->priv->source;
-}
-
-/**
- * gdk_device_set_source:
- * @device: a #GdkDevice.
- * @source: the source type.
- *
- * Sets the source type for an input device.
- **/
-void
-gdk_device_set_source (GdkDevice *device,
- GdkInputSource source)
-{
- g_return_if_fail (GDK_IS_DEVICE (device));
-
- device->priv->source = source;
- g_object_notify (G_OBJECT (device), "input-source");
+ return device->source;
}
/**
{
g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
- return device->priv->mode;
+ return device->mode;
}
/**
{
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
- if (device->priv->mode == mode)
+ if (device->mode == mode)
return TRUE;
if (mode == GDK_MODE_DISABLED &&
gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER)
return FALSE;
- /* FIXME: setting has_cursor when mode is window? */
-
- device->priv->mode = mode;
+ device->mode = mode;
g_object_notify (G_OBJECT (device), "input-mode");
- if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
- _gdk_input_check_extension_events (device);
-
return TRUE;
}
*
* Returns: the number of keys.
*
- * Since: 3.0
+ * Since: 2.24
**/
gint
gdk_device_get_n_keys (GdkDevice *device)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
- return device->priv->num_keys;
+ return device->num_keys;
}
/**
* 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.
GdkModifierType *modifiers)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
- g_return_val_if_fail (index_ < device->priv->num_keys, FALSE);
+ g_return_val_if_fail (index_ < device->num_keys, FALSE);
- if (!device->priv->keys[index_].keyval &&
- !device->priv->keys[index_].modifiers)
+ if (!device->keys[index_].keyval &&
+ !device->keys[index_].modifiers)
return FALSE;
if (keyval)
- *keyval = device->priv->keys[index_].keyval;
+ *keyval = device->keys[index_].keyval;
if (modifiers)
- *modifiers = device->priv->keys[index_].modifiers;
+ *modifiers = device->keys[index_].modifiers;
return TRUE;
}
**/
void
gdk_device_set_key (GdkDevice *device,
- guint index_,
- guint keyval,
- GdkModifierType modifiers)
+ guint index_,
+ guint keyval,
+ GdkModifierType modifiers)
{
g_return_if_fail (GDK_IS_DEVICE (device));
- g_return_if_fail (index_ < device->priv->num_keys);
+ g_return_if_fail (index_ < device->num_keys);
- device->priv->keys[index_].keyval = keyval;
- device->priv->keys[index_].modifiers = modifiers;
+ device->keys[index_].keyval = keyval;
+ device->keys[index_].modifiers = modifiers;
}
/**
* gdk_device_get_axis_use:
- * @device: a #GdkDevice.
+ * @device: a pointer #GdkDevice.
* @index_: the index of the axis.
*
* Returns the axis use for @index_.
GdkAxisInfo *info;
g_return_val_if_fail (GDK_IS_DEVICE (device), GDK_AXIS_IGNORE);
- g_return_val_if_fail (index_ < device->priv->axes->len, GDK_AXIS_IGNORE);
+ g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, GDK_AXIS_IGNORE);
+ g_return_val_if_fail (index_ < device->axes->len, GDK_AXIS_IGNORE);
- info = &g_array_index (device->priv->axes, GdkAxisInfo, index_);
+ info = &g_array_index (device->axes, GdkAxisInfo, index_);
return info->use;
}
/**
* gdk_device_set_axis_use:
- * @device: a #GdkDevice
+ * @device: a pointer #GdkDevice
* @index_: the index of the axis
* @use: specifies how the axis is used
*
**/
void
gdk_device_set_axis_use (GdkDevice *device,
- guint index_,
- GdkAxisUse use)
+ guint index_,
+ GdkAxisUse use)
{
- GdkDevicePrivate *priv;
GdkAxisInfo *info;
g_return_if_fail (GDK_IS_DEVICE (device));
- g_return_if_fail (index_ < device->priv->axes->len);
+ g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
+ g_return_if_fail (index_ < device->axes->len);
- priv = device->priv;
- info = &g_array_index (priv->axes, GdkAxisInfo, index_);
+ info = &g_array_index (device->axes, GdkAxisInfo, index_);
info->use = use;
switch (use)
*
* Returns the #GdkDisplay to which @device pertains.
*
- * Returns: a #GdkDisplay. This memory is owned by GTK+,
- * and must not be freed or unreffed.
+ * Returns: (transfer none): a #GdkDisplay. This memory is owned
+ * by GTK+, and must not be freed or unreffed.
*
* Since: 3.0
**/
GdkDisplay *
gdk_device_get_display (GdkDevice *device)
{
- GdkDevicePrivate *priv;
-
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
- priv = device->priv;
-
- return priv->display;
+ return device->display;
}
/**
* If @device is of type %GDK_DEVICE_TYPE_FLOATING, %NULL will be
* returned, as there is no associated device.
*
- * Returns: The associated device, or %NULL
+ * Returns: (transfer none): The associated device, or %NULL
*
* Since: 3.0
**/
GdkDevice *
gdk_device_get_associated_device (GdkDevice *device)
{
- GdkDevicePrivate *priv;
-
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
- priv = device->priv;
+ return device->associated;
+}
+
+static void
+_gdk_device_set_device_type (GdkDevice *device,
+ GdkDeviceType type)
+{
+ if (device->type != type)
+ {
+ device->type = type;
- return priv->associated;
+ g_object_notify (G_OBJECT (device), "type");
+ }
}
void
_gdk_device_set_associated_device (GdkDevice *device,
GdkDevice *associated)
{
- GdkDevicePrivate *priv;
-
g_return_if_fail (GDK_IS_DEVICE (device));
g_return_if_fail (associated == NULL || GDK_IS_DEVICE (associated));
- priv = device->priv;
-
- if (priv->associated == associated)
+ if (device->associated == associated)
return;
- if (priv->associated)
+ if (device->associated)
{
- g_object_unref (priv->associated);
- priv->associated = NULL;
+ g_object_unref (device->associated);
+ device->associated = NULL;
}
if (associated)
- priv->associated = g_object_ref (associated);
+ device->associated = g_object_ref (associated);
+
+ if (device->type != GDK_DEVICE_TYPE_MASTER)
+ {
+ if (device->associated)
+ _gdk_device_set_device_type (device, GDK_DEVICE_TYPE_SLAVE);
+ else
+ _gdk_device_set_device_type (device, GDK_DEVICE_TYPE_FLOATING);
+ }
+}
+
+/**
+ * gdk_device_list_slave_devices:
+ * @device: a #GdkDevice
+ *
+ * If the device if of type %GDK_DEVICE_TYPE_MASTER, it will return
+ * the list of slave devices attached to it, otherwise it will return
+ * %NULL
+ *
+ * Returns: (transfer container) (element-type GdkDevice): the list of
+ * slave devices, or %NULL. The list must be freed with
+ * g_list_free(), the contents of the list are owned by GTK+
+ * and should not be freed.
+ **/
+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);
+
+ return g_list_copy (device->slaves);
+}
+
+void
+_gdk_device_add_slave (GdkDevice *device,
+ GdkDevice *slave)
+{
+ g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
+ g_return_if_fail (gdk_device_get_device_type (slave) != GDK_DEVICE_TYPE_MASTER);
+
+ if (!g_list_find (device->slaves, slave))
+ device->slaves = g_list_prepend (device->slaves, slave);
+}
+
+void
+_gdk_device_remove_slave (GdkDevice *device,
+ GdkDevice *slave)
+{
+ GList *elem;
+
+ g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
+ g_return_if_fail (gdk_device_get_device_type (slave) != GDK_DEVICE_TYPE_MASTER);
+
+ elem = g_list_find (device->slaves, slave);
+
+ if (!elem)
+ return;
+
+ device->slaves = g_list_delete_link (device->slaves, elem);
}
/**
GdkDeviceType
gdk_device_get_device_type (GdkDevice *device)
{
- GdkDevicePrivate *priv;
-
g_return_val_if_fail (GDK_IS_DEVICE (device), GDK_DEVICE_TYPE_MASTER);
- priv = device->priv;
-
- return priv->type;
+ return device->type;
}
/**
* gdk_device_get_n_axes:
- * @device: a #GdkDevice
+ * @device: a pointer #GdkDevice
*
* Returns the number of axes the device currently has.
*
gdk_device_get_n_axes (GdkDevice *device)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
+ g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, 0);
- return device->priv->axes->len;
+ return device->axes->len;
}
/**
* gdk_device_list_axes:
- * @device: a #GdkDevice
+ * @device: a pointer #GdkDevice
*
* Returns a #GList of #GdkAtom<!-- -->s, containing the labels for
* the axes that @device currently has.
GList *
gdk_device_list_axes (GdkDevice *device)
{
- GdkDevicePrivate *priv;
GList *axes = NULL;
gint i;
- priv = device->priv;
+ g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
+ g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
- for (i = 0; i < priv->axes->len; i++)
+ for (i = 0; i < device->axes->len; i++)
{
GdkAxisInfo axis_info;
- axis_info = g_array_index (priv->axes, GdkAxisInfo, i);
+ axis_info = g_array_index (device->axes, GdkAxisInfo, i);
axes = g_list_prepend (axes, GDK_ATOM_TO_POINTER (axis_info.label));
}
}
/**
- * gdk_device_get_axis_value:
- * @device: a #GdkDevice.
- * @axes: pointer to an array of axes
+ * gdk_device_get_axis_value: (skip)
+ * @device: a pointer #GdkDevice.
+ * @axes: (array): pointer to an array of axes
* @axis_label: #GdkAtom with the axis label.
* @value: location to store the found value.
*
GdkAtom axis_label,
gdouble *value)
{
- GdkDevicePrivate *priv;
gint i;
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
+ g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, FALSE);
if (axes == NULL)
return FALSE;
- priv = device->priv;
-
- for (i = 0; i < priv->axes->len; i++)
+ for (i = 0; i < device->axes->len; i++)
{
GdkAxisInfo axis_info;
- axis_info = g_array_index (priv->axes, GdkAxisInfo, i);
+ axis_info = g_array_index (device->axes, GdkAxisInfo, i);
if (axis_info.label != axis_label)
continue;
}
/**
- * 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.
GdkAxisUse use,
gdouble *value)
{
- GdkDevicePrivate *priv;
gint i;
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
+ g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, FALSE);
if (axes == NULL)
return FALSE;
- priv = device->priv;
-
- g_return_val_if_fail (priv->axes != NULL, FALSE);
+ g_return_val_if_fail (device->axes != NULL, FALSE);
- for (i = 0; i < priv->axes->len; i++)
+ for (i = 0; i < device->axes->len; i++)
{
GdkAxisInfo axis_info;
- axis_info = g_array_index (priv->axes, GdkAxisInfo, i);
+ axis_info = g_array_index (device->axes, GdkAxisInfo, i);
if (axis_info.use != use)
continue;
/**
* gdk_device_grab:
- * @device: a #GdkDevice
+ * @device: a #GdkDevice. To get the device you can use gtk_get_current_event_device()
+ * or gdk_event_get_device() if the grab is in reaction to an event. Also, you can use
+ * gdk_device_manager_get_client_pointer() but only in code that isn't triggered by a
+ * #GdkEvent and there aren't other means to get a meaningful #GdkDevice to operate on.
* @window: the #GdkWindow which will own the grab (the grab window)
* @grab_ownership: specifies the grab ownership.
* @owner_events: if %FALSE then all device events are reported with respect to
* @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.
GdkGrabStatus res;
GdkWindow *native;
- g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
- g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
+ 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 (((GdkWindowObject *) native)->window_type == GDK_WINDOW_OFFSCREEN)
+ while (native->window_type == GDK_WINDOW_OFFSCREEN)
{
native = gdk_offscreen_window_get_embedder (native);
if (native == NULL ||
- (!_gdk_window_has_impl (native) &&
- !gdk_window_is_viewable (native)))
- return GDK_GRAB_NOT_VIEWABLE;
+ (!_gdk_window_has_impl (native) &&
+ !gdk_window_is_viewable (native)))
+ return GDK_GRAB_NOT_VIEWABLE;
native = gdk_window_get_toplevel (native);
}
- res = _gdk_windowing_device_grab (device,
- window,
- native,
- owner_events,
- get_native_grab_event_mask (event_mask),
- NULL,
- cursor,
- time_);
+ if (native == NULL || GDK_WINDOW_DESTROYED (native))
+ return GDK_GRAB_NOT_VIEWABLE;
+
+ res = GDK_DEVICE_GET_CLASS (device)->grab (device,
+ native,
+ owner_events,
+ get_native_grab_event_mask (event_mask),
+ NULL,
+ cursor,
+ time_);
if (res == GDK_GRAB_SUCCESS)
{
gulong serial;
display = gdk_window_get_display (window);
- serial = _gdk_windowing_window_get_next_serial (display);
+ serial = _gdk_display_get_next_serial (display);
_gdk_display_add_device_grab (display,
device,
return res;
}
+/**
+ * gdk_device_ungrab:
+ * @device: a #GdkDevice
+ * @time_: a timestap (e.g. %GDK_CURRENT_TIME).
+ *
+ * Release any grab on @device.
+ *
+ * Since: 3.0
+ */
+void
+gdk_device_ungrab (GdkDevice *device,
+ guint32 time_)
+{
+ g_return_if_fail (GDK_IS_DEVICE (device));
+
+ GDK_DEVICE_GET_CLASS (device)->ungrab (device, time_);
+}
+
+/**
+ * gdk_device_warp:
+ * @device: the device to warp.
+ * @screen: the screen to warp @device to.
+ * @x: the X coordinate of the destination.
+ * @y: the Y coordinate of the destination.
+ *
+ * Warps @device in @display to the point @x,@y on
+ * the screen @screen, unless the device is confined
+ * to a window by a grab, in which case it will be moved
+ * as far as allowed by the grab. Warping the pointer
+ * creates events as if the user had moved the mouse
+ * instantaneously to the destination.
+ *
+ * Note that the pointer should normally be under the
+ * control of the user. This function was added to cover
+ * some rare use cases like keyboard navigation support
+ * for the color picker in the #GtkColorSelectionDialog.
+ *
+ * Since: 3.0
+ **/
+void
+gdk_device_warp (GdkDevice *device,
+ GdkScreen *screen,
+ gint x,
+ gint y)
+{
+ g_return_if_fail (GDK_IS_DEVICE (device));
+ g_return_if_fail (GDK_IS_SCREEN (screen));
+ g_return_if_fail (gdk_device_get_display (device) == gdk_screen_get_display (screen));
+
+ GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
+}
+
/* Private API */
void
_gdk_device_reset_axes (GdkDevice *device)
{
- GdkDevicePrivate *priv;
gint i;
- priv = device->priv;
-
- for (i = priv->axes->len - 1; i >= 0; i--)
- g_array_remove_index (priv->axes, i);
+ for (i = device->axes->len - 1; i >= 0; i--)
+ g_array_remove_index (device->axes, i);
g_object_notify (G_OBJECT (device), "n-axes");
}
gdouble max_value,
gdouble resolution)
{
- GdkDevicePrivate *priv;
GdkAxisInfo axis_info;
guint pos;
- priv = device->priv;
-
axis_info.use = use;
axis_info.label = label_atom;
axis_info.min_value = min_value;
break;
}
- priv->axes = g_array_append_val (priv->axes, axis_info);
- pos = device->priv->axes->len - 1;
+ device->axes = g_array_append_val (device->axes, axis_info);
+ pos = device->axes->len - 1;
g_object_notify (G_OBJECT (device), "n-axes");
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)
{
- if (device->priv->keys)
- g_free (device->priv->keys);
+ if (device->keys)
+ g_free (device->keys);
- device->priv->num_keys = num_keys;
- device->priv->keys = g_new0 (GdkDeviceKey, num_keys);
+ device->num_keys = num_keys;
+ device->keys = g_new0 (GdkDeviceKey, num_keys);
}
static GdkAxisInfo *
return NULL;
}
-GdkAxisUse
-_gdk_device_get_axis_use (GdkDevice *device,
- guint index_)
-{
- GdkDevicePrivate *priv;
- GdkAxisInfo info;
-
- priv = device->priv;
-
- info = g_array_index (priv->axes, GdkAxisInfo, index_);
- return info.use;
-}
-
gboolean
_gdk_device_translate_window_coord (GdkDevice *device,
GdkWindow *window,
gdouble value,
gdouble *axis_value)
{
- GdkDevicePrivate *priv;
GdkAxisInfo axis_info;
GdkAxisInfo *axis_info_x, *axis_info_y;
gdouble device_width, device_height;
gdouble x_resolution, y_resolution;
gdouble device_aspect;
gint window_width, window_height;
- GdkWindowObject *window_private;
-
- priv = device->priv;
- if (index_ >= priv->axes->len)
+ if (index_ >= device->axes->len)
return FALSE;
- axis_info = g_array_index (priv->axes, GdkAxisInfo, index_);
+ axis_info = g_array_index (device->axes, GdkAxisInfo, index_);
if (axis_info.use != GDK_AXIS_X &&
axis_info.use != GDK_AXIS_Y)
if (axis_info.use == GDK_AXIS_X)
{
axis_info_x = &axis_info;
- axis_info_y = find_axis_info (priv->axes, GDK_AXIS_Y);
+ axis_info_y = find_axis_info (device->axes, GDK_AXIS_Y);
}
else
{
- axis_info_x = find_axis_info (priv->axes, GDK_AXIS_X);
+ axis_info_x = find_axis_info (device->axes, GDK_AXIS_X);
axis_info_y = &axis_info;
}
y_min = 0;
}
- window_private = (GdkWindowObject *) window;
window_width = gdk_window_get_width (window);
window_height = gdk_window_get_height (window);
gdouble value,
gdouble *axis_value)
{
- GdkDevicePrivate *priv = device->priv;
GdkAxisInfo axis_info;
gdouble axis_width, scale, offset;
- GdkWindowObject *window_private;
- if (priv->mode != GDK_MODE_SCREEN)
+ if (device->mode != GDK_MODE_SCREEN)
return FALSE;
- if (index_ >= priv->axes->len)
+ if (index_ >= device->axes->len)
return FALSE;
- axis_info = g_array_index (priv->axes, GdkAxisInfo, index_);
+ axis_info = g_array_index (device->axes, GdkAxisInfo, index_);
if (axis_info.use != GDK_AXIS_X &&
axis_info.use != GDK_AXIS_Y)
return FALSE;
axis_width = axis_info.max_value - axis_info.min_value;
- window_private = (GdkWindowObject *) window;
if (axis_info.use == GDK_AXIS_X)
{
else
scale = 1;
- offset = - window_root_x - window_private->abs_x;
+ offset = - window_root_x - window->abs_x;
}
else
{
else
scale = 1;
- offset = - window_root_y - window_private->abs_y;
+ offset = - window_root_y - window->abs_y;
}
if (axis_value)
gdouble value,
gdouble *axis_value)
{
- GdkDevicePrivate *priv;
GdkAxisInfo axis_info;
gdouble axis_width, out;
- priv = device->priv;
-
- if (index_ >= priv->axes->len)
+ if (index_ >= device->axes->len)
return FALSE;
- axis_info = g_array_index (priv->axes, GdkAxisInfo, index_);
+ axis_info = g_array_index (device->axes, GdkAxisInfo, index_);
if (axis_info.use == GDK_AXIS_X ||
axis_info.use == GDK_AXIS_Y)
return TRUE;
}
+
+void
+_gdk_device_query_state (GdkDevice *device,
+ GdkWindow *window,
+ GdkWindow **root_window,
+ GdkWindow **child_window,
+ gint *root_x,
+ gint *root_y,
+ gint *win_x,
+ gint *win_y,
+ GdkModifierType *mask)
+{
+ GDK_DEVICE_GET_CLASS (device)->query_state (device,
+ window,
+ root_window,
+ child_window,
+ root_x,
+ root_y,
+ win_x,
+ win_y,
+ mask);
+}
+
+GdkWindow *
+_gdk_device_window_at_position (GdkDevice *device,
+ gint *win_x,
+ gint *win_y,
+ GdkModifierType *mask,
+ gboolean get_toplevel)
+{
+ return GDK_DEVICE_GET_CLASS (device)->window_at_position (device,
+ win_x,
+ win_y,
+ mask,
+ get_toplevel);
+}