XMoveWindow not Working before XMapWindow

2019-02-28 08:34发布

问题:

I have a window, and I'd like to be able to control where it appears. However, calling "XMoveWindow" seems to have no effect before "XMapWindow" is called.

The docs don't say anything. Help?

回答1:

In XtCreateWindow there are x and y coordinates, so you could specify the location when creating it. Note that the X server doesn't have to know about a window before it is mapped for the first time, thus moving a window which is unmapped may not have any effect.

But XtCreateWindow only works for subwindows of your main window; if you want to position a top-level window (either your main app or a popup dialog), you have to confer with the window manager to place the window. The following snippet of code does this using the Xt lib for the main window:

  Arg args[] = {
    { XtNx, (dis_width - WIN_WIDTH) / 2},
    { XtNy, (dis_height - WIN_HEIGHT) / 2},
    { XtNwidth, WIN_WIDTH},
    { XtNheight, WIN_HEIGHT},
    { XtNborderWidth, 10},
    { "minWidth", WIN_WIDTH},
    { "minHeight", WIN_HEIGHT},
    { "maxWidth", WIN_WIDTH},
    { "maxHeight", WIN_HEIGHT},
    { "mwmDecorations", 0xA}, // border + title; see MWM_DECOR_ constants
    { "mappedWhenManaged", False},
  };

  shell = XtAppCreateShell (_ ("Welcome"), NULL, applicationShellWidgetClass, Dis, args, XtNumber (args));

It creates a window centered on the screen.

For popup windows, see XtCreatePopupShell, which uses a similar array with arguments.



标签: window x11