Re: Getting screen position



Steve Fox wrote:

I'm a bit stumped at trying to get screen position. I need to save the
window position at the time of closing. This is what I'm doing:

my ($x, $y, $w, $h) = @{$win->allocation};

This fills in window size appropriately, but $x and $y are always zero.
Does anyone know a reliable way to get window position?


the Gtk2 docs say

        void        gtk_window_get_position         (GtkWindow 
<http://developer.gnome.org/doc/API/2.0/gtk/GtkWindow.html> *window,
                                                     gint 
<http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gint> *root_x,
                                                     gint 
<http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gint> *root_y);


something like

($x, $y) = $gtk2window->get_position;



it would appear, however, that for Gtk1.2 (the old gtkperl) you need to dip down to Gdk for this:

        void        gdk_window_get_position 
<http://developer.gnome.org/doc/API/gdk/gdk-windows.html#GDK-WINDOW-GET-POSITION>         (GdkWindow 
<http://developer.gnome.org/doc/API/gdk/gdk-windows.html#GDKWINDOW> *window,
                                                     gint 
<http://developer.gnome.org/doc/API/glib/glib-basic-types.html#GINT> *x,
                                                     gint 
<http://developer.gnome.org/doc/API/glib/glib-basic-types.html#GINT> *y);


aye --- Gtk::reference says of Gtk::Gdk::Window

$window->get_position ()

Get the position of the window. This function croaks if not called in
list context.



so, basically, you want to do

($x, $y) = $gtkwindow->window->get_position;




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