1. 程式人生 > 其它 >x11 window 第三章:視窗管理

x11 window 第三章:視窗管理

技術標籤:# x11 windows

目錄

3.1 Createwindows

3.1 建立視窗

3.1.1 XCreateWindow()

3.1.2 XCreateSimpleWindow()

3.2 Destroywindows

3.2 銷燬視窗

3.3 Mapwindows

3.3 視窗對映

3.4 Unmapwindows

3.4 視窗反對映

3.5 Configurewindows

3.5 視窗配置

3.6 Changethestackingorder

3.6 更改視窗堆疊順序

3.7 Changewindowattributes

3.7 改變視窗屬性

3.7.1 XConfigureWindow()

3.7.2XMoveWindow()

3.7.3 XResizeWindow()

3.7.4 XMoveResizeWindow()

3.7.5 XSetWindowBorderWidth()


In the X Window System, awindowis a rectangular area on the screen that lets you view graphic output. Client applications can display overlapping and nested windows on one or more screens that are driven by X servers on one or more machines. Clients who want to create windows must first connect their program to the X server by calling

XOpenDisplay(). This chapter begins with a discussion of visual types and window attributes. The chapter continues with a discussion of the Xlib functions you can use to:

在X視窗系統中,視窗是螢幕上的一個矩形區域,用於檢視圖形輸出。客戶機應用程式可以在一個或多個由一臺或多臺計算機上的X伺服器驅動的螢幕上顯示重疊和巢狀的視窗。要建立windows的客戶端必須首先通過呼叫XOpenDisplay()將其程式連線到X伺服器。本章首先討論視覺型別和視窗屬性。本章繼續討論Xlib函式,可用於:

This chapter also identifies the window actions that may generate events.

本章還確定了可能生成事件的視窗操作。

Note that it is vital that your application conform to the established conventions for communicating with window managers for it to work well with the various window managers in use (see section "Client to Window Manager Communication"). Toolkits generally adhere to these conventions for you, relieving you of the burden. Toolkits also often supersede many functions in this chapter with versions of their own. Refer to the documentation for the toolkit you are using for more information.

請注意,應用程式必須遵守與視窗管理器通訊的既定約定,這樣才能與使用中的各種視窗管理器良好地工作.工具箱通常會為您遵守這些約定,從而減輕您的負擔。工具箱也經常用自己的版本取代本章中的許多功能。有關詳細資訊,請參閱所使用的工具箱的文件

  • 3.1 Createwindows

  • 3.1 建立視窗

Xlib provides basic ways for creating windows, and toolkits often supply higher-level functions specifically for creating and placing top-level windows, which are discussed in the appropriate toolkit documentation. If you do not use a toolkit, however, you must provide some standard information or hints for the window manager by using theXlib inter-client communication functions.

Xlib提供了建立視窗的基本方法,工具箱通常提供更高階的功能,專門用於建立和放置頂級視窗,這些功能在相應的工具箱文件中有討論。但是,如果不使用工具箱,則必須使用Xlib客戶機間通訊功能為視窗管理器提供一些標準資訊或提示。

If you use Xlib to create your own top-level windows (direct children of the root window), you must observe the following rules so that all applications interact reasonably across the different styles of window management:

如果使用Xlib建立自己的頂級視窗(根視窗的直接子視窗),則必須遵守以下規則,以便所有應用程式在不同的視窗管理樣式之間進行合理的互動:

  • You must never fight with the window manager for the size or placement of your top-level window.
  • 您決不能與視窗管理器爭奪頂層視窗的大小或位置。
  • You must be able to deal with whatever size window you get, even if this means that your application just prints a message like ``Please make me bigger'' in its window.
  • 您必須能夠處理任何大小的視窗,即使這意味著您的應用程式只是在其視窗中列印一條訊息“Please make me bigger”。
  • You should only attempt to resize or move top-level windows in direct response to a user request. If a request to change the size of a top-level window fails, you must be prepared to live with what you get. You are free to resize or move the children of top-level windows as necessary. (Toolkits often have facilities for automatic relayout.)
  • 您應該只嘗試調整或移動頂層視窗以直接響應使用者請求。如果更改頂級視窗大小的請求失敗,則必須準備好接受所得到的結果。您可以根據需要自由調整或移動頂層視窗的子視窗。(工具箱通常具有自動重新佈局的功能。)
  • If you do not use a toolkit that automatically sets standard window properties, you should set these properties for top-level windows before mapping them.
  • 如果不使用自動設定標準視窗屬性的工具箱,則應在對映頂級視窗之前為其設定這些屬性。

For further information, see "Inter-Client Communication Functions" and theInter-Client Communication Conventions Manual.

XCreateWindow()is the more general function that allows you to set specific window attributes when you create a window.XCreateSimpleWindow()creates a window that inherits its attributes from its parent window.

The X server acts as ifInputOnlywindows do not exist for the purposes of graphics requests, exposure processing, andVisibilityNotifyevents. AnInputOnlywindow cannot be used as a drawable (that is, as a source or destination for graphics requests).InputOnlyandInputOutputwindows act identically in other respects (properties, grabs, input control, and so on). Extension packages can define other classes of windows.

3.1.1 XCreateWindow()

To create an unmapped window and set its window attributes, useXCreateWindow().

要建立未對映的視窗並設定其視窗屬性,請使用XCreateWindow()

Display *display;
Window parent;
int x, y; 
unsigned int width, height;
unsigned int border_width;
int depth;
unsigned int class;
Visual *visual
unsigned long valuemask;
XSetWindowAttributes *attributes; // Specifies the structure from which the values (as specified by the value mask) are to be taken. The value mask should have the appropriate bits set to indicate which attributes have been set in the structure.

Window XCreateWindow(display, parent, x, y, width, height, border_width, depth, class, visual, valuemask, attributes)

Display *display;
Window parent;
int x, y; 
unsigned int width, height;
unsigned int border_width;
int depth;
unsigned int class;
Visual *visual
unsigned long valuemask;
XSetWindowAttributes *attributes; //指定從中獲取值(由值掩碼指定)的結構。值掩碼應該設定適當的位,以指示在結構中設定了哪些屬性

Window XCreateWindow(display, parent, x, y, width, height, border_width, depth, class, visual, valuemask, attributes)

TheXCreateWindowfunction creates an unmapped subwindow for a specified parent window, returns the window ID of the created window, and causes the X server to generate aCreateNotifyevent. The created window is placed on top in the stacking order with respect to siblings.

XCreateWindow函式為指定的父視窗建立一個未對映的子視窗,返回所建立視窗的視窗ID,並使X伺服器生成CreateNotify事件。建立的視窗將按與同級視窗相關的堆疊順序放在最上面。

The coordinate system has the X axis horizontal and the Y axis vertical with the origin [0, 0] at the upper-left corner. Coordinates are integral, in terms of pixels, and coincide with pixel centers. Each window and pixmap has its own coordinate system. For a window, the origin is inside the border at the inside, upper-left corner.

座標系的X軸水平,Y軸垂直,原點[0,0]位於左上角。座標是完整的,以畫素為單位,並且與畫素中心重合。每個視窗和pixmap都有自己的座標系。對於視窗,原點在左上角的邊框內。

The border_width for an InputOnly window must be zero, or a BadMatch error results. For class InputOutput, the visual type and depth must be a combination supported for the screen, or a BadMatch error results. The depth need not be the same as the parent, but the parent must not be a window of class InputOnly, or a BadMatch error results. For an InputOnly window, the depth must be zero, and the visual must be one supported by the screen. If either condition is not met, a BadMatch error results. The parent window, however, may have any depth and class. If you specify any invalid window attribute for a window, a BadMatch error results.

僅限輸入視窗的邊框寬度必須為零,否則會導致不匹配錯誤。對於類InputOutput,視覺型別和深度必須是螢幕支援的組合,否則會出現不匹配的錯誤結果。深度不必與父級相同,但父級不能是類InputOnly的視窗,也不能是不匹配的錯誤結果。對於僅限輸入的視窗,深度必須為零,而視覺效果必須是螢幕支援的深度。如果兩個條件都不滿足,則會產生不匹配錯誤。但是,父視窗可以有任何深度和類。如果為視窗指定了任何無效的視窗屬性,則會出現不匹配錯誤。

The created window is not yet displayed (mapped) on the user's display. To display the window, callXMapWindow(). The new window initially uses the same cursor as its parent. A new cursor can be defined for the new window by callingXDefineCursor(). The window will not be visible on the screen unless it and all of its ancestors are mapped and it is not obscured by any of its ancestors.

建立的視窗尚未顯示(對映)在使用者的顯示器上。要顯示視窗,請呼叫XMapWindow()。新視窗最初使用與其父視窗相同的游標。可以通過呼叫XDefineCursor()為新視窗定義新遊標。除非視窗及其所有祖先都被對映並且沒有被任何祖先遮住,否則視窗在螢幕上將不可見。

3.1.2 XCreateSimpleWindow()

To create an unmappedInputOutputsubwindow of a given parent window, useXCreateSimpleWindow().

Display *display;
Window parent;
int x, y;
unsigned int width, height;
unsigned int border_width;
unsigned long border;
unsigned long background;

Window XCreateSimpleWindow(display, parent, x, y, width, height, border_width, border, background)

TheXCreateSimpleWindowfunction creates an unmappedInputOutputsubwindow for a specified parent window, returns the window ID of the created window, and causes the X server to generate aCreateNotifyevent. The created window is placed on top in the stacking order with respect to siblings. Any part of the window that extends outside its parent window is clipped. The border_width for anInputOnlywindow must be zero, or aBadMatcherror results.XCreateSimpleWindowinherits its depth, class, and visual from its parent. All other window attributes, except background and border, have their default values.

XCreateSimpleWindowcan generateBadAlloc,BadMatch,BadValue, andBadWindowerrors.

  • 3.2 Destroywindows

  • 3.2 銷燬視窗

  • 3.3 Mapwindows

  • 3.3 視窗對映

  • 3.4 Unmapwindows

  • 3.4 視窗反對映

  • 3.5 Configurewindows

  • 3.5 視窗配置

  • 3.6 Changethestackingorder

  • 3.6 更改視窗堆疊順序

  • 3.7 Changewindowattributes

  • 3.7 改變視窗屬性

Xlib provides functions that you can use to move a window, resize a window, move and resize a window, or change a window's border width. To change one of these parameters, set the appropriate member of the XWindowChanges structure and OR in the corresponding value mask in subsequent calls to XConfigureWindow(). The symbols for the value mask bits and the XWindowChanges structure are:

Xlib提供的函式可用於移動視窗、調整視窗大小、移動視窗和調整視窗大小,或更改視窗的邊框寬度。要更改其中一個引數,請在後續呼叫XConfigureWindow()時,在相應的值掩碼中設定XWindowChanges結構的相應成員和或值掩碼位和XWindowChanges結構的符號為:

/* Configure window value mask bits */

#define CWX		(1<<0)
#define CWY		(1<<1)
#define CWWidth		(1<<2)
#define CWHeight	(1<<3)
#define CWBorderWidth	(1<<4)
#define CWSibling	(1<<5)
#define CWStackMode	(1<<6)

/* Values */

typedef struct {
	int x, y;
	int width, height;
	int border_width;
	Window sibling;
	int stack_mode;
} XWindowChanges;

The x and y members are used to set the window's x and y coordinates, which are relative to the parent's origin and indicate the position of the upper-left outer corner of the window. The width and height members are used to set the inside size of the window, not including the border, and must be nonzero, or aBadValueerror results. Attempts to configure a root window have no effect.

x和y成員用於設定視窗的x和y座標,它們相對於父物件的原點,並指示視窗左上角的位置。width和height成員用於設定視窗的內部大小(不包括邊框),並且必須非零,否則會導致BadValue錯誤。嘗試配置根視窗無效。

The border_width member is used to set the width of the border in pixels. Note that setting just the border width leaves the outer-left corner of the window in a fixed position but moves the absolute position of the window's origin. If you attempt to set the border-width attribute of anInputOnlywindow nonzero, aBadMatcherror results.

border_width成員用於設定邊框的寬度(以畫素為單位)。請注意,僅設定邊框寬度會使視窗的左外角處於固定位置,但會移動視窗原點的絕對位置。如果試圖將僅輸入視窗的border width屬性設定為非零,則會出現不匹配錯誤

The sibling member is used to set the sibling window for stacking operations. The stack_mode member is used to set how the window is to be restacked and can be set toAbove,Below,TopIf, .PN BottomIf , orOpposite.

同級成員用於設定堆疊操作的同級視窗。stack_mode成員用於設定如何重新載入視窗,並可以設定為Above、Below、TopIf、.PN BottomIf或reverse。

If theoverride-redirectflag of the window isFalseand if some other client has selectedSubstructureRedirectMaskon the parent, the X server generates aConfigureRequestevent, and no further processing is performed. Otherwise, if some other client has selectedResizeRedirectMaskon the window and the inside width or height of the window is being changed, aResizeRequestevent is generated, and the current inside width and height are used instead. Note that the override-redirect flag of the window has no effect onResizeRedirectMaskand thatSubstructureRedirectMaskon the parent has precedence overResizeRedirectMaskon the window.

如果視窗的override redirect標誌為False,並且其他一些客戶機在父級上選擇了SubstructureRedirectMask,則X伺服器將生成ConfigureRequest事件,並且不會執行進一步的處理。否則,如果其他客戶機在視窗上選擇了ResizeRedirectMask,並且視窗的內部寬度或高度正在更改,則會生成ResizeRequest事件,並使用當前的內部寬度和高度。請注意,視窗的override redirect標誌對ResizeRedirectMask沒有影響,並且父視窗上的子結構redirectmask優先於視窗上的ResizeRedirectMask。

When the geometry of the window is changed as specified, the window is restacked among siblings, and aConfigureNotifyevent is generated if the state of the window actually changes.GravityNotifyevents are generated afterConfigureNotifyevents. If the inside width or height of the window has actually changed, children of the window are affected as specified.

當視窗的幾何結構按指定方式更改時,視窗將在同級之間重新載入,如果視窗的狀態實際發生更改,則會生成ConfigureNotify事件。在ConfigureNotify事件之後生成GravityNotify事件。如果視窗的內部寬度或高度實際上已更改,則視窗的子級將按指定的方式受到影響。

If a window's size actually changes, the window's subwindows move according to their window gravity. Depending on the window's bit gravity, the contents of the window also may be moved (see "GravityAttributes").

如果視窗的大小實際發生變化,則視窗的子視窗將根據其視窗重力移動。根據視窗的位重力,視窗的內容也可以移動(請參見“GravityAttributes”)。

If regions of the window were obscured but now are not, exposure processing is performed on these formerly obscured windows, including the window itself and its inferiors. As a result of increasing the width or height, exposure processing is also performed on any new regions of the window and any regions where window contents are lost.

如果視窗的區域被遮擋,但現在沒有,則對這些以前被遮擋的視窗(包括視窗本身及其下級視窗)執行曝光處理。作為增加寬度或高度的結果,還對視窗的任何新區域和視窗內容丟失的任何區域執行曝光處理。

The restack check (specifically, the computation forBottomIf,TopIf, andOpposite) is performed with respect to the window's final size and position (as controlled by the other arguments of the request), not its initial position. If a sibling is specified without a stack_mode, aBadMatcherror results.

restack檢查(特別是BottomIf、TopIf和reverse的計算)是根據視窗的最終大小和位置(由請求的其他引數控制)執行的,而不是其初始位置。如果指定的同級項沒有堆疊模式,則會產生不匹配錯誤。

If a stack_mode is specified but no sibling is specified, the window is restacked as follows:

如果指定了堆疊模式但未指定同級,則視窗將按如下方式重新標記:

AboveThe window is placed just above the sibling.窗正好位於同級窗的上方。
BelowThe window is placed just below the sibling.視窗正好位於同級物件的下方。
TopIfIf the sibling occludes the window, the window is placed at the top of the stack.如果同級物件阻擋了視窗,則該視窗將放置在堆疊的頂部
BottomIfIf the window occludes the sibling, the window is placed at the bottom of the stack.如果視窗遮擋了同級物件,則該視窗將放置在堆疊的底部。
OppositeIf the sibling occludes the window, the window is placed at the top of the stack. If the window occludes the sibling, the window is placed at the bottom of the stack.如果同級物件阻擋了視窗,則該視窗將放置在堆疊的頂部。如果視窗遮擋了同級物件,則該視窗將放置在堆疊的底部。

3.7.1 XConfigureWindow()

To configure a window's size, location, stacking, or border, useXConfigureWindow().Attempts to configure a root window have no effect.

Syntax


XConfigureWindow(display, w, value_mask, values)
      Display *display;
      Window w;
      unsigned int value_mask;
      XWindowChanges *values;

Arguments

displaySpecifies the connection to the X server.
wSpecifies the window to be reconfigured.
value_maskSpecifies which values are to be set using information in the values structure. This mask is the bitwise inclusive OR of the valid configure window values bits.
valuesSpecifies theXWindowChangesstructure.

Description

TheXConfigureWindow()function uses the values specified in theXWindowChangesstructure to reconfigure a window's size, position, border, and stacking order. Values not specified are taken from the existing geometry of the window.

If a sibling is specified without a stack_mode or if the window is not actually a sibling, aBadMatcherror results. Note that the computations forBottomIf,TopIf, andOppositeare performed with respect to the window's final geometry (as controlled by the other arguments passed toXConfigureWindow()), not its initial geometry. Any backing store contents of the window, its inferiors, and other newly visible windows are either discarded or changed to reflect the current screen contents (depending on the implementation).

XConfigureWindow()can generateBadMatch,BadValue, andBadWindowerrors.

Diagnostics

BadMatchAnInputOnlywindow is used as a Drawable.
BadMatchSome argument or pair of arguments has the correct type and range but fails to match in some other way required by the request.
BadValueSome numeric value falls outside the range of values accepted by the request. Unless a specific range is specified for an argument, the full range defined by the argument's type is accepted. Any argument defined as a set of alternatives can generate this error.
BadWindowA value for a Window argument does not name a defined Window.

3.7.2XMoveWindow()

To move a window without changing its size, useXMoveWindow().

Syntax

XMoveWindow(display, w, x, y)
      Display *display;
      Window w;
      int x, y;

Arguments

displaySpecifies the connection to the X server.
wSpecifies the window to be moved
x
y
Specify the x and y coordinates, which define the new location of the top-left pixel of the window's border or the window itself if it has no border.

Description

TheXMoveWindow()function moves the specified window to the specified x and y coordinates, but it does not change the window's size, raise the window, or change the mapping state of the window. Moving a mapped window may or may not lose the window's contents depending on if the window is obscured by nonchildren and if no backing store exists. If the contents of the window are lost, the X server generatesExposeevents. Moving a mapped window generatesExposeevents on any formerly obscured windows.

If theoverride-redirectflag of the window isFalseand some other client has selectedSubstructureRedirectMaskon the parent, the X server generates aConfigureRequestevent, and no further processing is performed. Otherwise, the window is moved.

XMoveWindow()can generate aBadWindowerror.

Diagnostics

BadWindowA value for a Window argument does not name a defined Window.

3.7.3 XResizeWindow()

To change a window's size without changing the upper-left coordinate, useXResizeWindow().

3.7.4 XMoveResizeWindow()

To change the size and location of a window, useXMoveResizeWindow().

3.7.5 XSetWindowBorderWidth()

To change the border width of a given window, useXSetWindowBorderWidth().