Wrong window position - Xwindows

This is a discussion on Wrong window position - Xwindows ; Hi, I create a window with a specified position Display *dpy = XOpenDisplay(0); // Get some colors int blackColor = BlackPixel(dpy, DefaultScreen(dpy)); int whiteColor = WhitePixel(dpy, DefaultScreen(dpy)); // Create the window Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 100, 100, 200, 100, ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Wrong window position

  1. Wrong window position

    Hi, I create a window with a specified position

    Display *dpy = XOpenDisplay(0);
    // Get some colors
    int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
    int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
    // Create the window
    Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 100, 100,
    200, 100, 0, blackColor,
    blackColor);

    XMapWindow(dpy, w);
    XFlush(dpy);

    I specified the position is (100, 100), and make a Application Luncher
    in taskbar for starting this test program, but the window displayes at
    the position of(0, 0). I don't know the reason...

    I am so confused in Xlib programming...

    Thanks in Advance

    Jinhao


  2. Re: Wrong window position

    Jinhao wrote:
    > Hi, I create a window with a specified position
    >
    > Display *dpy = XOpenDisplay(0);
    > // Get some colors
    > int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
    > int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
    > // Create the window
    > Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 100, 100,
    > 200, 100, 0, blackColor,
    > blackColor);
    >
    > XMapWindow(dpy, w);
    > XFlush(dpy);
    >
    > I specified the position is (100, 100), and make a Application Luncher
    > in taskbar for starting this test program, but the window displayes at
    > the position of(0, 0). I don't know the reason...
    >
    > I am so confused in Xlib programming...
    >
    > Thanks in Advance


    Hi Jinhao,

    My tutorial might help you understand:
    http://www.xmission.com/~georgeps/do...eginner-7.html

    The goal of my tutorial is to help you understand some of the core
    design principles behind Xlib.

    In your case the window manager isn't positioning your window exactly
    where you wanted. If you need a window exactly in a certain position
    you might want to consult manual for XCreateWindow, and the
    override_redirect attribute of XSetWindowAttributes, but note that this
    will be a window without decorations.


    -George

  3. Re: Wrong window position

    Thanks for your tutorial. but i am still confused in detail of
    programming

    I created a window by XCreateWindow at a right position, but it has not
    decorations. so I set the decorations manually..

    int main()
    {
    // Open the display
    Display *dpy = XOpenDisplay(NIL);


    // Create the window
    XSetWindowAttributes v;
    v.cursor = None;
    v.background_pixmap = None;
    v.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
    ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
    EnterWindowMask | LeaveWindowMask | StructureNotifyMask |
    PropertyChangeMask | FocusChangeMask;
    v.override_redirect = true;

    Window x = ::XCreateWindow(dpy, DefaultRootWindow(dpy), 100, 100,
    200, 200, 0,
    CopyFromParent,
    CopyFromParent, //InputOutput,
    CopyFromParent, //DefaultVisual(dpy,DefaultScreen(dpy)),
    CWBackPixmap | CWEventMask | CWCursor |CWOverrideRedirect,
    &v);

    Atom atom = XInternAtom(dpy, "_MOTIF_WM_HINTS", True);

    mwmhints_t motif_hints;
    motif_hints.flags =
    MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS|MWM_HINT S_INPUT_MODE;
    motif_hints.decorations=MWM_DECOR_BORDER|MWM_DECOR _TITLE |
    MWM_DECOR_MENU;
    motif_hints.functions=MWM_FUNC_MOVE|MWM_FUNC_CLOSE ;
    motif_hints.inputMode = MWM_INPUT_MODELESS;
    motif_hints.status = 0;

    XChangeProperty (
    dpy,
    x,
    atom, // Atom for
    "_MOTIF_WM_HINTS"
    atom, // type
    32, // format
    (32 bit quantities)
    PropModeReplace, // mode
    reinterpret_cast(&motif_hints), // data
    PROP_MOTIF_WM_HINTS_ELEMENTS //
    nelements
    );

    XMapWindow(dpy, x);

    XFlush(dpy);

    // Wait for 10 seconds
    sleep(10);
    }

    after XFlush, the Window still has not decorations, what am i missing?

    Thanks in Advance

    Jinhao


+ Reply to Thread