gtk_get_current_event() (gtk+970606)




Hi! 

I have encountered  a strange behavior of gtk_get_current_event()
in gtkmain.c.

------------------------ test0.c ----------------------------

#include <gtk/gtk.h>
     
void
hello (void)
{

    g_print ("Hello World\n");
    gtk_exit (0);
}

/* key handler */
void
key (void)
{
    GdkEvent *event;
    GdkEventKey kevent;
    gchar ch;

    gtk_get_current_event(event);
    kevent = event->key;
    ch = kevent.keyval;
    g_print("input char: %c\n", ch);
}

int
main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *button;
    
    gtk_init (&argc, &argv);
    
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    /* add "key_press_event" */
    gtk_signal_connect (GTK_OBJECT (window), "key_press_event", 
			GTK_SIGNAL_FUNC (key), NULL);
 
    gtk_container_border_width (GTK_CONTAINER (window), 10);
    
    button = gtk_button_new_with_label ("Hello World");
    gtk_signal_connect (GTK_OBJECT (button), "clicked",
			GTK_SIGNAL_FUNC (hello), NULL);
    gtk_container_add (GTK_CONTAINER (window), button);
    gtk_widget_show (button);
    gtk_widget_show (window);
    gtk_main ();
    
    return 0;
}

---------------------------------------------------------------
compile test0.c and run test0 like bellow.

  $ ./test0 &
  $ Input charactor: d           <- push key "d"
  ** ERROR **: sigsegv caught

To avoid ocurring an err of sigsegv, I modify gtk_get_current_event()
in gtkmain.c to bellow. Also, gtkmain.h too.

----------------------- gtkmain.c ------------------------------
GdkEvent 
gtk_get_current_event ()
{
  return current_event;
}
----------------------------------------------------------------

And modify test0.c to test1.c. 

------------------- key() in test1.c ---------------------------
/* key handler */
void
key (void)
{
    GdkEvent event;
    GdkEventKey kevent;
    gchar ch;

    event = gtk_get_current_event();
    kevent = event.key;
    ch = kevent.keyval;
    g_print("input char: %c\n", ch);
}
----------------------------------------------------------------

compile test1.c and run test1 like bellow.

  $ ./test1 &
  $ Input charactor: d           <- push key "d"
  Input charactor: d  

Although I don't know why character "d" is displayed twice,
I can avoid an err of sigsegv.

thanks.
---
Hideki

  










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