目录

Wayland窗口操作包括窗口切换,窗口移动,窗口缩放等,同时支持X11和wayland窗口。窗口切换由快捷键触发;窗口移动由鼠标持续按压窗口管理器的窗口标题栏拖动触发;窗口缩放由鼠标持续按压窗口管理器的窗口边框拖动触发。本文针对mutter源码的实现进行描述

杂记

窗口事件

mutter实现了wayland compositor,X window manager等功能,其对X11的窗口掩码进行了修改,包括xwayland的根窗口,顶层窗口和窗口管理器的页框窗口。

  • 根窗口事件掩码:

    • 核心事件:SubstructureRedirectMask | SubstructureNotifyMask | StructureNotifyMask | ColormapChangeMask | PropertyChangeMask

    • 扩展事件:XI_Enter | XI_Leave | XI_FocusIn | XI_FocusOut | XI_BarrierHit | XI_BarrierLeave | XFixesDisplayCursorNotifyMask

  • 顶级窗口掩码:增加

    • 核心事件:PropertyChangeMask (and StructureNotifyMask if override redirect window)

    • 扩展事件:XI_Enter | XI_Leave | XI_FocusIn | XI_FocusOut | ShapeNotifyMask

  • 页框窗口掩码:

    • 核心事件:SubstructureRedirectMask | SubstructureNotifyMask | StructureNotifyMask | ExposureMask | FocusChangeMask

event mask

event type

description

SubstructureRedirectMask

CirculateRequest


ConfigureRequest


MapRequest


StructureNotifyMask


SubstructureNotifyMask

CirculateNotify


ConfigureNotify

修改窗口显示属性通知

DestroyNotify

销毁窗口通知

GravityNotify


MapNotify


ReparentNotify


UnmapNotify


SubstructureNotifyMask

CreateNotify

创建窗口通知

ColormapChangeMask

ColormapNotify

修改色彩映射表通知

PropertyChangeMask

PropertyNotify

修改窗口资源属性通知

ExposureMask

Expose

暴露窗口通知

FocusChangeMask

FocusIn

焦点进入通知

FocusOut

焦点离开通知

ShapeNotifyMask

ShapeNotify


XFixesDisplayCursorNotifyMask

XFixesDisplayCursorNotify


特殊窗口

特殊窗口在mutter创建MetaX11Display时调用meta_x11_display_new和meta_display_init_x11_finish初始化,针对X11 server的特殊窗口,这些窗口都有override redirect属性

name

geometry

mask

description

composite_overlay_window

(0, 0, width, heigth)

NoEventMask

调用XCompositeGetOverlayWindow创建,未使用

leader_window

(-100, -100, 1, 1)

NoEventMask

X11窗口的默认组长,用于窗口分组

timestamp_pinging_window

(-100, -100, 1, 1)

PropertyChangeMask

获取X11 server时间戳

wm_sn_selection_window

(-100, -100, 1, 1)

NoEventMask

标记client为窗口管理器的窗口,

no_focus_window

(-100, -100, 1, 1)

FocusChangeMask | KeyPressMask | KeyReleaseMask

取消X11 display焦点时,焦点设在no_focus_window上

guard_window

(0, 0, width, heigth)

NoEventMask

对最小化窗口的优化处理,将其隐藏在guard窗口后面

wm_cm_selection_window

(-100, -100, 1, 1)

NoEventMask

标记client为compositor的窗口

The guard window allows us to leave minimized windows mapped so that compositor code may provide live previews of them. Instead of being unmapped/withdrawn, they get pushed underneath the guard window. We also select events on the guard window, which should effectively be forwarded to events on the background actor, providing that the scene graph is set up correctly.

注:composite_overlay_window在使用MetaCompositorX11时创建,而在MetaWaylandCompositor时不创建该窗口,xwayland非根模式使用的时MetaWaylandCompositor和MetaCompositorServer。

X11窗口树

X11 server以属性结构管理窗口,每个屏幕有一个根窗口,其它创建的窗口都为根窗口子孙窗口。其中有几个约束:

  1. 子窗口不能超过父窗口可显示区域显示,所有子窗口显示在父窗口上面

  2. 只能兄弟窗口间切换窗口,兄弟窗口有堆叠层次。若切换的窗口所在的顶层窗口不在顶层显示,则涉及顶层窗口间的切换

  3. 父窗口使用列表管理子窗口及其堆叠层次,排在列表前的子窗口显示在上层,也即是排在前的子窗口可能会遮挡排在后的子窗口。

以堆叠层次切换为例。X11 server收到ConfigureWindow中CWStackMode请求,X11 server对窗口树进行重排。

  • 更新窗口树结构:确定pWin位置并更新子窗口列表(MoveWindowInStack)

  • 识别重绘区域:父窗口原可见区域clipList,包含边框区域boardClip,窗口移动时,影响的可绘制区域,这些区域限制在父窗口的winSize区域内。(MoveWindowInStack)

  • 计算子窗口的重绘区域:按照深度优先顺序计算子窗口的重绘区域,生成exposed和borderExposed区域 (miMarkOverlappedWindows / miValidateTree)

  • 重绘各子窗口的exposed和borderExposed区域:在server端绘制窗口边框和背景,发送Expose事件由client绘制窗口内容(miHandleValidateExposures)

1// pWin为移动的窗口,pSib为pWin移动在该窗口之上。若pSib为空,则pWin窗口在最上层 2static void ReflectStackChange(WindowPtr pWin, WindowPtr pSib, VTKind kind){ 3    Bool WasViewable = (Bool) pWin->viewable; 4    Bool anyMarked; 5    WindowPtr pFirstChange; 6    WindowPtr pLayerWin; 7    ScreenPtr pScreen = pWin->drawable.pScreen; 8    if (!pWin->parent) 9        return; // if this is a root window, can't be restacked 10    // pWin为移动窗口,pSib为空,pWin置底;若pWin下一个相邻窗口为pSib,栈层次未变,则什么都不做 11    // pFirstChange:表示第一个被暴露的窗口 12    // pWin向下移,则pFirstChange为pWin相邻的下一个窗口。pWin与pSib中间有兄弟窗口,当pWin在pSib上方时,需下移。 13    // pWin向上移,则pFirstChange为pWin本身 14    pFirstChange = MoveWindowInStack(pWin, pSib); 15    if (WasViewable) { 16        // miMarkOverlappedWindows,标记与pWin窗口重叠的兄弟窗口及其子窗口所在位置,这些窗口可能需要重绘 17        // 若pFirstChange为pWin(窗口上移),则标记pWin及其子窗口,同时标记与pWin窗口(包括边框)重叠的兄弟窗口以及其子窗口 18        // 若pFirstChange不为pWin(窗口下移),标记与pWin窗口重叠的兄弟窗口以及其子窗口 19        anyMarked = (*pScreen->MarkOverlappedWindows) (pWin, pFirstChange, &pLayerWin); 20        // pLayerWin初始化为pWin,不清楚这里为什么要判断 21        if (pLayerWin != pWin) 22            pFirstChange = pLayerWin; 23        if (anyMarked) { 24            // 有窗口重叠。若无窗口则不需重绘,修改窗口树结构即可。此场景必有重叠,pWin窗口与其子窗口重叠。 25            // miValidateTree,计算父窗口以及所有子窗口的可剪接区域(boarderClip和clipList),以及exposed和borderExposed区域 26            (*pScreen->ValidateTree) (pLayerWin->parent, pFirstChange, kind); 27            // miHandleValidateExposures,深度优先,先绘制边框,再绘制exposed区域的背景,然后发送Expose事件给客户端绘制 28            // 边框和背景的绘制在server端完成,exposed区域的内容通过发送Expose事件由client发起绘制完成 29            (*pScreen->HandleExposures) (pLayerWin->parent); 30            // 一般为空,只有当视频窗口时,xv扩展才需处理 31            if (pWin->drawable.pScreen->PostValidateTree) 32                (*pScreen->PostValidateTree) (pLayerWin->parent, pFirstChange, kind); 33        } 34    } 35    if (pWin->realized) 36        // 处理焦点和光标 37        WindowsRestructured(); 38}

窗口栈管理

wayland对窗口栈管理分为组(group),层(layer),栈(stack),由MetaStack和MetaWindow管理实现。MetaStack处理3个信号事件:"changed", "window-added", "window-removed",这3个事件都涉及窗口栈的更新。

一般来说,顶层窗口作为组长,与子孙窗口分为一组。client可通过EWMH指定窗口为特定的组(WindowGroupHint)。一般只有X11窗口有该属性。MetaWindow::group保存组关系

1struct _MetaGroup { 2  int refcount; 3  MetaX11Display *x11_display; 4  GSList *windows;       // 窗口列表 5  Window group_leader;  // 组长 6  char *startup_id; 7  char *wm_client_machine; 8};

Wayland根据窗口类型来划分层的,对应关系如下,MetaWindow::layer保存窗口层次关系。在某个窗口组中的窗口来说,以其窗口组中层次最大的层划分。由MetaStackLayer定义。Wayland窗口只有META_LAYER_NORMAL、META_LAYER_TOP和META_LAYER_BOTTOM 3种类型

layer

enum

window type

description

META_LAYER_DESKTOP

0

META_WINDOW_DESKTOP

桌面层

META_LAYER_BOTTOM

1

wm_state_below

底层,由客户应用程序使用EWMH指定窗口为 wm_state_below(_NET_WM_STATE_BELOW)

META_LAYER_NORMAL

2

META_WINDOW_NORMAL or other

中间层

META_LAYER_TOP

4

wm_state_above and not maximized

顶层,可由客户应用程序使用EWMH指定窗口为 wm_state_above(_NET_WM_STATE_ABOVE)

META_LAYER_DOCK

4

META_WINDOW_DOCK and not wm_state_below

停靠层,与顶层同层

META_LAYER_OVERRIDE_REDIRECT

7

META_WINDOW_DROPDOWN_MENU

META_WINDOW_POPUP_MENU

META_WINDOW_TOOLTIP

META_WINDOW_NOTIFICATION

META_WINDOW_COMBO

META_WINDOW_OVERRIDE_OTHER

重载重定向层,一般为禁止窗口管理器管理的窗口,显示在最上层

Wayland使用MetaStack管理所有的MetaWindow窗口,wayland窗口由MetaWindowWayland表示,xwayland窗口由MetaWindowXwayland表示,均为MetaWindow派生类。MetaWindow::stack_position记录窗口在MetaStack中的位置,越大越显示在上层,后续操作均按该栈序处理。窗口的层次切换后,也需保持相对位置。

使用如下两个函数来增加和删除窗口:

  1. meta_stack_add增加窗口:初始化窗口的stack_position值,为列表大小,发送"window-added"同步信号。新增窗口都显示在最上面。只能增加可堆叠窗口,处理完成后再发送"changed"同步信号

    1. meta_window_x11_is_stackable:非override redirect窗口

    2. meta_window_wayland_is_stackable:可显示窗口,MetaWaylandBuffer不为空

  2. meta_stack_remove删除窗口:发送"window-removed"同步信号,从栈中删除窗口,处理完成后再发送"changed"同步信号

MetaStack响应”changed”信号,信号处理函数为on_stack_changed,重新对wayland和X11的顶层窗口堆栈排序。

注:使用MetaX11Stack管理X11窗口栈备份,为XID列表。MetaX11Stack响应这三个信号,响应函数在src/x11/meta-x11-stack.c文件中

  •  "window-added":stack_window_added_cb将window加入x11_stack->added临时列表中

  • "window-removed":stack_window_removed_cb将window加入x11_stack->removed临时列表,window的页框窗口也加入临时页表中

  • "changed": stack_changed_cb,

    • 处理added和removed两个临时列表,整理至x11_stack->xwindows列表中

    • 调用XChangeProperty同步"_NET_CLIENT_LIST"和"_NET_CLIENT_LIST_STACKING"两个根窗口的EWMH属性,前者值为xwindow列表,后者值为从MetaStack中过滤出来的X11窗口栈

1struct _MetaStack{ 2  GObject parent; 3  MetaDisplay *display;  // The MetaDisplay containing this stack. 4  GList *sorted;         // The MetaWindows of the windows we manage, sorted in order. 5  6  // If this is zero, the local stack oughtn't to be brought up to date with the X server's stack, because it is in the middle of being updated. 7  // If it is positive, the local stack is said to be "frozen", and will need to be thawed that many times before the stack can be brought up to date again. 8  // You may freeze the stack with meta_stack_freeze() and thaw it with meta_stack_thaw(). 9  int freeze_count;    // 计数可实现嵌套freeze  10  11  // The last-known stack of all windows, bottom to top.  We cache it here so that subsequent times we'll be able to do incremental moves. 12  GArray *last_all_root_children_stacked; 13  gint n_positions; // Number of stack positions; same as the length of added, but kept for quick reference. 14  15  unsigned int need_resort : 1;    // Is the stack in need of re-sorting? 16  unsigned int need_relayer : 1;   // Are the windows in the stack in need of having their layers recalculated? 17  unsigned int need_constrain : 1; // Are the windows in the stack in need of having their positions recalculated with respect to transiency (parent and child windows)? 18}; 19  20// 窗口排序需考虑窗口的层次,窗口显示的约束等,先按层次排序,再按位置排序。 21static void stack_ensure_sorted (MetaStack *stack) { 22  // 对stack中的窗口分层,若层次有变化,则需重新计算窗口约束和重新排序。窗口的层次为窗口组中的最高层次 23  stack_do_relayer (stack); 24  // 瞬态窗口须在指定窗口之上(MetaWindow::transient_for指定窗口或者所在窗口组的所有窗口),其它类型窗口无此约束 25  stack_do_constrain (stack); 26  // 重新排序,先按层,再按位置。重排完成后,延后调用check_fullscreen_func处理全屏窗口 27  stack_do_resort (stack); 28} 29  30// 临时窗口类型(瞬态窗口) 31gboolean meta_window_has_transient_type (MetaWindow *window) 32{ 33  return (window->type == META_WINDOW_DIALOG || 34          window->type == META_WINDOW_MODAL_DIALOG || 35          window->type == META_WINDOW_TOOLBAR || 36          window->type == META_WINDOW_MENU || 37          window->type == META_WINDOW_UTILITY); 38}

堆跟踪器

MetaStackTracker,跟踪所有窗口,包括unmanaging窗口。窗口用窗口ID表示,X11窗口为32位ID,Wayland窗口ID为64位,其值都大于(1<<32)。Wayland窗口的序列号为0。

unmanaging窗口:the window of withdrawn, destroyed, attaches, detaches, or changes attached parents.

1struct _MetaStackTracker { 2  MetaDisplay *display; 3  gulong xserver_serial;   // This is the serial of the last request we made that was reflected in xserver_stack 4  GArray *verified_stack; // A combined stack containing X and Wayland windows but without any unverified operations applied.    5  // This is a queue of requests we've made to change the stacking order, where we haven't yet gotten a reply back from the server. 6  GQueue *unverified_predictions; // Wayland server修改了X11窗口的配置,发送XConfigureWindow请求该X11 server,但还未收到X11 server的回复 7  8  // This is how we think the stack is, based on verified_stack, and on the unverified_predictions we've made subsequent to verified_stack. 9  GArray *predicted_stack;  // 操作和更新栈时,MetaWindow窗口栈的一个临时列表 10  11  // Idle function used to sync the compositor's view of the window stack up with our best guess before a frame is drawn. 12  guint sync_stack_later; 13};
  • 调用stack_tracker_apply_prediction会将window加入unverified列表中,一般有4个操作:record_add, record_remove, raise_above, lower_below。

  • 调用stack_tracker_event_received将unverified列表中的窗口加入verified列表中,调用该函数的有3种情况,Wayland收到X11的事件通知时,共3个通知:CreateNotify, ReparentNotify和ConfigureNotify。(X11窗口的序列号一般为处理时生成的递增序号,用来表示时序)

窗口切换

wayland server在启动时注册了窗口切换快捷键,在init_builtin_key_bindings函数中绑定了默认的快捷键,包含“switch-windows”和“switch-windows-backward”两个事件,由handle_switch函数实现,该函数可响应多个事件,还包括窗口组切换,应用程序切换,面板切换等,分别为"switch-group", "switch-applications", "switch-windows", "switch-panels"等正向切换事件,都对应有反向切换的事件。本次只描述窗口正向切换流程。

1// src/core/keybindings.c 2static void handle_switch (MetaDisplay *display, MetaWindow *event_window, ClutterKeyEvent *event, MetaKeyBinding  *binding, gpointer dummy) { 3  gboolean backwards = meta_key_binding_is_reversed (binding); 4  // backwards = false; 5  do_choose_window (display, event_window, event, binding, backwards); 6} 7  8static void do_choose_window (MetaDisplay *display, MetaWindow *event_window, ClutterKeyEvent *event, MetaKeyBinding  *binding, gboolean backward){ 9  MetaWorkspaceManager *workspace_manager = display->workspace_manager; 10  // type = META_TAB_LIST_NORMAL 11  MetaTabList type = binding->handler->data; 12  // 获取当前焦点窗口的下一个窗口 13  MetaWindow *window = meta_display_get_tab_next (display, type, workspace_manager->active_workspace, NULL, backward); 14  15  // 激活该窗口 16  if (window) 17    meta_window_activate (window, event->time); 18}
  1. meta_display_get_tab_next:从工作台中获取切换窗口

  2. meta_window_activate:激活切换窗口

    1. meta_window_raise:将切换窗口放置在顶层,更新MetaStack窗口栈顺序,同步至MetaStackTracker窗口顺序

      1. meta_window_set_stack_position_no_sync:移动切换窗口,更新MetaStack窗口栈顺序

      2. meta_stack_changed:同步tracker、compositor和X11 server栈信息

        1. 调整MetaStackTracer窗口栈顺序

        2. 发送XConfigureWindow给X11 Server修改server上栈信息,根据信息调整栈位置,更新窗口显示

        3. 同步compositor的窗口栈,即MetaWindowActor栈

      3. meta_stack_update_window_tile_matches:调整窗口平铺位置

    2. meta_window_focus:窗口获取焦点,包括键盘输入焦点和光标

      1. 显示窗口,包括隐藏窗口,第一次显示的窗口,未放置窗口和图标窗口

      2. 发送SetInputFocus请求给X11 server,同步X11 server的焦点信息,由X11 Server处理焦点

      3. 关联输入设备与切换窗口

获取窗口

有几个地方维护了窗口列表,

  • MetaWindow:维护两类窗口列表,一类为原生Wayland窗口列表(wayland_windows);另一类为X11对应的Wayland窗口列表(x11_display->xids)

  • MetaWorkspace:维护mru_list窗口列表,属于该工作台中的窗口列表,按照MRU(most recently used)排序,最近访问的窗口排在前面

从X11和wayland server中找到所有在workspace中的MetaWindow窗口。

  1. 获取所有窗口列表:从MetaDisplay中获取所有的X11和Wayland窗口(不包括override redirect窗口)

  2. 初始化候选窗口列表:获取工作台(workspace)中类型为META_TAB_LIST_NORMAL的窗口列表,非最小化窗口在前,最小化窗口在后,每组列表保序(MRU序),拼接成一个链表

  3. 向前追加状态为demands_attention的窗口值候选窗口列表中:该状态窗口不在工作台中,类型为META_TAB_LIST_NORMAL,需要额外追加

  4. 候选窗口列表中第一个非焦点窗口,即为候选窗口

注:获取所有窗口列表时,列表并未按照MRU排序,在追加demands_attention窗口时,窗口创建越迟越优先。

1// MetaDisplay (src/core/display.c) 2// 只列出上下文相关代码,其余被删除。type = META_TAB_LIST_NORMAL; window = NULL; backward = false; 3MetaWindow* meta_display_get_tab_next (MetaDisplay *display, MetaTabList type, MetaWorkspace *workspace, MetaWindow *window, gboolean backward){ 4 gboolean skip; 5 GList *tab_list; 6 MetaWindow *ret; 7 // tab_list中为type=META_TAB_LIST_NORMAL的窗口列表,这些窗口均在workspace中 8 tab_list = meta_display_get_tab_list (display, type, workspace); 9 if (tab_list == NULL) 10 return NULL; 11 12 // tab_list中的第一个为焦点窗口,则跳过该窗口 13 skip = display->focus_window != NULL && tab_list->data == display->focus_window; 14 // 先从tab_list中找到第一个类型为META_TAB_LIST_NORMAL的窗口,若未找到,则从workspace->mru_list中查找 15 ret = find_tab_forward (display, type, workspace, tab_list, skip); 16 g_list_free (tab_list); 17 return ret; 18} 19 20GList* meta_display_get_tab_list (MetaDisplay *display, MetaTabList type, MetaWorkspace *workspace){ 21 GList *tab_list = NULL; 22 GList *mru_list, *tmp; 23 // x11_display->xids记录了所有与X11窗口对应的MetaWindow,窗口由_meta_window_shared_new函数调用meta_window_x11_manage创建并注册 24 // 获取display->x11_display和display->wayland_windows所有的X11和Wayland窗口(不包括override redirect窗口),去重的窗口列表 25 GSList *windows = meta_display_list_windows (display, META_LIST_DEFAULT); 26 GSList *w; 27 mru_list = workspace->mru_list; 28 29 // Windows sellout mode - MRU order. Collect unminimized windows then minimized so minimized windows aren't in the way so much. 30 // 工作台中的META_TAB_LIST_NORMAL的窗口列表,先加入非最小化窗口,然后再加入最小化窗口 31 for (tmp = mru_list; tmp; tmp = tmp->next){ 32 MetaWindow *window = tmp->data; 33 if (!window->minimized && IN_TAB_CHAIN (window, type)) 34 tab_list = g_list_prepend (tab_list, window); 35 } 36 for (tmp = mru_list; tmp; tmp = tmp->next){ 37 MetaWindow *window = tmp->data; 38 if (window->minimized && IN_TAB_CHAIN (window, type)) 39 tab_list = g_list_prepend (tab_list, window); 40 } 41 // 非最小化窗口放在前面,最小化窗口放在后面,每组按mru列表顺序排列 42 tab_list = g_list_reverse (tab_list); 43 44 // If filtering by workspace, include windows from other workspaces that demand attention 45 if (workspace) 46 for (w = windows; w; w = w->next){ 47 MetaWindow *l_window = w->data; 48 // 不在此工作台中的类型为META_TAB_LIST_NORMAL的窗口,且标记wm_state_demands_attention(被焦点窗口遮挡时会设置该值) 49 if (l_window->wm_state_demands_attention && !meta_window_located_on_workspace (l_window, workspace) && IN_TAB_CHAIN (l_window, type)) 50 tab_list = g_list_prepend (tab_list, l_window); 51 } 52 g_slist_free (windows); 53 return tab_list; 54}

激活窗口

根据窗口类型分别处理:

  • 普通窗口,将该窗口切换至工作台,并在顶层显示

  • 具备transient_for属性的窗口,将该窗口中脱离父子关系的窗口都切换至同一个工作台中,先将与该窗口脱离关系的祖先窗口显示在顶层,再将该窗口显示在顶层

  • shaded或minimized窗口,需要先做unshade或unminimize

meta_window_activate

1void meta_window_activate (MetaWindow *window, guint32 timestamp){ 2  // We're not really a pager, but the behavior we want is the same as if we were such. 3  // If we change the pager behavior later, we could revisit this and just add extra flags to window_activate. 4  meta_window_activate_full (window, timestamp, META_CLIENT_TYPE_PAGER, NULL); 5} 6  7// 激活窗口以及与该窗口相关的transient_for属性的窗口 8void meta_window_activate_full (MetaWindow *window, guint32 timestamp, MetaClientType  source_indication, MetaWorkspace  *workspace){ 9  MetaWorkspaceManager *workspace_manager = window->display->workspace_manager; 10  // timestamp为0表示最新事件,默认取当前时间戳,比任何窗口的user_time时间戳新 11  gboolean allow_workspace_switch = (timestamp != 0); 12  if (timestamp != 0 && XSERVER_TIME_IS_BEFORE (timestamp, window->display->last_user_time)){ 13    // client通过类型为_NET_ACTIVE_WINDOW的atom请求,更新了display的交互时间,比该事件要新,则只设置window的wm_state_demands_attention为真,下次再处理 14    meta_window_set_demands_attention(window); 15    return; 16  } 17  18  // 获取最新时间戳 19  if (timestamp == 0) 20    timestamp = meta_display_get_current_time_roundtrip (window->display); 21  // 更新窗口的net_wm_user_time,以及display->last_user_time 22  meta_window_set_user_time (window, timestamp); 23  /* disable show desktop mode unless we're a desktop component */ 24  maybe_leave_show_desktop_mode (window); 25  26  // For non-transient windows, we just set up a pulsing indicator, rather than move windows or workspaces. See http://bugzilla.gnome.org/show_bug.cgi?id=482354 27  if (window->transient_for == NULL && !allow_workspace_switch && !meta_window_located_on_workspace (window, workspace)){ 28    // 不在工作台中,且事件时间戳为0的普通窗口 29    meta_window_set_demands_attention (window); 30    return; 31  } 32  else if (window->transient_for != NULL) { 33      /* Move transients to current workspace - preference dialogs should appear over the source window.  */ 34      // 3类窗口需切换至该工作台,有可能切换不成功,其中两类是由于transient_for属性脱离的关系的窗口,祖先和子孙窗口 35      // 1. 自身窗口 36      // 2. 将transient_for递归指向该窗口的所有窗口,即该窗口的子孙窗口 37      // 3. 该窗口的transient_for指向的窗口,以及transient_for递归指向的祖先窗口。也就是该窗口的祖先窗口 38      meta_window_change_workspace (window, workspace); 39    } 40  // 取消窗口的阴影,client设置该窗口为阴影,当激活时,需取消其阴影窗口 41  if (window->shaded) 42    meta_window_unshade (window, timestamp); 43  // 恢复窗口显示,以及脱离关系的祖先窗口,该窗口的transient_for指向的窗口 44  unminimize_window_and_all_transient_parents (window); 45  46  // 将窗口显示在最上面,在此上下文下,条件为真,更新compositor,actor的窗口栈顺序 47  if (meta_prefs_get_raise_on_click () || source_indication == META_CLIENT_TYPE_PAGER) 48    meta_window_raise (window); 49  // 窗口在此工作台中,则获取焦点,不在该工作台中,则切换至窗口所在工作台,并使窗口获得焦点 50  if (meta_window_located_on_workspace (window, workspace)) 51    meta_window_focus (window, timestamp); 52  else 53    meta_workspace_activate_with_focus (window->workspace, window, timestamp); 54  // 发送一个ping请求,检测client是否有响应,则弹出关闭对话框 55  meta_window_check_alive (window, timestamp); 56}

meta_window_raise

显示窗口,对于普通窗口只显示自身窗口,对于具有transient_for属性的窗口,先显示祖先窗口,再显示自身窗口

1void meta_window_raise (MetaWindow *window){ 2 MetaWindow *ancestor; 3 // 获取具有transient_for属性窗口的祖先;若无此属性,则祖先为自身窗口 4 ancestor = meta_window_find_root_ancestor (window); 5 // 祖先和自身窗口不在同一窗口栈中,则一定出了什么差错 6 if (window->display->stack == ancestor->display->stack) { 7 meta_stack_raise (window->display->stack, ancestor); 8 } 9 // 具备transient_for属性的窗口,将该窗口在顶层显示 10 if (window != ancestor) 11 meta_stack_raise (window->display->stack, window); 12 // 同步信号,触发调用window_raised(src/wayland/meta-wayland-pointer-constraints.c) 13 g_signal_emit (window, window_signals[RAISED], 0); 14} 15 16void meta_stack_raise (MetaStack *stack, MetaWindow *window) 17{ 18 MetaWorkspaceManager *workspace_manager = window->display->workspace_manager; 19 GList *l; 20 int max_stack_position = window->stack_position; 21 MetaWorkspace *workspace; 22 // 确保window在stack中有序,先分层,再排序 23 stack_ensure_sorted (stack); 24 25 // 计算工作台中最顶层window的位置,stack_position越大,越靠近顶层 26 workspace = meta_window_get_workspace (window); 27 for (l = stack->sorted; l; l = l->next){ 28 MetaWindow *w = (MetaWindow *) l->data; 29 if (meta_window_located_on_workspace (w, workspace) && w->stack_position > max_stack_position) 30 max_stack_position = w->stack_position; 31 } 32 33 // 窗口已在该工作台的顶层,则不处理 34 if (max_stack_position == window->stack_position) 35 return; 36 37 // 位置在[window->stack_position, max_stack_position]的窗口stack_position调整变化1个位置,更新window的stack_position为max_stack_position。 38 meta_window_set_stack_position_no_sync (window, max_stack_position); 39 // 对MetaStack重排序,并发送一个"changed"同步信号,调用MetaStack的on_stack_changed函数(src/core/stack.c) 40 meta_stack_changed (stack); 41 // 窗口平铺位置更新 42 meta_stack_update_window_tile_matches (stack, workspace_manager->active_workspace); 43}

on_stack_changed

1// MetaStack (src/core/stack.c) 2static void on_stack_changed (MetaStack *stack) { 3 MetaDisplay *display = stack->display; 4 GList *l; 5 GArray *all_root_children_stacked = g_array_new (FALSE, FALSE, sizeof (uint64_t)); 6 GArray *hidden_stack_ids = g_array_new (FALSE, FALSE, sizeof (uint64_t)); 7 // 获取MetaStack中的所有窗口列表,顺序与MetaStack相反,即队尾窗口显示在最顶层 8 GList *sorted = meta_stack_list_windows (stack, NULL); 9 // 分别获取所有可显示的子窗口和隐藏窗口列表 10 for (l = sorted; l; l = l->next) { 11 MetaWindow *w = l->data; 12 uint64_t top_level_window; 13 uint64_t stack_id; 14 if (w->unmanaging) 15 continue; 16 // X11的顶层窗口,若有页框窗口,则将页框窗口作为顶层窗口。 17 if (w->frame) 18 top_level_window = w->frame->xwindow; 19 else 20 top_level_window = w->xwindow; 21 if (w->client_type == META_WINDOW_CLIENT_TYPE_X11) 22 stack_id = top_level_window; 23 else 24 stack_id = w->stamp; 25 26 // We don't restack hidden windows along with the rest, though they are reflected in the _NET hints. 27 // Hidden windows all get pushed below the screens fullscreen guard_window. 28 if (w->hidden){ 29 g_array_append_val (hidden_stack_ids, stack_id); 30 continue; 31 } 32 g_array_append_val (all_root_children_stacked, stack_id); 33 } 34 35 if (display->x11_display) { 36 // The screen guard window sits above all hidden windows and acts as a barrier to input reaching these windows. 37 uint64_t guard_window_id = display->x11_display->guard_window; 38 g_array_append_val (hidden_stack_ids, guard_window_id); 39 } 40 41 /* Sync to server */ 42 meta_stack_tracker_restack_managed (display->stack_tracker, (uint64_t *)all_root_children_stacked->data, all_root_children_stacked->len); 43 // 将隐藏窗口放在底层 44 meta_stack_tracker_restack_at_bottom (display->stack_tracker, (uint64_t *)hidden_stack_ids->data, hidden_stack_ids->len); 45 46 g_array_free (hidden_stack_ids, TRUE); 47 g_array_free (all_root_children_stacked, TRUE); 48 g_list_free (sorted); 49}

meta_stack_tracker_restack_managed

1// managed为顶层窗口有序列表,队尾窗口显示在最顶层。 2// 更新MetaStackTracker中窗口列表序列,并将更新同步至X11 server,并启动META_LATER_SYNC_STACK延时调用stack_tracker_sync_stack_later,该函数用于同步compositor的窗口栈 3void meta_stack_tracker_restack_managed (MetaStackTracker *tracker, const guint64 *managed, int n_managed){ 4  guint64 *windows; 5  int n_windows; 6  int old_pos, new_pos; 7  if (n_managed == 0) 8    return; 9  // 获取tracker中的窗口列表,为有序列表,队尾的窗口显示在最顶层 10  meta_stack_tracker_get_stack (tracker, &windows, &n_windows); 11  // If the top window has to be restacked, we don't want to move it to the very top of the stack, 12  // since apps expect override-redirect windows to stay near the top of the X stack; 13  // we instead move it above all managed windows (or above the guard window if there are no non-hidden managed windows.) 14  old_pos = n_windows - 1; 15  // 跳过tracker中不存在的窗口,找到第一个顶级窗口或者guard窗口,顶级窗口为可显示的非override redirect窗口;guard窗口为可显示窗口与非显示窗口的分界线 16  for (old_pos = n_windows - 1; old_pos >= 0; old_pos--) { 17    MetaWindow *old_window = meta_display_lookup_stack_id (tracker->display, windows[old_pos]); 18    if ((old_window && !old_window->override_redirect && !old_window->unmanaging) || meta_stack_tracker_is_guard_window (tracker, windows[old_pos])) 19      break; 20  } 21  22  new_pos = n_managed - 1; 23  if (managed[new_pos] != windows[old_pos]){ 24    // Move the first managed window in the new stack above all managed windows 25    // 更新MetaStackTracer,将new窗口移至old窗口位置,其它窗口对应移一位。对于X11窗口,发送XConfigureWindow至X11 server同步窗口叠层。 26   meta_stack_tracker_raise_above (tracker, managed[new_pos], windows[old_pos]); 27    // 重新获取windows,更新了window在tracer中的位置 28    meta_stack_tracker_get_stack (tracker, &windows, &n_windows); 29  } 30  old_pos--; 31  new_pos--; 32  33  while (old_pos >= 0 && new_pos >= 0) { 34    if (meta_stack_tracker_is_guard_window (tracker, windows[old_pos])) 35      break; 36    // 窗口的相对位置未变,则跳过 37    if (windows[old_pos] == managed[new_pos]){ 38      old_pos--; 39      new_pos--; 40      continue; 41    } 42    // window不在tracker中,或者为override_redirect和unmanaging窗口,则跳过。managed中不存在这些窗口 43    MetaWindow *old_window = meta_display_lookup_stack_id (tracker->display, windows[old_pos]); 44    if (!old_window || old_window->override_redirect || old_window->unmanaging){ 45       old_pos--; 46       continue; 47    } 48    // 更新MetaStackTracer,将new_pos窗口移至new_pos+1窗口后面,其它窗口对应移一位。对于X11窗口,发送XConfigureWindow至X11 server同步窗口叠层。 49   meta_stack_tracker_lower_below (tracker, managed[new_pos], managed[new_pos + 1]); 50    meta_stack_tracker_get_stack (tracker, &windows, &n_windows); 51    // Moving managed[new_pos] above windows[old_pos] moves the window at old_pos down by one, we'll examine it again to see if it matches the next new window 52    old_pos--; 53    new_pos--; 54  } 55  while (new_pos > 0) { 56      meta_stack_tracker_lower_below (tracker, managed[new_pos], managed[new_pos - 1]); 57      new_pos--; 58    } 59} 60  61// 将window移至sibling位置,其它窗口相应移一位,类似于ALT+TAB键的窗口切换,下层窗口移至最前面 62static void meta_stack_tracker_raise_above (MetaStackTracker *tracker, guint64 window, guint64 sibling) { 63  gulong serial = 0; 64  MetaX11Display *x11_display = tracker->display->x11_display; 65  if (META_STACK_ID_IS_X11 (window)) { 66    // 向X11 server同步窗口堆叠层次请求,由X11 server处理该请求 67    XWindowChanges changes; 68    changes.sibling = sibling ? find_x11_sibling_downwards (tracker, sibling) : None; 69    if (changes.sibling != find_x11_sibling_downwards (tracker, window)){ 70      serial = XNextRequest (x11_display->xdisplay); 71      meta_x11_error_trap_push (x11_display); 72      changes.stack_mode = changes.sibling ? Above : Below; 73      XConfigureWindow (x11_display->xdisplay, (Window)window, (changes.sibling ? CWSibling : 0) | CWStackMode, &changes); 74      meta_x11_error_trap_pop (x11_display); 75    } 76  } 77  // 更新MetaStackTracer的窗口列表 78  meta_stack_tracker_record_raise_above (tracker, window, sibling, serial); 79} 80  81static void meta_stack_tracker_record_raise_above (MetaStackTracker *tracker, guint64 window, guint64 sibling, gulong serial){ 82  MetaStackOp *op = g_new0 (MetaStackOp, 1); 83  op->any.type = STACK_OP_RAISE_ABOVE; 84  op->any.serial = serial; 85  op->any.window = window; 86  op->raise_above.sibling = sibling; 87  stack_tracker_apply_prediction (tracker, op); 88} 89  90static void stack_tracker_apply_prediction (MetaStackTracker *tracker, MetaStackOp *op) { 91  gboolean free_at_end = FALSE; 92  // If this operation doesn't involve restacking X windows then it's implicitly verified. 93  // We can apply it immediately unless there are outstanding X restacks that haven't yet been confirmed. 94  if (op->any.serial == 0 && tracker->unverified_predictions->length == 0) { 95    if (meta_stack_op_apply (tracker, op, tracker->verified_stack, APPLY_DEFAULT)) 96      meta_stack_tracker_queue_sync_stack (tracker); 97    free_at_end = TRUE; 98  } 99  else { 100    g_queue_push_tail (tracker->unverified_predictions, op); 101  } 102  // 启动MetaLater,用于延后处理compositor的窗口栈同步(stack_tracker_sync_stack_later) 103  if (!tracker->predicted_stack || meta_stack_op_apply (tracker, op, tracker->predicted_stack, APPLY_DEFAULT)) 104    meta_stack_tracker_queue_sync_stack (tracker); 105  if (free_at_end) 106    meta_stack_op_free (op); 107} 108  109void meta_stack_tracker_queue_sync_stack (MetaStackTracker *tracker){ 110  if (tracker->sync_stack_later == 0) { 111    tracker->sync_stack_later = meta_later_add (META_LATER_SYNC_STACK, stack_tracker_sync_stack_later, tracker, NULL); 112  } 113}

stack_tracker_sync_stack_later

1static gboolean stack_tracker_sync_stack_later (gpointer data){ 2  meta_stack_tracker_sync_stack (data); 3  return FALSE; 4} 5  6void meta_stack_tracker_sync_stack (MetaStackTracker *tracker){ 7  guint64 *windows; 8  GList *meta_windows; 9  int n_windows; 10  int i; 11  12  if (tracker->sync_stack_later) { 13    meta_later_remove (tracker->sync_stack_later); 14    tracker->sync_stack_later = 0; 15  } 16  // 将override redirect层的窗口提到最上层,有可能更新MetaStackTracker的窗口栈,形成循环调用 17  meta_stack_tracker_keep_override_redirect_on_top (tracker); 18  meta_stack_tracker_get_stack (tracker, &windows, &n_windows); 19  meta_windows = NULL; 20  for (i = 0; i < n_windows; i++){ 21    guint64 window = windows[i]; 22    if (META_STACK_ID_IS_X11 (window)){ 23      MetaX11Display *x11_display = tracker->display->x11_display; 24      MetaWindow *meta_window = NULL; 25  26      if (x11_display) 27         meta_window = meta_x11_display_lookup_x_window (x11_display, (Window) window); 28       // When mapping back from xwindow to MetaWindow we have to be a bit careful; 29       // children of the root could include unmapped windows created by toolkits for internal purposes, including ones that we have registered in our XID => window table. 30       // (Wine uses a toplevel for _NET_WM_USER_TIME_WINDOW; see window-prop.c:reload_net_wm_user_time_window() for registration.) 31       if (meta_window && ((Window)window == meta_window->xwindow || (meta_window->frame && (Window)window == meta_window->frame->xwindow))) 32         meta_windows = g_list_prepend (meta_windows, meta_window); 33    } 34    else 35      meta_windows = g_list_prepend (meta_windows, meta_display_lookup_stamp (tracker->display, window)); 36  } 37  // 同步compositor的窗口栈,即MetaWindowActor栈 38  meta_compositor_sync_stack (tracker->display->compositor, meta_windows); 39  g_list_free (meta_windows); 40  meta_display_restacked (tracker->display); 41} 42  43void meta_compositor_sync_stack (MetaCompositor  *compositor, GList *stack){ 44  MetaCompositorPrivate *priv = meta_compositor_get_instance_private (compositor); 45  GList *old_stack; 46  // This is painful because hidden windows that we are in the process of animating out of existence. 47  // They'll be at the bottom of the stack of X windows, but we want to leave them in their old position until the animation effect finishes. 48  /* Sources: first window is the highest */ 49  stack = g_list_copy (stack); /* The new stack of MetaWindow */ 50  old_stack = g_list_reverse (priv->windows); /* The old stack of MetaWindowActor */ 51  priv->windows = NULL; 52  while (TRUE){ 53    MetaWindowActor *old_actor = NULL, *stack_actor = NULL, *actor; 54    MetaWindow *old_window = NULL, *stack_window = NULL, *window; 55  56    // Find the remaining top actor in our existing stack (ignoring windows that have been hidden and are no longer animating) 57    while (old_stack) { 58      old_actor = old_stack->data; 59      old_window = meta_window_actor_get_meta_window (old_actor); 60      if ((old_window->hidden || old_window->unmanaging) && !meta_window_actor_effect_in_progress (old_actor)){ 61        old_stack = g_list_delete_link (old_stack, old_stack); 62        old_actor = NULL; 63      } 64      else 65        break; 66    } 67  68    /* And the remaining top actor in the new stack */ 69    while (stack) { 70      stack_window = stack->data; 71      stack_actor = meta_window_actor_from_window (stack_window); 72      if (!stack_actor) { 73        stack = g_list_delete_link (stack, stack); 74      } 75      else 76        break; 77    } 78    if (!old_actor && !stack_actor) /* Nothing more to stack */ 79      break; 80  81    // We usually prefer the window in the new stack, but if we found a hidden window in the process of being animated out of existence in the old stack we use that instead. 82    // We've filtered out non-animating hidden windows above. 83    if (old_actor && (!stack_actor || old_window->hidden || old_window->unmanaging)){ 84      actor = old_actor; 85      window = old_window; 86    } 87    else{ 88      actor = stack_actor; 89      window = stack_window; 90    } 91  92    // OK, we know what actor we want next. Add it to our window list, and remove it from both source lists. 93    // (It will be at the front of at least one, hopefully it will be near the front of the other.) 94    priv->windows = g_list_prepend (priv->windows, actor); 95    stack = g_list_remove (stack, window); 96    old_stack = g_list_remove (old_stack, actor); 97  } 98  sync_actor_stacking (compositor); 99  update_top_window_actor (compositor); 100} 101  102// 根据compositor的MetaWindowActor序更新ClutterActor类型中的窗口栈 103static void sync_actor_stacking (MetaCompositor *compositor){ 104  MetaCompositorPrivate *priv = meta_compositor_get_instance_private (compositor); 105  GList *children; 106  GList *expected_window_node; 107  GList *tmp; 108  GList *old; 109  GList *backgrounds; 110  gboolean has_windows; 111  gboolean reordered; 112  113  // NB: The first entries in the lists are stacked the lowest 114  // Restacking will trigger full screen redraws, so it's worth a little effort to make sure we actually need to restack before we go ahead and do it 115  children = clutter_actor_get_children (priv->window_group); 116  has_windows = FALSE; 117  reordered = FALSE; 118  // We allow for actors in the window group other than the actors we know about, but it's up to a plugin to try and keep them stacked correctly 119  // First we collect a list of all backgrounds, and check if they're at the bottom. Then we check if the window actors are in the correct sequence 120  backgrounds = NULL; 121  expected_window_node = priv->windows; 122  for (old = children; old != NULL; old = old->next){ 123    ClutterActor *actor = old->data; 124    if (META_IS_BACKGROUND_GROUP (actor) || META_IS_BACKGROUND_ACTOR (actor)){ 125      backgrounds = g_list_prepend (backgrounds, actor); 126      // background actor在window actor的上面,则需要重排 127      if (has_windows) 128        reordered = TRUE; 129    } 130    else if (META_IS_WINDOW_ACTOR (actor) && !reordered){ 131      has_windows = TRUE; 132      // 跟composite的窗口序一致,则不需要重排,否则需要重排 133      if (expected_window_node != NULL && actor == expected_window_node->data) 134        expected_window_node = expected_window_node->next; 135      else 136        reordered = TRUE; 137    } 138  } 139  g_list_free (children); 140  if (!reordered){ 141    g_list_free (backgrounds); 142    return; 143  } 144  145  // reorder the actors by lowering them in turn to the bottom of the stack. windows first, then background. 146  // We reorder the actors even if they're not parented to the window group, to allow stacking to work with intermediate actors (eg during effects) 147  for (tmp = g_list_last (priv->windows); tmp != NULL; tmp = tmp->prev){ 148    ClutterActor *actor = tmp->data, *parent; 149    parent = clutter_actor_get_parent (actor); 150    clutter_actor_set_child_below_sibling (parent, actor, NULL); 151  } 152  153  // we prepended the backgrounds above so the last actor in the list should get lowered to the bottom last. 154  for (tmp = backgrounds; tmp != NULL; tmp = tmp->next){ 155    ClutterActor *actor = tmp->data, *parent; 156    parent = clutter_actor_get_parent (actor); 157    clutter_actor_set_child_below_sibling (parent, actor, NULL); 158  } 159  g_list_free (backgrounds); 160}

meta_window_focus

1// meta_window_focus (src/core/window.c) 2void meta_window_focus (MetaWindow *window, guint32 timestamp) { 3 MetaWorkspaceManager *workspace_manager = window->display->workspace_manager; 4 MetaWindow *modal_transient; 5 MetaBackend *backend; 6 ClutterStage *stage; 7 8 window->restore_focus_on_map = FALSE; // This is a oneshot flag 9 if (window->in_workspace_change) { 10 return; 11 } 12 // 键盘被其它窗口锁定,按键也被锁定了,则窗口无法获得焦点 13 if (window->display->grab_window && window->display->grab_window != window && 14 window->display->grab_window->all_keys_grabbed && !window->display->grab_window->unmanaging) { 15 return; 16 } 17 // window的模态窗口,即窗口类型为META_WINDOW_MODAL_DIALOG,transient_for指向window的窗口,若存在,则由模态窗口获取焦点 18 modal_transient = get_modal_transient (window); 19 if (modal_transient != NULL && !modal_transient->unmanaging && meta_window_transient_can_focus (modal_transient)) { 20 if (!meta_window_located_on_workspace (modal_transient, workspace_manager->active_workspace)) 21 meta_window_change_workspace (modal_transient, workspace_manager->active_workspace); 22 window = modal_transient; 23 } 24 // 最终调用update_window_visibilities显示窗口,对四类窗口进行显示:隐藏窗口,首次显示窗口,未放置窗口,图标窗口 25 meta_window_flush_calc_showing (window); 26 if ((!window->mapped || window->hidden) && !window->shaded) { 27 return; 28 } 29 30 // meta_window_x11_focus for xwayland :同步input focus事件给X11 server和Wayland compositor 31 // meta_window_wayland_focus for wayland :同步input focus事件给Wayland compositor 32 META_WINDOW_GET_CLASS (window)->focus (window, timestamp); 33 34 backend = meta_get_backend (); 35 stage = CLUTTER_STAGE (meta_backend_get_stage (backend)); 36 37 if (window->display->event_route == META_EVENT_ROUTE_NORMAL && clutter_stage_get_grab_actor (stage) == NULL) 38 clutter_stage_set_key_focus (stage, NULL); 39 40 if (window->close_dialog && meta_close_dialog_is_visible (window->close_dialog)) 41 meta_close_dialog_focus (window->close_dialog); 42 43 if (window->wm_state_demands_attention) 44 meta_window_unset_demands_attention(window); 45} 46 47static void meta_window_flush_calc_showing (MetaWindow *window){ 48 MetaWindowPrivate *priv = meta_window_get_instance_private (window); 49 if (!(priv->queued_types & META_QUEUE_CALC_SHOWING)) 50 return; 51 meta_display_flush_queued_window (window->display, window, META_QUEUE_CALC_SHOWING); 52 priv->queued_types &= ~META_QUEUE_CALC_SHOWING; 53} 54 55// meta_window_flush_calc_showing (src/core/window.c) 56void meta_display_flush_queued_window (MetaDisplay *display, MetaWindow *window, MetaQueueType queue_types){ 57 g_autoptr (GList) windows = NULL; 58 int queue_idx; 59 meta_display_unqueue_window (display, window, queue_types); 60 windows = g_list_prepend (windows, window); 61 for (queue_idx = 0; queue_idx < META_N_QUEUE_TYPES; queue_idx++){ 62 if (!(queue_types & 1 << queue_idx)) 63 continue; 64 // META_QUEUE_CALC_SHOWING : update_window_visibilities 65 // META_QUEUE_MOVE_RESIZE : move_resize 66 window_queue_func[queue_idx] (display, windows); 67 } 68}

update_window_visibilities

显示或隐藏窗口

1// update_window_visibilities (src/core/display.c) 2static void update_window_visibilities (MetaDisplay *display, GList *windows){ 3 g_autoptr (GList) unplaced = NULL; 4 g_autoptr (GList) should_show = NULL; 5 g_autoptr (GList) should_hide = NULL; 6 GList *l; 7 for (l = windows; l; l = l->next){ 8 MetaWindow *window = l->data; 9 if (!window->placed) 10 unplaced = g_list_prepend (unplaced, window); 11 else if (meta_window_should_be_showing (window)) 12 should_show = g_list_prepend (should_show, window); 13 else 14 should_hide = g_list_prepend (should_hide, window); 15 } 16 /* Sort bottom to top */ 17 unplaced = g_list_sort (unplaced, window_stack_cmp); 18 should_hide = g_list_sort (should_hide, window_stack_cmp); 19 /* Sort top to bottom */ 20 should_show = g_list_sort (should_show, window_stack_cmp); 21 should_show = g_list_reverse (should_show); 22 23 g_list_foreach (unplaced, (GFunc) meta_window_update_visibility, NULL); 24 25 meta_stack_freeze (display->stack); 26 g_list_foreach (should_show, (GFunc) meta_window_update_visibility, NULL); 27 g_list_foreach (should_hide, (GFunc) meta_window_update_visibility, NULL); 28 meta_stack_thaw (display->stack); 29 30 g_list_foreach (windows, (GFunc) meta_window_clear_queued, NULL); 31 32 // on_window_visibility_updated (src/x11/meta-x11-display.c) : XChangeProperty通知X11更新"_MUTTER_SENTINEL"属性,X11通过PropertyNotify事件通知XWM,这个机制用于避免竞争 33 // on_window_visibility_updated (src/compositor/compositor.c) : update_top_window_actor 34 g_signal_emit (display, display_signals[WINDOW_VISIBILITY_UPDATED], 0, unplaced, should_show, should_hide); 35 g_list_foreach (windows, (GFunc) warn_on_incorrectly_unmanaged_window, NULL); 36} 37 38void meta_window_update_visibility (MetaWindow *window) { 39 implement_showing (window, meta_window_should_be_showing (window)); 40} 41 42// 去掉了showing=false的处理代码 43static void implement_showing (MetaWindow *window, gboolean showing){ 44 /* Some windows are not stackable until being showed, so add those now. */ 45 if (meta_window_is_stackable (window) && !meta_window_is_in_stack (window)) 46 meta_stack_add (window->display->stack, window); 47 // 只对未显示的窗口进行显示,已显示但被部分遮挡的窗口不做任何操作 48 meta_window_show (window); 49 50 // meta_window_x11_map (src/x11/window-x11.c) : 发送XMapWindow给X11 server,若是已map的窗口,不会再发送请求 51 // meta_window_wayland_map (src/wayland/meta-window-wayland.c) : nothing to do. 52 if (!window->override_redirect) 53 sync_client_window_mapped (window); 54}

meta_window_show

meta_window_show主要对四类窗口进行显示,最终调用meta_compositor_show_window显示

  • 隐藏窗口(hidden),显示后的窗口被隐藏了

  • 第一次显示的窗口,窗口已map,但未显示过

  • 未放置窗口:从未计算过窗口的放置位置,也就是从未显示过的窗口

  • 图标窗口:窗口已最小化,使用图标显示的窗口

1static void meta_window_show (MetaWindow *window){ 2  gboolean takes_focus_on_map; 3  gboolean place_on_top_on_map; 4  gboolean notify_demands_attention = FALSE; 5  MetaDisplay *display = window->display; 6  MetaWindow *focus_window = window->display->focus_window;  /* May be NULL! */ 7  gboolean did_show = FALSE; 8  gboolean needs_stacking_adjustment = FALSE; 9  // window是否需要获取光标,是否需要顶层显示 10  window_state_on_map (window, &takes_focus_on_map, &place_on_top_on_map); 11  12  // Now, in some rare cases we should *not* put a new window on top. 13  // These cases include certain types of windows showing for the first time, 14  // and any window which would be covered because of another window being set "above" ("always on top"). 15  16  // FIXME: Although "place_on_top_on_map" and "takes_focus_on_map" are generally based on the window type, 17  // there is a special case when the focus window is a terminal for them both to be false; this should probably rather be a term in the "if" condition below. 18  if (focus_window != NULL && window->showing_for_first_time && ((!place_on_top_on_map && !takes_focus_on_map) || window_would_be_covered (window))) { 19    if (!meta_window_is_ancestor_of_transient (focus_window, window)){ 20      needs_stacking_adjustment = TRUE; 21      if (!window->placed) 22        window->denied_focus_and_not_transient = TRUE; 23    } 24  } 25  if (!window->placed){ 26    if (window->monitor && meta_prefs_get_auto_maximize() && window->showing_for_first_time && window->has_maximize_func){ 27      MetaRectangle work_area; 28      meta_window_get_work_area_for_monitor (window, window->monitor->number, &work_area); 29      /* Automaximize windows that map with a size > MAX_UNMAXIMIZED_WINDOW_AREA of the work area */ 30      if (window->rect.width * window->rect.height > work_area.width * work_area.height * MAX_UNMAXIMIZED_WINDOW_AREA){ 31        window->maximize_horizontally_after_placement = TRUE; 32        window->maximize_vertically_after_placement = TRUE; 33      } 34    } 35    meta_window_force_placement (window, FALSE); 36  } 37  if (needs_stacking_adjustment){ 38    // This window isn't getting focus on map.  We may need to do some special handing with it in regards to 39    // the stacking of the window, the MRU position of the window and the demands attention setting of the window. 40  41    // Firstly, set the flag so we don't give the window focus anyway and confuse people. 42   gboolean overlap = windows_overlap (window, focus_window); 43    takes_focus_on_map = FALSE; 44    /* We want alt tab to go to the denied-focus window */ 45    ensure_mru_position_after (window, focus_window); 46  47    // We don't want the denied-focus window to obscure the focus window, 48    // and if we're in both click-to-focus mode and raise-on-click mode then we want to maintain the invariant that MRU order == stacking order. 49    // The need for this if comes from the fact that in sloppy/mouse focus the focus window may not overlap other windows and also can be considered "below" them; 50    // this combination means that placing the denied-focus window "below" the focus window in the stack when it doesn't overlap it confusingly places 51    // that new window below a lot of other windows. 52    if (overlap || (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_CLICK && meta_prefs_get_raise_on_click ())) 53      meta_window_stack_just_below (window, focus_window); 54  55    // If the window will be obscured by the focus window, then the user might not notice the window appearing so set the demands attention hint. 56    // We set the hint ourselves rather than calling meta_window_set_demands_attention() because that would cause a recalculation of overlap, 57    // and a call to set_net_wm_state() which we are going to call ourselves here a few lines down. 58    if (overlap && !window->wm_state_demands_attention){ 59      window->wm_state_demands_attention = TRUE; 60      notify_demands_attention = TRUE; 61    } 62  } 63  if (window->hidden){ 64    meta_stack_freeze (window->display->stack); 65    window->hidden = FALSE; 66    meta_stack_thaw (window->display->stack); 67    did_show = TRUE; 68  } 69  if (window->iconic){ 70    window->iconic = FALSE; 71    set_wm_state (window); 72  } 73  if (!window->visible_to_compositor){ 74    MetaCompEffect effect = META_COMP_EFFECT_NONE; 75    window->visible_to_compositor = TRUE; 76    switch (window->pending_compositor_effect){ 77      case META_COMP_EFFECT_CREATE: 78      case META_COMP_EFFECT_UNMINIMIZE: 79        effect = window->pending_compositor_effect; 80        break; 81      case META_COMP_EFFECT_NONE: 82      case META_COMP_EFFECT_DESTROY: 83      case META_COMP_EFFECT_MINIMIZE: 84        break; 85    } 86    meta_compositor_show_window (window->display->compositor, window, effect); 87    window->pending_compositor_effect = META_COMP_EFFECT_NONE; 88  } 89  90  // We don't want to worry about all cases from inside implement_showing(); we only want to worry about focus if this window has not been shown before. 91  if (window->showing_for_first_time){ 92    window->showing_for_first_time = FALSE; 93    if (takes_focus_on_map){ 94      guint32     timestamp; 95      timestamp = meta_display_get_current_time_roundtrip (window->display); 96      meta_window_focus (window, timestamp); 97    } 98    else if (display->x11_display){ 99      // Prevent EnterNotify events in sloppy/mouse focus from erroneously focusing the window that had been denied focus. 100      // FIXME: This introduces a race; I have a couple ideas for a better way to accomplish the same thing, but they're more involved so do it this way for now. 101      meta_x11_display_increment_focus_sentinel (display->x11_display); 102    } 103  } 104  set_net_wm_state (window); 105  if (did_show && window->struts){ 106    invalidate_work_areas (window); 107  } 108  // 注册MetaLater(META_LATER_CHECK_FULLSCREEN),延后调用check_fullscreen_func处理全屏 109  if (did_show) 110    meta_display_queue_check_fullscreen (window->display); 111  112  // we have shown the window, we no longer want to consider the initial timestamp in any subsequent deliberations whether to focus this window or not, so clear the flag. 113  window->initial_timestamp_set = FALSE; 114  115  if (notify_demands_attention){ 116    g_object_notify_by_pspec (G_OBJECT (window), obj_props[PROP_DEMANDS_ATTENTION]); 117    g_signal_emit_by_name (window->display, "window-demands-attention", window); 118  } 119  120  // on_window_shown (src/wayland/meta-window-wayland.c) : 更新状态 121  if (did_show) 122    g_signal_emit (window, window_signals[SHOWN], 0); 123}

meta_window_x11_focus

1static void meta_window_x11_focus (MetaWindow *window, guint32 timestamp){ 2  MetaWindowX11 *window_x11 = META_WINDOW_X11 (window); 3  MetaWindowX11Private *priv = meta_window_x11_get_instance_private (window_x11); 4  // For output-only or shaded windows, focus the frame. 5  // This seems to result in the client window getting key events though, so I don't know if it's icccm-compliant. 6  7  // Still, we have to do this or keynav breaks for these windows. 8  // meta_window_x11_is_focusable : input为真,或者使用"WM_TAKE_FOCUS" atom 9  // meta_window_wayland_is_focusable : input为真,可输入的窗口 10  if (window->frame && (window->shaded || !meta_window_is_focusable (window))) { 11    meta_display_set_input_focus (window->display, window, TRUE, timestamp); 12  } 13  else { 14    if (window->input) { 15      meta_display_set_input_focus (window->display,  window, FALSE, timestamp); 16    } 17    if (priv->wm_take_focus) { 18      if (!window->input){ 19        // The "Globally Active Input" window case, where the window doesn't want us to call XSetInputFocus on it, but does want us to send a WM_TAKE_FOCUS. 20        // Normally, we want to just leave the focus undisturbed until the window responds to WM_TAKE_FOCUS, 21        // but if we're unmanaging the current focus window we *need* to move the focus away, so we focus the no focus window before sending WM_TAKE_FOCUS, 22        // and eventually the default focus window excluding this one, if meanwhile we don't get any focus request. 23        if (window->display->focus_window != NULL && window->display->focus_window->unmanaging){ 24          meta_display_unset_input_focus (window->display, timestamp); 25          maybe_focus_default_window (window->display, window, timestamp); 26        } 27      } 28      request_take_focus (window, timestamp); 29    } 30  } 31} 32  33void meta_display_set_input_focus (MetaDisplay *display, MetaWindow *window, gboolean focus_frame, guint32 timestamp){ 34  if (meta_display_timestamp_too_old (display, &timestamp)) 35    return; 36  if (display->x11_display){ 37    meta_x11_display_set_input_focus (display->x11_display, window, focus_frame, timestamp); 38  } 39  meta_display_update_focus_window (display, window); 40  display->last_focus_time = timestamp; 41  if (window == NULL || window != display->autoraise_window) 42    meta_display_remove_autoraise_callback (display); 43}
meta_x11_display_set_input_focus
1// 发送SetInputFocus请求给X11 server,由X11 server处理input focus事件;发送ChangeProperty请求,修改根窗口"_NET_ACTIVE_WINDOW"属性 2void meta_x11_display_set_input_focus (MetaX11Display *x11_display, MetaWindow *window, gboolean focus_frame, uint32_t timestamp){ 3  Window xwindow; 4  gulong serial; 5  if (window) 6    xwindow = focus_frame ? window->frame->xwindow : window->xwindow; 7  else 8    xwindow = x11_display->no_focus_window; 9  10  meta_x11_error_trap_push (x11_display); 11  // 发送SetInputFocus请求给X11 server 12  meta_x11_display_set_input_focus_internal (x11_display, xwindow, timestamp); 13  serial = XNextRequest (x11_display->xdisplay); 14  // 修改根窗口"_NET_ACTIVE_WINDOW"属性,发送ChangeProperty请求 15  meta_x11_display_update_focus_window (x11_display, xwindow, serial, TRUE); 16  meta_x11_error_trap_pop (x11_display); 17} 18  19static void meta_x11_display_set_input_focus_internal (MetaX11Display *x11_display, Window xwindow, uint32_t timestamp){ 20  meta_x11_error_trap_push (x11_display); 21  // In order for mutter to know that the focus request succeeded, we track the serial of the "focus request" we made, but if we take the serial of the XSetInputFocus request, 22  // then there's no way to determine the difference between focus events as a result of the SetInputFocus and focus events that other clients send around the same time. 23  // Ensure that we know which is which by making two requests that the server will process at the same time. 24  XGrabServer (x11_display->xdisplay); 25  // 发送SetInputFocus请求给X11 server,X11处理SetInputFocus实际工作 26  XSetInputFocus (x11_display->xdisplay, xwindow, RevertToPointerRoot,timestamp); 27  // 更改timestamp_pinging_window窗口属性"_MUTTER_FOCUS_SET"类型,发送ChangeProperty请求该X11 server。 28  XChangeProperty (x11_display->xdisplay, x11_display->timestamp_pinging_window, x11_display->atom__MUTTER_FOCUS_SET, XA_STRING, 8, PropModeAppend, NULL, 0); 29  30  XUngrabServer (x11_display->xdisplay); 31  XFlush (x11_display->xdisplay); 32  meta_x11_error_trap_pop (x11_display); 33} 34  35void meta_x11_display_update_focus_window (MetaX11Display *x11_display, Window xwindow, gulong serial, gboolean focused_by_us){ 36  x11_display->focus_serial = serial; 37  x11_display->focused_by_us = !!focused_by_us; 38  if (x11_display->focus_xwindow == xwindow) 39    return; 40  x11_display->focus_xwindow = xwindow; 41  meta_x11_display_update_active_window_hint (x11_display); 42} 43  44static void meta_x11_display_update_active_window_hint (MetaX11Display *x11_display){ 45  MetaWindow *focus_window; 46  gulong data[1]; 47  if (x11_display->display->closing) 48    return; /* Leave old value for a replacement */ 49  focus_window = meta_x11_display_lookup_x_window (x11_display, x11_display->focus_xwindow); 50  51  if (focus_window) 52    data[0] = focus_window->xwindow; 53  else 54    data[0] = None; 55  56  meta_x11_error_trap_push (x11_display); 57  XChangeProperty (x11_display->xdisplay, x11_display->xroot, x11_display->atom__NET_ACTIVE_WINDOW, XA_WINDOW, 32, PropModeReplace, (guchar*) data, 1); 58  meta_x11_error_trap_pop (x11_display); 59}
meta_display_update_focus_window
1void meta_display_update_focus_window (MetaDisplay *display, MetaWindow *window) 2{ 3 MetaWindow *previous = NULL; 4 if (display->focus_window == window) 5 return; 6 if (display->focus_window){ 7 // Make sure that signals handlers invoked by meta_window_set_focused_internal() don't see display->focus_window->has_focus == FALSE 8 previous = display->focus_window; 9 display->focus_window = NULL; 10 meta_window_set_focused_internal (previous, FALSE); 11 } 12 display->focus_window = window; 13 if (display->focus_window){ 14 meta_window_set_focused_internal (display->focus_window, TRUE); 15 } 16 17 if (!previous || !display->focus_window || !meta_window_unit_cgroup_equal (previous, display->focus_window)){ 18 if (previous) 19 meta_window_set_inactive_since (previous, g_get_monotonic_time ()); 20 if (display->focus_window) 21 meta_window_set_inactive_since (display->focus_window, -1); 22 } 23 24 if (meta_is_wayland_compositor ()) 25 meta_display_sync_wayland_input_focus (display); 26 27 // MetaWindowX11响应该属性变化的事件,处理函数:meta_window_x11_delayed_focus_data_free,释放focus资源 28 g_object_notify (G_OBJECT (display), "focus-window"); 29} 30 31void meta_window_set_focused_internal (MetaWindow *window, gboolean focused){ 32 MetaWorkspaceManager *workspace_manager = window->display->workspace_manager; 33 if (focused) { 34 window->has_focus = TRUE; 35 if (window->override_redirect) 36 return; 37 // Move to the front of the focusing workspace's MRU list. We should only be "removing" it from the MRU list if it's not already there. 38 // Note that it's possible that we might be processing this FocusIn after we've changed to a different workspace; 39 // we should therefore update the MRU list only if the window is actually on the active workspace. 40 if (workspace_manager->active_workspace && meta_window_located_on_workspace (window, workspace_manager->active_workspace)){ 41 GList* link = g_list_find (workspace_manager->active_workspace->mru_list, window); 42 workspace_manager->active_workspace->mru_list = g_list_remove_link (workspace_manager->active_workspace->mru_list, link); 43 g_list_free (link); 44 workspace_manager->active_workspace->mru_list = g_list_prepend (workspace_manager->active_workspace->mru_list, window); 45 } 46 47 if (window->frame) 48 meta_frame_queue_draw (window->frame); 49 50 // Ungrab click to focus button since the sync grab can interfere with some things you might do inside the focused window, 51 // by causing the client to get funky enter/leave events. 52 // The reason we usually have a passive grab on the window is so that we can intercept clicks and raise the window in response. 53 // For click-to-focus we don't need that since the focused window is already raised. 54 // When raise_on_click is FALSE we also don't need that since we don't do anything when the window is clicked. 55 if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_CLICK || !meta_prefs_get_raise_on_click()){ 56 meta_display_ungrab_focus_window_button (window->display, window); 57 // Since we ungrab with XIAnyModifier above, all button grabs go way so we need to re-grab the window buttons. 58 meta_display_grab_window_buttons (window->display, window->xwindow); 59 } 60 // 无人注册"focus"信号 61 g_signal_emit (window, window_signals[FOCUS], 0); 62 63 if (!window->attached_focus_window) 64 meta_window_update_appears_focused (window); 65 66 meta_window_propagate_focus_appearance (window, TRUE); 67 } 68 else{ 69 window->has_focus = FALSE; 70 if (window->override_redirect) 71 return; 72 meta_window_propagate_focus_appearance (window, FALSE); 73 if (!window->attached_focus_window) 74 meta_window_update_appears_focused (window); 75 76 if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_CLICK || !meta_prefs_get_raise_on_click ()) 77 meta_display_grab_focus_window_button (window->display, window); // Re-grab for click to focus and raise-on-click, if necessary 78 } 79} 80 81void meta_frame_queue_draw (MetaFrame *frame){ 82 meta_ui_frame_queue_draw (frame->ui_frame); 83} 84 85void meta_ui_frame_queue_draw (MetaUIFrame *frame){ 86 invalidate_whole_window (frame); 87} 88 89static void invalidate_whole_window (MetaUIFrame *frame){ 90 if (!frame->is_frozen){ 91 // 调用meta_window_xwayland_freeze_commits,发送ChangeProperty请求修改frame窗口"_XWAYLAND_ALLOW_COMMITS"属性 92 meta_window_x11_freeze_commits (frame->meta_window); 93 frame->is_frozen = TRUE; 94 } 95 gdk_window_invalidate_rect (frame->window, NULL, FALSE); 96} 97 98 99void meta_display_sync_wayland_input_focus (MetaDisplay *display){ 100 MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default (); 101 MetaWindow *focus_window = NULL; 102 MetaBackend *backend = meta_get_backend (); 103 ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); 104 ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend); 105 MetaStage *stage = META_STAGE (meta_backend_get_stage (backend)); 106 gboolean is_no_focus_xwindow = FALSE; 107 108 if (display->x11_display) 109 is_no_focus_xwindow = meta_x11_display_xwindow_is_a_no_focus_window (display->x11_display, display->x11_display->focus_xwindow); 110 111 if (!meta_display_windows_are_interactable (display)) 112 focus_window = NULL; 113 else if (is_no_focus_xwindow) 114 focus_window = NULL; 115 else if (display->focus_window && display->focus_window->surface) 116 focus_window = display->focus_window; 117 118 meta_stage_set_active (stage, focus_window == NULL); 119 meta_wayland_compositor_set_input_focus (compositor, focus_window); 120 // 重新配对输入设备与新窗口 121 clutter_stage_repick_device (CLUTTER_STAGE (stage), clutter_seat_get_pointer (seat)); 122} 123 124void meta_wayland_compositor_set_input_focus (MetaWaylandCompositor *compositor, MetaWindow *window){ 125 MetaWaylandSurface *surface = window ? window->surface : NULL; 126 meta_wayland_seat_set_input_focus (compositor->seat, surface); 127} 128 129void meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat, MetaWaylandSurface *surface){ 130 MetaWaylandTabletSeat *tablet_seat; 131 MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default (); 132 if (meta_wayland_seat_has_keyboard (seat)){ 133 // 更新focus资源,并向client发送事件 134 meta_wayland_keyboard_set_focus (seat->keyboard, surface); 135 meta_wayland_data_device_set_keyboard_focus (&seat->data_device); 136 meta_wayland_data_device_primary_set_keyboard_focus (&seat->primary_data_device); 137 meta_wayland_data_device_primary_legacy_set_keyboard_focus (&seat->primary_legacy_data_device); 138 } 139 140 tablet_seat = meta_wayland_tablet_manager_ensure_seat (compositor->tablet_manager, seat); 141 meta_wayland_tablet_seat_set_pad_focus (tablet_seat, surface); 142 // 文本输入资源处理 143 meta_wayland_text_input_set_focus (seat->text_input, surface); 144} 145 146void meta_wayland_text_input_set_focus (MetaWaylandTextInput *text_input, MetaWaylandSurface *surface){ 147 if (text_input->surface == surface) 148 return; 149 text_input->pending_state = META_WAYLAND_PENDING_STATE_NONE; 150 if (text_input->surface){ 151 if (!wl_list_empty (&text_input->focus_resource_list)){ 152 ClutterInputFocus *focus = text_input->input_focus; 153 ClutterInputMethod *input_method; 154 struct wl_resource *resource; 155 if (clutter_input_focus_is_focused (focus)){ 156 input_method = clutter_backend_get_input_method (clutter_get_default_backend ()); 157 clutter_input_focus_reset (focus); 158 meta_wayland_text_input_focus_flush_done (focus); 159 clutter_input_method_focus_out (input_method); 160 } 161 wl_resource_for_each (resource, &text_input->focus_resource_list){ 162 zwp_text_input_v3_send_leave (resource, text_input->surface->resource); 163 } 164 move_resources (&text_input->resource_list, &text_input->focus_resource_list); 165 } 166 wl_list_remove (&text_input->surface_listener.link); 167 text_input->surface = NULL; 168 } 169 170 if (surface){ 171 struct wl_resource *focus_surface_resource; 172 text_input->surface = surface; 173 focus_surface_resource = text_input->surface->resource; 174 wl_resource_add_destroy_listener (focus_surface_resource, &text_input->surface_listener); 175 176 move_resources_for_client (&text_input->focus_resource_list, &text_input->resource_list, wl_resource_get_client (focus_surface_resource)); 177 if (!wl_list_empty (&text_input->focus_resource_list)) { 178 struct wl_resource *resource; 179 wl_resource_for_each (resource, &text_input->focus_resource_list){ 180 zwp_text_input_v3_send_enter (resource, surface->resource); 181 } 182 } 183 } 184} 185 186void clutter_stage_repick_device (ClutterStage *stage, ClutterInputDevice *device){ 187 graphene_point_t point; 188 clutter_stage_get_device_coords (stage, device, NULL, &point); 189 clutter_stage_pick_and_update_device (stage, device, NULL, CLUTTER_DEVICE_UPDATE_IGNORE_CACHE | CLUTTER_DEVICE_UPDATE_EMIT_CROSSING, point, CLUTTER_CURRENT_TIME); 190} 191 192ClutterActor *clutter_stage_pick_and_update_device (ClutterStage *stage, ClutterInputDevice *device, ClutterEventSequence *sequence, 193 ClutterDeviceUpdateFlags flags, graphene_point_t point, uint32_t time_ms){ 194 ClutterActor *new_actor; 195 cairo_region_t *clear_area = NULL; 196 if ((flags & CLUTTER_DEVICE_UPDATE_IGNORE_CACHE) == 0) { 197 if (clutter_stage_check_in_clear_area (stage, device, sequence, point)){ 198 clutter_stage_set_device_coords (stage, device, sequence, point); 199 return clutter_stage_get_device_actor (stage, device, sequence); 200 } 201 } 202 203 new_actor = _clutter_stage_do_pick (stage, point.x, point.y, CLUTTER_PICK_REACTIVE, &clear_area); 204 clutter_stage_update_device (stage, device, sequence, point, time_ms, new_actor, clear_area, !!(flags & CLUTTER_DEVICE_UPDATE_EMIT_CROSSING)); 205 g_clear_pointer (&clear_area, cairo_region_destroy); 206 return new_actor; 207}