Nhảy chuyển tới nội dung

Xlib

本页使用了标题或全文手工转换
Duy cơ bách khoa, tự do bách khoa toàn thư
Xlib
Khai phá giảX.Org quỹ hội
Lần đầu tuyên bốƯớc chừng 1985 năm
Trước mặt phiên bản
  • 1.8.10(2024 năm 7 nguyệt 28 ngày; ổn định phiên bản )[1]
編輯維基數據鏈接
Nguyên số hiệu kho編輯維基數據鏈接
Biên trình ngôn ngữC
Loại hìnhKho
Cho phép hiệp nghị
  • Expat cho phép chứng
  • X11 cho phép chứng
  • Lịch sử cho phép thông tri cùng miễn trách thanh minh
編輯維基數據鏈接
Trang webwww.x.org,Hồ sơ:www.x.org/releases/current/doc/libX11/libX11/libX11.html

XlibLà một loạiX Window SystemHiệp định bản cài đặt, lấyC ngôn ngữSáng tác. Này công năng là cùng X server câu thông. Như vậy công năng có thể cho thể thức nhân viên sáng tác thể thức khi, không cần hiểu biết này hiệp định chi tiết. Nhưng rất ít ứng dụng thể thức sẽ trực tiếp sử dụng Xlib; thông thường là xuyên thấu qua mặt khác hàm thức kho tới gọi Xlib dùng để cung cấpBộ kiện thùng dụng cụ( widget toolkits ):

Xlib và ứng dụng

Xlib phát biểu với 1985 năm, trước mắt sử dụng ở rất nhiềuUnix-like tác nghiệp hệ thống thượng.

Trước mắtXCBCó khả năng thay thế được Xlib.

Tư liệu hình đừng

[Biên tập]

Xlib chủ yếu tư liệu hình hay làDisplay[2]Kết cấu.

Kiểu mẫu

[Biên tập]

Phía dưới là một cái XLib phạm liệt, sinh ra một cái cửa sổ.

/*
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>

intmain(void)
{
Display*d;
Windoww;
XEvente;
char*msg="Hello, World!";
ints;

booldone=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 */
AtomwmDeleteMessage=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){

caseKeyPress:
XDestroyWindow(d,w);
break;

caseDestroyNotify:
done=true;
break;

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

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

return0;
}

Chú thích

[Biên tập]
  1. ^"[ANNOUNCElibX11 1.8.10 "]; tác giả tên họ tự phù xuyến: Alan Coopersmith; kiểm tra ngày: 2024 năm 7 nguyệt 29 ngày.
  2. ^Display Structure on freedesktop CVS.Tip search for: typedef struct _XDisplay Display.[2009-07-09].(Nguyên thủy nội dungLưu trữ với 2008-01-31 ).

Phần ngoài liên kết

[Biên tập]