(Translated by https://www.hiragana.jp/)
Xlib - 维基百科,自由的百科全书 とべ转到内容ないよう

Xlib

本页使用了标题或全文手工转换
维基百科ひゃっか自由じゆうてき百科ひゃっかぜん
Xlib
開發かいはつしゃX.Org基金ききんかい
くび发布だい约1985ねん
とうぜん版本はんぽん
  • 1.8.10 (2024ねん7がつ28にち;穩定版本はんぽん)[1]
編輯維基數據鏈接
みなもとだい码库 編輯維基數據鏈接
编程语言C
类型
许可协议
編輯維基數據鏈接
网站www.x.org, ぶん档: www.x.org/releases/current/doc/libX11/libX11/libX11.html

XlibいちしゅX Window System協定きょうていてきようはし,以Cげんせんうつし。其功のうあずかX serverみぞどおり。這樣てきこうのう以讓ほどしき人員じんいんせんうつしほどしき,毋須了解りょうかい協定きょうていてきほそぶしただし甚少應用おうようほどしきかい直接ちょくせつ使用しようXlib;通常つうじょう透過とうか其他てきはこしきらいよびさけべXlibよう提供ていきょうけん工具こうぐばこ(widget toolkits):

Xlib及其應用おうよう

Xlib發表はっぴょう於1985ねん目前もくぜん使用しようざい許多きょたてきUnix-like作業さぎょう系統けいとうじょう

目前もくぜんXCB有可ゆか能取のとろだいXlib.

資料しりょうがたべつ

[编辑]

Xlib主要しゅようてき資料しりょうがたべつDisplay[2]結構けっこう

はんれい

[编辑]

下面かめんいちXLibてきはんれつさんせいいちまど

/*
  Simple Xlib application drawing a box in a window.
  gcc input.c -o output -lX11
*/

#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int main(void)
{
  Display *d;
  Window w;
  XEvent e;
  char *msg = "Hello, World!";
  int s;

  bool done = false;

  /* open connection with the server */
  d = XOpenDisplay(NULL);
  if (d == NULL) {
    fprintf(stderr, "Cannot open display\n");
    exit(1);
  }

  s = DefaultScreen(d);

  /* create window */
  w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 640, 480, 0,
			  BlackPixel(d, s), WhitePixel(d, s));

  /* register interest in the delete window message */
  Atom wmDeleteMessage = XInternAtom(d, "WM_DELETE_WINDOW", False);
  XSetWMProtocols(d, w, &wmDeleteMessage, 1);
   
  /* select kind of events we are interested in */
  XSelectInput(d, w, ExposureMask | KeyPressMask | StructureNotifyMask);

  /* map (show) the window */
  XMapWindow(d, w);

  /* event loop */
  while (!done) {
    XNextEvent(d, &e);
    /* draw or redraw the window */
    if (e.type == Expose) {
      XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
      XDrawString(d, w, DefaultGC(d, s), 50, 50, msg, strlen(msg));
    }

    /* exit on key press */
    switch(e.type){
      
    case KeyPress:
      XDestroyWindow(d, w);
      break;

    case DestroyNotify:
      done = true;
      break;

    case ClientMessage:
      if (e.xclient.data.l[0] == wmDeleteMessage){
	done = true;
      }
      break;      
    }
  }

  /* close connection to server */
  XCloseDisplay(d);

  return 0;
}

注釋ちゅうしゃく

[编辑]
  1. ^ "[ANNOUNCE libX11 1.8.10"]; 作者さくしゃせい名字みょうじくし: Alan Coopersmith; 检索: 2024ねん7がつ29にち.
  2. ^ Display Structure on freedesktop CVS. Tip search for: typedef struct _XDisplay Display. [2009-07-09]. (原始げんし内容ないようそん档于2008-01-31). 

外部がいぶ連結れんけつ

[编辑]