Compare commits
6 Commits
event-sour
...
wip/matthi
Author | SHA1 | Date | |
---|---|---|---|
|
a0df3ac544 | ||
|
6dde66d4d8 | ||
|
3e2363eb03 | ||
|
d66ba60128 | ||
|
e52675206b | ||
|
1521bdbaa7 |
@@ -93,6 +93,7 @@
|
|||||||
#include <gtk/gtkentrycompletion.h>
|
#include <gtk/gtkentrycompletion.h>
|
||||||
#include <gtk/gtkenums.h>
|
#include <gtk/gtkenums.h>
|
||||||
#include <gtk/gtkeventcontroller.h>
|
#include <gtk/gtkeventcontroller.h>
|
||||||
|
#include <gtk/gtkeventcontrollermotion.h>
|
||||||
#include <gtk/gtkeventcontrollerscroll.h>
|
#include <gtk/gtkeventcontrollerscroll.h>
|
||||||
#include <gtk/gtkexpander.h>
|
#include <gtk/gtkexpander.h>
|
||||||
#include <gtk/gtkfixed.h>
|
#include <gtk/gtkfixed.h>
|
||||||
|
@@ -59,6 +59,8 @@
|
|||||||
#include "gtkprivate.h"
|
#include "gtkprivate.h"
|
||||||
#include "gtkintl.h"
|
#include "gtkintl.h"
|
||||||
#include "gtkdialogprivate.h"
|
#include "gtkdialogprivate.h"
|
||||||
|
#include "gtkeventcontrollermotion.h"
|
||||||
|
#include "gtkgesturemultipress.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -181,6 +183,11 @@ struct _GtkAboutDialogPrivate
|
|||||||
|
|
||||||
GSList *visited_links;
|
GSList *visited_links;
|
||||||
|
|
||||||
|
GtkGesture *license_press;
|
||||||
|
GtkGesture *system_press;
|
||||||
|
GtkEventController *license_motion;
|
||||||
|
GtkEventController *system_motion;
|
||||||
|
|
||||||
GtkLicense license_type;
|
GtkLicense license_type;
|
||||||
|
|
||||||
guint hovering_over_link : 1;
|
guint hovering_over_link : 1;
|
||||||
@@ -227,7 +234,6 @@ static void follow_if_link (GtkAboutDialog
|
|||||||
GtkTextIter *iter);
|
GtkTextIter *iter);
|
||||||
static void set_cursor_if_appropriate (GtkAboutDialog *about,
|
static void set_cursor_if_appropriate (GtkAboutDialog *about,
|
||||||
GtkTextView *text_view,
|
GtkTextView *text_view,
|
||||||
GdkDevice *device,
|
|
||||||
gint x,
|
gint x,
|
||||||
gint y);
|
gint y);
|
||||||
static void populate_credits_page (GtkAboutDialog *about);
|
static void populate_credits_page (GtkAboutDialog *about);
|
||||||
@@ -241,12 +247,15 @@ static gboolean emit_activate_link (GtkAboutDialog
|
|||||||
static gboolean text_view_key_press_event (GtkWidget *text_view,
|
static gboolean text_view_key_press_event (GtkWidget *text_view,
|
||||||
GdkEventKey *event,
|
GdkEventKey *event,
|
||||||
GtkAboutDialog *about);
|
GtkAboutDialog *about);
|
||||||
static gboolean text_view_event_after (GtkWidget *text_view,
|
static void text_view_released (GtkGestureMultiPress *press,
|
||||||
GdkEvent *event,
|
int n,
|
||||||
GtkAboutDialog *about);
|
double x,
|
||||||
static gboolean text_view_motion_notify_event (GtkWidget *text_view,
|
double y,
|
||||||
GdkEventMotion *event,
|
GtkAboutDialog *about);
|
||||||
GtkAboutDialog *about);
|
static void text_view_motion (GtkEventControllerMotion *motion,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
GtkAboutDialog *about);
|
||||||
static void toggle_credits (GtkToggleButton *button,
|
static void toggle_credits (GtkToggleButton *button,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
static void toggle_license (GtkToggleButton *button,
|
static void toggle_license (GtkToggleButton *button,
|
||||||
@@ -634,9 +643,7 @@ gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
|
|||||||
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, system_view);
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, system_view);
|
||||||
|
|
||||||
gtk_widget_class_bind_template_callback (widget_class, emit_activate_link);
|
gtk_widget_class_bind_template_callback (widget_class, emit_activate_link);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, text_view_event_after);
|
|
||||||
gtk_widget_class_bind_template_callback (widget_class, text_view_key_press_event);
|
gtk_widget_class_bind_template_callback (widget_class, text_view_key_press_event);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, text_view_motion_notify_event);
|
|
||||||
gtk_widget_class_bind_template_callback (widget_class, stack_visible_child_notify);
|
gtk_widget_class_bind_template_callback (widget_class, stack_visible_child_notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -800,6 +807,15 @@ gtk_about_dialog_init (GtkAboutDialog *about)
|
|||||||
switch_page (about, "main");
|
switch_page (about, "main");
|
||||||
update_stack_switcher_visibility (about);
|
update_stack_switcher_visibility (about);
|
||||||
|
|
||||||
|
priv->license_press = gtk_gesture_multi_press_new (priv->license_view);
|
||||||
|
g_signal_connect (priv->license_press, "released", G_CALLBACK (text_view_released), about);
|
||||||
|
priv->system_press = gtk_gesture_multi_press_new (priv->system_view);
|
||||||
|
g_signal_connect (priv->system_press, "released", G_CALLBACK (text_view_released), about);
|
||||||
|
priv->license_motion = gtk_event_controller_motion_new (priv->license_view);
|
||||||
|
g_signal_connect (priv->license_motion, "motion", G_CALLBACK (text_view_motion), about);
|
||||||
|
priv->system_motion = gtk_event_controller_motion_new (priv->system_view);
|
||||||
|
g_signal_connect (priv->system_motion, "motion", G_CALLBACK (text_view_motion), about);
|
||||||
|
|
||||||
/* force defaults */
|
/* force defaults */
|
||||||
gtk_about_dialog_set_program_name (about, NULL);
|
gtk_about_dialog_set_program_name (about, NULL);
|
||||||
gtk_about_dialog_set_logo (about, NULL);
|
gtk_about_dialog_set_logo (about, NULL);
|
||||||
@@ -836,6 +852,11 @@ gtk_about_dialog_finalize (GObject *object)
|
|||||||
g_slist_free_full (priv->credit_sections, destroy_credit_section);
|
g_slist_free_full (priv->credit_sections, destroy_credit_section);
|
||||||
g_slist_free_full (priv->visited_links, g_free);
|
g_slist_free_full (priv->visited_links, g_free);
|
||||||
|
|
||||||
|
g_object_unref (priv->license_press);
|
||||||
|
g_object_unref (priv->system_press);
|
||||||
|
g_object_unref (priv->license_motion);
|
||||||
|
g_object_unref (priv->system_motion);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2026,46 +2047,41 @@ text_view_key_press_event (GtkWidget *text_view,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
text_view_event_after (GtkWidget *text_view,
|
text_view_released (GtkGestureMultiPress *gesture,
|
||||||
GdkEvent *event,
|
int n_press,
|
||||||
GtkAboutDialog *about)
|
double x,
|
||||||
|
double y,
|
||||||
|
GtkAboutDialog *about)
|
||||||
{
|
{
|
||||||
|
GtkWidget *text_view;
|
||||||
GtkTextIter start, end, iter;
|
GtkTextIter start, end, iter;
|
||||||
GtkTextBuffer *buffer;
|
GtkTextBuffer *buffer;
|
||||||
gdouble event_x, event_y;
|
gint tx, ty;
|
||||||
gint x, y;
|
|
||||||
guint button;
|
|
||||||
|
|
||||||
if (gdk_event_get_event_type (event) != GDK_BUTTON_RELEASE)
|
if (gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)) != GDK_BUTTON_PRIMARY)
|
||||||
return FALSE;
|
return;
|
||||||
|
|
||||||
if (!gdk_event_get_button (event, &button) || button != GDK_BUTTON_PRIMARY)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
|
text_view = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
||||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
|
||||||
|
|
||||||
/* we shouldn't follow a link if the user has selected something */
|
/* we shouldn't follow a link if the user has selected something */
|
||||||
gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
|
gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
|
||||||
if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
|
if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
|
||||||
return FALSE;
|
return;
|
||||||
|
|
||||||
gdk_event_get_coords (event, &event_x, &event_y);
|
|
||||||
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
|
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
|
||||||
GTK_TEXT_WINDOW_WIDGET,
|
GTK_TEXT_WINDOW_WIDGET,
|
||||||
event_x, event_y, &x, &y);
|
x, y, &tx, &ty);
|
||||||
|
|
||||||
gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
|
gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, tx, ty);
|
||||||
|
|
||||||
follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
|
follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_cursor_if_appropriate (GtkAboutDialog *about,
|
set_cursor_if_appropriate (GtkAboutDialog *about,
|
||||||
GtkTextView *text_view,
|
GtkTextView *text_view,
|
||||||
GdkDevice *device,
|
|
||||||
gint x,
|
gint x,
|
||||||
gint y)
|
gint y)
|
||||||
{
|
{
|
||||||
@@ -2102,23 +2118,22 @@ set_cursor_if_appropriate (GtkAboutDialog *about,
|
|||||||
g_slist_free (tags);
|
g_slist_free (tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
text_view_motion_notify_event (GtkWidget *text_view,
|
text_view_motion (GtkEventControllerMotion *motion,
|
||||||
GdkEventMotion *event,
|
double x,
|
||||||
GtkAboutDialog *about)
|
double y,
|
||||||
|
GtkAboutDialog *about)
|
||||||
{
|
{
|
||||||
gdouble event_x, event_y;
|
gint tx, ty;
|
||||||
gint x, y;
|
GtkWidget *widget;
|
||||||
|
|
||||||
gdk_event_get_coords ((GdkEvent *) event, &event_x, &event_y);
|
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (motion));
|
||||||
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
|
|
||||||
|
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (widget),
|
||||||
GTK_TEXT_WINDOW_WIDGET,
|
GTK_TEXT_WINDOW_WIDGET,
|
||||||
event_x, event_y, &x, &y);
|
x, y, &tx, &ty);
|
||||||
|
|
||||||
set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view),
|
set_cursor_if_appropriate (about, GTK_TEXT_VIEW (widget), tx, ty);
|
||||||
gdk_event_get_device ((GdkEvent *) event), x, y);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkTextBuffer *
|
static GtkTextBuffer *
|
||||||
|
160
gtk/gtkeventcontrollermotion.c
Normal file
160
gtk/gtkeventcontrollermotion.c
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
/* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 2017, Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
* Author(s): Matthias Clasen <mclasen@redhat.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:gtkeventcontrollermotion
|
||||||
|
* @Short_description: Event controller for motion events
|
||||||
|
* @Title: GtkEventControllerMotion
|
||||||
|
* @See_also: #GtkEventController
|
||||||
|
*
|
||||||
|
* #GtkEventControllerMotion is an event controller meant for situations
|
||||||
|
* where you need to track the position of the pointer.
|
||||||
|
*
|
||||||
|
* This object was added in 3.94.
|
||||||
|
**/
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "gtkintl.h"
|
||||||
|
#include "gtkwidget.h"
|
||||||
|
#include "gtkeventcontrollerprivate.h"
|
||||||
|
#include "gtkeventcontrollermotion.h"
|
||||||
|
#include "gtktypebuiltins.h"
|
||||||
|
#include "gtkmarshalers.h"
|
||||||
|
|
||||||
|
struct _GtkEventControllerMotion
|
||||||
|
{
|
||||||
|
GtkEventController parent_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _GtkEventControllerMotionClass
|
||||||
|
{
|
||||||
|
GtkEventControllerClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ENTER,
|
||||||
|
LEAVE,
|
||||||
|
MOTION,
|
||||||
|
N_SIGNALS
|
||||||
|
};
|
||||||
|
|
||||||
|
static guint signals[N_SIGNALS] = { 0 };
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (GtkEventControllerMotion, gtk_event_controller_motion, GTK_TYPE_EVENT_CONTROLLER)
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gtk_event_controller_motion_handle_event (GtkEventController *controller,
|
||||||
|
const GdkEvent *event)
|
||||||
|
{
|
||||||
|
GtkEventControllerClass *parent_class;
|
||||||
|
GdkEventType type;
|
||||||
|
|
||||||
|
type = gdk_event_get_event_type (event);
|
||||||
|
if (type == GDK_ENTER_NOTIFY)
|
||||||
|
g_signal_emit (controller, signals[ENTER], 0);
|
||||||
|
else if (type == GDK_LEAVE_NOTIFY)
|
||||||
|
g_signal_emit (controller, signals[LEAVE], 0);
|
||||||
|
else if (type == GDK_MOTION_NOTIFY)
|
||||||
|
{
|
||||||
|
double x, y;
|
||||||
|
gdk_event_get_coords (event, &x, &y);
|
||||||
|
g_signal_emit (controller, signals[MOTION], 0, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
parent_class = GTK_EVENT_CONTROLLER_CLASS (gtk_event_controller_motion_parent_class);
|
||||||
|
|
||||||
|
return parent_class->handle_event (controller, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_event_controller_motion_class_init (GtkEventControllerMotionClass *klass)
|
||||||
|
{
|
||||||
|
GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
|
||||||
|
|
||||||
|
controller_class->handle_event = gtk_event_controller_motion_handle_event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GtkEventControllerMotion::enter:
|
||||||
|
* @controller: The object that received the signal
|
||||||
|
*
|
||||||
|
* Signals that the pointer has entered the widget.
|
||||||
|
*/
|
||||||
|
signals[ENTER] =
|
||||||
|
g_signal_new (I_("enter"),
|
||||||
|
GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
||||||
|
G_SIGNAL_RUN_FIRST,
|
||||||
|
0, NULL, NULL,
|
||||||
|
NULL,
|
||||||
|
G_TYPE_NONE, 0);
|
||||||
|
/**
|
||||||
|
* GtkEventControllerMotion::leave:
|
||||||
|
* @controller: The object that received the signal
|
||||||
|
*
|
||||||
|
* Signals that pointer has left the widget.
|
||||||
|
*/
|
||||||
|
signals[LEAVE] =
|
||||||
|
g_signal_new (I_("leave"),
|
||||||
|
GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
||||||
|
G_SIGNAL_RUN_FIRST,
|
||||||
|
0, NULL, NULL,
|
||||||
|
NULL,
|
||||||
|
G_TYPE_NONE, 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GtkEventControllerMotion::motion:
|
||||||
|
* @controller: The object that received the signal
|
||||||
|
* @x: the x coordinate
|
||||||
|
* @y: the y coordinate
|
||||||
|
*
|
||||||
|
* Emitted when the pointer moves inside the widget.
|
||||||
|
*/
|
||||||
|
signals[MOTION] =
|
||||||
|
g_signal_new (I_("motion"),
|
||||||
|
GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
||||||
|
G_SIGNAL_RUN_FIRST,
|
||||||
|
0, NULL, NULL,
|
||||||
|
NULL,
|
||||||
|
G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_event_controller_motion_init (GtkEventControllerMotion *motion)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_event_controller_motion_new:
|
||||||
|
* @widget: a #GtkWidget
|
||||||
|
*
|
||||||
|
* Creates a new event controller that will handle motion events
|
||||||
|
* for the given @widget.
|
||||||
|
*
|
||||||
|
* Returns: a new #GtkEventControllerMotion
|
||||||
|
*
|
||||||
|
* Since: 3.94
|
||||||
|
**/
|
||||||
|
GtkEventController *
|
||||||
|
gtk_event_controller_motion_new (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
|
||||||
|
|
||||||
|
return g_object_new (GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
||||||
|
"widget", widget,
|
||||||
|
NULL);
|
||||||
|
}
|
50
gtk/gtkeventcontrollermotion.h
Normal file
50
gtk/gtkeventcontrollermotion.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 2017, Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
* Author(s): Matthias Clasen <mclasen@redhat.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GTK_EVENT_CONTROLLER_MOTION_H__
|
||||||
|
#define __GTK_EVENT_CONTROLLER_MOTION_H__
|
||||||
|
|
||||||
|
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||||
|
#error "Only <gtk/gtk.h> can be included directly."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gdk/gdk.h>
|
||||||
|
#include <gtk/gtkeventcontroller.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GTK_TYPE_EVENT_CONTROLLER_MOTION (gtk_event_controller_motion_get_type ())
|
||||||
|
#define GTK_EVENT_CONTROLLER_MOTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_EVENT_CONTROLLER_MOTION, GtkEventControllerMotion))
|
||||||
|
#define GTK_EVENT_CONTROLLER_MOTION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_EVENT_CONTROLLER_MOTION, GtkEventControllerMotionClass))
|
||||||
|
#define GTK_IS_EVENT_CONTROLLER_MOTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_EVENT_CONTROLLER_MOTION))
|
||||||
|
#define GTK_IS_EVENT_CONTROLLER_MOTION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_EVENT_CONTROLLER_MOTION))
|
||||||
|
#define GTK_EVENT_CONTROLLER_MOTION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_EVENT_CONTROLLER_MOTION, GtkEventControllerMotionClass))
|
||||||
|
|
||||||
|
typedef struct _GtkEventControllerMotion GtkEventControllerMotion;
|
||||||
|
typedef struct _GtkEventControllerMotionClass GtkEventControllerMotionClass;
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_3_94
|
||||||
|
GType gtk_event_controller_motion_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_3_94
|
||||||
|
GtkEventController *gtk_event_controller_motion_new (GtkWidget *widget);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __GTK_EVENT_CONTROLLER_MOTION_H__ */
|
@@ -54,6 +54,7 @@
|
|||||||
#include "gtkwindow.h"
|
#include "gtkwindow.h"
|
||||||
#include "gtkcssnodeprivate.h"
|
#include "gtkcssnodeprivate.h"
|
||||||
#include "gtkwidgetprivate.h"
|
#include "gtkwidgetprivate.h"
|
||||||
|
#include "gtkeventcontrollermotion.h"
|
||||||
|
|
||||||
#include "a11y/gtklabelaccessibleprivate.h"
|
#include "a11y/gtklabelaccessibleprivate.h"
|
||||||
|
|
||||||
@@ -334,6 +335,7 @@ struct _GtkLabelSelectionInfo
|
|||||||
|
|
||||||
GtkGesture *drag_gesture;
|
GtkGesture *drag_gesture;
|
||||||
GtkGesture *multipress_gesture;
|
GtkGesture *multipress_gesture;
|
||||||
|
GtkEventController *motion_controller;
|
||||||
|
|
||||||
gint drag_start_x;
|
gint drag_start_x;
|
||||||
gint drag_start_y;
|
gint drag_start_y;
|
||||||
@@ -414,10 +416,12 @@ static gboolean gtk_label_focus (GtkWidget *widget,
|
|||||||
static void gtk_label_realize (GtkWidget *widget);
|
static void gtk_label_realize (GtkWidget *widget);
|
||||||
static void gtk_label_unmap (GtkWidget *widget);
|
static void gtk_label_unmap (GtkWidget *widget);
|
||||||
|
|
||||||
static gboolean gtk_label_motion (GtkWidget *widget,
|
static void gtk_label_motion (GtkEventControllerMotion *controller,
|
||||||
GdkEventMotion *event);
|
double x,
|
||||||
static gboolean gtk_label_leave_notify (GtkWidget *widget,
|
double y,
|
||||||
GdkEventCrossing *event);
|
gpointer data);
|
||||||
|
static void gtk_label_leave (GtkEventControllerMotion *controller,
|
||||||
|
gpointer data);
|
||||||
|
|
||||||
static void gtk_label_grab_focus (GtkWidget *widget);
|
static void gtk_label_grab_focus (GtkWidget *widget);
|
||||||
|
|
||||||
@@ -596,8 +600,6 @@ gtk_label_class_init (GtkLabelClass *class)
|
|||||||
widget_class->snapshot = gtk_label_snapshot;
|
widget_class->snapshot = gtk_label_snapshot;
|
||||||
widget_class->realize = gtk_label_realize;
|
widget_class->realize = gtk_label_realize;
|
||||||
widget_class->unmap = gtk_label_unmap;
|
widget_class->unmap = gtk_label_unmap;
|
||||||
widget_class->motion_notify_event = gtk_label_motion;
|
|
||||||
widget_class->leave_notify_event = gtk_label_leave_notify;
|
|
||||||
widget_class->hierarchy_changed = gtk_label_hierarchy_changed;
|
widget_class->hierarchy_changed = gtk_label_hierarchy_changed;
|
||||||
widget_class->display_changed = gtk_label_display_changed;
|
widget_class->display_changed = gtk_label_display_changed;
|
||||||
widget_class->mnemonic_activate = gtk_label_mnemonic_activate;
|
widget_class->mnemonic_activate = gtk_label_mnemonic_activate;
|
||||||
@@ -3211,6 +3213,7 @@ gtk_label_finalize (GObject *object)
|
|||||||
{
|
{
|
||||||
g_object_unref (priv->select_info->drag_gesture);
|
g_object_unref (priv->select_info->drag_gesture);
|
||||||
g_object_unref (priv->select_info->multipress_gesture);
|
g_object_unref (priv->select_info->multipress_gesture);
|
||||||
|
g_object_unref (priv->select_info->motion_controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_label_clear_links (label);
|
gtk_label_clear_links (label);
|
||||||
@@ -4898,36 +4901,28 @@ gtk_label_update_active_link (GtkWidget *widget,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gtk_label_motion (GtkWidget *widget,
|
gtk_label_motion (GtkEventControllerMotion *controller,
|
||||||
GdkEventMotion *event)
|
double x,
|
||||||
|
double y,
|
||||||
|
gpointer data)
|
||||||
{
|
{
|
||||||
gdouble x, y;
|
gtk_label_update_active_link (GTK_WIDGET (data), x, y);
|
||||||
|
|
||||||
gdk_event_get_coords ((GdkEvent *) event, &x, &y);
|
|
||||||
gtk_label_update_active_link (widget, x, y);
|
|
||||||
|
|
||||||
return GTK_WIDGET_CLASS (gtk_label_parent_class)->motion_notify_event (widget, event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gtk_label_leave_notify (GtkWidget *widget,
|
gtk_label_leave (GtkEventControllerMotion *controller,
|
||||||
GdkEventCrossing *event)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GtkLabel *label = GTK_LABEL (widget);
|
GtkLabel *label = GTK_LABEL (data);
|
||||||
GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
|
GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
|
||||||
|
|
||||||
if (priv->select_info)
|
if (priv->select_info)
|
||||||
{
|
{
|
||||||
priv->select_info->active_link = NULL;
|
priv->select_info->active_link = NULL;
|
||||||
gtk_label_update_cursor (label);
|
gtk_label_update_cursor (label);
|
||||||
gtk_widget_queue_draw (widget);
|
gtk_widget_queue_draw (GTK_WIDGET (label));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GTK_WIDGET_CLASS (gtk_label_parent_class)->leave_notify_event)
|
|
||||||
return GTK_WIDGET_CLASS (gtk_label_parent_class)->leave_notify_event (widget, event);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -5089,6 +5084,12 @@ gtk_label_ensure_select_info (GtkLabel *label)
|
|||||||
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->select_info->multipress_gesture), 0);
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->select_info->multipress_gesture), 0);
|
||||||
gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (priv->select_info->multipress_gesture), TRUE);
|
gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (priv->select_info->multipress_gesture), TRUE);
|
||||||
|
|
||||||
|
priv->select_info->motion_controller = gtk_event_controller_motion_new (GTK_WIDGET (label));
|
||||||
|
g_signal_connect (priv->select_info->motion_controller, "motion",
|
||||||
|
G_CALLBACK (gtk_label_motion), label);
|
||||||
|
g_signal_connect (priv->select_info->motion_controller, "leave",
|
||||||
|
G_CALLBACK (gtk_label_leave), label);
|
||||||
|
|
||||||
priv->select_info->provider = g_object_new (GTK_TYPE_LABEL_CONTENT, NULL);
|
priv->select_info->provider = g_object_new (GTK_TYPE_LABEL_CONTENT, NULL);
|
||||||
GTK_LABEL_CONTENT (priv->select_info->provider)->label = label;
|
GTK_LABEL_CONTENT (priv->select_info->provider)->label = label;
|
||||||
}
|
}
|
||||||
@@ -5106,6 +5107,7 @@ gtk_label_clear_select_info (GtkLabel *label)
|
|||||||
{
|
{
|
||||||
g_object_unref (priv->select_info->drag_gesture);
|
g_object_unref (priv->select_info->drag_gesture);
|
||||||
g_object_unref (priv->select_info->multipress_gesture);
|
g_object_unref (priv->select_info->multipress_gesture);
|
||||||
|
g_object_unref (priv->select_info->motion_controller);
|
||||||
GTK_LABEL_CONTENT (priv->select_info->provider)->label = NULL;
|
GTK_LABEL_CONTENT (priv->select_info->provider)->label = NULL;
|
||||||
g_object_unref (priv->select_info->provider);
|
g_object_unref (priv->select_info->provider);
|
||||||
|
|
||||||
|
@@ -43,6 +43,7 @@
|
|||||||
#include "gtkcssstylepropertyprivate.h"
|
#include "gtkcssstylepropertyprivate.h"
|
||||||
#include "gtkrendericonprivate.h"
|
#include "gtkrendericonprivate.h"
|
||||||
#include "gtkgizmoprivate.h"
|
#include "gtkgizmoprivate.h"
|
||||||
|
#include "gtkeventcontrollermotion.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@@ -140,6 +141,7 @@ struct _GtkPanedPrivate
|
|||||||
|
|
||||||
GtkGesture *pan_gesture; /* Used for touch */
|
GtkGesture *pan_gesture; /* Used for touch */
|
||||||
GtkGesture *drag_gesture; /* Used for mice */
|
GtkGesture *drag_gesture; /* Used for mice */
|
||||||
|
GtkEventController *motion_controller;
|
||||||
|
|
||||||
gint child1_size;
|
gint child1_size;
|
||||||
gint drag_pos;
|
gint drag_pos;
|
||||||
@@ -304,32 +306,28 @@ get_handle_area (GtkPaned *paned,
|
|||||||
area->height += extra * 2;
|
area->height += extra * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gtk_paned_motion_notify (GtkWidget *widget,
|
gtk_paned_motion (GtkEventControllerMotion *motion,
|
||||||
GdkEventMotion *event)
|
double x,
|
||||||
|
double y,
|
||||||
|
GtkPaned *paned)
|
||||||
{
|
{
|
||||||
GtkPaned *paned = GTK_PANED (widget);
|
|
||||||
GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned);
|
GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned);
|
||||||
GdkRectangle handle_area;
|
GdkRectangle handle_area;
|
||||||
gdouble x, y;
|
|
||||||
|
|
||||||
get_handle_area (paned, &handle_area);
|
get_handle_area (paned, &handle_area);
|
||||||
|
|
||||||
if (gdk_event_get_coords ((GdkEvent *) event, &x, &y) &&
|
if (gdk_rectangle_contains_point (&handle_area, x, y) || priv->panning)
|
||||||
(gdk_rectangle_contains_point (&handle_area, x, y) ||
|
|
||||||
priv->panning))
|
|
||||||
{
|
{
|
||||||
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
gtk_widget_set_cursor_from_name (widget, "col-resize");
|
gtk_widget_set_cursor_from_name (GTK_WIDGET (paned), "col-resize");
|
||||||
else
|
else
|
||||||
gtk_widget_set_cursor_from_name (widget, "row-resize");
|
gtk_widget_set_cursor_from_name (GTK_WIDGET (paned), "row-resize");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gtk_widget_set_cursor (widget, NULL);
|
gtk_widget_set_cursor (GTK_WIDGET (paned), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GTK_WIDGET_CLASS (gtk_paned_parent_class)->motion_notify_event (widget, event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkWidget *
|
static GtkWidget *
|
||||||
@@ -374,7 +372,6 @@ gtk_paned_class_init (GtkPanedClass *class)
|
|||||||
widget_class->unrealize = gtk_paned_unrealize;
|
widget_class->unrealize = gtk_paned_unrealize;
|
||||||
widget_class->snapshot = gtk_paned_snapshot;
|
widget_class->snapshot = gtk_paned_snapshot;
|
||||||
widget_class->focus = gtk_paned_focus;
|
widget_class->focus = gtk_paned_focus;
|
||||||
widget_class->motion_notify_event = gtk_paned_motion_notify;
|
|
||||||
widget_class->direction_changed = gtk_paned_direction_changed;
|
widget_class->direction_changed = gtk_paned_direction_changed;
|
||||||
widget_class->pick = gtk_paned_pick;
|
widget_class->pick = gtk_paned_pick;
|
||||||
|
|
||||||
@@ -1019,6 +1016,7 @@ gtk_paned_finalize (GObject *object)
|
|||||||
|
|
||||||
g_clear_object (&paned->priv->pan_gesture);
|
g_clear_object (&paned->priv->pan_gesture);
|
||||||
g_clear_object (&paned->priv->drag_gesture);
|
g_clear_object (&paned->priv->drag_gesture);
|
||||||
|
g_clear_object (&paned->priv->motion_controller);
|
||||||
|
|
||||||
gtk_widget_unparent (priv->handle_widget);
|
gtk_widget_unparent (priv->handle_widget);
|
||||||
|
|
||||||
@@ -1561,6 +1559,9 @@ gtk_paned_init (GtkPaned *paned)
|
|||||||
connect_drag_gesture_signals (paned, gesture);
|
connect_drag_gesture_signals (paned, gesture);
|
||||||
priv->drag_gesture = gesture;
|
priv->drag_gesture = gesture;
|
||||||
|
|
||||||
|
priv->motion_controller = gtk_event_controller_motion_new (GTK_WIDGET (paned));
|
||||||
|
g_signal_connect (priv->motion_controller, "motion", G_CALLBACK (gtk_paned_motion), paned);
|
||||||
|
|
||||||
priv->handle_widget = gtk_gizmo_new ("separator",
|
priv->handle_widget = gtk_gizmo_new ("separator",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
@@ -146,6 +146,7 @@ gtk_public_sources = files([
|
|||||||
'gtkentrycompletion.c',
|
'gtkentrycompletion.c',
|
||||||
'gtkeventcontroller.c',
|
'gtkeventcontroller.c',
|
||||||
'gtkeventcontrollerlegacy.c',
|
'gtkeventcontrollerlegacy.c',
|
||||||
|
'gtkeventcontrollermotion.c',
|
||||||
'gtkeventcontrollerscroll.c',
|
'gtkeventcontrollerscroll.c',
|
||||||
'gtkexpander.c',
|
'gtkexpander.c',
|
||||||
'gtkfilechooser.c',
|
'gtkfilechooser.c',
|
||||||
|
@@ -168,9 +168,7 @@
|
|||||||
<property name="left-margin">8</property>
|
<property name="left-margin">8</property>
|
||||||
<property name="right-margin">8</property>
|
<property name="right-margin">8</property>
|
||||||
<property name="cursor-visible">0</property>
|
<property name="cursor-visible">0</property>
|
||||||
<signal name="event-after" handler="text_view_event_after" swapped="no"/>
|
|
||||||
<signal name="key-press-event" handler="text_view_key_press_event" swapped="no"/>
|
<signal name="key-press-event" handler="text_view_key_press_event" swapped="no"/>
|
||||||
<signal name="motion-notify-event" handler="text_view_motion_notify_event" swapped="no"/>
|
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
@@ -199,9 +197,7 @@
|
|||||||
<property name="left-margin">8</property>
|
<property name="left-margin">8</property>
|
||||||
<property name="right-margin">8</property>
|
<property name="right-margin">8</property>
|
||||||
<property name="cursor-visible">0</property>
|
<property name="cursor-visible">0</property>
|
||||||
<signal name="event-after" handler="text_view_event_after" swapped="no"/>
|
|
||||||
<signal name="key-press-event" handler="text_view_key_press_event" swapped="no"/>
|
<signal name="key-press-event" handler="text_view_key_press_event" swapped="no"/>
|
||||||
<signal name="motion-notify-event" handler="text_view_motion_notify_event" swapped="no"/>
|
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
@@ -92,6 +92,28 @@ set_texture (GtkWidget *button,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char cssdata[] =
|
||||||
|
".entry-frame:not(:focus) { "
|
||||||
|
" border: 2px solid alpha(gray,0.3);"
|
||||||
|
"}"
|
||||||
|
".entry-frame:focus { "
|
||||||
|
" border: 2px solid red;"
|
||||||
|
"}"
|
||||||
|
".entry-frame entry { "
|
||||||
|
" border: none; "
|
||||||
|
" box-shadow: none; "
|
||||||
|
"}";
|
||||||
|
|
||||||
|
static void
|
||||||
|
icon_pressed_cb (GtkGesture *gesture,
|
||||||
|
int n_press,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
g_print ("You clicked me!\n");
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@@ -100,6 +122,7 @@ main (int argc, char **argv)
|
|||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
GtkWidget *entry;
|
GtkWidget *entry;
|
||||||
GtkWidget *box;
|
GtkWidget *box;
|
||||||
|
GtkWidget *image;
|
||||||
GtkWidget *button1;
|
GtkWidget *button1;
|
||||||
GtkWidget *button2;
|
GtkWidget *button2;
|
||||||
GtkWidget *button3;
|
GtkWidget *button3;
|
||||||
@@ -119,6 +142,7 @@ main (int argc, char **argv)
|
|||||||
gtk_container_add (GTK_CONTAINER (window), grid);
|
gtk_container_add (GTK_CONTAINER (window), grid);
|
||||||
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
||||||
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
||||||
|
g_object_set (grid, "margin", 10, NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open File - Sets the icon using a GIcon
|
* Open File - Sets the icon using a GIcon
|
||||||
@@ -283,8 +307,33 @@ main (int argc, char **argv)
|
|||||||
g_object_set (entry, "show-emoji-icon", TRUE, NULL);
|
g_object_set (entry, "show-emoji-icon", TRUE, NULL);
|
||||||
gtk_widget_set_hexpand (entry, TRUE);
|
gtk_widget_set_hexpand (entry, TRUE);
|
||||||
gtk_grid_attach (GTK_GRID (grid), entry, 1, 6, 1, 1);
|
gtk_grid_attach (GTK_GRID (grid), entry, 1, 6, 1, 1);
|
||||||
gtk_widget_show (window);
|
|
||||||
|
|
||||||
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||||
|
gtk_style_context_add_class (gtk_widget_get_style_context (box), "view");
|
||||||
|
gtk_style_context_add_class (gtk_widget_get_style_context (box), "entry-frame");
|
||||||
|
gtk_widget_set_cursor_from_name (box, "text");
|
||||||
|
entry = gtk_entry_new ();
|
||||||
|
gtk_widget_set_hexpand (entry, TRUE);
|
||||||
|
gtk_container_add (GTK_CONTAINER (box), entry);
|
||||||
|
image = gtk_image_new_from_icon_name ("edit-find-symbolic");
|
||||||
|
gtk_widget_set_cursor_from_name (image, "default");
|
||||||
|
g_object_set (image, "margin", 6, NULL);
|
||||||
|
gtk_widget_set_tooltip_text (image, "Click me");
|
||||||
|
|
||||||
|
GtkGesture *gesture;
|
||||||
|
gesture = gtk_gesture_multi_press_new (image);
|
||||||
|
g_signal_connect (gesture, "pressed", G_CALLBACK (icon_pressed_cb), NULL);
|
||||||
|
gtk_container_add (GTK_CONTAINER (box), image);
|
||||||
|
image = gtk_image_new_from_icon_name ("document-save-symbolic");
|
||||||
|
g_object_set (image, "margin", 6, NULL);
|
||||||
|
gtk_container_add (GTK_CONTAINER (box), image);
|
||||||
|
gtk_grid_attach (GTK_GRID (grid), box, 1, 7, 1, 1);
|
||||||
|
|
||||||
|
GtkCssProvider *provider;
|
||||||
|
provider = gtk_css_provider_new ();
|
||||||
|
gtk_css_provider_load_from_data (provider, cssdata, -1);
|
||||||
|
gtk_style_context_add_provider_for_display (gdk_display_get_default (), GTK_STYLE_PROVIDER (provider), 800);
|
||||||
|
gtk_widget_show (window);
|
||||||
gtk_main();
|
gtk_main();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user