Re: [gtk-list] How to hide windows & show again later in the same position



"Damon Chaplin" <DAChaplin@email.msn.com> writes:

> How do you hide a window and then show it in the same position
> again later?
> 
> This is what I'm doing at present:
> 
> static gint
> close_window (GtkWidget  *widget,
> 	      GdkEvent   *event,
> 	      gpointer    data)
> {
>   gint x, y;
>   /* remember position - doesn't work properly yet - moves down each time */
>   gdk_window_get_position(widget->window, &x, &y);
>   gtk_widget_set_uposition(widget, x, y);
>   gtk_widget_hide(widget);
>   return TRUE;
> }
> 
> However, gdk_window_get_position returns the position of the window
> without the window manager border, whereas gtk_widget_set_uposition
> sets the position of the window including the wm border.
> 
> So, is there a way of getting the position of the window including the wm
> border?

 Well after playing with all the g[dt]k_window_get_* type functions
for a bit and not understanding what they were giving me. I just
did...
 I hope there was is a better way, but non of the obvious functions
seemed to give it.

static void get_size_pos(GtkWidget *window,
                         int *x_pos, int *y_pos, int *x_size, int *y_size)
{
 int dummy = 0;

 if (!x_pos) x_pos = &dummy;
 if (!y_pos) y_pos = &dummy;
 if (!x_size) x_size = &dummy;
 if (!y_size) y_size = &dummy;
 
 if (GTK_WIDGET_VISIBLE(window))
 {
  /* NOTE: I really don't know the `gtk' way of doing this
   * but this seems to work */
  Window root;
  int tx = 0;
  int ty = 0;
  unsigned int tborder_width = 0;
  unsigned int tdepth = 0;
  gdk_window_get_origin(window->window, x_pos, y_pos);
  
  XGetGeometry(((GdkWindowPrivate *)window->window)->xdisplay,
               ((GdkWindowPrivate *)window->window)->xwindow,
               &root, &tx, &ty, x_size, y_size,
               &tborder_width, &tdepth);

  *x_pos -= (tx + 1 + tborder_width);
  *y_pos -= (ty + 1 + tborder_width);
 }
}


-- 
James Antill -- jamesa@demon.net



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