2016-04-09 19:20:07 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
* Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "gdkdevicetoolprivate.h"
|
2021-09-24 19:11:00 +00:00
|
|
|
#include "gdkenumtypes.h"
|
2022-09-24 03:33:42 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2016-04-09 19:20:07 +00:00
|
|
|
|
2021-02-21 05:13:57 +00:00
|
|
|
/**
|
|
|
|
* GdkDeviceTool:
|
|
|
|
*
|
|
|
|
* A physical tool associated to a `GdkDevice`.
|
|
|
|
*/
|
2016-04-09 19:20:07 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (GdkDeviceTool, gdk_device_tool, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TOOL_PROP_0,
|
|
|
|
TOOL_PROP_SERIAL,
|
|
|
|
TOOL_PROP_TOOL_TYPE,
|
|
|
|
TOOL_PROP_AXES,
|
2016-08-04 16:49:13 +00:00
|
|
|
TOOL_PROP_HARDWARE_ID,
|
2016-04-09 19:20:07 +00:00
|
|
|
N_TOOL_PROPS
|
|
|
|
};
|
|
|
|
|
|
|
|
GParamSpec *tool_props[N_TOOL_PROPS] = { 0 };
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_device_tool_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdkDeviceTool *tool = GDK_DEVICE_TOOL (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case TOOL_PROP_SERIAL:
|
|
|
|
tool->serial = g_value_get_uint64 (value);
|
|
|
|
break;
|
|
|
|
case TOOL_PROP_TOOL_TYPE:
|
|
|
|
tool->type = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case TOOL_PROP_AXES:
|
|
|
|
tool->tool_axes = g_value_get_flags (value);
|
|
|
|
break;
|
2016-08-04 16:49:13 +00:00
|
|
|
case TOOL_PROP_HARDWARE_ID:
|
|
|
|
tool->hw_id = g_value_get_uint64 (value);
|
|
|
|
break;
|
2016-04-09 19:20:07 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_device_tool_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdkDeviceTool *tool = GDK_DEVICE_TOOL (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case TOOL_PROP_SERIAL:
|
|
|
|
g_value_set_uint64 (value, tool->serial);
|
|
|
|
break;
|
|
|
|
case TOOL_PROP_TOOL_TYPE:
|
|
|
|
g_value_set_enum (value, tool->type);
|
|
|
|
break;
|
|
|
|
case TOOL_PROP_AXES:
|
|
|
|
g_value_set_flags (value, tool->tool_axes);
|
|
|
|
break;
|
2016-08-04 16:49:13 +00:00
|
|
|
case TOOL_PROP_HARDWARE_ID:
|
|
|
|
g_value_set_uint64 (value, tool->hw_id);
|
|
|
|
break;
|
2016-04-09 19:20:07 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_device_tool_class_init (GdkDeviceToolClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->set_property = gdk_device_tool_set_property;
|
|
|
|
object_class->get_property = gdk_device_tool_get_property;
|
|
|
|
|
2021-02-21 05:13:57 +00:00
|
|
|
/**
|
2021-02-25 01:02:33 +00:00
|
|
|
* GdkDeviceTool:serial: (attributes org.gtk.Property.get=gdk_device_tool_get_serial)
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
|
|
|
* The serial number of the tool.
|
|
|
|
*/
|
2022-05-11 12:19:39 +00:00
|
|
|
tool_props[TOOL_PROP_SERIAL] = g_param_spec_uint64 ("serial", NULL, NULL,
|
2016-04-09 19:20:07 +00:00
|
|
|
0, G_MAXUINT64, 0,
|
|
|
|
G_PARAM_READWRITE |
|
2017-11-18 02:38:08 +00:00
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2021-02-21 05:13:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 01:02:33 +00:00
|
|
|
* GdkDeviceTool:tool-type: (attributes org.gtk.Property.get=gdk_device_tool_get_tool_type)
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
|
|
|
* The type of the tool.
|
|
|
|
*/
|
2022-05-11 12:19:39 +00:00
|
|
|
tool_props[TOOL_PROP_TOOL_TYPE] = g_param_spec_enum ("tool-type", NULL, NULL,
|
2016-04-09 19:20:07 +00:00
|
|
|
GDK_TYPE_DEVICE_TOOL_TYPE,
|
|
|
|
GDK_DEVICE_TOOL_TYPE_UNKNOWN,
|
|
|
|
G_PARAM_READWRITE |
|
2017-11-18 02:38:08 +00:00
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2021-02-21 05:13:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 01:02:33 +00:00
|
|
|
* GdkDeviceTool:axes: (attributes org.gtk.Property.get=gdk_device_tool_get_axes)
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
|
|
|
* The axes of the tool.
|
|
|
|
*/
|
2022-05-11 12:19:39 +00:00
|
|
|
tool_props[TOOL_PROP_AXES] = g_param_spec_flags ("axes", NULL, NULL,
|
2016-04-09 19:20:07 +00:00
|
|
|
GDK_TYPE_AXIS_FLAGS, 0,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
2021-02-21 05:13:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 01:02:33 +00:00
|
|
|
* GdkDeviceTool:hardware-id: (attributes org.gtk.Property.get=gdk_device_tool_get_hardware_id)
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
|
|
|
* The hardware ID of the tool.
|
|
|
|
*/
|
2022-05-11 12:19:39 +00:00
|
|
|
tool_props[TOOL_PROP_HARDWARE_ID] = g_param_spec_uint64 ("hardware-id", NULL, NULL,
|
2016-08-04 16:49:13 +00:00
|
|
|
0, G_MAXUINT64, 0,
|
|
|
|
G_PARAM_READWRITE |
|
2017-11-18 02:38:08 +00:00
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2016-04-09 19:20:07 +00:00
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, N_TOOL_PROPS, tool_props);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_device_tool_init (GdkDeviceTool *tool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkDeviceTool *
|
|
|
|
gdk_device_tool_new (guint64 serial,
|
2016-08-04 16:52:51 +00:00
|
|
|
guint64 hw_id,
|
2016-04-09 19:20:07 +00:00
|
|
|
GdkDeviceToolType type,
|
|
|
|
GdkAxisFlags tool_axes)
|
|
|
|
{
|
|
|
|
return g_object_new (GDK_TYPE_DEVICE_TOOL,
|
|
|
|
"serial", serial,
|
2016-08-04 16:52:51 +00:00
|
|
|
"hardware-id", hw_id,
|
2016-04-09 19:20:07 +00:00
|
|
|
"tool-type", type,
|
|
|
|
"axes", tool_axes,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 01:02:33 +00:00
|
|
|
* gdk_device_tool_get_serial: (attributes org.gtk.Method.get_property=serial)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @tool: a `GdkDeviceTool`
|
2016-04-09 19:20:07 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Gets the serial number of this tool.
|
|
|
|
*
|
|
|
|
* This value can be used to identify a physical tool
|
|
|
|
* (eg. a tablet pen) across program executions.
|
2016-04-09 19:20:07 +00:00
|
|
|
*
|
|
|
|
* Returns: The serial ID for this tool
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2016-08-04 16:44:36 +00:00
|
|
|
guint64
|
2016-04-09 19:20:07 +00:00
|
|
|
gdk_device_tool_get_serial (GdkDeviceTool *tool)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (tool != NULL, 0);
|
|
|
|
|
|
|
|
return tool->serial;
|
|
|
|
}
|
|
|
|
|
2016-08-04 16:49:13 +00:00
|
|
|
/**
|
2021-02-25 01:02:33 +00:00
|
|
|
* gdk_device_tool_get_hardware_id: (attributes org.gtk.Method.get_property=hardware-id)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @tool: a `GdkDeviceTool`
|
|
|
|
*
|
|
|
|
* Gets the hardware ID of this tool, or 0 if it's not known.
|
2016-08-04 16:49:13 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* When non-zero, the identificator is unique for the given tool model,
|
2016-08-04 16:49:13 +00:00
|
|
|
* meaning that two identical tools will share the same @hardware_id,
|
2021-02-21 05:13:57 +00:00
|
|
|
* but will have different serial numbers (see
|
|
|
|
* [method@Gdk.DeviceTool.get_serial]).
|
2016-08-04 16:49:13 +00:00
|
|
|
*
|
|
|
|
* This is a more concrete (and device specific) method to identify
|
2021-02-21 05:13:57 +00:00
|
|
|
* a `GdkDeviceTool` than [method@Gdk.DeviceTool.get_tool_type],
|
|
|
|
* as a tablet may support multiple devices with the same
|
|
|
|
* `GdkDeviceToolType`, but different hardware identificators.
|
2016-08-04 16:49:13 +00:00
|
|
|
*
|
|
|
|
* Returns: The hardware identificator of this tool.
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2016-08-04 16:49:13 +00:00
|
|
|
guint64
|
|
|
|
gdk_device_tool_get_hardware_id (GdkDeviceTool *tool)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (tool != NULL, 0);
|
|
|
|
|
|
|
|
return tool->hw_id;
|
|
|
|
}
|
|
|
|
|
2016-04-09 19:20:07 +00:00
|
|
|
/**
|
2021-02-25 01:02:33 +00:00
|
|
|
* gdk_device_tool_get_tool_type: (attributes org.gtk.Method.get_property=tool-type)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @tool: a `GdkDeviceTool`
|
2016-04-09 19:20:07 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Gets the `GdkDeviceToolType` of the tool.
|
2016-04-09 19:20:07 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Returns: The physical type for this tool. This can be used to
|
|
|
|
* figure out what sort of pen is being used, such as an airbrush
|
|
|
|
* or a pencil.
|
|
|
|
*/
|
2016-04-09 19:20:07 +00:00
|
|
|
GdkDeviceToolType
|
|
|
|
gdk_device_tool_get_tool_type (GdkDeviceTool *tool)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (tool != NULL, GDK_DEVICE_TOOL_TYPE_UNKNOWN);
|
|
|
|
|
|
|
|
return tool->type;
|
|
|
|
}
|
2020-07-28 14:31:54 +00:00
|
|
|
|
2020-07-29 01:58:06 +00:00
|
|
|
/**
|
2021-02-25 01:02:33 +00:00
|
|
|
* gdk_device_tool_get_axes: (attributes org.gtk.Method.get_property=axes)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @tool: a `GdkDeviceTool`
|
2020-07-29 01:58:06 +00:00
|
|
|
*
|
|
|
|
* Gets the axes of the tool.
|
|
|
|
*
|
|
|
|
* Returns: the axes of @tool
|
|
|
|
*/
|
2020-07-28 14:31:54 +00:00
|
|
|
GdkAxisFlags
|
|
|
|
gdk_device_tool_get_axes (GdkDeviceTool *tool)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (tool != NULL, 0);
|
|
|
|
|
|
|
|
return tool->tool_axes;
|
|
|
|
}
|