Re: Determining window position



On Sun, 2001-09-02 at 06:39, Thomas Bütikofer wrote:
> Hi,
> 
> could anybody help me to determine the position of a window on the
> screen?
> I already tried
> 
> GtkWindow* window;
> int x,y;
> ...
> gdk_window_get_root_origin(window,&x,&y);
> 
> but obviously, window is of the wrong type (GtkWindow* instead of
> GdkWindow*).

You can get the GdkWindow from the gtkWidget structure (widget->window),
but I am not sure this is the right interface for it.  Anyway, I've
attached a program that uses this to give you the position of a window.

	/mailund

-- 
A computer lets you make more mistakes faster than any invention in
human history - with the possible exceptions of handguns and tequila.

Mitch Ratcliffe, "Technology Review" (1992)
#include <gtk/gtk.h>

static void
button_clicked (GtkWidget *button, GtkWidget *win)
{
  int x, y;
  GdkWindow *gdk_win = win->window;
  gdk_window_get_root_origin (gdk_win, &x, &y);
  g_print ("window is at (%d,%d)\n", x, y);
}

int
main (int argc, char *argv[])
{
  GtkWidget *win;
  GtkWidget *button;

  gtk_init (&argc, &argv);

  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  button = gtk_button_new_with_label ("Send");
  gtk_container_add (GTK_CONTAINER (win), button);

  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (button_clicked),
		      win);

  gtk_widget_show_all (win);

  gtk_main ();

  return 0;
}

Attachment: pgpI2S7GEvoAm.pgp
Description: PGP signature



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