Re: gtk2 multithreaded programming win32 issue

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

 



This message explains my question and fix my problem :-)

http://www.mail-archive.com/gtk-app-devel-list@xxxxxxxxx/msg11790.html

Since I did not found this behavior on Linux, so I think the Win32 port of Gtk+
may still has this "bug".


KC


On Sat, Aug 30, 2008 at 2:08 PM, Kuang-Chun Cheng <kcc1967@xxxxxxxxx> wrote:
>>> 2008/8/28 Tor Lillqvist <tml@xxxxxx>:
>>>> Have the idle callback function return FALSE... Schedule it again with
>>>> g_idle_add() whenever you have something new that needs to be done in
>>>> the GUI thread.
>
> First, thanks for you guys here, I had successfully porting my Gtk2 app. from
> Linux to Win32 :-)  However, I found a behavior of Linux and Win32 is
> quite different ...
> Let me explain what I'm doing:
>
> hello button ---> disable itself and create a thread to run non-gui job.
>        ---> after non-gui job done, use g_add_idle() to enable hello
> button again.
>
> What's odd is when I click on the button, it works OK at the first time.
> But when I click on it again ... it stop receive my mouse event !!!!
>
> If I move my mouse away from the button then move it back and click on it again,
> it works again.
>
> I did not see this strange behavior under Linux.  I can keep my mouse on top of
> the button, just click on it again and again ... all clicks work perfectly.
>
> The source code is here (hopefully, not too long), could someone tell me what's
> wrong in my code ??
> My Win32 platform is WinXP/SP3, and I'm using gtk+-bundle-2.12.11.zip which I
> downloaded from http://www.gtk.org/download-windows.html.
>
> Thanks a lot
> KC
>
> ------------------------------------------------------------------
> /* button2.c */
>
> #include <stdlib.h>
> #include <gtk/gtk.h>
>
> gpointer non_gui_worker(gpointer data);
> gboolean non_gui_idle(gpointer data);
> void gui_cb_clicked(GtkWidget *widget, gpointer data);
>
> gboolean non_gui_idle(gpointer data)
> {
>    GtkWidget *widget = data;
>    gtk_widget_set_sensitive(widget, TRUE);
>    return FALSE;
> }
>
> gpointer non_gui_worker(gpointer data)
> {
>    printf("DO SOMETHING IN NON-GUI THREAD ...\n");
>    g_idle_add(non_gui_idle, data);
>    return NULL;
> }
>
> void gui_cb_clicked(GtkWidget *widget, gpointer data)
> {
>    gtk_widget_set_sensitive(widget, FALSE);
>    g_thread_create(non_gui_worker, widget, FALSE, NULL);
> }
>
> int main (int argc, char *argv[])
> {
>    GtkWidget *win    = NULL;
>    GtkWidget *button = NULL;
>
>    g_thread_init(NULL);
>    gdk_threads_init();
>    gtk_init(&argc, &argv);
>
>    gdk_threads_enter();
>    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>    gtk_container_set_border_width(GTK_CONTAINER(win), 10);
>
>    g_signal_connect(G_OBJECT(win), "destroy",
>        G_CALLBACK(gtk_main_quit), NULL);
>
>    gtk_widget_realize(win);
>    button = gtk_button_new_with_label("Hello Gtk+-2.0");
>
>    g_signal_connect(G_OBJECT(button), "clicked",
>        G_CALLBACK(gui_cb_clicked), (gpointer) "Data Passed");
>
>    gtk_container_add(GTK_CONTAINER(win), button);
>
>    gtk_widget_show_all(win);
>    gtk_main();
>    gdk_threads_leave();
>    exit(0);
> }
>
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux