Re: gtk_window_move



What is probably better is to use gdk_flush() after the execution of gtk_window_move() or _resize(), and after that make sure that you run the main event loop with gtk_main_iteration(); you can use a GTimer to determine the time elapsed. Obviously, and also since this involves the windowing system whose timing can not really be predicted, this is nothing for time critical applications and can't be very precise, but tweaks of the mentioned mechanism are surely possible.

An example would look like this (off the top of my head, might contain some errors):

GTimer *timer = g_timer_new();
gtk_window_move(GTK_WINDOW(window), x, y);
g_timer_reset(timer);
while(g_timer_elapsed(timer) > 0.5)
    while(gtk_events_pending())
        gtk_main_iteration();
g_timer_destroy(timer);

Hopefully someone has a more elegant solution :)

-- Milosz

2008/6/18 Craig Harding <craigwharding gmail com>:
I'm trying to move a gtk window multiple times within a period of time
but it seems that it doesn't update the window position for each
window move until gtk_main() is called and then all window moves are
done at once it seems. I want to move a window with a usleep call
inbetween window moves.

Can any provide me with some guidance? Is there a flush or update call
I'm missing?

Below is my code..

#include <gdk/gdk.h>
#include <gtk/gtk.h>

int main (int argc, char **argv) {

  GtkWidget *window;
  int w=200, h=200;
  int x, y;

  x=100;
  y=50;

  gtk_init(&argc, &argv);
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_show_all(window);
  g_signal_connect (G_OBJECT (window), "delete-event", gtk_main_quit, NULL);
  usleep(500000);
  printf("sleep fnished\n");
  gtk_widget_show(window);
  gtk_window_resize (GTK_WINDOW (window), w, h);
  usleep(500000);
  printf("sleep fnished\n");
  gtk_window_move (GTK_WINDOW (window), x, y);

  usleep(500000);
  gtk_widget_show(window);
  gtk_window_resize (GTK_WINDOW (window), w+300, h);

  printf("gtk_main()\n");
  gtk_main();

  return 0;
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list



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