forked from AuroraMiddleware/gtk
gtk3-demo: Show multiple master devices on the "Event axes" demo
This commit is contained in:
parent
505dac94be
commit
89b7f859a4
@ -31,7 +31,7 @@ typedef struct {
|
||||
} AxesInfo;
|
||||
|
||||
typedef struct {
|
||||
AxesInfo *pointer_info;
|
||||
GHashTable *pointer_info; /* GdkDevice -> AxesInfo */
|
||||
GHashTable *touch_info; /* GdkEventSequence -> AxesInfo */
|
||||
} EventData;
|
||||
|
||||
@ -65,20 +65,16 @@ axes_info_new (void)
|
||||
return info;
|
||||
}
|
||||
|
||||
static void
|
||||
axes_info_free (AxesInfo *info)
|
||||
{
|
||||
g_free (info);
|
||||
}
|
||||
|
||||
static EventData *
|
||||
event_data_new (void)
|
||||
{
|
||||
EventData *data;
|
||||
|
||||
data = g_new0 (EventData, 1);
|
||||
data->pointer_info = g_hash_table_new_full (NULL, NULL, NULL,
|
||||
(GDestroyNotify) g_free);
|
||||
data->touch_info = g_hash_table_new_full (NULL, NULL, NULL,
|
||||
(GDestroyNotify) axes_info_free);
|
||||
(GDestroyNotify) g_free);
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -86,8 +82,7 @@ event_data_new (void)
|
||||
static void
|
||||
event_data_free (EventData *data)
|
||||
{
|
||||
if (data->pointer_info)
|
||||
axes_info_free (data->pointer_info);
|
||||
g_hash_table_destroy (data->pointer_info);
|
||||
g_hash_table_destroy (data->touch_info);
|
||||
g_free (data);
|
||||
}
|
||||
@ -96,11 +91,12 @@ static void
|
||||
update_axes_from_event (GdkEvent *event,
|
||||
EventData *data)
|
||||
{
|
||||
GdkDevice *source_device;
|
||||
GdkDevice *device, *source_device;
|
||||
GdkEventSequence *sequence;
|
||||
gdouble x, y;
|
||||
AxesInfo *info;
|
||||
|
||||
device = gdk_event_get_device (event);
|
||||
source_device = gdk_event_get_source_device (event);
|
||||
sequence = gdk_event_get_event_sequence (event);
|
||||
|
||||
@ -112,17 +108,19 @@ update_axes_from_event (GdkEvent *event,
|
||||
}
|
||||
else if (event->type == GDK_LEAVE_NOTIFY)
|
||||
{
|
||||
if (data->pointer_info)
|
||||
axes_info_free (data->pointer_info);
|
||||
data->pointer_info = NULL;
|
||||
g_hash_table_remove (data->pointer_info, device);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sequence)
|
||||
{
|
||||
if (!data->pointer_info)
|
||||
data->pointer_info = axes_info_new ();
|
||||
info = data->pointer_info;
|
||||
info = g_hash_table_lookup (data->pointer_info, device);
|
||||
|
||||
if (!info)
|
||||
{
|
||||
info = axes_info_new ();
|
||||
g_hash_table_insert (data->pointer_info, device, info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -144,11 +142,7 @@ update_axes_from_event (GdkEvent *event,
|
||||
event->type == GDK_TOUCH_UPDATE)
|
||||
{
|
||||
if (sequence && event->touch.emulating_pointer)
|
||||
{
|
||||
if (data->pointer_info)
|
||||
axes_info_free (data->pointer_info);
|
||||
data->pointer_info = NULL;
|
||||
}
|
||||
g_hash_table_remove (data->pointer_info, device);
|
||||
}
|
||||
if (event->type == GDK_MOTION_NOTIFY)
|
||||
{
|
||||
@ -352,7 +346,7 @@ draw_cb (GtkWidget *widget,
|
||||
{
|
||||
EventData *data = user_data;
|
||||
GtkAllocation allocation;
|
||||
AxesInfo *touch_info;
|
||||
AxesInfo *info;
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
gint y = 0;
|
||||
@ -360,27 +354,37 @@ draw_cb (GtkWidget *widget,
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
/* Draw Abs info */
|
||||
if (data->pointer_info)
|
||||
draw_axes_info (cr, data->pointer_info, &allocation);
|
||||
g_hash_table_iter_init (&iter, data->pointer_info);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, NULL, &value))
|
||||
{
|
||||
info = value;
|
||||
draw_axes_info (cr, info, &allocation);
|
||||
}
|
||||
|
||||
g_hash_table_iter_init (&iter, data->touch_info);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, NULL, &value))
|
||||
{
|
||||
touch_info = value;
|
||||
draw_axes_info (cr, touch_info, &allocation);
|
||||
info = value;
|
||||
draw_axes_info (cr, info, &allocation);
|
||||
}
|
||||
|
||||
/* Draw name, color legend and misc data */
|
||||
if (data->pointer_info)
|
||||
draw_device_info (widget, cr, NULL, &y, data->pointer_info);
|
||||
g_hash_table_iter_init (&iter, data->pointer_info);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, NULL, &value))
|
||||
{
|
||||
info = value;
|
||||
draw_device_info (widget, cr, NULL, &y, info);
|
||||
}
|
||||
|
||||
g_hash_table_iter_init (&iter, data->touch_info);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
{
|
||||
touch_info = value;
|
||||
draw_device_info (widget, cr, key, &y, touch_info);
|
||||
info = value;
|
||||
draw_device_info (widget, cr, key, &y, info);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
Loading…
Reference in New Issue
Block a user