Button events not working



Title: Button events not working

Given following code:

#include <gtk/gtk.h>

gboolean
button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
  g_print("button-press-event\n");
  return FALSE;
}

gboolean
button_release_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
  g_print("button-release-event\n");
  return FALSE;
}

gboolean
key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
  g_print("key-press-event\n");
  return FALSE;
}

gboolean
key_release_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
  g_print("key-release-event\n");
  return FALSE;
}

gboolean
delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
  gtk_widget_destroy(widget);
  gtk_main_quit();
  return FALSE;
}

int main(int argc, char* argv[])
{
  GtkWidget *window;

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_signal_connect(GTK_OBJECT(window), "delete-event", GTK_SIGNAL_FUNC(delete_event), NULL);
  gtk_signal_connect(GTK_OBJECT(window), "button-press-event", GTK_SIGNAL_FUNC(button_press_event), NULL);
  gtk_signal_connect(GTK_OBJECT(window), "button-release-event", GTK_SIGNAL_FUNC(button_release_event), NULL);
  gtk_signal_connect(GTK_OBJECT(window), "key-press-event", GTK_SIGNAL_FUNC(key_press_event), NULL);
  gtk_signal_connect(GTK_OBJECT(window), "key-release-event", GTK_SIGNAL_FUNC(key_release_event), NULL);

  gtk_widget_show(window);

  gtk_main ();

  return 0;
}

I tested this program under RH Linux 7.0 and under Windows 2000 with the gtk port to win32 and it behaves exactly the same.

- Both button-press-event and button-release-event are not responding at all when clicking over the window.
- key-release-event is not responding either.
- When I press a key without releasing it, the window starts calling key_press_event(...) many, many times.

I supposed that the key-press-event would be emitted only once when I press a key so, when I release it the key-release-event is emitted.

Is there a problem connecting these events with toplevel windows?
Is this the correct behavior?

Thanks,

Esteban Quijano Vincenzi
Artinsoft corp.
Quality Assurance
Intel Project




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