Unverified Commit 3444ce5b authored by Florian "SpiritCS / sp1ritCS"'s avatar Florian "SpiritCS / sp1ritCS"
Browse files

gtk: gtkgesturestylus: implemented `anydev` property

this allows setting a Gtk.GestureStylus to a state, where it can be
used to handle non-stylus devices (e.g. mice).
This might be useful for applications that handle stylus input, but
want to allow falling back to a mice, if the user is unable to provide
stylus input.
parent 48f21994
Pipeline #395926 passed with stages
in 11 minutes and 46 seconds
......@@ -35,7 +35,16 @@
#include "gtkmain.h"
#include "gtknative.h"
G_DEFINE_TYPE (GtkGestureStylus, gtk_gesture_stylus, GTK_TYPE_GESTURE_SINGLE)
typedef struct {
gboolean anydev;
} GtkGestureStylusPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GtkGestureStylus, gtk_gesture_stylus, GTK_TYPE_GESTURE_SINGLE)
enum {
PROP_ANYDEV = 1,
N_PROPERTIES
};
enum {
PROXIMITY,
......@@ -45,20 +54,55 @@ enum {
N_SIGNALS
};
static GParamSpec* obj_properties[N_PROPERTIES] = { NULL, };
static guint signals[N_SIGNALS] = { 0, };
static void gtk_gesture_stylus_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec)
{
GtkGestureStylus* gesture = GTK_GESTURE_STYLUS(object);
switch (prop_id) {
case PROP_ANYDEV:
g_value_set_boolean(value, gtk_gesture_stylus_get_anydevice(gesture));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void gtk_gesture_stylus_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec)
{
GtkGestureStylus* gesture = GTK_GESTURE_STYLUS(object);
switch (prop_id) {
case PROP_ANYDEV:
gtk_gesture_stylus_set_anydevice(gesture, g_value_get_boolean(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static gboolean
gtk_gesture_stylus_handle_event (GtkEventController *controller,
GdkEvent *event,
double x,
double y)
{
GtkGestureStylusPrivate* priv;
GdkModifierType modifiers;
guint n_signal;
priv = gtk_gesture_stylus_get_instance_private(GTK_GESTURE_STYLUS(controller));
GTK_EVENT_CONTROLLER_CLASS (gtk_gesture_stylus_parent_class)->handle_event (controller, event, x, y);
if (!gdk_event_get_device_tool (event))
if (!(priv->anydev || gdk_event_get_device_tool (event)))
return FALSE;
switch ((guint) gdk_event_get_event_type (event))
......@@ -89,8 +133,25 @@ gtk_gesture_stylus_handle_event (GtkEventController *controller,
static void
gtk_gesture_stylus_class_init (GtkGestureStylusClass *klass)
{
GObjectClass* object_class;
GtkEventControllerClass *event_controller_class;
object_class = G_OBJECT_CLASS (klass);
object_class->get_property = gtk_gesture_stylus_get_property;
object_class->set_property = gtk_gesture_stylus_set_property;
/**
* GtkGestureStylus:anydevice: (attributes org.gtk.Property.get=gtk_gesture_stylus_get_anydevice org.gtk.Property.set=gtk_gesture_stylus_set_anydevice)
*
* If this gesture should also signal events from non-stylus devices. (e.g. mice)
*/
obj_properties[PROP_ANYDEV] = g_param_spec_boolean("anydevice",
P_("Any Device"),
P_("Should this gesture also signal events from non-stylus devices."),
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_CONSTRUCT);
g_object_class_install_properties(object_class, N_PROPERTIES, obj_properties);
event_controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
event_controller_class->handle_event = gtk_gesture_stylus_handle_event;
......@@ -178,6 +239,9 @@ gtk_gesture_stylus_class_init (GtkGestureStylusClass *klass)
static void
gtk_gesture_stylus_init (GtkGestureStylus *gesture)
{
GtkGestureStylusPrivate* priv = gtk_gesture_stylus_get_instance_private(gesture);
priv->anydev = FALSE;
}
/**
......@@ -194,6 +258,53 @@ gtk_gesture_stylus_new (void)
NULL);
}
/**
* gtk_gesture_stylus_get_anydevice: (attributes org.gtk.Method.get_property=anydevice)
* @gesture: A `GtkGestureStylus`
*
* gets the state of anydevice, based on which the gesture will
* either exclusively signal events from stylus input devices or
* for any input devices (e.g. mice).
*
* Returns: The state of anydevice set via [method@Gtk.GestureStylus.set_anydevice]
*/
gboolean
gtk_gesture_stylus_get_anydevice(GtkGestureStylus* gesture) {
GtkGestureStylusPrivate* priv;
g_return_val_if_fail(GTK_IS_GESTURE_STYLUS(gesture), FALSE);
priv = gtk_gesture_stylus_get_instance_private(gesture);
return priv->anydev;
}
/**
* gtk_gesture_stylus_set_anydevice: (attributes org.gtk.Method.set_property=anydevice)
* @gesture: A `GtkGestureStylus`
* @anydev: %TRUE if the gesture should process events from any input device
*
* sets the state of anydevice
*
* If true, the gesture will handle events from any input deivce,
* otherwise it'll handle events from styluses exclusively.
*/
void
gtk_gesture_stylus_set_anydevice(GtkGestureStylus* gesture, gboolean anydev) {
GtkGestureStylusPrivate* priv;
g_return_if_fail(GTK_IS_GESTURE_STYLUS(gesture));
priv = gtk_gesture_stylus_get_instance_private(gesture);
if (priv->anydev == anydev)
return;
priv->anydev = anydev;
g_object_notify_by_pspec (G_OBJECT (gesture), obj_properties[PROP_ANYDEV]);
}
/**
* gtk_gesture_stylus_get_axis:
* @gesture: a `GtkGestureStylus`
......
......@@ -43,6 +43,12 @@ GType gtk_gesture_stylus_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkGesture * gtk_gesture_stylus_new (void);
GDK_AVAILABLE_IN_4_8
gboolean gtk_gesture_stylus_get_anydevice (GtkGestureStylus* gesture);
GDK_AVAILABLE_IN_4_8
void gtk_gesture_stylus_set_anydevice (GtkGestureStylus* gesture,
gboolean anydev);
GDK_AVAILABLE_IN_ALL
gboolean gtk_gesture_stylus_get_axis (GtkGestureStylus *gesture,
GdkAxisUse axis,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment