Re: [gtk-app-devel-list] Getting and restoring window position...



Hi,

I do it this way:

Test which functions are needed to set the correct position.
(This is different for different window managers because the
window decorations are handled differently)

call  xxx_widget_test_uposition(GtkWidget *gtk_window) at first.

This defines the variable get_deskrelative_origin.

You need a window that is displayed. Note that the window does move
with some window managers when you call xxx_widget_test_uposition

After this you can call 

  xxx_window_get_position(gtk_window, &x, &y)
  gtk_widget_set_uposition(gtk_window, x, y);

and the window will not move any more.


I hope this helps.

Bye
Oliver

(the code is cut and paste with some changes, so there may
be some typos):

static int get_deskrelative_origin = 0;

void xxx_window_get_position(GtkWidget *gtk_window, gint *x, gint *y)
{
  if (get_deskrelative_origin)
  {
    gdk_window_get_deskrelative_origin(gtk_window->window, x, y);
  }
  else
  {
    gdk_window_get_root_origin(gtk_window->window, x, y);
  }
}          

void xxx_widget_test_uposition(GtkWidget *gtk_window)
{
 gint x, y, x_orig, y_orig;
 
  gtk_widget_realize(gtk_window);
 
  while (!GTK_WIDGET_REALIZED(gtk_window) || (gtk_events_pending()))
  {
    gtk_main_iteration();
  }
 
  xxx_window_get_position(gtk_window, &x, &y);
  xxx_window_get_position(gtk_window, &x, &y); /* sometimes is needed twice */
 
  x_orig = x;
  y_orig = y;
  gtk_widget_set_uposition(gtk_window, x, y);
 
  xxx_window_get_position(gtk_window, &x, &y);
 
  if ( (x != x_orig) || (y != y_orig) )
  {
    get_deskrelative_origin = 1;
  }
}
           

Thierry FLORAC wrote:

  Hi...

I know that this problem have already been noticed several times in this
list, but as I didn't found any completely working answer, I'd like to
ask for it a new time...

My problem is simple : how can I get and restore the position of a
GtkWindow in a way that is compatible with any window manager ??

I've tried several methods with functions like gdk_window_get_position,
gdk_window_get_root_origin, gdk_window_get_deskrelative_origin,
gdk_window_move, gtk_window_set_position, gtk_widget_set_uposition,...,
but I didn't found any method which can work fine with every window
managers (I'm currently testing on SawFish, Enlightenment and
WindowMaker).

-- 
Homepage:       http://www.rauch-domain.de
sane-umax:      http://www.rauch-domain.de/sane-umax
xsane:          http://www.xsane.org
E-Mail:         mailto:Oliver Rauch rauch-domain de



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