gtk_window_move

View: New views
4 Messages — Rating Filter:   Alert me  

gtk_window_move

by Craig Harding-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
http://mail.gnome.org/mailman/listinfo/gtk-list

Re: gtk_window_move

by milosz derezynski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...>:
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@...
http://mail.gnome.org/mailman/listinfo/gtk-list


_______________________________________________
gtk-list mailing list
gtk-list@...
http://mail.gnome.org/mailman/listinfo/gtk-list

Re: gtk_window_move

by milosz derezynski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ooops, obviously i meant

while (g_timer_elapsed(timer) < 0.5)

not "> 0.5"

2008/6/18 Milosz Derezynski <internalerror@...>:
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@...>:

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@...
http://mail.gnome.org/mailman/listinfo/gtk-list



_______________________________________________
gtk-list mailing list
gtk-list@...
http://mail.gnome.org/mailman/listinfo/gtk-list

RE: gtk_window_move

by Vallone, Anthony :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You are misunderstanding one of the basic principles of event driven
programming.  None of the events (window show, window move, user button
click, etc...) are processed until gtk_main() starts the event loop.
Each event is handled in one iteration of the event loop.  Your code is
queuing some shows and moves with sleeps in between, then it calls
gtk_main() to start processing events.  So, it is quickly processing
your queued events one after the other.

There are a few ways to get the behavior you desire.  Here is one
pseudo-code-ish solution:

bool timeoutCb() {
  gtk_window_move();
  if(done annoying the user)
    return false;
  return true;
}

main() {
  ...
  gtk_window_show();
  g_timeout_add(5000, &timeoutCb);
  gtk_main();
}

-Anthony Vallone


-----Original Message-----
From: gtk-list-bounces@... [mailto:gtk-list-bounces@...] On
Behalf Of Craig Harding
Sent: Wednesday, June 18, 2008 7:07 AM
To: gtk-list@...
Subject: gtk_window_move

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@...
http://mail.gnome.org/mailman/listinfo/gtk-list
_______________________________________________
gtk-list mailing list
gtk-list@...
http://mail.gnome.org/mailman/listinfo/gtk-list