[comp.windows.x] Moving window

andrew@ee.su.oz.au (Andrew Ho) (11/28/90)

Hi,

  I am a new x-window programmer. I am writing an application
to display a window on a specified location on the screen. 
The followings are my sample codes :

{
  Arg wargs[3];
  int  j;

  topapp = XtCreateApplicationShell("topapp", topLevelShellWidgetClass,
            NULL, 0);

  j=0;
  XtSetArg(wargs[j], XtNwidth, WIN_WIDTH); j++;
  XtSetArg(wargs[j], XtNheight, WIN_HEIGHT); j++;
  XtSetArg(wargs[j], XtNstring, "TEXT"); j++;
  text = XtCreateManagedWidget("TEXT", XwstatictextWidgetClass, topapp,
            wargs, j);

  XMoveWindow(XtDisplay(topapp), DefaultRootWindow(XtDisplay(topapp)),
                20, 2);

  XtRealizeWidget(topapp);

}

   However, the above codes seem don't work well (the applcation
shell doesn't appear at location (20, 2)). Any thing wrong with
my codes ? Please mail me.

   Thanks in advance. 

andrew@ee.su.oz.au

mouse@LARRY.MCRCIM.MCGILL.EDU (11/28/90)

> I am a new x-window programmer.  I am writing an application to
> display a window on a specified location on the screen.

This should generally be left up to the user and/or the window manager.
Some window managers simply do not permit the application program to
control the window's location.  (Some do.  Most are capable of either.)

> The followings are my sample codes :

>   topapp = XtCreateApplicationShell("topapp", topLevelShellWidgetClass, NULL, 0);
...
>   XMoveWindow(XtDisplay(topapp), DefaultRootWindow(XtDisplay(topapp)), 20, 2);
>   XtRealizeWidget(topapp);

> However, the above codes seem don't work well (the applcation shell
> doesn't appear at location (20, 2)).  Any thing wrong with my codes?

One thing definitely wrong and another thing possibly wrong.

Definitely wrong: you're trying to move the wrong window.  The
XMoveWindow call you've written tries to move the root window, which of
course won't do very much.  (I am assuming XtDisplay(topapp) does what
the name implies: returns the Xlib Display pointer in use.)  To move
your window, you'd need to call XMoveWindow(XtDisplay(topapp), <foo>,
20, 2) where the <foo> represents some sort of toolkit or widget
incantation to obtain the window in question.  I also recall messages
on xpert that talk about the window not existing until you realize the
widget; this may cause you grief too.

Possibly wrong: you're trying to use an Xlib routine on a widget.  This
is usually the wrong thing to do.  (It is right only when no toolkit or
widget routine exists to do what you want; I don't know whether that's
the case here.)

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

etaylor@wilkins.iaims.bcm.tmc.edu (Eric Taylor) (11/29/90)

Additional notes:

	If you really MUST place a shell window, use the XtNgeometry
resource for the app shell.

	If you use the XtNx and XtNy resources
on the shell window, it might work for some window managers.

	If you really must use XMoveWindow, you can do so only
	after the shell window is realized.  Your code sequence might look
	something like this :


  XtRealizeWidget(topapp);
  XMoveWindow(XtDisplay(topapp), XtWindow(topapp),
                20, 2);


	Secondly, you are confusing DefaultRootWindow with
	your own shell window.  The DefaultRootWindow exists
	at all times even when your program is not active.
	You can think of it as the background window.
--
					Eric Taylor
					Baylor College of Medicine
					etaylor@wilkins.bmc.tmc.edu
					(713) 798-3776