跳到主要内容

事件

当指针位于某个窗口 W 中按下某个按钮时,若当前没有进行中的活动指针抓取,则从根窗口向下查找 W 的各级上级窗口,寻找可激活的被动抓取。若不存在与该按钮匹配的被动抓取,则自动为接收到该事件的客户端启动一次活动抓取,并把 last-pointer-grab 时间设置为当前服务器时间。其效果本质上等同于带以下参数的 GrabButton:

event-window: the event window
event-mask: the client's selected events on the event window
pointer-mode and keyboard-mode: Asynchronous
owner-events: True if the client has OwnerGrabButton selected
on the event window, else False
confine-to: None
cursor: None

当所有按钮都被释放时,抓取自动终止。UngrabPointer 和 ChangeActiveGrab 都可用于修改活动抓取。

KeyPress
and
KeyRelease
and
ButtonPress
and
ButtonRelease
and
MotionNotify
root, event: WINDOW
child: WINDOW or None
same-screen: BOOL
root-x, root-y, event-x, event-y: INT16
detail: <see below>
state: SETofKEYBUTMASK
time: TIMESTAMP

当某个键或按钮改变状态,或者指针移动时生成。事件的“源”是指针所在的窗口。通常针对其报告该事件的窗口是这样确定的:从源窗口开始沿层次结构向上查找第一个有客户端对该事件表示兴趣的窗口,前提是没有中间窗口通过在其 do-not-propagate-mask 中包含该事件类型而禁止生成该事件。实际用于报告的窗口可以由活动抓取和焦点窗口加以修改。事件所针对报告的那个窗口称为“事件”窗口。

root 是“源”窗口的根窗口,root-x 和 root-y 是事件发生时相对于 root 原点的指针坐标。event 是“事件”窗口。若事件窗口与 root 位于同一屏幕上,则 event-x 和 event-y 是相对于事件窗口原点的指针坐标;否则 event-x 和 event-y 为零。若源窗口是事件窗口的下级窗口,则 child 被设置为事件窗口中那个作为源窗口上级窗口的子窗口。state 分量给出事件发生前按钮和修饰键的状态。detail 分量随事件类型而变化:

KeyPress, KeyRelease:               KEYCODE
ButtonPress, ButtonRelease: BUTTON
MotionNotify: {Normal, Hint}

MotionNotify 事件仅在运动开始和结束都发生于该窗口内时才生成。运动事件的粒度不作保证,但选择运动事件的客户端可以保证在指针移动并静止时至少收到一个事件。选择 PointerMotion 会接收到与指针按钮状态无关的事件。而若改为选择 Button[1-5]Motion 的某个子集,则只有在一个或多个指定按钮被按下时才会收到 MotionNotify 事件。选择 ButtonMotion 时,只有在至少有一个按钮被按下时才会收到 MotionNotify 事件。这些事件的类型始终是 MotionNotify,与所选择的内容无关。若选择了 PointerMotionHint,则服务器可以自由地只向该事件窗口的客户端发送一个 MotionNotify 事件(其 detail 为 Hint),直至键或按钮状态改变、指针离开事件窗口,或者该客户端发出 QueryPointer 或 GetMotionEvents 请求。

EnterNotify
and
LeaveNotify
root, event: WINDOW
child: WINDOW or None
same-screen: BOOL
root-x, root-y, event-x, event-y: INT16
mode: {Normal, Grab, Ungrab}
detail: {Ancestor, Virtual, Inferior, Nonlinear,
NonlinearVirtual}
focus: BOOL
state: SETofKEYBUTMASK
time: TIMESTAMP

若指针移动导致指针处于与先前不同的窗口,则生成 EnterNotify 和 LeaveNotify 事件而不生成 MotionNotify 事件。只有在某窗口上选择 EnterWindow 的客户端才会收到 EnterNotify 事件,也只有选择 LeaveNotify 的客户端才会收到 LeaveNotify 事件。事件中报告的指针位置始终是“最终”位置,而不是指针的“初始”位置。在 LeaveNotify 事件中,若事件窗口的某个子窗口包含指针的“初始”位置,则 child 分量被设置为该子窗口,否则为 None。对于 EnterNotify 事件,若事件窗口的某个子窗口包含指针的“最终”位置,则 child 分量被设置为该子窗口,否则为 None。若事件窗口是焦点窗口或焦点窗口的下级窗口,则 focus 为 True,否则 focus 为 False。

普通的指针运动事件的 mode 为 Normal;抓取激活时的伪运动事件的 mode 为 Grab,抓取去激活时的伪运动事件的 mode 为 Ungrab。

普通事件的生成方式如下​

当指针从窗口 A 移动到窗口 B,且 A 是 B 的下级窗口时:

LeaveNotify with detail Ancestor is generated on A
LeaveNotify with detail Virtual is generated on each window
between A and B exclusive (in that order)
EnterNotify with detail Inferior is generated on B

当指针从窗口 A 移动到窗口 B,且 B 是 A 的下级窗口时:

LeaveNotify with detail Inferior is generated on A
EnterNotify with detail Virtual is generated on each window
between A and B exclusive (in that order)
EnterNotify with detail Ancestor is generated on B

当指针从窗口 A 移动到窗口 B,窗口 C 为二者的最近公共上级窗口时:

LeaveNotify with detail Nonlinear is generated on A
LeaveNotify with detail NonlinearVirtual is generated on each
window between A and C exclusive (in that order)
EnterNotify with detail NonlinearVirtual is generated on each
window between C and B exclusive (in that order)
EnterNotify with detail Nonlinear is generated on B

当指针从窗口 A 移动到位于不同屏幕上的窗口 B 时:

LeaveNotify with detail Nonlinear is generated on A
LeaveNotify with detail NonlinearVirtual is generated on each
window above A up to and including its root (in
order)
EnterNotify with detail NonlinearVirtual is generated on each
window
from B's root down to but not including B (in order)
EnterNotify with detail Nonlinear is generated on B

当一次指针抓取被激活时(在最初为进入 confine-to 窗口所做的任何 warp 之后),设 G 为该抓取的抓取窗口,P 为指针所在的窗口:

EnterNotify and LeaveNotify events with mode Grab are
generated (as for Normal above) as if the pointer were to
suddenly warp from its current position in P to some position
in G.However, the pointer does not warp, and the pointer
position is used as both the "initial"and "final" positions
for the events.

当一次指针抓取去激活时,设 G 为该抓取的抓取窗口,P 为指针所在的窗口:

生成 mode 为 Ungrab 的 EnterNotify 和 LeaveNotify 事件(与上面的 Normal 情形相同),就仿佛指针突然从 G 中的某个位置 warp 到其当前在 P 中的位置。然而指针并不发生 warp,并且以当前的指针位置作为这些事件的“初始”位置和“最终”位置。

FocusIn
and
FocusOut
event: WINDOW
mode: {Normal, WhileGrabbed, Grab, Ungrab}
detail: {Ancestor, Virtual, Inferior, Nonlinear,
NonlinearVirtual, Pointer, PointerRoot, None}

当输入焦点改变时生成。报告给在该窗口上选择 FocusChange 的客户端。键盘未被抓取时由 SetInputFocus 生成的事件其 mode 为 Normal;键盘被抓取时由 SetInputFocus 生成的事件其 mode 为 WhileGrabbed;键盘抓取激活时生成的事件其 mode 为 Grab,键盘抓取去激活时生成的事件其 mode 为 Ungrab。

Normal 和 WhileGrabbed 事件的生成方式如下​

当焦点从窗口 A 移到窗口 B,且 A 是 B 的下级窗口,指针位于窗口 P 中时:

FocusOut with detail Ancestor is generated on A
FocusOut with detail Virtual is generated on each window
between A and B exclusive (in that order)
FocusIn with detail Inferior is generated on B
If P is an inferior of B, but P is not A or an inferior of A
or an ancestor of A, FocusIn with detail Pointer is
generated on each window below B down to and
including P (in order)

当焦点从窗口 A 移到窗口 B,且 B 是 A 的下级窗口,指针位于窗口 P 中时:

If P is an inferior of A, but P is not A or an inferior of B
or an ancestor of B, FocusOut with detail Pointer is
generated on each window from P up to but not
including A (in order)
FocusOut with detail Inferior is generated on A
FocusIn with detail Virtual is generated on each window
between A and B exclusive (in that order)
FocusIn with detail Ancestor is generated on B

当焦点从窗口 A 移到窗口 B,窗口 C 为二者的最近公共上级窗口,且指针位于窗口 P 中时:

If P is an inferior of A, FocusOut with detail Pointer is
generated on each window from P up to but not
including A (in order)
FocusOut with detail Nonlinear is generated on A
FocusOut with detail NonlinearVirtual is generated on each
window between A and C exclusive (in that order)
FocusIn with detail NonlinearVirtual is generated on each
window between C and B exclusive (in that order)
FocusIn with detail Nonlinear is generated on B
If P is an inferior of B, FocusIn with detail Pointer is
generated on each window below B down to and
including P (in order)

当焦点在位于不同屏幕上的窗口 A 与窗口 B 之间移动,且指针位于窗口 P 中时:

If P is an inferior of A, FocusOut with detail Pointer is
generated on each window from P up to but not
including A (in order)
FocusOut with detail Nonlinear is generated on A
FocusOut with detail NonlinearVirtual is generated on each
window above A up to and including its root (in
order)
FocusIn with detail NonlinearVirtual is generated on each
window from B's root down to but not including B
(in order)
FocusIn with detail Nonlinear is generated on B
If P is an inferior of B, FocusIn with detail Pointer is
generated on each window below B down to and
including P (in order)

当焦点从窗口 A 移到 PointerRoot(或 None)时

If P is an inferior of A, FocusOut with detail Pointer is
generated on each window from P up to but not
including A (in order)
FocusOut with detail Nonlinear is generated on A
FocusOut with detail NonlinearVirtual is generated on each
window above A up to and including its root (in
order)
FocusIn with detail PointerRoot (or None) is generated on
all root windows

当焦点从 PointerRoot(或 None)移到窗口 A 时​

在下列窗口上生成 detail 为 PointerRoot(或 None)的 FocusOut:

all root windows

在每一个下列窗口上生成 detail 为 NonlinearVirtual 的 FocusIn:

window from A's root down to but not including A
(in order)

在 A 上生成 detail 为 Nonlinear 的 FocusIn;若 P 是 A 的下级窗口,则生成 detail 为 Pointer 的 FocusIn……

generated on each window below A down to and
including P (in order)

当焦点从 PointerRoot 移到 None(或反之)时​

在下列窗口上生成 detail 为 PointerRoot(或 None)的 FocusOut:

all root windows

在下列窗口上生成 detail 为 None(或 PointerRoot)的 FocusIn:

all root windows

当一次键盘抓取被激活时,设 G 为该抓取的抓取窗口,F 为当前焦点:

FocusIn and FocusOut events with mode Grab are generated (as
for Normal above) as if the focus were to change from F to G

当一次键盘抓取去激活时,设 G 为该抓取的抓取窗口,F 为当前焦点:

FocusIn and FocusOut events with mode Ungrab are generated
(as for Normal above) as if the focus were to change from G
to F

KeymapNotify​

keys: LISTofCARD8

该值是一个位向量,如 QueryKeymap 中所述。报告给在某窗口上选择 KeymapState 的客户端。在每个 EnterNotify 和 FocusIn 之后立即生成。

Expose​

window: WINDOW
x, y, width, height: CARD16
last-in-series: BOOL

报告给在该窗口上选择 Exposure 的客户端。当窗口的某个区域变为可视图时可能生成,但也可以只在某个区域变为可见时才生成。由给定“动作”暴露的所有区域都保证被连续地报告;若 last-in-series 为 False,则后面还会跟着另一次暴露。

x 和 y 坐标相对于可绘制对象的原点,指定一个矩形的左上角。width 和 height 指定该矩形的范围。

在 InputOnly 窗口上绝不生成 Expose 事件。

GraphicsExposure​

drawable: DRAWABLE
x, y, width, height: CARD16
last-in-series: BOOL
major-opcode: CARD8
minor-opcode: CARD16

报告给在某图形上下文中选择 graphics-exposures 的客户端。当由于源区域被遮挡或越界而无法计算出目标区域时生成。由给定图形请求暴露的所有区域都保证被连续地报告;若 last-in-series 为 False,则后面还会跟着另一次暴露。

x 和 y 坐标相对于可绘制对象的原点,指定一个矩形的左上角。width 和 height 指定该矩形的范围。

主操作码和次操作码标识所用的图形请求。对于核心协议,major-opcode 总是 CopyArea 或 CopyPlane,而 minor-opcode 总为零。

NoExposure​

drawable: DRAWABLE
major-opcode: CARD8
minor-opcode: CARD16

报告给在某图形上下文中选择 graphics-exposures 的客户端。当某个可能产生 GraphicsExposure 事件的图形请求没有产生任何此类事件时生成。drawable 指定该图形请求所用的目标。

主操作码和次操作码标识所用的图形请求。对于核心协议,major-opcode 总是 CopyArea 或 CopyPlane,而 minor-opcode 总为零。

VisibilityNotify​

window: WINDOW
state: {Unobscured, PartiallyObscured, FullyObscured}

报告给在该窗口上选择 VisibilityChange 的客户端。在下文中,窗口状态的计算忽略该窗口的所有子窗口。当窗口的状态从部分遮挡、完全遮挡或不可视图变为可视图且完全无遮挡时,生成一个 state 为 Unobscured 的事件。当窗口的状态从 a) 可视图且完全无遮挡,或 b) 不可视图,变为可视图且部分遮挡时,生成一个 state 为 PartiallyObscured 的事件。当窗口的状态从 a) 可视图且完全无遮挡,或 b) 可视图且部分遮挡,或 c) 不可视图,变为可视图且完全遮挡时,生成一个 state 为 FullyObscured 的事件。

在 InputOnly 窗口上绝不生成 VisibilityNotify 事件。

CreateNotify​

parent, window: WINDOW
x, y: INT16
width, height, border-width: CARD16
override-redirect: BOOL

报告给在父窗口上选择 SubstructureNotify 的客户端。当该窗口被创建时生成。其参数与 CreateWindow 请求中的相同。

DestroyNotify​

event, window: WINDOW

报告给在该窗口上选择 StructureNotify 的客户端,以及在父窗口上选择 SubstructureNotify 的客户端。当该窗口被销毁时生成。“event”是生成该事件的窗口,“window”是那个被销毁的窗口。

UnmapNotify​

event, window: WINDOW
from-configure: BOOL

报告给在该窗口上选择 StructureNotify 的客户端,以及在父窗口上选择 SubstructureNotify 的客户端。当该窗口的状态从已映射变为未映射时生成。“event”是生成该事件的窗口,“window”是那个被取消映射的窗口。若该事件是由于窗口的父窗口被改变大小、而窗口本身的 win-gravity 为 Unmap 所致,则 from-configure 标志为 True。

MapNotify​

event, window: WINDOW
override-redirect: BOOL

报告给在该窗口上选择 StructureNotify 的客户端,以及在父窗口上选择 SubstructureNotify 的客户端。当该窗口的状态从未映射变为已映射时生成。“event”是生成该事件的窗口,“window”是那个被映射的窗口。override-redirect 标志取自该窗口的属性。

MapRequest​

parent, window: WINDOW

报告给在父窗口上选择 SubstructureRedirect 的客户端。当在一个未映射窗口上发出 MapWindow 请求且该窗口的 override-redirect 属性为 False 时生成。

ReparentNotify​

event, window, parent: WINDOW
x, y: INT16
override-redirect: BOOL

报告给在旧父窗口或新父窗口上选择 SubstructureNotify 的客户端,以及在该窗口上选择 StructureNotify 的客户端。当该窗口被重新设置父窗口时生成。“event”是生成该事件的窗口,“window”是那个已被重新定根的窗口,“parent”指定新的父窗口。x 和 y 坐标相对于新父窗口的原点,指定该窗口左上外角的位置。override-redirect 标志取自该窗口的属性。

ConfigureNotify​

event, window: WINDOW
x, y: INT16
width, height, border-width: CARD16
above-sibling: WINDOW or None
override-redirect: BOOL

报告给在该窗口上选择 StructureNotify 的客户端,以及在父窗口上选择 SubstructureNotify 的客户端。当 ConfigureWindow 请求确实改变了该窗口的状态时生成。“event”是生成该事件的窗口,“window”是那个被改变的窗口。若 above-sibling 为 None,则该窗口在同层兄弟中位于栈的底部;否则该窗口紧接在所指定兄弟窗口的上方。override-redirect 标志取自该窗口的属性。

GravityNotify​

event, window: WINDOW
x, y: INT16

报告给在父窗口上选择 SubstructureNotify 的客户端,以及在该窗口上选择 StructureNotify 的客户端。当某窗口因父窗口大小发生变化而被移动时生成。“event”是生成该事件的窗口,“window”是那个被移动的窗口。

ResizeRequest​

window: WINDOW
width, height: CARD16

报告给在该窗口上选择 ResizeRedirect 的客户端。当某个其他客户端对该窗口发出的 ConfigureWindow 请求试图改变该窗口的大小时生成。width 和 height 是内部尺寸,不包括边框。

ConfigureRequest​

parent, window: WINDOW
x, y: INT16
width, height, border-width: CARD16
above-sibling: WINDOW or None

报告给在父窗口上选择 SubstructureRedirect 的客户端。当某个其他客户端对该窗口发出 ConfigureWindow 请求时生成。几何参数即由该请求导出的结果。above-sibling 是该窗口应直接置于其上方的兄弟窗口;若为 None,则该窗口应置于底部。

CirculateNotify​

event, window: WINDOW
place: {Top, Bottom}

报告给在该窗口上选择 StructureNotify 的客户端,以及在父窗口上选择 SubstructureNotify 的客户端。当该窗口因 CirculateWindow 请求而实际被重新置栈时生成。“event”是生成该事件的窗口,“window”是那个被重新置栈的窗口。若 place 为 Top,则该窗口现在位于所有兄弟窗口之上;否则它位于所有兄弟窗口之下。

CirculateRequest​

parent, window: WINDOW
place: {Top, Bottom}

报告给在父窗口上选择 SubstructureRedirect 的客户端。当在父窗口上发出 CirculateWindow 请求且确有窗口需要被重新置栈时生成。window 指定要被重新置栈的窗口,place 指定在栈序中的新位置应是什么。

PropertyNotify​

window: WINDOW
atom: ATOM
state: {NewValue, Deleted}
time: TIMESTAMP

报告给在该窗口上选择 PropertyChange 的客户端。当该窗口的某个属性被改变时生成。时间戳指示该属性被改变时的服务器时间。

SelectionClear​

owner: WINDOW
selection: ATOM
time: TIMESTAMP

报告给某个选择区的当前所有者。在定义新的所有者时,于失去所有权的那个窗口上生成。时间戳是为该选择区记录的最近一次改变的时间。

SelectionRequest​

owner: WINDOW
selection: ATOM
target: ATOM
property: ATOM or None
requestor: WINDOW
time: TIMESTAMP or CurrentTime

报告给某个选择区的所有者。当客户端发出 ConvertSelection 请求时生成。其参数与该请求中的相同。

所有者应按所指定的目标类型把该选择区进行转换。若指定了属性,所有者应把结果作为该属性存储在请求方窗口上,然后使用 SendEvent 向请求方发送一个 SelectionNotify 事件。若该选择区无法按请求进行转换,所有者应发送一个属性置为 None 的 SelectionNotify。

SelectionNotify​

requestor: WINDOW
selection, target: ATOM
property: ATOM or None
time: TIMESTAMP or CurrentTime

此事件只能由使用 SendEvent 的客户端生成。当某个选择区已被转换并作为属性存储,或当选择区转换无法执行(以属性 None 表示)时,选择区的所有者应向请求方发送此事件。

ColormapNotify​

window: WINDOW
colormap: COLORMAP or None
new: BOOL
state: {Installed, Uninstalled}

报告给在该窗口上选择 ColormapChange 的客户端。当该窗口的颜色映射属性被改变时生成,此时 new 的值为 True。当某个窗口的颜色映射被装入或卸出时生成,此时 new 的值为 False。在这两种情况下,state 指示该颜色映射当前是否已装入。

ClientMessage​

window: WINDOW
type: ATOM
format: {8, 16, 32}
data: LISTofINT8 or LISTofINT16 or LISTofINT32

此事件只能由使用 SendEvent 的客户端生成。type 指定接收客户端应如何解释 data;服务器不对 type 或 data 施加任何解释。format 指定 data 应被视为 8 位、16 位或 32 位量的列表,以便服务器在必要时正确地进行字节交换。data 总是由 20 个 8 位值、10 个 16 位值或 5 个 32 位值之一构成,尽管特定的消息类型可能不会用到其中所有的值。