From 3913d1778318cd0c6bfb871148d38abb33ec7fd3 Mon Sep 17 00:00:00 2001 From: nasr Date: Wed, 28 Jan 2026 13:13:40 +0100 Subject: checkpoint --- xlib-tutorial/prog-2.cc | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 xlib-tutorial/prog-2.cc (limited to 'xlib-tutorial/prog-2.cc') diff --git a/xlib-tutorial/prog-2.cc b/xlib-tutorial/prog-2.cc new file mode 100644 index 0000000..51ea0e9 --- /dev/null +++ b/xlib-tutorial/prog-2.cc @@ -0,0 +1,74 @@ +// Written by Ch. Tronche (http://tronche.lri.fr:8000/) +// Copyright by the author. This is unmaintained, no-warranty free software. +// Please use freely. It is appreciated (but by no means mandatory) to +// acknowledge the author's contribution. Thank you. +// Started on Thu Jun 26 23:29:03 1997 + +// +// Xlib tutorial: 2nd program +// Make a window appear on the screen and draw a line inside. +// If you don't understand this program, go to +// http://tronche.lri.fr:8000/gui/x/xlib-tutorial/2nd-program-anatomy.html +// + +#include // Every Xlib program must include this +#include // I include this to test return values the lazy way +#include // So we got the profile for 10 seconds + +#define NIL (0) // A name for the void pointer + +main() +{ + // Open the display + + Display *dpy = XOpenDisplay(NIL); + assert(dpy); + + // Get some colors + + int blackColor = BlackPixel(dpy, DefaultScreen(dpy)); + int whiteColor = WhitePixel(dpy, DefaultScreen(dpy)); + + // Create the window + + Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, + 200, 100, 0, blackColor, blackColor); + + // We want to get MapNotify events + + XSelectInput(dpy, w, StructureNotifyMask); + + // "Map" the window (that is, make it appear on the screen) + + XMapWindow(dpy, w); + + // Create a "Graphics Context" + + GC gc = XCreateGC(dpy, w, 0, NIL); + + // Tell the GC we draw using the white color + + XSetForeground(dpy, gc, whiteColor); + + // Wait for the MapNotify event + + for(;;) { + XEvent e; + XNextEvent(dpy, &e); + if (e.type == MapNotify) + break; + } + + // Draw the line + + XDrawLine(dpy, w, gc, 10, 60, 180, 20); + + // Send the "DrawLine" request to the server + + XFlush(dpy); + + // Wait for 10 seconds + + sleep(10); +} + -- cgit v1.3