没有合适的资源?快使用搜索试试~ 我知道了~
An Introduction to X11 User Interfaces
需积分: 3 18 下载量 179 浏览量
2009-05-29
08:17:43
上传
评论
收藏 65KB PDF 举报
温馨提示
试读
19页
作者:G. Edwards, 题目如题,副标题是 A tutorial prepared for SciC 8011. 这是一份只有19页的简介,对 UNIX/Linux 系统上的 X Window 系统的架构作了一个概略性的介绍。
资源推荐
资源详情
资源评论
An Introduction to X11 User Interfaces
A tutorial prepared for SciC 8011
Grant Edwards
Spring, 1995
An HTML version of this paper is available via the at www.visi.com/users/grante/Xtut
— this page includes links to information about the various toolkits and software pack-
ages mentioned.
1 Overview
This paper provides an introductory look at the X Window System. It is intended to
provide the reader with information in two areas:
A basic understanding of what goes on behind the glass.
Anybody who uses a modern Unix based workstation for scientific visualiza-
tion has almost certainly used programs running under X. While little technical
knowledge is required to use today’s point-and-click interfaces, a little knowl-
edge about what goes on behind the scenes can make things less imposing and
mysterious.
A general idea of what must be done to implement a portable GUI for a program.
In scientific visualization, like other fields, we are often faced with the age-old
decision to “build or buy.” To make reasonable decisions, we must have a realis-
tic idea of the amount of time required to “build” a portable, graphical program.
Hopefully, this paper will provide readers with a starting point for this under-
standing, and make them go back and re-examine existing software packages
should they get the urge to write a custom X11 based program.
2 Introduction to
X
1
is a system for implementing a window-based user interface on bit-mapped dis-
plays. More technically, it is a specification for a high level communications protocol
that is used between two programs. One of these programs is called the “server” and
1
The official name is “The X Window System.” It is considered tres uncool to call it “X Windows”
– presumably because it sounds too much like “Microsoft Windows.” The preferred moniker seems to be
simply “X.” If you want to sound like an old timer you can call it “X11” implying that you might have been
around at MIT when version 10 was in use. Most experienced users refer to it as simply “X” or as “X11R3”
if a particular version/release is to be specified.
1
does the actually drawing on the screen and receives the raw input from the keyboard
and mouse. The other program is called the “client” and this is where the useful work
gets done. These programs may be on different computers, or they may be on the same
computer.
It is important to notice that the location of the client and server are reversed com-
pared to many client/server situations. This often causes confusion among people
new to X. For example, you have a Sun workstation at your desk: you are running
a CAD/simulation program on a large computer somewhere else and displaying the
user interface on your desktop Sun. The Sun is running the server (it’s what talks to the
keyboard, mouse, and graphics hardware). The CAD program on the large computer is
the “client” program.
The client requests that graphical operations be performed and the server provides
those services.
The X protocol specification defines what goes back and forth between those two
programs. The X protocol is usually implemented as a layer on top of another transport
layer such as TCP/IP.
3 History
X was developed in a joint effort by MIT and Digital Equipment Corporation based
somewhat on the “W” windowing system previously developed at Stanford. In 1986,
X10 became the first widely used version of X, though it was quickly replaced by
version 11 a year later. Since then X11 has gone through 5 more “releases” and is now
at release 6 (referred to as X11R6). Almost all workstation vendors have adopted X11
as their windowing system, though many vendors still have proprietary extensions built
into the X servers shipped with their hardware.
2
4 What X isn’t
The X specifications do not specify what a program’s user interface should look like,
what a window manager should do, or how applications should behave. X is simply a
low-level method of creating windows; receiving user inputs (key-presses and mouse
events); and drawing strings, drawing lines, curves and bitmaps. The behavior of the
application and the design and style of the user interface are left entirely up to client
programs. While this allows for a great deal of flexibility, it results in the lack of a
common “look and feel” for X applications.
Printing is another area where the X specifications are mute. X does not provide
any printing or hard copy services as does Microsoft Windows or the Mac OS tool box.
In the absence of any other standard, postscript has been largely adopted as a de facto
standard for hard copy output by designers of X applications.
2
For example, Sun Microsystems includes a display Postscript extension as well as a SunView extension
in its X servers.
2
5 The X Protocol
5.1 Services provided by the Server
The X server provides a set of fairly low-level services that are used by clients to im-
plement whatever user interface is desired. These services are basically the following:
Input handling
The server receives input from the keyboard and mouse. These are passed as
“events” to the appropriate client program. The method used to decide which
window should receive input events various depending on the window manager
(which is actually just another client). Typical events are key-presses, mouse
movements and mouse button press/release.
Hierarchical window services.
These allow a client to tell the server to create or destroy a “window” which is
a rectangular area on the screen. Windows may be nested hierarchically within
other windows. Various operations may be performed on windows (set or query
the size and position, for example).
Graphical operations.
The client can request that the server draw lines, rectangles, arcs, dots, and poly-
gons. The color, line-width, and fill style are specified by the client. X11 also
supports various bitmap operations
3
that can be performed on regions of win-
dows.
Text and font operations.
The client can request that text strings be “drawn” into a window at a particular
position using a specified font. Before this can be done, the client must tell the
server to load the font to be used. The client can request information about what
fonts are available and also about sizes and parameters of loaded fonts.
That’s it. The X protocol doesn’t know anything about radio buttons, scroll bars,
sliders, text entry fields or menu bars. Those are all implemented in the client – usually
using off-the shelf libraries and toolkits.
5.2 The Client/Server Interface
As stated earlier, the X protocol defines what passes back and forth between the client
and the server. The information that travels between client and server is broken up into
“packets” at the X protocol level (which is different than Ethernet or TCP/IP packets
or frames). There are four types of packets:
Request
A request packet is sent by the client to the server to ask that the server perform
some action or return some information.
3
Often called “bitblt” operations (short for bit block transfer).
3
Reply
A reply packet is sent by the server to the client in response to a request from the
server. Not all requests generate replies.
Event
An event packet is sent by the server to the client to inform it of user input or
some other happening about which it might want to do something (for example
a window was re-sized or a previously obscured window was uncovered).
Error
An error packet is sent by the server to the client to inform it that a request was
not valid. Since requests are queued, the error might not be discovered until after
several more requests have been queued by the client.
6 Low level X programming: Xlib
It is theoretically possible to write a client program using just the standard C run-
time library routines. The client would have to open a socket-based connection to a
server, construct requests and write them to the socket and interpret the reply, event,
and error error packets. Though possible, this is unnecessary since there are libraries
available that contain routines to interface to an X server using the X protocol. The
most common such library is called “Xlib” and is intended to be called from the C
programming language. The definitive books on Xlib are probably those published by
O’Reilly and Associates: Xlib Programming Manual and Xlib Reference Manual.
Though Xlib hides the details of communicating with the server, it does little else.
The functions provided by Xlib perform only the basic tasks described in section 5.1.
Even a simple program written using nothing but Xlib can require large amounts of
code. A “hello world” program
4
whose output is shown in figure 1 requires 200 lines
of C code. This program does nothing other than create a window, check the window
size and the size of the root display, display the text shown, and wait for any key or
mouse button before exiting. The source code for this program is shown in Appendix
A for the morbidly curious.
As you might guess, writing an entire application using Xlib directly is not prac-
tical. The client application must specify every window to be drawn and every bit of
text or line to be drawn. The application must then read events from the the server and
process them. When a window is resized, the application must take appropriate actions
and redraw everything in the correct places. What is needed is a higher level interface
that hides much of the gritty details from the application programmer.
7 X Toolkits
Since Xlib is obviously not practical as a basis for applications programming, various
toolkits have been written that provide another layer above Xlib. Several of the more
4
This is the “basicwn” program shown as an example in by Adrian Nye’s Xlib Programming Manual.
4
剩余18页未读,继续阅读
资源评论
zhoubihn
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- uniapp中tab切换,底部内容跟着移动,相反,底部移动,tab也跟着切换-组件
- 基于JS+TS实现跨平台3D相机控制器-附项目源码-优质项目分享.zip
- 跨相机-基于Rust实现的跨平台相机捕获-附项目源码-优质项目分享.zip
- odise 14离线安装包 大众斯柯达奥迪 5054 6153
- 网页设计期末作业-纯html加css+少量js-盗墓笔记旅游导航网站.rar
- 算法笔记模拟退火.rar
- MATLAB大数据仿真案例-蚁群算法(ACO)用于求解旅行商(TSP)问题.rar
- 基于yolov5的吸烟行为检测源码+模型.zip
- MySQL基础知识-个人笔记.rar
- Project8.ipynb
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功