summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2017-08-28 19:11:14 -0400
committerMatthias Clasen <mclasen@redhat.com>2017-08-28 19:11:14 -0400
commit3e24eae76647ee247ad85bb28cc90275d1a602dd (patch)
tree75761b377a050bbad3dce0607789baab2ccab03d
parentb97e8f6214ee1551e7e8300a6bb94815ac2b0400 (diff)
downloadgtk+-3e24eae76647ee247ad85bb28cc90275d1a602dd.tar.gz
tests: Use GdkEvent API
-rw-r--r--tests/motion-compression.c9
-rw-r--r--tests/testgtk.c38
-rw-r--r--tests/testiconview.c13
-rw-r--r--tests/testinput.c67
-rw-r--r--tests/testpopup.c6
-rw-r--r--tests/testtreeedit.c6
-rw-r--r--tests/testtreepos.c6
-rw-r--r--tests/testwidgetfocus.c7
8 files changed, 101 insertions, 51 deletions
diff --git a/tests/motion-compression.c b/tests/motion-compression.c
index 1dc746954a..82f949c091 100644
--- a/tests/motion-compression.c
+++ b/tests/motion-compression.c
@@ -8,12 +8,15 @@ static void
on_motion_notify (GtkWidget *window,
GdkEventMotion *event)
{
- if (event->window == gtk_widget_get_window (window))
+ if (gdk_event_get_window ((GdkEvent*)event) == gtk_widget_get_window (window))
{
+ gdouble x, y;
float processing_ms = gtk_adjustment_get_value (adjustment);
g_usleep (processing_ms * 1000);
- cursor_x = event->x;
- cursor_y = event->y;
+
+ gdk_event_get_coords ((GdkEvent *)event, &x, &y);
+ cursor_x = x;
+ cursor_y = y;
gtk_widget_queue_draw (window);
}
}
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 37513bd013..86effa2187 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -3812,6 +3812,8 @@ cursor_event (GtkWidget *widget,
const gchar *name;
gint i;
const gint n = G_N_ELEMENTS (cursor_names);
+ GdkEventType type;
+ guint button;
name = (const gchar *)g_object_get_data (G_OBJECT (widget), "name");
if (name != NULL)
@@ -3823,11 +3825,13 @@ cursor_event (GtkWidget *widget,
else
i = 0;
- if ((event->type == GDK_BUTTON_PRESS) &&
- ((event->button.button == GDK_BUTTON_PRIMARY) ||
- (event->button.button == GDK_BUTTON_SECONDARY)))
+ type = gdk_event_get_event_type (event);
+ gdk_event_get_button (event, &button);
+ if (type == GDK_BUTTON_PRESS &&
+ (button == GDK_BUTTON_PRIMARY ||
+ button == GDK_BUTTON_SECONDARY))
{
- if (event->button.button == GDK_BUTTON_PRIMARY)
+ if (button == GDK_BUTTON_PRIMARY)
i = (i + 1) % n;
else
i = (i + n - 1) % n;
@@ -5799,21 +5803,23 @@ window_state_callback (GtkWidget *widget,
{
GtkWidget *label = data;
gchar *msg;
+ GdkWindowState changed, new_state;
+ gdk_event_get_window_state ((GdkEvent *)event, &changed, &new_state);
msg = g_strconcat (gtk_window_get_title (GTK_WINDOW (widget)), ": ",
- (event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN) ?
+ (new_state & GDK_WINDOW_STATE_WITHDRAWN) ?
"withdrawn" : "not withdrawn", ", ",
- (event->new_window_state & GDK_WINDOW_STATE_ICONIFIED) ?
+ (new_state & GDK_WINDOW_STATE_ICONIFIED) ?
"iconified" : "not iconified", ", ",
- (event->new_window_state & GDK_WINDOW_STATE_STICKY) ?
+ (new_state & GDK_WINDOW_STATE_STICKY) ?
"sticky" : "not sticky", ", ",
- (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) ?
+ (new_state & GDK_WINDOW_STATE_MAXIMIZED) ?
"maximized" : "not maximized", ", ",
- (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) ?
+ (new_state & GDK_WINDOW_STATE_FULLSCREEN) ?
"fullscreen" : "not fullscreen",
- (event->new_window_state & GDK_WINDOW_STATE_ABOVE) ?
+ (new_state & GDK_WINDOW_STATE_ABOVE) ?
"above" : "not above", ", ",
- (event->new_window_state & GDK_WINDOW_STATE_BELOW) ?
+ (new_state & GDK_WINDOW_STATE_BELOW) ?
"below" : "not below", ", ",
NULL);
@@ -6109,7 +6115,7 @@ configure_event_callback (GtkWidget *widget,
msg = g_strdup_printf ("event: %d,%d %d x %d\n"
"position: %d, %d",
- event->x, event->y, event->width, event->height,
+ 0, 0, 0, 0, // FIXME
x, y);
gtk_label_set_text (GTK_LABEL (label), msg);
@@ -6952,7 +6958,7 @@ snapshot_widget_event (GtkWidget *widget,
if (!data->in_query)
return FALSE;
- if (event->type == GDK_BUTTON_RELEASE)
+ if (gdk_event_get_event_type (event) == GDK_BUTTON_RELEASE)
{
gtk_grab_remove (widget);
gdk_seat_ungrab (gdk_event_get_seat (event));
@@ -7259,7 +7265,11 @@ static gint
scroll_test_scroll (GtkWidget *widget, GdkEventScroll *event,
GtkAdjustment *adjustment)
{
- gdouble new_value = gtk_adjustment_get_value (adjustment) + ((event->direction == GDK_SCROLL_UP) ?
+ GdkScrollDirection direction;
+ gdouble new_value;
+
+ gdk_event_get_scroll_direction ((GdkEvent *)event, &direction);
+ new_value = gtk_adjustment_get_value (adjustment) + (direction == GDK_SCROLL_UP ?
-gtk_adjustment_get_page_increment (adjustment) / 2:
gtk_adjustment_get_page_increment (adjustment) / 2);
new_value = CLAMP (new_value, gtk_adjustment_get_lower (adjustment), gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_page_size (adjustment));
diff --git a/tests/testiconview.c b/tests/testiconview.c
index c35916cc7d..053edf6a6e 100644
--- a/tests/testiconview.c
+++ b/tests/testiconview.c
@@ -341,7 +341,12 @@ do_popup_menu (GtkWidget *icon_list,
GList *list;
if (event)
- path = gtk_icon_view_get_path_at_pos (icon_view, event->x, event->y);
+ {
+ double x, y;
+
+ gdk_event_get_coords ((GdkEvent *)event, &x, &y);
+ path = gtk_icon_view_get_path_at_pos (icon_view, x, y);
+ }
else
{
list = gtk_icon_view_get_selected_items (icon_view);
@@ -370,8 +375,8 @@ do_popup_menu (GtkWidget *icon_list,
if (event)
{
- button = event->button;
- event_time = event->time;
+ gdk_event_get_button ((GdkEvent*)event, &button);
+ event_time = gdk_event_get_time ((GdkEvent *)event);
}
else
{
@@ -390,7 +395,7 @@ button_press_event_handler (GtkWidget *widget,
{
/* Ignore double-clicks and triple-clicks */
if (gdk_event_triggers_context_menu ((GdkEvent *) event) &&
- event->type == GDK_BUTTON_PRESS)
+ gdk_event_get_event_type ((GdkEvent*)event) == GDK_BUTTON_PRESS)
{
do_popup_menu (widget, event);
return TRUE;
diff --git a/tests/testinput.c b/tests/testinput.c
index ef3503e5d0..b47037b86d 100644
--- a/tests/testinput.c
+++ b/tests/testinput.c
@@ -133,17 +133,27 @@ print_axes (GdkDevice *device, gdouble *axes)
static gint
button_press_event (GtkWidget *widget, GdkEventButton *event)
{
- if (event->button == GDK_BUTTON_PRIMARY &&
- surface != NULL)
+ guint button;
+
+ gdk_event_get_button ((GdkEvent *)event, &button);
+
+ if (button == GDK_BUTTON_PRIMARY && surface != NULL)
{
gdouble pressure = 0.5;
+ GdkDevice *device;
+ gdouble *axes;
+ guint n_axes;
+ gdouble x, y;
- print_axes (event->device, event->axes);
+ device = gdk_event_get_device ((GdkEvent *)event);
+ gdk_event_get_axes ((GdkEvent *)event, &axes, &n_axes);
+ gdk_event_get_coords ((GdkEvent *)event, &x, &y);
+
+ print_axes (device, axes);
gdk_event_get_axis ((GdkEvent *)event, GDK_AXIS_PRESSURE, &pressure);
- draw_brush (widget, gdk_device_get_source (event->device),
- event->x, event->y, pressure);
+ draw_brush (widget, gdk_device_get_source (device), x, y, pressure);
- motion_time = event->time;
+ motion_time = gdk_event_get_time ((GdkEvent *)event);
}
return TRUE;
@@ -152,8 +162,12 @@ button_press_event (GtkWidget *widget, GdkEventButton *event)
static gint
key_press_event (GtkWidget *widget, GdkEventKey *event)
{
- if ((event->keyval >= 0x20) && (event->keyval <= 0xFF))
- printf("I got a %c\n", event->keyval);
+ guint keyval;
+
+ gdk_event_get_keyval ((GdkEvent*)event, &keyval);
+
+ if ((keyval >= 0x20) && (keyval <= 0xFF))
+ printf("I got a %c\n", keyval);
else
printf("I got some other key\n");
@@ -166,41 +180,50 @@ motion_notify_event (GtkWidget *widget, GdkEventMotion *event)
GdkTimeCoord **events;
gint n_events;
int i;
+ GdkModifierType state;
+ GdkDevice *device;
+ gdouble *axes;
+ guint n_axes;
+
+ gdk_event_get_state ((GdkEvent *)event, &state);
+ device = gdk_event_get_device ((GdkEvent *)event);
- if (event->state & GDK_BUTTON1_MASK && surface != NULL)
+ if (state & GDK_BUTTON1_MASK && surface != NULL)
{
- if (gdk_device_get_history (event->device, event->window,
- motion_time, event->time,
+ if (gdk_device_get_history (device,
+ gdk_event_get_window ((GdkEvent *)event),
+ motion_time,
+ gdk_event_get_time ((GdkEvent *)event),
&events, &n_events))
{
for (i=0; i<n_events; i++)
{
double x = 0, y = 0, pressure = 0.5;
- gdk_device_get_axis (event->device, events[i]->axes, GDK_AXIS_X, &x);
- gdk_device_get_axis (event->device, events[i]->axes, GDK_AXIS_Y, &y);
- gdk_device_get_axis (event->device, events[i]->axes, GDK_AXIS_PRESSURE, &pressure);
- draw_brush (widget, gdk_device_get_source (event->device),
- x, y, pressure);
+ gdk_device_get_axis (device, events[i]->axes, GDK_AXIS_X, &x);
+ gdk_device_get_axis (device, events[i]->axes, GDK_AXIS_Y, &y);
+ gdk_device_get_axis (device, events[i]->axes, GDK_AXIS_PRESSURE, &pressure);
+ draw_brush (widget, gdk_device_get_source (device), x, y, pressure);
- print_axes (event->device, events[i]->axes);
+ print_axes (device, events[i]->axes);
}
gdk_device_free_history (events, n_events);
}
else
{
double pressure = 0.5;
+ gdouble x, y;
gdk_event_get_axis ((GdkEvent *)event, GDK_AXIS_PRESSURE, &pressure);
- draw_brush (widget, gdk_device_get_source (event->device),
- event->x, event->y, pressure);
+ gdk_event_get_coords ((GdkEvent *)event, &x, &y);
+ draw_brush (widget, gdk_device_get_source (device), x, y, pressure);
}
- motion_time = event->time;
+ motion_time = gdk_event_get_time ((GdkEvent *)event);
}
-
- print_axes (event->device, event->axes);
+ gdk_event_get_axes ((GdkEvent *)event, &axes, &n_axes);
+ print_axes (device, axes);
return TRUE;
}
diff --git a/tests/testpopup.c b/tests/testpopup.c
index 8037b3e31e..0b4863a3b2 100644
--- a/tests/testpopup.c
+++ b/tests/testpopup.c
@@ -18,11 +18,13 @@ place_popup (GtkWidget *parent,
{
GdkEventMotion *ev_motion = (GdkEventMotion *) event;
gint width, height;
+ gdouble x, y;
gtk_window_get_size (GTK_WINDOW (popup), &width, &height);
+ gdk_event_get_root_coords (event, &x, &y);
gtk_window_move (GTK_WINDOW (popup),
- (int) ev_motion->x_root - width / 2,
- (int) ev_motion->y_root - height / 2);
+ (int) x - width / 2,
+ (int) y - height / 2);
return FALSE;
}
diff --git a/tests/testtreeedit.c b/tests/testtreeedit.c
index e7faa61829..65329136db 100644
--- a/tests/testtreeedit.c
+++ b/tests/testtreeedit.c
@@ -136,9 +136,11 @@ edited (GtkCellRendererText *cell,
static gboolean
button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer callback_data)
{
+ double x, y;
+
+ gdk_event_get_coords ((GdkEvent *)event, &x, &y);
/* Deselect if people click outside any row. */
- if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
- event->x, event->y, NULL, NULL, NULL, NULL)) {
+ if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), x, y, NULL, NULL, NULL, NULL)) {
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)));
}
diff --git a/tests/testtreepos.c b/tests/testtreepos.c
index 2c8fd889c5..88af5e8bd3 100644
--- a/tests/testtreepos.c
+++ b/tests/testtreepos.c
@@ -57,11 +57,13 @@ release_event (GtkTreeView *tv,
GdkEventButton *event)
{
GtkTreePath *path;
+ gdouble x, y;
- if (event->type != GDK_BUTTON_RELEASE)
+ if (gdk_event_get_event_type ((GdkEvent *)event) != GDK_BUTTON_RELEASE)
return TRUE;
- if (clicked_icon (tv, event->x, event->y, &path))
+ gdk_event_get_coords ((GdkEvent *)event, &x, &y);
+ if (clicked_icon (tv, x, y, &path))
{
GtkTreeModel *model;
GtkTreeIter iter;
diff --git a/tests/testwidgetfocus.c b/tests/testwidgetfocus.c
index 97e3074ea0..3524bb990e 100644
--- a/tests/testwidgetfocus.c
+++ b/tests/testwidgetfocus.c
@@ -203,9 +203,12 @@ gtk_focus_widget_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event)
{
GtkFocusWidget *self = GTK_FOCUS_WIDGET (widget);
+ gdouble x, y;
- self->mouse_x = event->x;
- self->mouse_y = event->y;
+ gdk_event_get_coords ((GdkEvent *)event, &x, &y);
+
+ self->mouse_x = x;
+ self->mouse_y = y;
gtk_widget_queue_draw (widget);