GTK threads
I posted this on gtk-list but in the hope of catching a wider audience ... I'm developing a program(s) which runs in the client/server environment. I'm using GTK, sockets, and threads. (GTK and threads only on the client side.) I don't have very much experience using threads and this is the first time I've tried to call GTK functions within a thread, and I'm having problems. I've tried different ways of approaching the problem but can't seem to get anywhere. I suspect there's something I don't understand about thread processing or I'm under some misconception. Maybe someone can help me? Any help is much appreciated. I get the following errors when trying to run the code below (the errors show up when the program calls gtk_dialog_run() in the thread (Wait4Challenge()): src/xcb_io.c:242: process_responses: Assertion `(((long) (dpy-last_request_read) - (long) (dpy-request)) = 0)' failed. Fatal IO error 0 (Success) on X server :0.0. void * Wait4Challenge () { int wsock, x, port = 0, listensock, connected; char buffer[5000], *msg[5], challenger[50]; listensock = -1; for (x = 0; x 5; x++) msg[x] = NULL; wsock = get_connection (SOCK_STREAM, port, listensock); connected = 1; while (connected) { GtkWidget *dialog; int response; if (sock_gets (wsock, buffer[0], sizeof (buffer)) 0) { msg[0] = There is a problem with the server.\n\n; outMessage (msg); connected = 0; } if (buffer[0] == 'R') connected = 0; if (buffer[0] != 'C') continue; strcpy (challenger[0], buffer[1]); gdk_threads_enter (); dialog = gtk_message_dialog_new (GTK_WINDOW (mainwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, %s has challenged you to a game. Do you wish to play?, challenger); gtk_window_set_title (GTK_WINDOW (dialog), Play Challenger?); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); gdk_flush(); gdk_threads_leave (); if (response == GTK_RESPONSE_YES) { sock_puts (wsock, OK\n); connected = 0; } else { sock_puts (wsock, NO\n); for (x = 0; x 5; x++) msg[x] = NULL; continue; } } shutdown (wsock, SHUT_RDWR); close (wsock); return (NULL); } int main (int argc, char *argv[]) { g_thread_init (NULL); gdk_threads_init (); gtk_init (argc, argv); mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_usize (mainwin, WINSIZEX, WINSIZEY); gtk_widget_realize (mainwin); gtk_widget_add_events (mainwin, GDK_BUTTON_PRESS_MASK); gtk_signal_connect (GTK_OBJECT (mainwin), delete_event, GTK_SIGNAL_FUNC (delete_event), 0); gtk_widget_show_all (mainwin); if (!g_thread_create (Wait4Challenge, NULL, FALSE, NULL)) syslog (LOG_INFO, error trying to create new thread); gdk_threads_enter (); gtk_main (); gdk_flush(); gdk_threads_leave (); return 0; } -- Marshall Lake -- ml...@mlake.net -- http://mlake.net ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK threads
Hi, You should be aware when call GTK+ function in another thread, if you do this from another thread, GTK+ is likely not send commands to the X server. When you run a dialog in the main thread, main loop is blocked, so the dialog's window remain displayed until a response was given (eg. button was clicked). But in you code, you run the dialog outside the main loop (main thread) the main loop of course is not blocked, and it fails to show the dialog. See http://library.gnome.org/devel/gtk-faq/stable/x499.html on howto send GTK+ funcs to the main loop. Another way is to provide mechanism so you can run the dialog from the main thread by using such as condition variable (GCond). -- ajhwb --- ml...@mlake.net wrote: From: Marshall Lake ml...@mlake.net To: gtk-app-devel-list@gnome.org Subject: GTK threads Date: Wed, 8 Jul 2009 09:38:30 -0400 (EDT) I posted this on gtk-list but in the hope of catching a wider audience ... I'm developing a program(s) which runs in the client/server environment. I'm using GTK, sockets, and threads. (GTK and threads only on the client side.) I don't have very much experience using threads and this is the first time I've tried to call GTK functions within a thread, and I'm having problems. I've tried different ways of approaching the problem but can't seem to get anywhere. I suspect there's something I don't understand about thread processing or I'm under some misconception. Maybe someone can help me? Any help is much appreciated. I get the following errors when trying to run the code below (the errors show up when the program calls gtk_dialog_run() in the thread (Wait4Challenge()): src/xcb_io.c:242: process_responses: Assertion `(((long) (dpy-last_request_read) - (long) (dpy-request)) = 0)' failed. Fatal IO error 0 (Success) on X server :0.0. void * Wait4Challenge () { int wsock, x, port = 0, listensock, connected; char buffer[5000], *msg[5], challenger[50]; listensock = -1; for (x = 0; x 5; x++) msg[x] = NULL; wsock = get_connection (SOCK_STREAM, port, listensock); connected = 1; while (connected) { GtkWidget *dialog; int response; if (sock_gets (wsock, buffer[0], sizeof (buffer)) 0) { msg[0] = There is a problem with the server.\n\n; outMessage (msg); connected = 0; } if (buffer[0] == 'R') connected = 0; if (buffer[0] != 'C') continue; strcpy (challenger[0], buffer[1]); gdk_threads_enter (); dialog = gtk_message_dialog_new (GTK_WINDOW (mainwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, %s has challenged you to a game. Do you wish to play?, challenger); gtk_window_set_title (GTK_WINDOW (dialog), Play Challenger?); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); gdk_flush(); gdk_threads_leave (); if (response == GTK_RESPONSE_YES) { sock_puts (wsock, OK\n); connected = 0; } else { sock_puts (wsock, NO\n); for (x = 0; x 5; x++) msg[x] = NULL; continue; } } shutdown (wsock, SHUT_RDWR); close (wsock); return (NULL); } int main (int argc, char *argv[]) { g_thread_init (NULL); gdk_threads_init (); gtk_init (argc, argv); mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_usize (mainwin, WINSIZEX, WINSIZEY); gtk_widget_realize (mainwin); gtk_widget_add_events (mainwin, GDK_BUTTON_PRESS_MASK); gtk_signal_connect (GTK_OBJECT (mainwin), delete_event, GTK_SIGNAL_FUNC (delete_event), 0); gtk_widget_show_all (mainwin); if (!g_thread_create (Wait4Challenge, NULL, FALSE, NULL)) syslog (LOG_INFO, error trying to create new thread); gdk_threads_enter (); gtk_main (); gdk_flush(); gdk_threads_leave (); return 0; } -- Marshall Lake -- ml...@mlake.net -- http://mlake.net ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list _ Listen to KNAC, Hit the Home page and Tune In Live! --- http://www.knac.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re:Re: Can I set background image for GtkTextView
When you reply, please add CC to the mailing-list, so other peoples know and may help you more. Thanks, --- win...@126.com wrote: From: winsty win...@126.com To: ajhwb aj...@knac.com Subject: Re:Re: Can I set background image for GtkTextView Date: Fri, 3 Jul 2009 10:32:29 +0800 (CST) It works fine, thanks. 在2009-07-02?23:32:21,Ardhan?Madras?aj...@knac.com?写道: Hi, I?already?wrote?a?simple?demo?in?the?past?when?working?on?my?project,?this?may?help?you,?feel?free?to?explore?the?codes?because?this?is?a?really?simple?one: #include?gtk/gtk.h int? main?(intargc, ??char?**argv) { ??GtkWidget?*window; ??GtkWidget?*textv; ??GdkWindow?*textv_window; ??GdkPixmap?*pixmap; ??GdkColor?color; ?? ??gtk_init?(argc,?argv); ?? ??window?=?gtk_window_new?(GTK_WINDOW_TOPLEVEL); ??gtk_window_set_default_size?(GTK_WINDOW?(window),?400,?600); ??g_signal_connect?(window,?destroy,?G_CALLBACK?(gtk_main_quit),?NULL); ?? ??textv?=?gtk_text_view_new?(); ??gtk_container_add?(GTK_CONTAINER?(window),?textv); ?? ??gtk_widget_show_all?(window); ?? ??/*?Windows?are?are?nonexistent?before?the?widget?has?been?realized.?*/ ??textv_window?=?gtk_text_view_get_window?(GTK_TEXT_VIEW?(textv),? ???GTK_TEXT_WINDOW_TEXT); ??gdk_color_parse?(#68604d,?color); ??pixmap?=?gdk_pixmap_create_from_xpm?((GdkDrawable?*)?textv_window,?NULL,? ???color,?back-gimp.xpm); ??gdk_window_set_back_pixmap?(textv_window,?pixmap,?FALSE); ?? ??gtk_main?(); ?? ??return?0; } ---?amolgkulka...@gmail.com?wrote: From:?Amol?amolgkulka...@gmail.com To:?winsty?win...@126.com Cc:?gtk-app-devel-list?gtk-app-devel-list@gnome.org Subject:?Re:?Can?I?set?background?image?for?GtkTextView Date:?Wed,?01?Jul?2009?10:48:18?+0530 Try?setting?background?to?textwindow?of?GtkTextView. you?can?get?text_window?through?gtk_text_view_get_window (textview,window_type); I?don't?remember?exact?syntax?though. Regards, Amol On?Tue,?2009-06-30?at?15:54?+0800,?winsty?wrote: ?Hi,?All ?? ?I?want?to?set?a?background?image?for?GtkTextView?in?my?program,?but?i?don't?know?how?to?do?it.?And?i?also?can't?find?something?useful?about? ?this?question,?that's?why?I'm?sending?it?here.? ?? ?Best?Regards ?winsty ?? ? ? ?___ ?gtk-app-devel-list?mailing?list ?gtk-app-devel-l...@gnome.org ?http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list?mailing?list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list _ Listen?to?KNAC,?Hit?the?Home?page?and?Tune?In?Live!?---?http://www.knac.com ___ gtk-app-devel-list?mailing?list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list _ Listen to KNAC, Hit the Home page and Tune In Live! --- http://www.knac.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK threads
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Marshall Lake wrote: I posted this on gtk-list but in the hope of catching a wider audience ... I'm developing a program(s) which runs in the client/server environment. I'm using GTK, sockets, and threads. (GTK and threads only on the client side.) I don't have very much experience using threads and this is the first time I've tried to call GTK functions within a thread, and I'm having problems. I've tried different ways of approaching the problem but can't seem to get anywhere. I suspect there's something I don't understand about thread processing or I'm under some misconception. Maybe someone can help me? Any help is much appreciated. If I'm not mistaken, X isn't tread-safe, which may be the root cause of the specific error message that you're seeing. The implication is that any call which may invoke X should be done from the main thread. When an auxiliary thread does need to do some drawing, one way to achieve that would be with a g_idle_add(), which will get invoked by the main thread when there is nothing else to do. Hope this helps, - -Greg I get the following errors when trying to run the code below (the errors show up when the program calls gtk_dialog_run() in the thread (Wait4Challenge()): src/xcb_io.c:242: process_responses: Assertion `(((long) (dpy-last_request_read) - (long) (dpy-request)) = 0)' failed. Fatal IO error 0 (Success) on X server :0.0. void * Wait4Challenge () { int wsock, x, port = 0, listensock, connected; char buffer[5000], *msg[5], challenger[50]; listensock = -1; for (x = 0; x 5; x++) msg[x] = NULL; wsock = get_connection (SOCK_STREAM, port, listensock); connected = 1; while (connected) { GtkWidget *dialog; int response; if (sock_gets (wsock, buffer[0], sizeof (buffer)) 0) { msg[0] = There is a problem with the server.\n\n; outMessage (msg); connected = 0; } if (buffer[0] == 'R') connected = 0; if (buffer[0] != 'C') continue; strcpy (challenger[0], buffer[1]); gdk_threads_enter (); dialog = gtk_message_dialog_new (GTK_WINDOW (mainwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, %s has challenged you to a game. Do you wish to play?, challenger); gtk_window_set_title (GTK_WINDOW (dialog), Play Challenger?); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); gdk_flush(); gdk_threads_leave (); if (response == GTK_RESPONSE_YES) { sock_puts (wsock, OK\n); connected = 0; } else { sock_puts (wsock, NO\n); for (x = 0; x 5; x++) msg[x] = NULL; continue; } } shutdown (wsock, SHUT_RDWR); close (wsock); return (NULL); } int main (int argc, char *argv[]) { g_thread_init (NULL); gdk_threads_init (); gtk_init (argc, argv); mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_usize (mainwin, WINSIZEX, WINSIZEY); gtk_widget_realize (mainwin); gtk_widget_add_events (mainwin, GDK_BUTTON_PRESS_MASK); gtk_signal_connect (GTK_OBJECT (mainwin), delete_event, GTK_SIGNAL_FUNC (delete_event), 0); gtk_widget_show_all (mainwin); if (!g_thread_create (Wait4Challenge, NULL, FALSE, NULL)) syslog (LOG_INFO, error trying to create new thread); gdk_threads_enter (); gtk_main (); gdk_flush(); gdk_threads_leave (); return 0; } - -- +-+ Please also check the log file at /dev/null for additional information. (from /var/log/Xorg.setup.log) | Greg Hosler ghos...@redhat.com| +-+ -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iEYEARECAAYFAkpU99MACgkQ404fl/0CV/QP0gCdFjSI6ASkdRfr70QXpy5amjQn z28AoKG55bgTe2t9dUERYc1G8wxPULaT =DMvb -END PGP SIGNATURE- ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Stop alt-spacebar window menu
Bill Farmer wrote: Thanks for all the help. I've put it in the too hard box for the moment, but will come back to it later... So it looks like it is certainly possible to take alt-spacebar away from the window manager. Just now I noticed that VirtualBox's virtual machine windows do this very thing. In fact alt-clicking to drag/resize is eaten by virtualbox as well. So there must be a way to do what you want. I suppose the open source VirtualBox source code may shed light on this. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Stop alt-spacebar window menu
Michael Torrie wrote: So it looks like it is certainly possible to take alt-spacebar away from the window manager. Just now I noticed that VirtualBox's virtual machine windows do this very thing. In fact alt-clicking to drag/resize is eaten by virtualbox as well. So there must be a way to do what you want. I suppose the open source VirtualBox source code may shed light on this. I should add that this behavior seems to be true on Gnome when the pointer grab is turned *off*. In other words I haven't captured the keyboard and mouse into the virtual machine window yet alt-spacebar, alt-click, etc, are all not passed to the window manager. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK threads
(When you reply, please add CC to devel mailing list, so other peoples know it's progress and may help you more). --- ml...@mlake.net wrote: From: Marshall Lake ml...@mlake.net To: Ardhan Madras aj...@knac.com Subject: Re: GTK threads Date: Wed, 8 Jul 2009 12:21:34 -0400 (EDT) Thanks for your feedback. I think what you say is likely my problem. On Wed, 8 Jul 2009, Ardhan Madras wrote: Hi, You should be aware when call GTK+ function in another thread, if you do this from another thread, GTK+ is likely not send commands to the X server. When you run a dialog in the main thread, main loop is blocked, so the dialog's window remain displayed until a response was given (eg. button was clicked). But in you code, you run the dialog outside the main loop (main thread) the main loop of course is not blocked, and it fails to show the dialog. See http://library.gnome.org/devel/gtk-faq/stable/x499.html on howto send GTK+ funcs to the main loop. Another way is to provide mechanism so you can run the dialog from the main thread by using such as condition variable (GCond). -- ajhwb --- ml...@mlake.net wrote: From: Marshall Lake ml...@mlake.net To: gtk-app-devel-list@gnome.org Subject: GTK threads Date: Wed, 8 Jul 2009 09:38:30 -0400 (EDT) I posted this on gtk-list but in the hope of catching a wider audience ... I'm developing a program(s) which runs in the client/server environment. I'm using GTK, sockets, and threads. (GTK and threads only on the client side.) I don't have very much experience using threads and this is the first time I've tried to call GTK functions within a thread, and I'm having problems. I've tried different ways of approaching the problem but can't seem to get anywhere. I suspect there's something I don't understand about thread processing or I'm under some misconception. Maybe someone can help me? Any help is much appreciated. I get the following errors when trying to run the code below (the errors show up when the program calls gtk_dialog_run() in the thread (Wait4Challenge()): src/xcb_io.c:242: process_responses: Assertion `(((long) (dpy-last_request_read) - (long) (dpy-request)) = 0)' failed. Fatal IO error 0 (Success) on X server :0.0. void * Wait4Challenge () { int wsock, x, port = 0, listensock, connected; char buffer[5000], *msg[5], challenger[50]; listensock = -1; for (x = 0; x 5; x++) msg[x] = NULL; wsock = get_connection (SOCK_STREAM, port, listensock); connected = 1; while (connected) { GtkWidget *dialog; int response; if (sock_gets (wsock, buffer[0], sizeof (buffer)) 0) { msg[0] = There is a problem with the server.\n\n; outMessage (msg); connected = 0; } if (buffer[0] == 'R') connected = 0; if (buffer[0] != 'C') continue; strcpy (challenger[0], buffer[1]); gdk_threads_enter (); dialog = gtk_message_dialog_new (GTK_WINDOW (mainwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, %s has challenged you to a game. Do you wish to play?, challenger); gtk_window_set_title (GTK_WINDOW (dialog), Play Challenger?); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); gdk_flush(); gdk_threads_leave (); if (response == GTK_RESPONSE_YES) { sock_puts (wsock, OK\n); connected = 0; } else { sock_puts (wsock, NO\n); for (x = 0; x 5; x++) msg[x] = NULL; continue; } } shutdown (wsock, SHUT_RDWR); close (wsock); return (NULL); } int main (int argc, char *argv[]) { g_thread_init (NULL); gdk_threads_init (); gtk_init (argc, argv); mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_usize (mainwin, WINSIZEX, WINSIZEY); gtk_widget_realize (mainwin); gtk_widget_add_events (mainwin, GDK_BUTTON_PRESS_MASK); gtk_signal_connect (GTK_OBJECT (mainwin), delete_event, GTK_SIGNAL_FUNC (delete_event), 0); gtk_widget_show_all (mainwin); if (!g_thread_create (Wait4Challenge, NULL, FALSE, NULL)) syslog (LOG_INFO, error trying to create new thread); gdk_threads_enter (); gtk_main (); gdk_flush(); gdk_threads_leave (); return 0; } -- Marshall Lake -- ml...@mlake.net -- http://mlake.net ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list _ Listen to KNAC, Hit the Home page and Tune
gtk_file_chooser_hangs
Hello, I have the problem, that the gtk_file_chooser is not working anymore in my application under win32. I get just a sandglass-curser over it. I get no warning or errormessage on the console. I Setup a new Computer with Mingw and the actual (2009/06/01) All-In ONE Bundle. I had the same Problem earlier this year, but it is not solved yet. http://mail.gnome.org/archives/gtk-app-devel-list/2009-January/msg00075.html Any Idea what I can do? Best regards Arne ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list