How set cursor in GTK apps using gdk_window_set_cursor



Hi guys,

help me to solve this segmentation fault ....

I am having a gtk application running on top of icewm window manager & X.

During running like this, i have a cursor for my gtk applications.

If i remove icewm window manager & run my gtk application on top of X , it running perfectly but there is no cursor,
its getting a pointer with "x" as my cursor. So i decided to use set_cursor to set my mouse for my gtk application.

Now I want to draw my cursor for my gtk window application.

I used gdk_cursor_new & gdk_window_set_cursor to set my cursor.

During running, it getting segmentation fault.

My code is follows,

#include <gtk/gtk.h>

static void destroy(GtkWidget *widget,gpointer data)
{
    gtk_main_quit();
}


int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *widget;
    GtkWidget *align;
    GtkWidget *separator;
    GtkWidget *table;
    GtkWidget *vbox;
    GtkWidget *button,*button1;
    GdkCursor *cursor=NULL;

    cursor = gdk_cursor_new (GDK_ARROW);

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_resizable (GTK_WINDOW(window),TRUE);
    gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
   g_signal_connect(G_OBJECT (window),"destroy",G_CALLBACK(destroy),NULL);
 
    gtk_window_set_title (GTK_WINDOW(window),"Test Application");
    gtk_container_set_border_width (GTK_CONTAINER(window),0);

    vbox = gtk_vbox_new (FALSE, 5);
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 50);
    gtk_container_add (GTK_CONTAINER (window), vbox);
    gtk_widget_show (vbox);

    /* Create a centering alignment object */
    align = gtk_alignment_new (0.5, 0.5, 0, 0);
    gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 5);
    gtk_widget_show (align);

    separator = gtk_hseparator_new ();
    gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
    gtk_widget_show (separator);

    /* rows, columns, homogeneous */
    table = gtk_table_new (2, 3, FALSE);
    gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
    gtk_widget_show (table);

    /* Add a check button to select displaying of the trough text */
    button = gtk_check_button_new_with_label ("</b Show text /b>");
    gtk_table_attach (GTK_TABLE (table), button, 0, 1, 0, 1,
                      GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
                      5, 5);
    gtk_widget_show (button);

    /* Add a check button to toggle activity mode */
    button1 = gtk_check_button_new_with_label ("Activity mode");
    gtk_table_attach (GTK_TABLE (table), button1, 0, 1, 1, 2,
                      GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
                      5, 5);
    gtk_widget_show (button1);
     gdk_window_set_cursor ((GTK_WIDGET(widget)->window), cursor);
     gtk_widget_show(window);

    gtk_main();

    return 0;

}


Guys help me ...

harish




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