GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Nov 27, 2015 10:05 am

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Motion compression and gdk_device_get_history(): working?
PostPosted: Wed Aug 07, 2013 6:52 pm 
Familiar Face

Joined: Tue Aug 06, 2013 1:09 pm
Posts: 6

GTK 3.8 introduces motion event compression, essentially a limiting of "motion-notify-event"s to a maximum of one per display frame. That's fine for most apps, but for MyPaint, which I work on, and for GIMP and other painting programs. It's messing up our ability to capture brush strikes smoothly enough for our purposes (see bug #702392 and the bugs linked there for pictures of what I mean).

Question for the forum (and some modern-ish sample code as an answer to that earlier thread ☺): has anyone been able to get motion history working under any combination of X11, GTK and/or GDK?

/* CC0/public domain, Andrew Chadwick, 2013
* */

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <stdio.h>
#include <X11/Xlib.h>

static guint32 last_event_time = 0;

label_motion_notify_cb (GtkWidget *label, GdkEvent *event)
    gdouble x, y;
    guint32 time = gdk_event_get_time(event);
    if (last_event_time > 0) {
        GdkDevice *device = gdk_event_get_device(event);
        if (device != NULL) {
            gint n_events = 0;
            GdkTimeCoord **history = NULL;
            GdkWindow *window = gtk_widget_get_window(label);
            if (gdk_device_get_history(device, window,
                                       last_event_time, time,
                                       &history, &n_events))
                printf("gdk_device_get_history: n_events=%d\n", n_events);
                gdk_device_free_history(history, n_events);
    gdk_event_get_coords(event, &x, &y);
    printf("motion-notify: %.02lf, %.02lf\n", x, y);
    last_event_time = time;

win_delete_event_cb (GtkWidget *win, GdkEvent *event)

main (int argc, char **argv)
    /* X11's view of the motion history size */
    Display *disp = XOpenDisplay(NULL);
    if (disp == NULL) {
        printf("unable to open display\n");
        return 1;
    else {
        printf("XDisplayMotionBufferSize: size=%ld\n",

    /* GDK test window */
    gtk_init(&argc, &argv);
    GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    GtkWidget *label = gtk_label_new("Move the mouse pointer here;\n"
                                     "close window to exit.");
    gtk_container_add(GTK_CONTAINER(win), label);
    gtk_widget_set_has_window(label, TRUE);
    gtk_widget_set_size_request(GTK_WIDGET(label), 300, 200);
    g_signal_connect(win, "delete-event",
                     G_CALLBACK(&win_delete_event_cb), NULL);
    g_signal_connect(label, "motion-notify-event",
                     G_CALLBACK(&label_motion_notify_cb), NULL);
    GdkEventMask events = GDK_POINTER_MOTION_MASK
                     /* | GDK_ALL_EVENTS_MASK */
                        | GDK_BUTTON_MOTION_MASK
                        | GDK_BUTTON_PRESS_MASK
                        | GDK_BUTTON_RELEASE_MASK;
    gtk_widget_add_events(label, events);
    return 0;


$ ./gdkmotion
XDisplayMotionBufferSize: size=256
motion-notify: 145.54, 91.58
motion-notify: 140.62, 91.58
motion-notify: 136.22, 91.58
motion-notify: 133.22, 91.83

with no mention of n_events ever for me on all systems I've tried it on (Debian testing/jessie with GTK+ 3.8.2, xorg 7.7, xf86-input-wacom 0.15.0, synaptics 1.6.2; and under Ubuntu 12.04).

Does gdk_device_get_history() actually work for anyone out there, with any hardware or combination of underlying libs?

(Sadly GDK_POINTER_MOTION_HINT is not a solution to the problem we've been having here: see the bug report above)

[EDIT: spellling, punctuation]

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group