Search code examples
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:

  • CygWin for Windows comes with a X-Server port for Windows
  • How can I create a "moveable" Window, with the X-Server functions that are available when you (me) programming with the GNU C++ Compiler
  • I have already programming with Qt5 but I would do this with built-in Functions from the X-Server without the useing of a Window Manager

Thanks for reading, and Helping Feedback

  • I already able to create a Window with Qt5 Framework but this Framework need a huge amount of space because the big libraries that come with
  • I expecting a small Example without using any Framework, only the X-Server Functions that are available for Cygwin X-Server

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: