XMoveWindow not Working before XMapWindow

浪子不回头ぞ 提交于 2019-12-20 04:04:37

问题


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.



来源:https://stackoverflow.com/questions/14801536/xmovewindow-not-working-before-xmapwindow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!