环境:debian 12.5、mate desktop。
参考:marco 1.20.2
当用户点击窗口菜单的最大化按钮,这个要求是如何传递到marco的呢?
对此,我们需要分以下几个步骤完成。
- 跟踪代码,查看函数在marco中的调用流程
- GtkWidgetClass中的函数button_press_event何时被调用
对于第一个问题,调用流程如下:
void
meta_window_show_menu (MetaWindow *window,
int root_x,
int root_y,
int button,
guint32 timestamp)
{
......
menu =
meta_ui_window_menu_new (window->screen->ui,
window->xwindow,
ops,
insensitive,
meta_window_get_net_wm_desktop (window),
meta_screen_get_n_workspaces (window->screen),
menu_callback,
NULL);
}
void
meta_core_show_window_menu (Display *xdisplay,
Window frame_xwindow,
int root_x,
int root_y,
int button,
guint32 timestamp)
{
MetaWindow *window = get_window (xdisplay, frame_xwindow);
if (meta_prefs_get_raise_on_click ())
meta_window_raise (window);
meta_window_focus (window, timestamp);
meta_window_show_menu (window, root_x, root_y, button, timestamp);
}
static gboolean
meta_frames_button_press_event (GtkWidget *widget,
GdkEventButton *event)
{
......
MetaFrameControl control;
......
control = get_control (frames, frame, event->x, event->y);
......
if ((event->button == 1 &&
(control == META_FRAME_CONTROL_MINIMIZE ||
control == META_FRAME_CONTROL_DELETE ||
control == META_FRAME_CONTROL_SHADE ||
control == META_FRAME_CONTROL_UNSHADE ||
control == META_FRAME_CONTROL_ABOVE ||
control == META_FRAME_CONTROL_UNABOVE ||
control == META_FRAME_CONTROL_STICK ||
control == META_FRAME_CONTROL_UNSTICK ||
control == META_FRAME_CONTROL_MENU)) ||
(control == META_FRAME_CONTROL_MAXIMIZE ||
control == META_FRAME_CONTROL_UNMAXIMIZE))
{
......
if (op == META_GRAB_OP_CLICKING_MENU)
{
......
if (op == META_GRAB_OP_CLICKING_MENU)
{
meta_core_show_window_menu (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
frame->xwindow,
rect->x + dx,
rect->y + rect->height + dy,
event->button,
event->time);
}
}
}
......
}
static void
meta_frames_class_init (MetaFramesClass *class)
{
......
GtkWidgetClass *widget_class;
......
widget_class = (GtkWidgetClass*) class;
......
widget_class->button_press_event = meta_frames_button_press_event;
......
}
最终,函数的调用源头是在meta_frame这个新创建的GObject的button_press_event中。
对于第二个问题:
当用户在GTK+应用程序的某个widget(如按钮、窗口等)上按下鼠标时,操作系统会捕获此操作,并将这个事件传递到GTK+的事件处理系统。GTK事件处理系统接收到事件后,会确定事件该由哪个widget处理(根据事件发生的坐标及widget的几何位置来确定)。当事件传递到widget后,GTK+会查找是否注册了button_press_event信号的处理函数(对于我们现在分析的情况,我们是通过meta_frames_class_init来注册的meta_frames_button_press_event函数),如果找,GTK+就会调用。