tests: Use GdkEvent API

This commit is contained in:
Matthias Clasen 2017-08-28 19:11:14 -04:00 committed by Carlos Garnacho
parent d5d0ee6f9d
commit e1ea408161
8 changed files with 102 additions and 53 deletions

View File

@ -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);
}
}

View File

@ -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));

View File

@ -336,12 +336,17 @@ do_popup_menu (GtkWidget *icon_list,
GtkWidget *menu;
GtkWidget *menuitem;
GtkTreePath *path = NULL;
int button, event_time;
guint button, event_time;
ItemData *data;
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;

View File

@ -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;
if (event->state & GDK_BUTTON1_MASK && surface != NULL)
gdk_event_get_state ((GdkEvent *)event, &state);
device = gdk_event_get_device ((GdkEvent *)event);
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;
}

View File

@ -16,13 +16,14 @@ place_popup (GtkWidget *parent,
GdkEvent *event,
GtkWidget *popup)
{
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;
}

View File

@ -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)));
}

View File

@ -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;

View File

@ -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);