开发者

Moving window in the signal function

I'm writing something like gtk_window_move(w, 0, 0); sleep(5); but the window position changes only after the "sleep" call. I wonder, if you could help me to开发者_如何转开发 make this code work correctly. Btw, I use gtk_signal_connect.


You have to call the gdk_flush function to actually send the command to the server. Note that this is only needed because of the sleep call which you shouldn't use anyway (application becomes unresponsive during the time); had you used g_timeout_add, gdk would flush the X command queue automatically.

About making widgets visible: this is an operation that requires bidirectional communication between the program and the server, basically, the server asks the client to paint the window and the client responds with commands to draw it. In Gtk, this means you have to let the main loop run. Either:

  • setup a timeout for the sleep with gtk_timeout_add, and do the rest of the work in the callback
  • run a nested main loop with gtk_main (return from it with gtk_main_quit, possibly from a callback of a timeout
  • run the loop iterations with gtk_main_iteration. This is the least promising approach, because it will be hard to combine it with the sleep.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜