events: Add gdk_event_[gs]et_device_tool()

This getter/setter will manage the tool pointer in GdkEventPrivate. The
setter should be most notably used by backends.
This commit is contained in:
Carlos Garnacho 2015-01-06 14:52:42 +01:00
parent 5a25c5a9f2
commit 6d73e75153
4 changed files with 62 additions and 0 deletions

View File

@ -888,6 +888,8 @@ gdk_event_get_device
gdk_event_set_device
gdk_event_get_source_device
gdk_event_set_source_device
gdk_event_get_device_tool
gdk_event_set_device_tool
<SUBSECTION>
gdk_setting_get

View File

@ -650,6 +650,7 @@ gdk_event_copy (const GdkEvent *event)
new_private->device = private->device ? g_object_ref (private->device) : NULL;
new_private->source_device = private->source_device ? g_object_ref (private->source_device) : NULL;
new_private->seat = private->seat;
new_private->tool = private->tool;
}
switch (event->any.type)
@ -2412,3 +2413,54 @@ gdk_event_set_seat (GdkEvent *event,
priv->seat = seat;
}
}
/**
* gdk_event_get_device_tool:
* @event: a #GdkEvent
*
* If the event was generated by a device that supports
* different tools (eg. a tablet), this function will
* return a #GdkDeviceTool representing the tool that
* caused the event. Otherwise, %NULL will be returned.
*
* Note: the #GdkDeviceTool<!-- -->s will be constant during
* the application lifetime, if settings must be stored
* persistently across runs, see gdk_device_tool_get_serial()
*
* Returns: (transfer none): The current device tool, or %NULL
*
* Since: 3.22
**/
GdkDeviceTool *
gdk_event_get_device_tool (const GdkEvent *event)
{
GdkEventPrivate *private;
if (!gdk_event_is_allocated (event))
return NULL;
private = (GdkEventPrivate *) event;
return private->tool;
}
/**
* gdk_event_set_device_tool:
* @event: a #GdkEvent
* @tool: (nullable): tool to set on the event, or %NULL
*
* Sets the device tool for this event, should be rarely used.
*
* Since: 3.22
**/
void
gdk_event_set_device_tool (GdkEvent *event,
GdkDeviceTool *tool)
{
GdkEventPrivate *private;
if (!gdk_event_is_allocated (event))
return;
private = (GdkEventPrivate *) event;
private->tool = tool;
}

View File

@ -1443,6 +1443,13 @@ GDK_AVAILABLE_IN_ALL
gboolean gdk_setting_get (const gchar *name,
GValue *value);
GDK_AVAILABLE_IN_3_16
GdkDeviceTool *gdk_event_get_device_tool (const GdkEvent *event);
GDK_AVAILABLE_IN_3_16
void gdk_event_set_device_tool (GdkEvent *event,
GdkDeviceTool *tool);
G_END_DECLS
#endif /* __GDK_EVENTS_H__ */

View File

@ -189,6 +189,7 @@ struct _GdkEventPrivate
GdkDevice *device;
GdkDevice *source_device;
GdkSeat *seat;
GdkDeviceTool *tool;
};
typedef struct _GdkWindowPaint GdkWindowPaint;