In the context of my gtk app I have an optional "console" -- not a real shell, but a means of sending commands to the app besides point-and-click. It's working OK, but for various reasons I'd like to reformulate it so that I have a loop like this:
while (command != quit) { get_a_command(); do_stuff(); } I'm having trouble with get_a_command(). The criterion for a command being entered is that Return is pressed in a certain GtkTextView, to which I have a pointer. But how does the get_a_command() function know that this has happened? I've implemented this via a static int, "command_entered" (a file-scope global), which is set to 1 by Return and is monitored by the function in question: void get_a_command () { while (!command_entered) { if (gtk_events_pending()) { gtk_main_iteration(); } } command_entered = 0; } This works, but not surprisingly it uses a lot of CPU running around its tight loop waiting for Return. I then tried adding g_usleep(10000) into the loop on "while (!command_entered)". That brought CPU usage down to a sane level, but of course it made the whole GUI quite gummy. It seems there must be a smarter way of doing this, probably using some of the g_main* apparatus or g_threads, which I'm not really familiar with, and at my current level of ignorance looking at the API docs leaves me guessing. Any pointers to get me started would be very helpful. Allin Cottrell _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list