Re: Open a window on top of another



On Wed, 22 Aug 2001 13:01:16 +0200, Fabio Rotondo said:

 #include <gtk/gtk.h>
 
 #include <stdio.h>
 
 // This function center the windows win on the parent_win
 //
 // It has some strange things due to the fact that some calls
 // seem to return unexpected results.
 void center_window_on_parent ( GtkWidget * parent_win, GtkWidget * win )
 {
   guint parent_xpos,  parent_ypos;
   guint parent_width, parent_height;
   guint win_width,    win_height;
   gint  xpos, ypos;
   guint tmp, tmp1, tmp2;
   
      // WHY?: this function does not return xpos and ypos correctly
      //       (you should expect gdk_window x,y position, but it
   //        always returns 0,0 - maybe it is returning the ROOT x,y pos? )
   gdk_window_get_geometry ( parent_win->window,
                             &tmp1,         &tmp2,
                             &parent_width, &parent_height,
                             &tmp );

I remember some issues with this, but you just need to get the
root coordinates for your main toplevel GtkWindow's GdkWindow.
The dialog window's coordinates you should have stored somewhere.

Remember that you only need to deal with coordiantes relative to
the desktop (the root window).


I use this to get the root window coords of a GdkWindow:

void GUIGetWindowRootPosition(
        GdkWindow *w, gint *x, gint *y
)
{
        GdkWindow *cur_w = w;
        GdkWindow *root_w;
        gint cx, cy;


        if(x != NULL)
            (*x) = 0;
        if(y != NULL)
            (*y) = 0;

        if(cur_w == NULL)
            return;

        root_w = (GdkWindow *)GDK_ROOT_PARENT();
        if(root_w == NULL)
            return;

        while(cur_w != root_w)
        {
            gdk_window_get_position(cur_w, &cx, &cy);
            if(x != NULL)
                (*x) = ((*x) + cx);
            if(y != NULL)
                (*y) = ((*y) + cy);
            cur_w = gdk_window_get_parent(cur_w);
        }
}



      // This function is needed because the x,y pos of the parent_win cannot be
      // retrieved using gtk_window_get_geometry.
   gdk_window_get_root_origin ( parent_win->window, 
                                &parent_xpos, &parent_ypos );
 
      // Fortunately, width and height are returned correctly :-)
   gdk_window_get_geometry ( win->window,
                             &tmp1,         &tmp2,
                             &win_width,    &win_height,
                             &tmp ); 
 
      // NOTICE: I should have used gdk_window_get_size(), but it doesn't seem to work either :-(
      //
      //                               Almost for sure, it's me missing something...

Just use gdk_window_get_geometry for the window's size and the
function I showed you earlier to get the root coordinates... or
gdk_window_get_root_origin() should work fine.


-- 
--
Sincerely,                  ,"-_                         \|/
-Capt. Taura M.             ,   O=__                    --X--
.__                          ,_JNMNNEO=_                 /|\
OMNOUMmnne.                  {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn.               'LONMMMMNNEEEOOO=.__..,,..
UUOOEUUOOOOOOOObe              '"=OMMMMWNEEEOOOOO,"=OEEEOO=,._
OOUUUIEEIOONNOIUbe.                "7OMMMMNNNNNWWEEEEOOOOOO"   "'.
EEBNNMMMNWNWWEEIMMNe.             __  7EMMMNNNNNWWWEEEEEEEOO.     " .
NNMMMMWWWMMMWEINMMMNn            "=BBEEEEMMMMMMMMNNNWWWEEOOOOO=._     .
                  http://furry.ao.net/~learfox/






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