On Tue, Jun 17, 2025 at 2:20 AM Jan Stary <[email protected]> wrote:
>
> Dear all,
>
> the day has come when I need to do some elementary  programming
> (open a window and draw pixels into it). I started with chapter 27
> from Stevens: Advanced UNIX Programming, being my favourite author,
> but the examples seem to be a bit outdated, at least the manpages
> of the X functions describe a slightly different interface.
> At any rate, the example below does not open a window.
>
> I am looking at
> https://www.x.org/releases/current/doc/libX11/libX11/libX11.html
> next, but do people have a favourite X programming intro?

If you are looking for a physical book (I like books myself), I found
"X Window System Programming" by Nabajyoti Barkukati (ISBN
0-672-30542-9) quite helpful when I first wanted to have a reference
book.  You can pick a used copy pretty cheap. From there you may look
into obtaining various volumes of "The Definitive Guides to the X
Window System" by O'Reilly & Associates, Inc. Specifically Volume One
"Xlib Programming Manual" (ISBN 1-56592-002-3" and Two "Xlib Reference
Manual" (ISBN 1-56592-006-6)

Cheers,
--patrick.

> BTW, the manpage for XSetStandardProperties()
> doesn't seem to exist on my current/arm64.
>
>         Jan
>
>
>
> #include <unistd.h>
> #include <stdio.h>
> #include <err.h>
>
> #include <X11/Xlib.h>
> #include <X11/Xutil.h>
>
> int
> main(int argc, char** argv)
> {
>         Display* display;
>         XSizeHints hints;
>         Window window;
>
>         int screen;
>         unsigned long white;
>         unsigned long black;
>
>         if ((display = XOpenDisplay(NULL)) == NULL) {
>                 /* err() is not usefull here, these are not system errors.
>                  * Does X11 have any arror reporting framework? */
>                 errx(1, "Error getting Display");
>         }
>
>         screen = DefaultScreen(display);
>         white = WhitePixel(display, screen);
>         black = BlackPixel(display, screen);
>
>         hints.x = 300;
>         hints.y = 500;
>         hints.width = 200;
>         hints.height = 100;
>         hints.flags = PPosition | PSize;
>
>         window = XCreateSimpleWindow(display, DefaultRootWindow(display),
>                 hints.x, hints.y, hints.width, hints.height, 10, white, 
> black);
>
>         XSetStandardProperties(display, window, "wname", "iname", None,
>                 NULL, 0, &hints);
>
>         /*XMapWindow(display, window);*/
>         XMapRaised(display, window);
>
>         while (1) {
>                 sleep(1);
>         }
>
>         XDestroyWindow(display, window);
>         XCloseDisplay(display);
>
>         return 0;
> }
>

Reply via email to