How could I get any widgets position?

GTK+ FAQ
<<< Previous | Development with GTK+: general questions | Next >>>

# How could I get any widgets position?

As Tim Janik pointed out, there are different cases, and each case requires a different solution.

- If you want the position of a widget relative to its parent, you should use `widget->allocation.x` and `widget->allocation.y`.

- If you want the position of a window relative to the X root window, you should use `gdk_window_get_geometry()` `gdk_window_get_position()` or `gdk_window_get_origin()`.

- If you want to get the position of the window (including the WM decorations), you should use `gdk_window_get_root_origin()`.

- Last but not least, if you want to get a Window Manager frame position, you should use `gdk_window_get_deskrelative_origin()`.

Your choice of Window Manager will have an effect of the results of the above functions. You should keep this in mind when writing your application. This is dependant upon how the Window Managers manage the decorations that they add around windows.

<<< Previous | Home | Next >>>
How do I reparent a widget? | Up | How do I set the size of a widget/window? How do I prevent the user resizing my window? [GTK 2.x]