Re: Using gtk_widget_set_extension_events() for a button?



Owen Taylor wrote:
David Bourguignon wrote:
Right now, if I understand correctly, I only have one option to know what device pressed a button: derive a new class of button from the drawing area widget. Is that correct?

I don't think that would guarantee you any more future compatibility
than the simpler hack of calling gdk_input_set_extension_events() on
button->event_window in a ::realize signal handler.

Following your advice, here is the solution I came up with for the scribble-xinput.c example. I define two new signal handlers for the quit button: one for the "realize" signal and the other for the "button_press_event" signal. (I write down the code below for anybody interested in doing the same thing...) It works well in practice. Is this the simple hack you were thinking about?

Thanks for your help,

David.


static void
realize_cb (GtkWidget *widget, gpointer data)
{
  printf ("Quit button set extension events\n");
  gdk_input_set_extension_events (GTK_BUTTON(widget)->event_window,
				  GDK_BUTTON_PRESS_MASK |
				  GDK_BUTTON_RELEASE_MASK,
				  GDK_EXTENSION_EVENTS_CURSOR);
}

static gint
button_press_event_cb (GtkWidget *widget, GdkEventButton *event)
{
  printf ("Quit button report extension events: ");
  print_button_press (event->device);
  return FALSE;
}

int
main (int argc, char *argv[])
{
  /* ... */

  button = gtk_button_new_with_label ("Quit");
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
  g_signal_connect (G_OBJECT (button), "realize",
                    G_CALLBACK (realize_cb), NULL);
  g_signal_connect (G_OBJECT (button), "button_press_event",
                    G_CALLBACK (button_press_event_cb), NULL);

  /* ... */

  return 0;
}




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