热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

XlibProgrammingManual(O'Reilly&Associates,Inc.)

http:www.sbin.orgdocXlibchapt_01.htmlXlibProgrammingManual(OReilly&a

http://www.sbin.org/doc/Xlib/chapt_01.html


Xlib Programming Manual (O'Reilly & Associates, Inc.)


Introduction This chapter gives the big picture: what X is all about and some fundamentals of how it works. Everyone should look at this chapter, though readers who are already familiar with X may only want to skim it.

In September 1987, the Massachusetts Institute of Technology released the first snapshot of what may well become one of the most significant software technologies of the 1990s: Version 11 of the X Window System, commonly referred to as X11. X11 may not change the world, but it is likely to change the world of workstations.

The X Window System is being adopted as a standard by nearly every workstation manufacturer and should eventually replace or be supported under their proprietary windowing systems. Versions will also be available for personal computers and supercomputers.

For the first time, portable applications can be written for an entire class of machines rather than for a single manufacturer's equipment. Programmers can write in a single graphics language and expect their applications to work without significant modifications on dozens of different computers.

What's more, since X is a network-based windowing system, applications can run in a network of systems from different vendors. Programs can be run on a remote computer, and the results displayed on a local workstation. Proprietary networks have been around for a while. However, network cooperation of different computers has been held up by the lack of a common applications language. Now there is one.

Vendors hope that X will lead to a software explosion similar to the one that occurred in response to the PC standard on microcomputers.


Versions of X

X was developed jointly by MIT's Project Athena and Digital Equipment Corporation, with contributions from many other companies. It was masterminded by Robert Scheifler and colleagues at MIT, though it owes some debt to the "W" windowing package developed by Paul Asente at Stanford.

There have been numerous research versions of X. Version 10, Release 4 (popularly known as X10.4), which was released in 1986, became the basis for several commercial products. Development of most X10.4 products was curtailed, however, when it became apparent that Version 11 would not be compatible with it. Version 11, Release 1 became available in September 1987, Release 2 in March 1988, Release 3 in February 1989, Release 4 in January 1990, and Release 5 in August 1991.

Version 11 is a complete window programming package. It offers much more flexibility in the areas of supported display features, window manager styles, and support for multiple screens and provides better performance than X Version 10. It is fully extensible. But just as important, the X11 subroutine library (Xlib) is expected to be stable for several years and to be at least a de facto industry standard. That means that programs written with this library will not need major revisions because of software updates. While there may be additions to this library, there will not be incompatible changes to it.

With X11 Release 2, control of X passed from MIT to the X Consortium, an association of major computer manufacturers who plan to support the X standard. The Consortium was formed in January 1988 and includes virtually all large computer manufacturers. Many software houses and universities are associate members, who also have a voice in controlling the standard and receive advance access to newly released software. 


X Window System Concepts

The X Window System is complex, but it is based on a few premises that can be quickly understood. This section describes these major concepts.

Displays and Screens

The first and most obvious thing to note about X is that it is a windowing system for bitmapped graphics displays. It supports color as well as monochrome and gray-scale displays.

A slightly unusual feature is that a display is defined as a workstation consisting of a keyboard, a pointing device such as a mouse, and one or more screens. Multiple screens can work  together, with mouse movement allowed to cross physical screen boundaries. As long as multiple screens are controlled by a single user with a single keyboard and pointing device, they comprise only a single display, as shown in Figure 1-1.

A display consisting of more than one screen

fig.1.01.gif

The Server-Client Model

The next thing to note is that X is a network-oriented windowing system. An application need not be running on the same system that actually supports the display. While many applications can execute locally on a workstation, other applications can execute on other machines, sending requests across the network to a particular display and receiving keyboard and pointer events from the system controlling the display.

At this point, only TCP/IP and DECnet networks are supported by the X Consortium and most vendors, though that may change before long.

The program that controls each display is known as a server. At first, this usage of the term server may seem a little odd--when you sit at a workstation, you tend to think of a server as something across the network (such as a file or print server) rather than the local program that controls your own display. The thing to remember is that your display is accessible to other systems across the network, and for those systems, the code executing in your system does act as a true display server.

The server acts as an intermediary between user programs (called clients or applications) running on either the local or remote systems and the resources of the local system. The server (without extensions) performs the following tasks:

  • Allows access to the display by multiple clients.
  • Interprets network messages from clients.
  • Passes user input to the clients by sending network messages.
  • Does two-dimensional drawing--graphics are performed by the display server rather than by the client.
  • Maintains complex data structures, including windows, cursors, fonts, and "graphics contexts," as resources that can be shared between clients and referred to simply by resource IDs. Server-maintained resources reduce the amount of data that has to be maintained by each client and the amount of data that has to be transferred over the network.
Since the X Window System makes the network transparent to clients, these programs may connect to any display in the network if the host they are running on has permission from the server that controls that display. In a network environment, it is common for a user to have programs running on several different hosts in the network, all invoked from and displaying their windows on a single screen, as shown in Figure 1-2.

Applications can run on any system across the network

fig.1.02.gif

 In practice, each user is sitting at a server and can start applications locally to display on the local server or can start applications on remote hosts for display on the local server, if the remote hosts have permission to connect to the local server. All other users in the network are in a similar situation--they can run applications on their own system or on yours, but they will, for the most part, be displaying on their own server. This use of the network is known as distributed processing. Distributed processing helps solve the problem of unbalanced system loads. When one host machine is overloaded, the users of that machine can arrange for some of their programs to run on other hosts.

One extreme of this arrangement is the PC server or X terminal. Because these single-task systems can run only the X server (and sometimes a window manager), a user sitting at one of these servers must run all clients on systems across the network, with their results displayed on the PC or X terminal screen. This makes the single-tasking PC or X terminal look and work just like X on a multitasking workstation.

Window Management

Another important concept in X programming is that applications do not actually control such things as where a window appears or what size it is. Given multiprocessor, multiclient access to the same workstation display, clients must not be dependent on a particular window configuration. Instead, a client gives  hints  about how long and where it would like to be displayed. The screen layout or appearance and the style of user interaction with the system are left up to a separate program, called the  window manager .

The window manager is just another program written with Xlib, except that it is given special authority to control the layout of windows on the screen. The window manager typically allows the user to move or resize windows, start new applications, and control the stacking of windows on the screen, but only according to the window manager's window layout policy. A window layout policy is a set of rules that specify allowable sizes and positions of windows and icons.

Unlike citizens, the window manager has rights but not responsibilities. Programs must be prepared to cooperate with any type of window manager or with none at all (there are fairly simple ways to prepare programs for these contingencies). The simple window manager twmdoes not enforce any window layout policy, but clients should still assume that there could be one. For example, the window manager must be informed of the desired size of a new window before the window is displayed on the screen. If the window manager does not accept the desired window size and position, the program must be prepared to accept a different size or position or be able to display a message such as "Too small!"

If you are having trouble visualizing this situation, imagine a window manager where no windows are allowed to overlap. This is known as a tiled window manager. The Siemens RTL tiled window manager lets only transient windows (such as pop-up menus) overlap. The twm window manager, on the other hand, is referred to as real-estate-driven because keyboard input is automatically assigned to whatever window the pointer currently happens to be in.

There is at least one other window manager variety that you will encounter, called a listener or click-to-type. Its distinguishing feature is that it assigns all keyboard input to a single window when that window is selected by clicking on it with the pointer. A listener may or may not allow windows to overlap. Apple MacintoshÔ users will recognize this type of interface.

X is somewhat unusual in that it does not mandate a particular type of window manager. Its developers have tried to make X itself as free of window management or user interface policy as possible. And, while the X11 distribution includes twm as a sample window manager, individual manufacturers are expected to write their own window managers and user interface guidelines. In fact, two commercial window managers with user interface guidelines are already becoming established. They are olwm, the OPEN LOOKÔ window manager from AT&T and Sun, and mwm, the MotifÔ window manager from Open Software Foundation. The OSF Motif window manager mwm, and OPEN LOOK window managerolwm both can be configured to be real-estate-driven or click-to-type.

In the long run, the developers of X may well have made the right choice, in that the lack of clear user interface guidelines will allow a period of experimentation in which the marketplace could come up with better designs than are presently available. Some industry observers, however, decry this move, pointing out that it undercuts X's appeal as a standard user platform--X programs may be portable across systems from multiple vendors, but if users have to deal with a different user interface on each system, half the benefit of that portability will be lost. Until a clear user interface standard emerges from the marketplace, developers must be careful to write their programs in such a way that they can run under different window managers and user interface conventions.

Events

As in any mouse-driven window system, an X client must be prepared to respond to any of many different  events . Events include user input (keypress, mouse click, or mouse movement) as well as interaction with other programs. (For example, if an obscured portion of a window is exposed when another overlapping window is moved, closed, or resized, the client must redraw it.) Events of many different types can occur at any time and in any order. They are placed on a queue in the order they occur and usually are processed by clients in that order. Event-driven programming makes it natural to let the user tell the program what to do instead of vice versa.

The need to handle events is a major difference between programming under a window system and traditional UNIX or PC programming. X programs do not use the standard C functions for getting characters, and they do not poll for input. Instead there are functions for receiving events, and then the program must branch according to the type of event and perform the appropriate response. But unlike traditional programs, an X program must be ready for any kind of event at any time. In traditional programs the program is in control, asking for certain types of input at certain times. In X programs, the user is in control most of the time.

Extensions to X

The final thing to know about X is that it is  extensible . The code includes a defined mechanism for incorporating extensions, so that vendors are not forced to hack up the existing system in incompatible ways when adding features. These extensions are used just like the core Xlib routines and perform at the same level. Some extensions are standards of the MIT X Consortium, such as the Shape extension, which supports non-rectangular windows, and the X Input extension, which supports input devices other than keyboard and mouse. There is also a standard 3-D graphics extension called PEX, with two APIs called PHIGS and PEXlib. Other extensions are under development.

Extensions have both client-side and server-side code. A server vendor is not required to provide support for all the standard extensions. Therefore, before using an extension, you must query the server to see if the extension is supported. At this writing, only the Shape extension is widely supported. 


X Window System Software Architecture

By now, we have described enough to draw a simple picture of the X Window System architecture (see Figure 1-3).

Clients communicate with the server via Xlib calls

fig.1.03.gif

 A display server is a program that runs on each system that supports a graphics display, keyboard, and mouse. The X release from MIT includes sample monochrome and color servers for Sun, DEC, Hewlett Packard, IBM, Apple Macintosh, and many other systems. Commercially developed servers are available for virtually all major workstation vendors. In addition, companies such as Graphics Software Systems, Interactive Systems, and Locus Computing offer server implementations for IBM-compatible PCs. Finally, there are X terminals, which are screens controlled by an X server running in ROM. X terminals are available from companies such as Visual, Network Computing Devices, and GraphOn.

Applications communicate with the server by means of calls to a low-level library of C language routines known as Xlib.  Xlib provides functions for connecting to a particular display server, creating windows, drawing graphics, responding to events, and so on. Xlib calls are translated to protocol requests sent via tcp/ip either to the local server or to another server across the network. Some of the many sample applications available on the X release include xterm (a terminal emulator), xcalc (a calculator), xmh (a mail handler), xclock(a clock), and a troff previewer.

The window manager is just another program written with the X library, except that by convention it is given special authority to control the layout of windows on the screen.

Client is a slightly more general term than application, although they are almost synonymous. All clients except the window manager are called applications. When a statement in this manual applies only to the window manager or only to the applications managed by the window manager, the appropriate term is used. In other instances, whichever term seems more natural is used.

Applications and window managers can be written solely with Xlib or with a set of higher-level subroutine libraries known as toolkits. Toolkits implement a set of user interface features such as menus or command buttons (referred to generically as toolkit widgets) and allow applications to manipulate these features using object-oriented programming techniques. Toolkit intrinsics allow programmers to create new widgets.

There are several toolkits distributed with the X11 release, the most notable of them being the Xt Toolkit, which was developed by Digital and MIT, and the Interviews toolkit, which was developed by Stanford University. Xt is now officially part of the X11 standard.

Toolkits can make programming much, much easier and the finished project more thorough. Toolkits have built-in user configurability and built-in code for interaction with the window manager, which will save you a lot of trouble. You are advised to use a toolkit for most of your X programming. However, all existing toolkits in C also require or allow you to use Xlib code. And, more than that, they use Xlib internally; so understanding Xlib will help you understand how the toolkits work.

Another reason to use a toolkit is to take advantage of established user interface conventions. Several of these are available, such as OSF's Motif and Sun's OPEN LOOK. If you use Xlib for all your X programming, either you will have to reimplement one of the established conventions such as OPEN LOOK or your program will be an oddball that will not look or respond as people expect.

There are tradeoffs in using toolkits, however. One is that the executable for a given program using a toolkit is considerably larger than the equivalent program written using Xlib. Another is that the toolkits utilize highly abstract concepts and require strict programming conventions because of their object-oriented design. These take time to learn.

This manual describes how to write programs with Xlib. Other volumes in our X Window System series cover the toolkits. 


Overview of Xlib

Just what does the X library contain? Table 1-1 groups the Xlib routines according to their major function and lists the chapter in which the group is discussed. 
 

 As you can see, Xlib provides a lot of functionality. X was designed to allow any style of user interface, and that requires a very flexible set of routines. But not all the routines are necessary or intended for writing normal applications. Many are intended for window management or for other specialized purposes. 

A more detailed listing that provides the name and a brief description of the routines in each group can be found in Appendix A,Function Group Summary, of Volume Two, Xlib Reference Manual.

Function Group Description Chapter Color Routines to change the way colors drawn by an application are interpreted on the screen. Chapter 7 Cursors Routines to change the shape and colors of the image that tracks the pointer around the screen. Chapter 6 Data Management Several mechanisms to associate data with windows or numbers. Chapter 15 Display Connection Routines to connect and disconnect an application with a display, possibly across the network. Chapter 3 Display and Server Specifications Macros and equivalent functions are provided that provide information about a particular server implementation and the connected display hardware. Volume One, throughout;Volume Two, Appendix C Drawing Routines to draw dots, lines, rectangles, polygons, and arcs, and an analogous set to fill the last three. Chapter 6 Errors Routines to set the functions called when errors occur. Chapter 2 Events Routines to get input from the user, from other applications, and from the server. In X, these are collectively called events. Chapter 8 Extensions Routines to find out what extensions are available on a particular server and get information about how to use one. Chapter 15 Fonts Routines to list available fonts, load fonts, and find out their characteristics. Chapter 6 Geometry Routines to manipulate and translate geometry specifications. Chapter 13 Graphics Context Routines to set the way drawing requests are interpreted. Chapter 5 Host Access Routines to control access to a server from other machines connected in a network. Chapter 15 Images Routines to get, display, or manipulate screen images. Chapter 6 Interclient Communication Routines enabling any client to make available information for any other client to read. Chapter 12 Internationalization Functions to handle user input and draw text independent of language. Chapters 6, 10, and 11 Keyboard Functions to modify the way keyboard input is handled, including the keyboard mapping. Chapter 9 Pointer Functions to modify the way pointer input is handled. Chapter 9 Regions Routines to perform mathematical operations on polygonal regions. Chapter 6 Resource Management Routines to make managing user preferences and command line arguments easier. Chapter 13, Chapter 14 Screen Saver Routines to set the operating characteristics of the daemon that blanks the screen when the keyboard and pointer have been idle for a time. Chapter 15 Text Routines for drawing text and for determining the size of a string to be drawn. Chapter 6 User Preferences Routines for setting and getting the keyboard click and auto-repeat settings. Chapter 9 Window Attributes Routines for setting and getting the current characteristics of a window. Chapter 4 Window Life Routines to create or destroy a window. Chapter 3 Window Management Routines to allow the manipulation of windows around the screen, changing their size, their visibility on the screen, and their apparent position above or below other windows. Chapter 16  


 

Xlib Programming Manual (O'Reilly & Associates, Inc.)



推荐阅读
  • 本文讨论了如何使用Web.Config进行自定义配置节的配置转换。作者提到,他将msbuild设置为详细模式,但转换却忽略了带有替换转换的自定义部分的存在。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • Gitlab接入公司内部单点登录的安装和配置教程
    本文介绍了如何将公司内部的Gitlab系统接入单点登录服务,并提供了安装和配置的详细教程。通过使用oauth2协议,将原有的各子系统的独立登录统一迁移至单点登录。文章包括Gitlab的安装环境、版本号、编辑配置文件的步骤,并解决了在迁移过程中可能遇到的问题。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • 使用nodejs爬取b站番剧数据,计算最佳追番推荐
    本文介绍了如何使用nodejs爬取b站番剧数据,并通过计算得出最佳追番推荐。通过调用相关接口获取番剧数据和评分数据,以及使用相应的算法进行计算。该方法可以帮助用户找到适合自己的番剧进行观看。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • 怎么在PHP项目中实现一个HTTP断点续传功能发布时间:2021-01-1916:26:06来源:亿速云阅读:96作者:Le ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • 统一知识图谱学习和建议:更好地理解用户偏好
    本文介绍了一种将知识图谱纳入推荐系统的方法,以提高推荐的准确性和可解释性。与现有方法不同的是,本方法考虑了知识图谱的不完整性,并在知识图谱中传输关系信息,以更好地理解用户的偏好。通过大量实验,验证了本方法在推荐任务和知识图谱完成任务上的优势。 ... [详细]
  • 总结一下C中string的操作,来自〈CPrimer〉第四版。1.string对象的定义和初始化:strings1;空串strings2(s1);将s2初始 ... [详细]
  • 本文介绍了使用C++Builder实现获取USB优盘序列号的方法,包括相关的代码和说明。通过该方法,可以获取指定盘符的USB优盘序列号,并将其存放在缓冲中。该方法可以在Windows系统中有效地获取USB优盘序列号,并且适用于C++Builder开发环境。 ... [详细]
  • 本文整理了Java中org.apache.solr.common.SolrDocument.setField()方法的一些代码示例,展示了SolrDocum ... [详细]
  • 文件路径的生成及其在文件操作中的应用
    本文介绍了文件路径的生成方法及其在文件操作中的应用。在进行文件操作时,需要知道文件的具体位置才能打开文件。文件的位置有绝对路径和相对路径之分。绝对路径通常只在特定电脑上有效,不同电脑上的文件存放路径可能不同,导致程序报错。相对路径是解决这个问题的最好方式,它不依赖于文件的具体存放位置,只需要按照统一的规范进行文件存放即可。使用相对路径可以避免冗余和麻烦,特别适用于大项目和团队维护代码的情况。 ... [详细]
author-avatar
丁城雨
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有