From e17d70a5925e19a8785d50ab3ad2106dabe8ad70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 14 Oct 2019 11:32:54 +0200 Subject: [PATCH] x11/window-controls: Pass around MetaX11Display directly Instead of passing around an X11 Display pointer that is retrieved from the default Gdk backend, then finding the MetaX11Display from said X11 Display, pass the MetaX11Display directly. https://gitlab.gnome.org/GNOME/mutter/merge_requests/854 --- src/ui/frames.c | 119 +++++++++++++-------------- src/ui/frames.h | 4 +- src/ui/ui.c | 2 +- src/x11/meta-x11-display-private.h | 2 + src/x11/meta-x11-display.c | 6 ++ src/x11/meta-x11-window-control.c | 128 +++++++++++++---------------- src/x11/meta-x11-window-control.h | 81 +++++++++--------- 7 files changed, 167 insertions(+), 175 deletions(-) diff --git a/src/ui/frames.c b/src/ui/frames.c index 39e2f2653..6ee7da2ae 100644 --- a/src/ui/frames.c +++ b/src/ui/frames.c @@ -276,13 +276,16 @@ meta_frames_finalize (GObject *object) } static void -queue_recalc_func (gpointer key, gpointer value, gpointer data) +queue_recalc_func (gpointer key, + gpointer value, + gpointer user_data) { MetaUIFrame *frame = value; + MetaFrames *frames = user_data; invalidate_whole_window (frame); - meta_core_queue_frame_resize (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), - frame->xwindow); + meta_x11_wm_queue_frame_resize (frames->x11_display, + frame->xwindow); g_clear_object (&frame->text_layout); } @@ -430,13 +433,14 @@ meta_ui_frame_calc_geometry (MetaUIFrame *frame, } MetaFrames* -meta_frames_new (void) +meta_frames_new (MetaX11Display *x11_display) { MetaFrames *frames; frames = g_object_new (META_TYPE_FRAMES, "type", GTK_WINDOW_POPUP, NULL); + frames->x11_display = x11_display; /* Put the window at an arbitrary offscreen location; the one place * it can't be is at -100x-100, since the meta_window_new() will @@ -523,7 +527,7 @@ meta_frames_manage_window (MetaFrames *frames, frame->prelit_control = META_FRAME_CONTROL_NONE; frame->button_state = META_BUTTON_STATE_NORMAL; - meta_core_grab_buttons (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), frame->xwindow); + meta_x11_wm_grab_buttons (frames->x11_display, frame->xwindow); g_hash_table_replace (frames->frames, &frame->xwindow, frame); @@ -536,9 +540,9 @@ meta_ui_frame_unmanage (MetaUIFrame *frame) MetaFrames *frames = frame->frames; /* restore the cursor */ - meta_core_set_screen_cursor (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), - frame->xwindow, - META_CURSOR_DEFAULT); + meta_x11_wm_set_screen_cursor (frames->x11_display, + frame->xwindow, + META_CURSOR_DEFAULT); gdk_window_set_user_data (frame->window, NULL); @@ -756,14 +760,14 @@ meta_frame_titlebar_event (MetaUIFrame *frame, int action) { MetaFrameFlags flags; - Display *display; + MetaX11Display *x11_display; uint32_t evtime; float x, y; g_assert (event->type == CLUTTER_BUTTON_PRESS || event->type == CLUTTER_TOUCH_BEGIN); - display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + x11_display = frame->frames->x11_display; flags = meta_frame_get_flags (frame->meta_window->frame); @@ -788,7 +792,7 @@ meta_frame_titlebar_event (MetaUIFrame *frame, { if (flags & META_FRAME_ALLOWS_MAXIMIZE) { - meta_core_toggle_maximize (display, frame->xwindow); + meta_x11_wm_toggle_maximize (x11_display, frame->xwindow); } } break; @@ -797,7 +801,8 @@ meta_frame_titlebar_event (MetaUIFrame *frame, { if (flags & META_FRAME_ALLOWS_MAXIMIZE) { - meta_core_toggle_maximize_horizontally (display, frame->xwindow); + meta_x11_wm_toggle_maximize_horizontally (x11_display, + frame->xwindow); } } break; @@ -806,7 +811,7 @@ meta_frame_titlebar_event (MetaUIFrame *frame, { if (flags & META_FRAME_ALLOWS_MAXIMIZE) { - meta_core_toggle_maximize_vertically (display, frame->xwindow); + meta_x11_wm_toggle_maximize_vertically (x11_display, frame->xwindow); } } break; @@ -823,16 +828,16 @@ meta_frame_titlebar_event (MetaUIFrame *frame, break; case G_DESKTOP_TITLEBAR_ACTION_LOWER: - meta_core_user_lower_and_unfocus (display, - frame->xwindow, - evtime); + meta_x11_wm_user_lower_and_unfocus (x11_display, + frame->xwindow, + evtime); break; case G_DESKTOP_TITLEBAR_ACTION_MENU: - meta_core_show_window_menu (display, - frame->xwindow, - META_WINDOW_MENU_WM, - x, y, evtime); + meta_x11_wm_show_window_menu (x11_display, + frame->xwindow, + META_WINDOW_MENU_WM, + x, y, evtime); break; } @@ -876,19 +881,17 @@ meta_frames_try_grab_op (MetaUIFrame *frame, guint32 time) { MetaFrames *frames = frame->frames; - Display *display; gboolean ret; - display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - ret = meta_core_begin_grab_op (display, - frame->xwindow, - op, - FALSE, - TRUE, - frame->grab_button, - 0, - time, - grab_x, grab_y); + ret = meta_x11_wm_begin_grab_op (frames->x11_display, + frame->xwindow, + op, + FALSE, + TRUE, + frame->grab_button, + 0, + time, + grab_x, grab_y); if (!ret) { frames->current_grab_op = op; @@ -906,7 +909,6 @@ static gboolean meta_frames_retry_grab_op (MetaFrames *frames, guint time) { - Display *display; MetaGrabOp op; gboolean ret; @@ -915,18 +917,17 @@ meta_frames_retry_grab_op (MetaFrames *frames, op = frames->current_grab_op; frames->current_grab_op = META_GRAB_OP_NONE; - display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - ret = meta_core_begin_grab_op (display, - frames->grab_frame->xwindow, - op, - FALSE, - TRUE, - frames->grab_frame->grab_button, - 0, - time, - frames->grab_x, - frames->grab_y); + ret = meta_x11_wm_begin_grab_op (frames->x11_display, + frames->grab_frame->xwindow, + op, + FALSE, + TRUE, + frames->grab_frame->grab_button, + 0, + time, + frames->grab_x, + frames->grab_y); if (ret) frames->grab_touch = NULL; @@ -1012,7 +1013,7 @@ static gboolean meta_frame_left_click_event (MetaUIFrame *frame, const ClutterEvent *event) { - Display *display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + MetaX11Display *x11_display = frame->frames->x11_display; MetaFrameControl control; guint32 evtime; gfloat x, y; @@ -1056,11 +1057,11 @@ meta_frame_left_click_event (MetaUIFrame *frame, * button state while the menu is open */ frame->maybe_ignore_leave_notify = TRUE; - meta_core_show_window_menu_for_rect (display, - frame->xwindow, - META_WINDOW_MENU_WM, - &root_rect, - evtime); + meta_x11_wm_show_window_menu_for_rect (x11_display, + frame->xwindow, + META_WINDOW_MENU_WM, + &root_rect, + evtime); } else { @@ -1111,7 +1112,6 @@ handle_press_event (MetaUIFrame *frame, const ClutterEvent *event) { MetaFrameControl control; - Display *display; uint32_t evtime, action; float x, y; @@ -1122,8 +1122,6 @@ handle_press_event (MetaUIFrame *frame, if (action == META_ACTION_IGNORE) return FALSE; - display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - evtime = clutter_event_get_time (event); clutter_event_get_coords (event, &x, &y); control = get_control (frame, x, y); @@ -1148,11 +1146,11 @@ handle_press_event (MetaUIFrame *frame, if (control == META_FRAME_CONTROL_TITLE && action == META_ACTION_DOUBLE_CLICK) { - meta_core_end_grab_op (display, evtime); + meta_x11_wm_end_grab_op (frame->frames->x11_display, evtime); return meta_frame_double_click_event (frame, event); } - if (meta_core_get_grab_op (display) != META_GRAB_OP_NONE) + if (meta_x11_wm_get_grab_op (frame->frames->x11_display) != META_GRAB_OP_NONE) return FALSE; /* already up to something */ frame->grab_button = get_button_number (event); @@ -1174,7 +1172,6 @@ static gboolean handle_release_event (MetaUIFrame *frame, const ClutterEvent *event) { - Display *display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); guint32 evtime, button; gfloat x, y; @@ -1186,7 +1183,7 @@ handle_release_event (MetaUIFrame *frame, button = get_button_number (event); frame->frames->current_grab_op = META_GRAB_OP_NONE; - meta_core_end_grab_op (display, evtime); + meta_x11_wm_end_grab_op (frame->frames->x11_display, evtime); /* We only handle the releases we handled the presses for (things * involving frame controls). Window ops that don't require a @@ -1288,9 +1285,9 @@ meta_ui_frame_update_prelit_control (MetaUIFrame *frame, } /* set/unset the prelight cursor */ - meta_core_set_screen_cursor (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), - frame->xwindow, - cursor); + meta_x11_wm_set_screen_cursor (frame->frames->x11_display, + frame->xwindow, + cursor); switch (control) { @@ -1586,11 +1583,9 @@ static gboolean handle_leave_notify_event (MetaUIFrame *frame, ClutterCrossingEvent *event) { - Display *display; MetaGrabOp grab_op; - display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - grab_op = meta_core_get_grab_op (display); + grab_op = meta_x11_wm_get_grab_op (frame->frames->x11_display); /* ignore the first LeaveNotify event after opening a window menu * if it is the result of a compositor grab diff --git a/src/ui/frames.h b/src/ui/frames.h index cc6316b3e..555bd8e0a 100644 --- a/src/ui/frames.h +++ b/src/ui/frames.h @@ -87,6 +87,8 @@ struct _MetaFrames { GtkWindow parent_instance; + MetaX11Display *x11_display; + GHashTable *text_heights; GHashTable *frames; @@ -111,7 +113,7 @@ struct _MetaFramesClass GType meta_frames_get_type (void) G_GNUC_CONST; -MetaFrames *meta_frames_new (void); +MetaFrames * meta_frames_new (MetaX11Display *x11_display); MetaUIFrame * meta_frames_manage_window (MetaFrames *frames, MetaWindow *meta_window, diff --git a/src/ui/ui.c b/src/ui/ui.c index f716dea11..64afb0134 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -59,7 +59,7 @@ meta_ui_new (MetaX11Display *x11_display) ui = g_new0 (MetaUI, 1); ui->xdisplay = x11_display->xdisplay; - ui->frames = meta_frames_new (); + ui->frames = meta_frames_new (x11_display); /* GTK+ needs the frame-sync protocol to work in order to properly * handle style changes. This means that the dummy widget we create * to get the style for title bars actually needs to be mapped diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h index 7c61d7b0d..36d4bad38 100644 --- a/src/x11/meta-x11-display-private.h +++ b/src/x11/meta-x11-display-private.h @@ -253,6 +253,8 @@ void meta_x11_display_set_input_focus (MetaX11Display *x11_display, gboolean focus_frame, uint32_t timestamp); +MetaDisplay * meta_x11_display_get_display (MetaX11Display *x11_display); + const gchar * meta_x11_get_display_name (void); #endif /* META_X11_DISPLAY_PRIVATE_H */ diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index 3ae5b3d8d..9fb3853bd 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -1407,6 +1407,12 @@ meta_x11_display_get_screen_number (MetaX11Display *x11_display) return DefaultScreen (x11_display->xdisplay); } +MetaDisplay * +meta_x11_display_get_display (MetaX11Display *x11_display) +{ + return x11_display->display; +} + /** * meta_x11_display_get_xdisplay: (skip) * @x11_display: a #MetaX11Display diff --git a/src/x11/meta-x11-window-control.c b/src/x11/meta-x11-window-control.c index 88840c179..aaf3d7fe1 100644 --- a/src/x11/meta-x11-window-control.c +++ b/src/x11/meta-x11-window-control.c @@ -35,28 +35,14 @@ #include "x11/window-x11-private.h" #include "x11/window-x11.h" -/* Looks up the MetaWindow representing the frame of the given X window. - * Used as a helper function by a bunch of the functions below. - * - * FIXME: The functions that use this function throw the result away - * after use. Many of these functions tend to be called in small groups, - * which results in get_window() getting called several times in succession - * with the same parameters. We should profile to see whether this wastes - * much time, and if it does we should look into a generalised - * meta_core_get_window_info() which takes a bunch of pointers to variables - * to put its results in, and only fills in the non-null ones. - */ static MetaWindow * -get_window (Display *xdisplay, - Window frame_xwindow) +window_from_frame (MetaX11Display *x11_display, + Window frame_xwindow) { - MetaDisplay *display; MetaWindow *window; - display = meta_display_for_x_display (xdisplay); - window = meta_x11_display_lookup_x_window (display->x11_display, frame_xwindow); - - if (window == NULL || window->frame == NULL) + window = meta_x11_display_lookup_x_window (x11_display, frame_xwindow); + if (!window || !window->frame) { meta_bug ("No such frame window 0x%lx!\n", frame_xwindow); return NULL; @@ -66,10 +52,10 @@ get_window (Display *xdisplay, } void -meta_core_queue_frame_resize (Display *xdisplay, - Window frame_xwindow) +meta_x11_wm_queue_frame_resize (MetaX11Display *x11_display, + Window frame_xwindow) { - MetaWindow *window = get_window (xdisplay, frame_xwindow); + MetaWindow *window = window_from_frame (x11_display, frame_xwindow); meta_window_queue (window, META_QUEUE_MOVE_RESIZE); meta_window_frame_size_changed (window); @@ -115,11 +101,11 @@ lower_window_and_transients (MetaWindow *window, } void -meta_core_user_lower_and_unfocus (Display *xdisplay, - Window frame_xwindow, - guint32 timestamp) +meta_x11_wm_user_lower_and_unfocus (MetaX11Display *x11_display, + Window frame_xwindow, + uint32_t timestamp) { - MetaWindow *window = get_window (xdisplay, frame_xwindow); + MetaWindow *window = window_from_frame (x11_display, frame_xwindow); MetaWorkspaceManager *workspace_manager = window->display->workspace_manager; lower_window_and_transients (window, NULL); @@ -134,10 +120,10 @@ meta_core_user_lower_and_unfocus (Display *xdisplay, } void -meta_core_toggle_maximize_vertically (Display *xdisplay, - Window frame_xwindow) +meta_x11_wm_toggle_maximize_vertically (MetaX11Display *x11_display, + Window frame_xwindow) { - MetaWindow *window = get_window (xdisplay, frame_xwindow); + MetaWindow *window = window_from_frame (x11_display, frame_xwindow); if (meta_prefs_get_raise_on_click ()) meta_window_raise (window); @@ -149,10 +135,10 @@ meta_core_toggle_maximize_vertically (Display *xdisplay, } void -meta_core_toggle_maximize_horizontally (Display *xdisplay, - Window frame_xwindow) +meta_x11_wm_toggle_maximize_horizontally (MetaX11Display *x11_display, + Window frame_xwindow) { - MetaWindow *window = get_window (xdisplay, frame_xwindow); + MetaWindow *window = window_from_frame (x11_display, frame_xwindow); if (meta_prefs_get_raise_on_click ()) meta_window_raise (window); @@ -164,10 +150,10 @@ meta_core_toggle_maximize_horizontally (Display *xdisplay, } void -meta_core_toggle_maximize (Display *xdisplay, - Window frame_xwindow) +meta_x11_wm_toggle_maximize (MetaX11Display *x11_display, + Window frame_xwindow) { - MetaWindow *window = get_window (xdisplay, frame_xwindow); + MetaWindow *window = window_from_frame (x11_display, frame_xwindow); if (meta_prefs_get_raise_on_click ()) meta_window_raise (window); @@ -179,14 +165,14 @@ meta_core_toggle_maximize (Display *xdisplay, } void -meta_core_show_window_menu (Display *xdisplay, - Window frame_xwindow, - MetaWindowMenuType menu, - int root_x, - int root_y, - guint32 timestamp) +meta_x11_wm_show_window_menu (MetaX11Display *x11_display, + Window frame_xwindow, + MetaWindowMenuType menu, + int root_x, + int root_y, + uint32_t timestamp) { - MetaWindow *window = get_window (xdisplay, frame_xwindow); + MetaWindow *window = window_from_frame (x11_display, frame_xwindow); if (meta_prefs_get_raise_on_click ()) meta_window_raise (window); @@ -196,13 +182,13 @@ meta_core_show_window_menu (Display *xdisplay, } void -meta_core_show_window_menu_for_rect (Display *xdisplay, - Window frame_xwindow, - MetaWindowMenuType menu, - MetaRectangle *rect, - guint32 timestamp) +meta_x11_wm_show_window_menu_for_rect (MetaX11Display *x11_display, + Window frame_xwindow, + MetaWindowMenuType menu, + MetaRectangle *rect, + uint32_t timestamp) { - MetaWindow *window = get_window (xdisplay, frame_xwindow); + MetaWindow *window = window_from_frame (x11_display, frame_xwindow); if (meta_prefs_get_raise_on_click ()) meta_window_raise (window); @@ -212,21 +198,21 @@ meta_core_show_window_menu_for_rect (Display *xdisplay, } gboolean -meta_core_begin_grab_op (Display *xdisplay, - Window frame_xwindow, - MetaGrabOp op, - gboolean pointer_already_grabbed, - gboolean frame_action, - int button, - gulong modmask, - guint32 timestamp, - int root_x, - int root_y) +meta_x11_wm_begin_grab_op (MetaX11Display *x11_display, + Window frame_xwindow, + MetaGrabOp op, + gboolean pointer_already_grabbed, + gboolean frame_action, + int button, + gulong modmask, + uint32_t timestamp, + int root_x, + int root_y) { - MetaWindow *window = get_window (xdisplay, frame_xwindow); + MetaWindow *window = window_from_frame (x11_display, frame_xwindow); MetaDisplay *display; - display = meta_display_for_x_display (xdisplay); + display = meta_x11_display_get_display (x11_display); return meta_display_begin_grab_op (display, window, op, pointer_already_grabbed, @@ -236,44 +222,44 @@ meta_core_begin_grab_op (Display *xdisplay, } void -meta_core_end_grab_op (Display *xdisplay, - guint32 timestamp) +meta_x11_wm_end_grab_op (MetaX11Display *x11_display, + uint32_t timestamp) { MetaDisplay *display; - display = meta_display_for_x_display (xdisplay); + display = meta_x11_display_get_display (x11_display); meta_display_end_grab_op (display, timestamp); } MetaGrabOp -meta_core_get_grab_op (Display *xdisplay) +meta_x11_wm_get_grab_op (MetaX11Display *x11_display) { MetaDisplay *display; - display = meta_display_for_x_display (xdisplay); + display = meta_x11_display_get_display (x11_display); return display->grab_op; } void -meta_core_grab_buttons (Display *xdisplay, - Window frame_xwindow) +meta_x11_wm_grab_buttons (MetaX11Display *x11_display, + Window frame_xwindow) { MetaDisplay *display; - display = meta_display_for_x_display (xdisplay); + display = meta_x11_display_get_display (x11_display); meta_verbose ("Grabbing buttons on frame 0x%lx\n", frame_xwindow); meta_display_grab_window_buttons (display, frame_xwindow); } void -meta_core_set_screen_cursor (Display *xdisplay, - Window frame_on_screen, - MetaCursor cursor) +meta_x11_wm_set_screen_cursor (MetaX11Display *x11_display, + Window frame_on_screen, + MetaCursor cursor) { - MetaWindow *window = get_window (xdisplay, frame_on_screen); + MetaWindow *window = window_from_frame (x11_display, frame_on_screen); meta_frame_set_screen_cursor (window->frame, cursor); } diff --git a/src/x11/meta-x11-window-control.h b/src/x11/meta-x11-window-control.h index 067d42918..dfb66f262 100644 --- a/src/x11/meta-x11-window-control.h +++ b/src/x11/meta-x11-window-control.h @@ -27,54 +27,55 @@ #include "meta/boxes.h" #include "meta/common.h" +#include "x11/meta-x11-display-private.h" -void meta_core_queue_frame_resize (Display *xdisplay, - Window frame_xwindow); +void meta_x11_wm_queue_frame_resize (MetaX11Display *x11_display, + Window frame_xwindow); -void meta_core_user_lower_and_unfocus (Display *xdisplay, - Window frame_xwindow, - guint32 timestamp); +void meta_x11_wm_user_lower_and_unfocus (MetaX11Display *x11_display, + Window frame_xwindow, + uint32_t timestamp); -void meta_core_toggle_maximize (Display *xdisplay, - Window frame_xwindow); -void meta_core_toggle_maximize_horizontally (Display *xdisplay, - Window frame_xwindow); -void meta_core_toggle_maximize_vertically (Display *xdisplay, - Window frame_xwindow); +void meta_x11_wm_toggle_maximize (MetaX11Display *x11_display, + Window frame_xwindow); +void meta_x11_wm_toggle_maximize_horizontally (MetaX11Display *xdisplay, + Window frame_xwindow); +void meta_x11_wm_toggle_maximize_vertically (MetaX11Display *x11_display, + Window frame_xwindow); -void meta_core_show_window_menu (Display *xdisplay, - Window frame_xwindow, - MetaWindowMenuType menu, - int root_x, - int root_y, - guint32 timestamp); +void meta_x11_wm_show_window_menu (MetaX11Display *x11_xdisplay, + Window frame_xwindow, + MetaWindowMenuType menu, + int root_x, + int root_y, + uint32_t timestamp); -void meta_core_show_window_menu_for_rect (Display *xdisplay, - Window frame_xwindow, - MetaWindowMenuType menu, - MetaRectangle *rect, - guint32 timestamp); +void meta_x11_wm_show_window_menu_for_rect (MetaX11Display *x11_display, + Window frame_xwindow, + MetaWindowMenuType menu, + MetaRectangle *rect, + uint32_t timestamp); -gboolean meta_core_begin_grab_op (Display *xdisplay, - Window frame_xwindow, - MetaGrabOp op, - gboolean pointer_already_grabbed, - gboolean frame_action, - int button, - gulong modmask, - guint32 timestamp, - int root_x, - int root_y); -void meta_core_end_grab_op (Display *xdisplay, - guint32 timestamp); -MetaGrabOp meta_core_get_grab_op (Display *xdisplay); +gboolean meta_x11_wm_begin_grab_op (MetaX11Display *x11_display, + Window frame_xwindow, + MetaGrabOp op, + gboolean pointer_already_grabbed, + gboolean frame_action, + int button, + gulong modmask, + uint32_t timestamp, + int root_x, + int root_y); +void meta_x11_wm_end_grab_op (MetaX11Display *x11_display, + uint32_t timestamp); +MetaGrabOp meta_x11_wm_get_grab_op (MetaX11Display *x11_display); -void meta_core_grab_buttons (Display *xdisplay, - Window frame_xwindow); +void meta_x11_wm_grab_buttons (MetaX11Display *x11_display, + Window frame_xwindow); -void meta_core_set_screen_cursor (Display *xdisplay, - Window frame_on_screen, - MetaCursor cursor); +void meta_x11_wm_set_screen_cursor (MetaX11Display *x11_display, + Window frame_on_screen, + MetaCursor cursor); #endif /* META_X11_WINDOW_CONTROL_H */