<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh">
	<id>https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=Xlib</id>
	<title>Xlib - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=Xlib"/>
	<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=Xlib&amp;action=history"/>
	<updated>2026-07-08T19:45:55Z</updated>
	<subtitle>在这个wiki上该页的修订历史</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://arolstar52-zhtest.hf.space/index.php?title=Xlib&amp;diff=559410&amp;oldid=prev</id>
		<title>imported&gt;InternetArchiveBot：​补救3个来源，并将0个来源标记为失效。) #IABot (v2.0.8.7</title>
		<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=Xlib&amp;diff=559410&amp;oldid=prev"/>
		<updated>2022-05-19T03:16:48Z</updated>

		<summary type="html">&lt;p&gt;补救3个来源，并将0个来源标记为失效。) #IABot (v2.0.8.7&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{noteTA|G1=IT}}&lt;br /&gt;
{{Infobox software&lt;br /&gt;
| name                   = Xlib&lt;br /&gt;
| title                  = Xlib&lt;br /&gt;
| logo                   = &lt;br /&gt;
| logo caption           = &lt;br /&gt;
| screenshot             = &lt;br /&gt;
| caption                = &lt;br /&gt;
| collapsible            = &lt;br /&gt;
| author                 = &lt;br /&gt;
| developer              = [[X.Org基金会]]&lt;br /&gt;
| released               = 大约1985年 &lt;br /&gt;
| discontinued           = &lt;br /&gt;
| latest release version = &lt;br /&gt;
| latest release date    = &lt;br /&gt;
| latest preview version = &lt;br /&gt;
| latest preview date    = &lt;br /&gt;
| programming language   = [[C语言|C]]&lt;br /&gt;
| operating system       = &lt;br /&gt;
| platform               = &lt;br /&gt;
| size                   = &lt;br /&gt;
| language               = &lt;br /&gt;
| genre                  = [[函式库|库]]&lt;br /&gt;
| license                = &lt;br /&gt;
| website                = {{URL|https://www.x.org}}, 文档: {{URL|https://www.x.org/releases/current/doc/libX11/libX11/libX11.html}}&lt;br /&gt;
}}&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Xlib&amp;#039;&amp;#039;&amp;#039;是一種[[X Window System]]協定的用戶端，以[[C語言]]撰寫。其功能是與X server溝通。這樣的功能可以讓程式人員撰寫程式時，毋須了解其協定的細節。但甚少應用程式會直接使用Xlib;通常是透過其他的函式庫來呼叫Xlib用以提供[[部件工具箱]]（widget toolkits）：&lt;br /&gt;
&lt;br /&gt;
[[File:Xlib and XCB in the X Window System graphics stack.svg|thumb|300px|Xlib及其應用]]&lt;br /&gt;
&lt;br /&gt;
* [[Intrinsics]]（Xt）&lt;br /&gt;
* [[Xaw]]（Xaw）&lt;br /&gt;
* [[Motif]]&lt;br /&gt;
* [[GTK+]]&lt;br /&gt;
* [[Qt]]（X11 version）&lt;br /&gt;
* [[Tk]]&lt;br /&gt;
&lt;br /&gt;
Xlib發表於1985年，目前使用在許多的[[Unix]]-like作業系統上。&lt;br /&gt;
&lt;br /&gt;
目前[[XCB]]有可能取代Xlib.&lt;br /&gt;
&lt;br /&gt;
== 資料型別 ==&lt;br /&gt;
Xlib主要的資料型別是&amp;lt;code&amp;gt;Display&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;DisplayStructure&amp;quot;&amp;gt;{{cite web|url=http://webcvs.freedesktop.org/xorg/lib/X11/include/X11/Xlib.h?revision=1.6&amp;amp;view=markup|title=Display Structure on freedesktop CVS|date=|work=Tip search for: typedef struct _XDisplay Display|publisher=|deadurl=yes|archiveurl=https://web.archive.org/web/20080131195430/http://webcvs.freedesktop.org/xorg/lib/X11/include/X11/Xlib.h?revision=1.6&amp;amp;view=markup|archivedate=2008-01-31|accessdate=2009-07-09}}&amp;lt;/ref&amp;gt;結構。&lt;br /&gt;
&lt;br /&gt;
== 範例 ==&lt;br /&gt;
下面是一個XLib的範列，產生一個視窗。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  Simple Xlib application drawing a box in a window.&lt;br /&gt;
  gcc input.c -o output -lX11&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;X11/Xlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdbool.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  Display *d;&lt;br /&gt;
  Window w;&lt;br /&gt;
  XEvent e;&lt;br /&gt;
  char *msg = &amp;quot;Hello, World!&amp;quot;;&lt;br /&gt;
  int s;&lt;br /&gt;
&lt;br /&gt;
  bool done = false;&lt;br /&gt;
&lt;br /&gt;
  /* open connection with the server */&lt;br /&gt;
  d = XOpenDisplay(NULL);&lt;br /&gt;
  if (d == NULL) {&lt;br /&gt;
    fprintf(stderr, &amp;quot;Cannot open display\n&amp;quot;);&lt;br /&gt;
    exit(1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  s = DefaultScreen(d);&lt;br /&gt;
&lt;br /&gt;
  /* create window */&lt;br /&gt;
  w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 640, 480, 0,&lt;br /&gt;
			  BlackPixel(d, s), WhitePixel(d, s));&lt;br /&gt;
&lt;br /&gt;
  /* register interest in the delete window message */&lt;br /&gt;
  Atom wmDeleteMessage = XInternAtom(d, &amp;quot;WM_DELETE_WINDOW&amp;quot;, False);&lt;br /&gt;
  XSetWMProtocols(d, w, &amp;amp;wmDeleteMessage, 1);&lt;br /&gt;
   &lt;br /&gt;
  /* select kind of events we are interested in */&lt;br /&gt;
  XSelectInput(d, w, ExposureMask | KeyPressMask | StructureNotifyMask);&lt;br /&gt;
&lt;br /&gt;
  /* map (show) the window */&lt;br /&gt;
  XMapWindow(d, w);&lt;br /&gt;
&lt;br /&gt;
  /* event loop */&lt;br /&gt;
  while (!done) {&lt;br /&gt;
    XNextEvent(d, &amp;amp;e);&lt;br /&gt;
    /* draw or redraw the window */&lt;br /&gt;
    if (e.type == Expose) {&lt;br /&gt;
      XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);&lt;br /&gt;
      XDrawString(d, w, DefaultGC(d, s), 50, 50, msg, strlen(msg));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /* exit on key press */&lt;br /&gt;
    switch(e.type){&lt;br /&gt;
      &lt;br /&gt;
    case KeyPress:&lt;br /&gt;
      XDestroyWindow(d, w);&lt;br /&gt;
      break;&lt;br /&gt;
&lt;br /&gt;
    case DestroyNotify:&lt;br /&gt;
      done = true;&lt;br /&gt;
      break;&lt;br /&gt;
&lt;br /&gt;
    case ClientMessage:&lt;br /&gt;
      if (e.xclient.data.l[0] == wmDeleteMessage){&lt;br /&gt;
	done = true;&lt;br /&gt;
      }&lt;br /&gt;
      break;      &lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* close connection to server */&lt;br /&gt;
  XCloseDisplay(d);&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
The client creates a connection with the server by calling &amp;lt;code&amp;gt;XOpenDisplay&amp;lt;/code&amp;gt;. It then requests the creation of a window with &amp;lt;code&amp;gt;XCreateSimpleWindow&amp;lt;/code&amp;gt;. A separate call to &amp;lt;code&amp;gt;XMapWindow&amp;lt;/code&amp;gt; is necessary for mapping the window, that is, for making it visible on the screen.&lt;br /&gt;
&lt;br /&gt;
The square is drawn by calling &amp;lt;code&amp;gt;XFillRectangle&amp;lt;/code&amp;gt;. This operation can only be performed after the window is created. However, performing it once may not be enough. Indeed, the content of the window is not always guaranteed to be preserved. For example, if the window is covered and then uncovered again, its content might require being redrawn. The program is informed that the window or a part of it has to be drawn by the reception of an &amp;lt;code&amp;gt;Expose&amp;lt;/code&amp;gt; event.&lt;br /&gt;
&lt;br /&gt;
The drawing of the window content is therefore made inside the [[Event loop|loop handling the events]]. Before entering this loop, the events the application is interested in are selected, in this case with &amp;lt;code&amp;gt;XSelectInput&amp;lt;/code&amp;gt;. The event loop waits for an incoming event: if this event is a key press, the application exits; if it is an expose event, the window content is drawn. The function &amp;lt;code&amp;gt;XNextEvent&amp;lt;/code&amp;gt; blocks and flushes the request buffer if there is no event in the queue.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 注釋 ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 外部連結 ==&lt;br /&gt;
* [https://web.archive.org/web/20090217235848/http://www.sbin.org/doc/Xlib/ Xlib Programming Manual]&lt;br /&gt;
* [http://tronche.com/gui/x/xlib/function-index.html Manual pages for all Xlib functions] {{Wayback|url=http://tronche.com/gui/x/xlib/function-index.html |date=20210401114216 }}&lt;br /&gt;
* [http://www.rahul.net/kenton/bib.html Kenton Lee&amp;#039;s pages on X Window and Motif] {{Wayback|url=http://www.rahul.net/kenton/bib.html |date=20130520013725 }}&lt;br /&gt;
* [http://tronche.com/gui/x/xlib-tutorial/ A short tutorial on Xlib] {{Wayback|url=http://tronche.com/gui/x/xlib-tutorial/ |date=20120316210630 }}&lt;br /&gt;
* [https://web.archive.org/web/20071018025425/http://users.actcom.co.il/~choo/lupg/tutorials/xlib-programming/xlib-programming.html#create_window#create_window A longer tutorial on Xlib]&lt;br /&gt;
* [http://www.dis.uniroma1.it/%7eliberato/screensaver Using Xlib for creating a screensaver module] {{Wayback|url=http://www.dis.uniroma1.it/%7eliberato/screensaver |date=20120319215932 }}&lt;br /&gt;
* [https://web.archive.org/web/20090308084753/http://www.init0.nl/simplex11tk.php Simple X11 toolkit for learning Xlib]&lt;br /&gt;
&lt;br /&gt;
{{XWinSys}}&lt;br /&gt;
&lt;br /&gt;
[[Category:C函式庫]]&lt;/div&gt;</summary>
		<author><name>imported&gt;InternetArchiveBot</name></author>
	</entry>
</feed>