cwindowscygwinxserver

CygWin How to create a Window with GNU C++ that can be move without a X-Server Window Manager


like the Subject of the Topic said:

Thanks for reading, and Helping Feedback


Solution

  • Followed the [YouTube]: Future Tech Labs - X11 Tutorials - 1 - Creating a Simple Window tutorial, and came up with the following (dummy) example.

    main00.c:

    #include <stdio.h>
    
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>
    
    
    int main()
    {
        Display *pd = NULL;
        if ((pd = XOpenDisplay((char*)NULL)) == NULL) {
            printf("XOpenDisplay error\n");
            return -1;
        }
        int scr = DefaultScreen(pd);
        Window win = XCreateSimpleWindow(pd, RootWindow(pd, scr),
            100, 100, 320, 200, 15, BlackPixel(pd, scr), WhitePixel(pd, scr));
        XSetStandardProperties(pd, win, "Cygwin X q075977479", "q075977479", None, NULL, 0, NULL);
        XMapWindow(pd, win);
    
        XEvent ev;
    
        while (XNextEvent(pd, &ev) == 0) {
        }
    
        XUnmapWindow(pd, win);
        XDestroyWindow(pd, win);
        XCloseDisplay(pd);
    
        printf("\nDone.\n\n");
        return 0;
    }
    

    Output:

    [cfati@cfati-5510-0:/cygdrive/e/Work/Dev/StackExchange/StackOverflow/q075977479]> ~/sopr.sh
    ### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
    
    [064bit prompt]> uname -a
    CYGWIN_NT-10.0-19045 cfati-5510-0 3.4.6-1.x86_64 2023-02-14 13:23 UTC x86_64 Cygwin
    [064bit prompt]> ls
    main00.c
    [064bit prompt]> gcc main00.c -o main00.exe -lX11
    [064bit prompt]> ls
    main00.c  main00.exe
    [064bit prompt]> DISPLAY=:0 ./main00.exe
    

    And the window:

    Img0

    Might also want to check: