summaryrefslogtreecommitdiff
path: root/xlib-tutorial/prog-2.cc
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-03-13 22:31:21 +0100
committernasr <nsrddyn@gmail.com>2026-03-13 22:31:21 +0100
commit444bfa2f41143aff7490e4fa21565947565b7d30 (patch)
tree696b06d40140c85805d171597e37deb8290ead73 /xlib-tutorial/prog-2.cc
parent3913d1778318cd0c6bfb871148d38abb33ec7fd3 (diff)
cleanup: generalisation
Diffstat (limited to 'xlib-tutorial/prog-2.cc')
-rw-r--r--xlib-tutorial/prog-2.cc74
1 files changed, 0 insertions, 74 deletions
diff --git a/xlib-tutorial/prog-2.cc b/xlib-tutorial/prog-2.cc
deleted file mode 100644
index 51ea0e9..0000000
--- a/xlib-tutorial/prog-2.cc
+++ /dev/null
@@ -1,74 +0,0 @@
1// Written by Ch. Tronche (http://tronche.lri.fr:8000/)
2// Copyright by the author. This is unmaintained, no-warranty free software.
3// Please use freely. It is appreciated (but by no means mandatory) to
4// acknowledge the author's contribution. Thank you.
5// Started on Thu Jun 26 23:29:03 1997
6
7//
8// Xlib tutorial: 2nd program
9// Make a window appear on the screen and draw a line inside.
10// If you don't understand this program, go to
11// http://tronche.lri.fr:8000/gui/x/xlib-tutorial/2nd-program-anatomy.html
12//
13
14#include <X11/Xlib.h> // Every Xlib program must include this
15#include <assert.h> // I include this to test return values the lazy way
16#include <unistd.h> // So we got the profile for 10 seconds
17
18#define NIL (0) // A name for the void pointer
19
20main()
21{
22 // Open the display
23
24 Display *dpy = XOpenDisplay(NIL);
25 assert(dpy);
26
27 // Get some colors
28
29 int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
30 int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
31
32 // Create the window
33
34 Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
35 200, 100, 0, blackColor, blackColor);
36
37 // We want to get MapNotify events
38
39 XSelectInput(dpy, w, StructureNotifyMask);
40
41 // "Map" the window (that is, make it appear on the screen)
42
43 XMapWindow(dpy, w);
44
45 // Create a "Graphics Context"
46
47 GC gc = XCreateGC(dpy, w, 0, NIL);
48
49 // Tell the GC we draw using the white color
50
51 XSetForeground(dpy, gc, whiteColor);
52
53 // Wait for the MapNotify event
54
55 for(;;) {
56 XEvent e;
57 XNextEvent(dpy, &e);
58 if (e.type == MapNotify)
59 break;
60 }
61
62 // Draw the line
63
64 XDrawLine(dpy, w, gc, 10, 60, 180, 20);
65
66 // Send the "DrawLine" request to the server
67
68 XFlush(dpy);
69
70 // Wait for 10 seconds
71
72 sleep(10);
73}
74