Question

I have tried to use the clutter-gtk. I wrote a small piece of code that create a gtk window with a clutter stage in it. I try to get mouse button press event on the stage but there is nothing.

Here is the code:

#include <clutter/clutter.h>
#include <clutter-gtk/clutter-gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
/*gcc 3_clutter_app_clickable_text_in_gtk.c -o 3_clutter_app_clickable_text_in_gtk `pkg-config clutter-1.0 clutter-gtk-1.0 glib --cflags --libs`*/

/*mouse clic handler*/
void on_stage_button_press( ClutterStage *stage, ClutterEvent *event, gpointer data) 
{
  printf("ok\n");
}


int main(int argc, char *argv[])
{
  if (gtk_clutter_init(&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return EXIT_FAILURE;

   /*create the window*/
   GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);

   /*destroy from window close all*/
   g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);    
   /*vertical box, 0 spacing*/
   GtkWidget * box = gtk_box_new(GTK_ORIENTATION_VERTICAL,0);
   /*add box in the window*/
   gtk_container_add(GTK_CONTAINER(window), box);

   /*create the cutter widget*/
   GtkWidget *clutter_widget = gtk_clutter_embed_new ();
   gtk_widget_set_size_request (clutter_widget, 200, 200);

   ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(clutter_widget));
   clutter_stage_set_use_alpha(CLUTTER_STAGE(stage), TRUE);
   ClutterColor stage_color ;
   GString * bg_color = g_string_new("#555753ff");
   clutter_color_from_string(&stage_color,bg_color->str);
   clutter_actor_set_background_color(stage, &stage_color);

   /*add the cutter widget in the box expand and fill are TRUE and spacing is 0*/
   gtk_box_pack_start (GTK_BOX (box), clutter_widget, TRUE, TRUE, 0);

   /*create line text*/
   ClutterColor text_color;
   GString * fg_color = g_string_new("#00000055");
   clutter_color_from_string(&text_color, fg_color->str);
   ClutterActor *some_text = clutter_text_new_full("Sans 24", "Hello, world", &text_color);
   clutter_actor_set_size(some_text, 256, 128);
   clutter_actor_set_position(some_text, 128, 128);
   clutter_actor_add_child(CLUTTER_ACTOR(stage), some_text);
   clutter_text_set_editable(CLUTTER_TEXT(some_text), TRUE);    
   /*define clic event*/
   g_signal_connect(stage, "button-press-event", G_CALLBACK(on_stage_button_press), NULL);

   /* Show the window and all its widgets: */
   gtk_widget_show_all (GTK_WIDGET (window));

   /* Start the main loop, so we can respond to events: */
   gtk_main ();

   return EXIT_SUCCESS;
}

Nothing happens when I click on the stage. I have made some tests and I can handle click event on the main windows, on the clutter_widget but not directly on the clutter stage.

This code is modified one from http://www.openismus.com/documents/clutter_tutorial/0.9/docs/tutorial/html/sec-stage-widget.html. In this one the author connect the signal directly on the stage but this example is for clutter 0.9 and don't compile anymore with clutter v > 1.0.

Any ideas on what I am doing wrong?

Edit

I have made some test with "key-press-event" which are handled. So the problem seems to come from the events mask of the stage.

Does anyone know how to change the event mask of the stage in order to force the stage to react on mouse events?

Was it helpful?

Solution

I close this question because :

  1. clutter-gtk is just a proof of concept
  2. clutter-gtk will not be used in the future

see https://mail.gnome.org/archives/clutter-list/2013-February/msg00059.html

so I don't want to loose more time with this.

For information,the same example using juste clutter works as expected.

OTHER TIPS

CLUTTER_BACKEND=gdk ./yourexecutable

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top