Slow spin button signal get doubled



Hi!

I guess I have found a bug: I am encountering strange behaviour from spin button. If the callback of a spin button "value-changed" signal is slow enough, the callback will be called twice when the spin button is adjusted for the first time. Further actions work normally. This behaviour only happens when operating the spin button with mouse. By using keyboard up or down arrows, the spin button only takes one step as it should.

The minimal code that can reproduce this problem follows:
--
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <gtk/gtk.h>

void spinbutton_signal( GtkSpinButton *spinbutton, gpointer object )
{
int level = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(spinbutton) );
    printf( "Spinbutton: %d\n", level );
    sleep( 2 );
}


int main( int argc, char **argv )
{
    gtk_init( &argc, &argv );

    GtkWidget *window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
    g_signal_connect( G_OBJECT(window), "delete_event",
                      G_CALLBACK(gtk_main_quit),
                      (gpointer)NULL );

    GtkWidget *spinbutton = gtk_spin_button_new_with_range( 0, 10, 1 );
    gtk_spin_button_set_value( GTK_SPIN_BUTTON(spinbutton), 5 );
    g_signal_connect( G_OBJECT(spinbutton), "value-changed",
                      G_CALLBACK(spinbutton_signal),
                      (gpointer)NULL );

    gtk_container_add( GTK_CONTAINER(window), spinbutton );

    gtk_widget_show_all( window );
    gtk_window_present( GTK_WINDOW(window) );

    gtk_main();

    return( 0 );
}
--
I also tried the same with GtkButton, but that doesn't double the signal calls. The problem must be therefore connected to spin button.

--
Taneli Kalvas
M.Sc., Researcher
Physics Department, room FL114
P.O. Box 35 (YFL)
40014 University of Jyväskylä, Finland
Phone: +358-44-314-1602
Fax:   +358-14-260-2351
Email: taneli kalvas jyu fi


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]