forked from AuroraMiddleware/gtk
gtkcolorplane: Stop using ::key-press-event
Use GtkEventControllerKey for the task
This commit is contained in:
parent
5081472d97
commit
6f4107c8de
@ -27,6 +27,7 @@
|
|||||||
#include "gtkintl.h"
|
#include "gtkintl.h"
|
||||||
#include "gtksnapshot.h"
|
#include "gtksnapshot.h"
|
||||||
#include "gtkprivate.h"
|
#include "gtkprivate.h"
|
||||||
|
#include "gtkeventcontrollerkey.h"
|
||||||
|
|
||||||
struct _GtkColorPlanePrivate
|
struct _GtkColorPlanePrivate
|
||||||
{
|
{
|
||||||
@ -38,6 +39,7 @@ struct _GtkColorPlanePrivate
|
|||||||
|
|
||||||
GtkGesture *drag_gesture;
|
GtkGesture *drag_gesture;
|
||||||
GtkGesture *long_press_gesture;
|
GtkGesture *long_press_gesture;
|
||||||
|
GtkEventController *key_controller;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -308,16 +310,14 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
plane_key_press (GtkWidget *widget,
|
key_controller_key_pressed (GtkEventControllerKey *controller,
|
||||||
GdkEventKey *event)
|
guint keyval,
|
||||||
|
guint keycode,
|
||||||
|
GdkModifierType state,
|
||||||
|
GtkWidget *widget)
|
||||||
{
|
{
|
||||||
GtkColorPlane *plane = GTK_COLOR_PLANE (widget);
|
GtkColorPlane *plane = GTK_COLOR_PLANE (widget);
|
||||||
gdouble step;
|
gdouble step;
|
||||||
guint keyval, state;
|
|
||||||
|
|
||||||
if (!gdk_event_get_keyval ((GdkEvent *) event, &keyval) ||
|
|
||||||
!gdk_event_get_state ((GdkEvent *) event, &state))
|
|
||||||
return GDK_EVENT_PROPAGATE;
|
|
||||||
|
|
||||||
if ((state & GDK_MOD1_MASK) != 0)
|
if ((state & GDK_MOD1_MASK) != 0)
|
||||||
step = 0.1;
|
step = 0.1;
|
||||||
@ -337,7 +337,7 @@ plane_key_press (GtkWidget *widget,
|
|||||||
keyval == GDK_KEY_KP_Right)
|
keyval == GDK_KEY_KP_Right)
|
||||||
sv_move (plane, 0, step);
|
sv_move (plane, 0, step);
|
||||||
else
|
else
|
||||||
return GTK_WIDGET_CLASS (gtk_color_plane_parent_class)->key_press_event (widget, event);
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -424,6 +424,10 @@ gtk_color_plane_init (GtkColorPlane *plane)
|
|||||||
G_CALLBACK (hold_action), plane);
|
G_CALLBACK (hold_action), plane);
|
||||||
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (plane->priv->long_press_gesture),
|
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (plane->priv->long_press_gesture),
|
||||||
TRUE);
|
TRUE);
|
||||||
|
|
||||||
|
plane->priv->key_controller = gtk_event_controller_key_new (GTK_WIDGET (plane));
|
||||||
|
g_signal_connect (plane->priv->key_controller, "key-pressed",
|
||||||
|
G_CALLBACK (key_controller_key_pressed), plane);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -439,6 +443,7 @@ plane_finalize (GObject *object)
|
|||||||
|
|
||||||
g_clear_object (&plane->priv->drag_gesture);
|
g_clear_object (&plane->priv->drag_gesture);
|
||||||
g_clear_object (&plane->priv->long_press_gesture);
|
g_clear_object (&plane->priv->long_press_gesture);
|
||||||
|
g_clear_object (&plane->priv->key_controller);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gtk_color_plane_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gtk_color_plane_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
@ -500,7 +505,6 @@ gtk_color_plane_class_init (GtkColorPlaneClass *class)
|
|||||||
widget_class->size_allocate = plane_size_allocate;
|
widget_class->size_allocate = plane_size_allocate;
|
||||||
widget_class->realize = plane_realize;
|
widget_class->realize = plane_realize;
|
||||||
widget_class->unrealize = plane_unrealize;
|
widget_class->unrealize = plane_unrealize;
|
||||||
widget_class->key_press_event = plane_key_press;
|
|
||||||
|
|
||||||
g_object_class_install_property (object_class,
|
g_object_class_install_property (object_class,
|
||||||
PROP_H_ADJUSTMENT,
|
PROP_H_ADJUSTMENT,
|
||||||
|
Loading…
Reference in New Issue
Block a user