summaryrefslogtreecommitdiff
path: root/xlib-tutorial/index.html
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-01-28 13:13:40 +0100
committernasr <nsrddyn@gmail.com>2026-01-28 13:13:40 +0100
commit3913d1778318cd0c6bfb871148d38abb33ec7fd3 (patch)
tree917728adbf32c877ad591ad9d42f727cc7540b9b /xlib-tutorial/index.html
parent7dead79e05e03a71a502ca4e75d05d126ff9f25c (diff)
checkpoint
Diffstat (limited to 'xlib-tutorial/index.html')
-rw-r--r--xlib-tutorial/index.html116
1 files changed, 116 insertions, 0 deletions
diff --git a/xlib-tutorial/index.html b/xlib-tutorial/index.html
new file mode 100644
index 0000000..5e57eaf
--- /dev/null
+++ b/xlib-tutorial/index.html
@@ -0,0 +1,116 @@
1<HTML>
2<HEAD>
3<TITLE>Xlib programming: a short tutorial</TITLE>
4</HEAD>
5
6<BODY>
7
8<H1>Xlib programming: a short tutorial</H1>
9
10I haven't found anything very satisfying on the Web as an Xlib
11tutorial. Many of them are too much Motif-oriented for my
12taste. Furthermore, I answer questions about X programming almost
13daily, so I've started to put together some small coursewares.
14
15<H4>Important note:</H4> the example programs are written in C++, but
16this is mainly for the ability to declare variables anywhere.
17
18<HR>
19
20Let's begin with a short story: the eternal story of the newbie at
21Xlib writing his/her first program.
22
23<P>
24
25<I>
26"Ok, I've to open a connection to the X server (whatever this means),
27with XOpenDisplay, then create a window with XCreateWindow, then draw
28a line with XDrawLine. Then, the program sleeps for ten seconds so I
29can see the result. Sounds easy."
30</I>
31
32<P>
33
34The poor newbie writes the program. And nothing happens. He then
35calls his wizard friend.
36
37<P>
38
39<I>
40-"Did you perform an XFlush after you've done everything ?<BR>
41- No, why ?<BR>
42- The requests stay in the client," </I>wizard doubletalk, thinks the
43poor newbie<I>, " if you
44don't."
45</I>
46
47<P>
48
49The poor newbie changes the program. And nothing happens. He then
50calls his wizard friend.
51
52<P>
53
54<I>
55-"Did you map your window ?<BR>
56- Did I do what ???<BR>
57- Creating a window doesn't make it appear on the screen. You've to
58 map it with XMapWindow first.
59</I>
60
61<P>
62
63The poor newbie changes the program. The window appears with nothing
64in it (<A HREF="prog-1.cc">like this</A>). The poor newbie then calls
65his wizard friend.
66
67<P>
68
69<I>
70-"Did you wait for a MapNotify before drawing your line ?" </I>(more wizard doubletalk)<I><BR>
71- "No, why ?</BR>
72- X has a stateless drawing model, the content of the window may be lost
73 when the window isn't on the screen." </I>(overflow, why can't these
74 wizard guys speak just like you and me ?)<I> "You've to wait for a MapNotify
75 before drawing."
76</I>
77
78<P>
79
80The poor newbie changes the program. Things are getting more and more
81complex. Not as easy as it first seemed. A loop gets the events until a
82MapNotify. The window appears with nothing
83in it. The poor newbie then calls his wizard friend.
84
85<P>
86
87<I>
88-"I got it, did you select the StructureNotifyMask on your window ?<BR>
89- ???<BR>
90- Just do it, and everything'll be fine.
91</I>
92
93<P>
94
95The poor newbie fixes the program. And the miracle happens ! A line in the
96window. Until now, the program looks like <A HREF="prog-2.cc">this</A>
97(it is actually slighty more complex than the dialog may let you think).
98
99<P>
100
101Now you've learned at least 2 things:
102
103<UL>
104<LI> How to draw a line in a window with X.
105<LI> Why some may need an X tutorial.
106</UL>
107
108Now, if you want to learn more and get a deeper understanding of the
109program, go to <A HREF="2nd-program-anatomy.html">next lesson</A>.
110
111<H4><A HREF="/gui/x/">More about X</A>.</H4>
112
113
114<HR><ADDRESS><A HREF="http://tronche.com/">Christophe Tronche</A>, <A HREF="mailto:ch.tronche@computer.org">ch.tronche@computer.org</A></ADDRESS>
115</BODY>
116</HTML>