[gtk+/wip/carlosg/private-event-structs] gtk-demo: Use GdkEvent API
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/carlosg/private-event-structs] gtk-demo: Use GdkEvent API
- Date: Mon, 28 Aug 2017 23:12:04 +0000 (UTC)
commit 68afbcdb818678f13ac392decf18a482d0b7e7cc
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Aug 28 18:47:03 2017 -0400
gtk-demo: Use GdkEvent API
demos/gtk-demo/application.c | 6 ++++--
demos/gtk-demo/clipboard.c | 9 ++++++---
demos/gtk-demo/drawingarea.c | 12 +++++++++---
demos/gtk-demo/event_axes.c | 36 +++++++++++++++++++-----------------
demos/gtk-demo/font_features.c | 6 +++++-
demos/gtk-demo/hypertext.c | 35 ++++++++++++++++++-----------------
demos/gtk-demo/popover.c | 14 ++++++++------
7 files changed, 69 insertions(+), 49 deletions(-)
---
diff --git a/demos/gtk-demo/application.c b/demos/gtk-demo/application.c
index d2aa1f7..732c376 100644
--- a/demos/gtk-demo/application.c
+++ b/demos/gtk-demo/application.c
@@ -475,12 +475,14 @@ demo_application_window_state_event (GtkWidget *widget,
{
DemoApplicationWindow *window = (DemoApplicationWindow *)widget;
gboolean res = GDK_EVENT_PROPAGATE;
+ GdkWindowState changed, new_state;
if (GTK_WIDGET_CLASS (demo_application_window_parent_class)->window_state_event)
res = GTK_WIDGET_CLASS (demo_application_window_parent_class)->window_state_event (widget, event);
- window->maximized = (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
- window->fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0;
+ gdk_event_get_window_state ((GdkEvent *)event, &changed, &new_state);
+ window->maximized = (new_state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
+ window->fullscreen = (new_state & GDK_WINDOW_STATE_FULLSCREEN) != 0;
return res;
}
diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c
index a9576aa..b3b8e60 100644
--- a/demos/gtk-demo/clipboard.c
+++ b/demos/gtk-demo/clipboard.c
@@ -172,13 +172,16 @@ paste_image (GtkMenuItem *item,
static gboolean
button_press (GtkWidget *widget,
- GdkEventButton *button,
+ GdkEventButton *event,
gpointer data)
{
GtkWidget *menu;
GtkWidget *item;
+ guint button;
- if (button->button != GDK_BUTTON_SECONDARY)
+ gdk_event_get_button ((GdkEvent *)event, &button);
+
+ if (button != GDK_BUTTON_SECONDARY)
return FALSE;
menu = gtk_menu_new ();
@@ -193,7 +196,7 @@ button_press (GtkWidget *widget,
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *) button);
+ gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *) event);
return TRUE;
}
diff --git a/demos/gtk-demo/drawingarea.c b/demos/gtk-demo/drawingarea.c
index a6a685b..8240c54 100644
--- a/demos/gtk-demo/drawingarea.c
+++ b/demos/gtk-demo/drawingarea.c
@@ -94,11 +94,17 @@ scribble_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
{
+ double x, y;
+ guint button;
+
if (surface == NULL)
return FALSE; /* paranoia check, in case we haven't gotten a configure event */
- if (event->button == GDK_BUTTON_PRIMARY)
- draw_brush (widget, event->x, event->y);
+ gdk_event_get_button ((GdkEvent *)event, &button);
+ gdk_event_get_coords ((GdkEvent *)event, &x, &y);
+
+ if (button == GDK_BUTTON_PRIMARY)
+ draw_brush (widget, x, y);
/* We've handled the event, stop processing */
return TRUE;
@@ -126,7 +132,7 @@ scribble_motion_notify_event (GtkWidget *widget,
* can cope.
*/
- gdk_window_get_device_position (event->window, event->device, &x, &y, &state);
+ gdk_window_get_device_position (gdk_event_get_window (event), gdk_event_get_device (event), &x, &y,
&state);
if (state & GDK_BUTTON1_MASK)
draw_brush (widget, x, y);
diff --git a/demos/gtk-demo/event_axes.c b/demos/gtk-demo/event_axes.c
index 544f0a7..5a04fdd 100644
--- a/demos/gtk-demo/event_axes.c
+++ b/demos/gtk-demo/event_axes.c
@@ -120,6 +120,7 @@ update_axes_from_event (GdkEvent *event,
GdkDevice *device, *source_device;
GdkEventSequence *sequence;
GdkDeviceTool *tool;
+ GdkEventType type;
gdouble x, y;
AxesInfo *info;
@@ -127,14 +128,15 @@ update_axes_from_event (GdkEvent *event,
source_device = gdk_event_get_source_device (event);
sequence = gdk_event_get_event_sequence (event);
tool = gdk_event_get_device_tool (event);
+ type = gdk_event_get_event_type (event);
- if (event->type == GDK_TOUCH_END ||
- event->type == GDK_TOUCH_CANCEL)
+ if (type == GDK_TOUCH_END ||
+ type == GDK_TOUCH_CANCEL)
{
g_hash_table_remove (data->touch_info, sequence);
return;
}
- else if (event->type == GDK_LEAVE_NOTIFY)
+ else if (type == GDK_LEAVE_NOTIFY)
{
g_hash_table_remove (data->pointer_info, device);
return;
@@ -172,24 +174,24 @@ update_axes_from_event (GdkEvent *event,
g_clear_pointer (&info->axes, g_free);
- if (event->type == GDK_TOUCH_BEGIN ||
- event->type == GDK_TOUCH_UPDATE)
+ if (type == GDK_TOUCH_BEGIN ||
+ type == GDK_TOUCH_UPDATE)
{
- if (sequence && event->touch.emulating_pointer)
+ gboolean emulating_pointer;
+
+ gdk_event_get_touch_emulating_pointer (event, &emulating_pointer);
+ if (sequence && emulating_pointer)
g_hash_table_remove (data->pointer_info, device);
}
- if (event->type == GDK_MOTION_NOTIFY)
- {
- info->axes =
- g_memdup (event->motion.axes,
- sizeof (gdouble) * gdk_device_get_n_axes (source_device));
- }
- else if (event->type == GDK_BUTTON_PRESS ||
- event->type == GDK_BUTTON_RELEASE)
+ if (type == GDK_MOTION_NOTIFY ||
+ type == GDK_BUTTON_PRESS ||
+ type == GDK_BUTTON_RELEASE)
{
- info->axes =
- g_memdup (event->button.axes,
- sizeof (gdouble) * gdk_device_get_n_axes (source_device));
+ gdouble *axes;
+ guint n_axes;
+
+ gdk_event_get_axes (event, &axes, &n_axes);
+ info->axes = g_memdup (axes, sizeof (double) * n_axes);
}
if (gdk_event_get_coords (event, &x, &y))
diff --git a/demos/gtk-demo/font_features.c b/demos/gtk-demo/font_features.c
index 761bf8f..b75508f 100644
--- a/demos/gtk-demo/font_features.c
+++ b/demos/gtk-demo/font_features.c
@@ -456,7 +456,11 @@ switch_to_label (void)
static gboolean
entry_key_press (GtkEntry *entry, GdkEventKey *event)
{
- if (event->keyval == GDK_KEY_Escape)
+ guint keyval;
+
+ gdk_event_get_keyval ((GdkEvent *)event, &keyval);
+
+ if (keyval == GDK_KEY_Escape)
{
gtk_entry_set_text (GTK_ENTRY (entry), text);
switch_to_label ();
diff --git a/demos/gtk-demo/hypertext.c b/demos/gtk-demo/hypertext.c
index c655453..4de7ed9 100644
--- a/demos/gtk-demo/hypertext.c
+++ b/demos/gtk-demo/hypertext.c
@@ -110,8 +110,11 @@ key_press_event (GtkWidget *text_view,
{
GtkTextIter iter;
GtkTextBuffer *buffer;
+ guint keyval;
- switch (event->keyval)
+ gdk_event_get_keyval ((GdkEvent *)event, &keyval);
+
+ switch (keyval)
{
case GDK_KEY_Return:
case GDK_KEY_KP_Enter:
@@ -137,31 +140,27 @@ event_after (GtkWidget *text_view,
GtkTextIter start, end, iter;
GtkTextBuffer *buffer;
gdouble ex, ey;
- gint x, y;
+ int x, y;
+ GdkEventType type;
+
+ type = gdk_event_get_event_type (ev);
- if (ev->type == GDK_BUTTON_RELEASE)
+ if (type == GDK_BUTTON_RELEASE)
{
- GdkEventButton *event;
+ guint button;
- event = (GdkEventButton *)ev;
- if (event->button != GDK_BUTTON_PRIMARY)
+ gdk_event_get_button (ev, &button);
+ if (button != GDK_BUTTON_PRIMARY)
return FALSE;
-
- ex = event->x;
- ey = event->y;
}
- else if (ev->type == GDK_TOUCH_END)
+ else if (type == GDK_TOUCH_END)
{
- GdkEventTouch *event;
-
- event = (GdkEventTouch *)ev;
-
- ex = event->x;
- ey = event->y;
}
else
return FALSE;
+ gdk_event_get_coords (ev, &ex, &ey);
+
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
/* we shouldn't follow a link if the user has selected something */
@@ -232,11 +231,13 @@ static gboolean
motion_notify_event (GtkWidget *text_view,
GdkEventMotion *event)
{
+ gdouble ex, ey;
gint x, y;
+ gdk_event_get_coords ((GdkEvent *)event, &ex, &ey);
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
GTK_TEXT_WINDOW_WIDGET,
- event->x, event->y, &x, &y);
+ ex, ey, &x, &y);
set_cursor_if_appropriate (GTK_TEXT_VIEW (text_view), x, y);
diff --git a/demos/gtk-demo/popover.c b/demos/gtk-demo/popover.c
index a95ca1b..ba33f68 100644
--- a/demos/gtk-demo/popover.c
+++ b/demos/gtk-demo/popover.c
@@ -100,18 +100,20 @@ day_selected_cb (GtkCalendar *calendar,
GtkAllocation allocation;
GtkWidget *popover;
GdkEvent *event;
+ GdkWindow *window;
+ gdouble x, y;
event = gtk_get_current_event ();
- if (event->type != GDK_BUTTON_PRESS)
+ if (gdk_event_get_event_type (event) != GDK_BUTTON_PRESS)
return;
- gdk_window_coords_to_parent (event->button.window,
- event->button.x, event->button.y,
- &event->button.x, &event->button.y);
+ window = gdk_event_get_window (event);
+ gdk_event_get_coords (event, &x, &y);
+ gdk_window_coords_to_parent (window, x, y, &x, &y);
gtk_widget_get_allocation (GTK_WIDGET (calendar), &allocation);
- rect.x = event->button.x - allocation.x;
- rect.y = event->button.y - allocation.y;
+ rect.x = x - allocation.x;
+ rect.y = y - allocation.y;
rect.width = rect.height = 1;
popover = create_popover (GTK_WIDGET (calendar),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]