From e8171ccdc1f8b37cfc6953a0b7d1e84440478a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20Krezovi=C4=87?= Date: Sun, 27 Aug 2017 20:44:38 +0200 Subject: [PATCH] Use MetaMonitorManager insted of MetaDisplay where possible This drops display's monitors-changed signal and makes all the code rely on MetaMonitorManager. https://bugzilla.gnome.org/show_bug.cgi?id=759538 --- src/compositor/compositor.c | 6 +++-- src/compositor/meta-background.c | 22 ++++++---------- src/compositor/plugins/default.c | 12 ++++++--- src/core/display-private.h | 1 - src/core/display.c | 42 ++++++++----------------------- src/core/edge-resistance.c | 6 ++++- src/core/window.c | 27 ++++++++++++++------ src/core/workspace.c | 22 ++++++++++------ src/x11/meta-x11-display.c | 43 ++++++++++++++++++++++---------- src/x11/window-x11.c | 10 +++++--- 10 files changed, 106 insertions(+), 85 deletions(-) diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c index e9cccd0f2..784a800c7 100644 --- a/src/compositor/compositor.c +++ b/src/compositor/compositor.c @@ -949,11 +949,13 @@ get_top_visible_window_actor (MetaCompositor *compositor) MetaWindowActor *window_actor = l->data; MetaWindow *window = meta_window_actor_get_meta_window (window_actor); MetaRectangle buffer_rect; + MetaRectangle display_rect = { 0 }; meta_window_get_buffer_rect (window, &buffer_rect); + meta_display_get_size (compositor->display, + &display_rect.width, &display_rect.height); - if (meta_rectangle_overlap (&compositor->display->rect, - &buffer_rect)) + if (meta_rectangle_overlap (&display_rect, &buffer_rect)) return window_actor; } diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c index 093e5f1f1..a6d41a4d6 100644 --- a/src/compositor/meta-background.c +++ b/src/compositor/meta-background.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "meta-background-private.h" #include "cogl-utils.h" @@ -151,8 +152,7 @@ invalidate_monitor_backgrounds (MetaBackground *self) } static void -on_monitors_changed (MetaDisplay *display, - MetaBackground *self) +on_monitors_changed (MetaBackground *self) { invalidate_monitor_backgrounds (self); } @@ -163,21 +163,8 @@ set_display (MetaBackground *self, { MetaBackgroundPrivate *priv = self->priv; - if (priv->display) - { - g_signal_handlers_disconnect_by_func (priv->display, - (gpointer)on_monitors_changed, - self); - } - g_set_object (&priv->display, display); - if (priv->display) - { - g_signal_connect (priv->display, "monitors-changed", - G_CALLBACK (on_monitors_changed), self); - } - invalidate_monitor_backgrounds (self); } @@ -329,11 +316,16 @@ meta_background_constructed (GObject *object) { MetaBackground *self = META_BACKGROUND (object); MetaBackgroundPrivate *priv = self->priv; + MetaMonitorManager *monitor_manager = meta_monitor_manager_get (); G_OBJECT_CLASS (meta_background_parent_class)->constructed (object); g_signal_connect_object (priv->display, "gl-video-memory-purged", G_CALLBACK (mark_changed), object, G_CONNECT_SWAPPED); + + g_signal_connect_object (monitor_manager, "monitors-changed", + G_CALLBACK (on_monitors_changed), self, + G_CONNECT_SWAPPED); } static void diff --git a/src/compositor/plugins/default.c b/src/compositor/plugins/default.c index ccf500a9e..12adbf245 100644 --- a/src/compositor/plugins/default.c +++ b/src/compositor/plugins/default.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -319,10 +320,12 @@ on_switch_workspace_effect_complete (ClutterTimeline *timeline, gpointer data) } static void -on_monitors_changed (MetaDisplay *display, - MetaPlugin *plugin) +on_monitors_changed (MetaMonitorManager *monitor_manager, + MetaPlugin *plugin) { MetaDefaultPlugin *self = META_DEFAULT_PLUGIN (plugin); + MetaDisplay *display = meta_plugin_get_display (plugin); + int i, n; GRand *rand = g_rand_new_with_seed (123456); @@ -374,15 +377,16 @@ start (MetaPlugin *plugin) { MetaDefaultPlugin *self = META_DEFAULT_PLUGIN (plugin); MetaDisplay *display = meta_plugin_get_display (plugin); + MetaMonitorManager *monitor_manager = meta_monitor_manager_get (); self->priv->background_group = meta_background_group_new (); clutter_actor_insert_child_below (meta_get_window_group_for_display (display), self->priv->background_group, NULL); - g_signal_connect (display, "monitors-changed", + g_signal_connect (monitor_manager, "monitors-changed", G_CALLBACK (on_monitors_changed), plugin); - on_monitors_changed (display, plugin); + on_monitors_changed (monitor_manager, plugin); clutter_actor_show (meta_get_stage_for_display (display)); } diff --git a/src/core/display-private.h b/src/core/display-private.h index 5f664ff41..b0924eea8 100644 --- a/src/core/display-private.h +++ b/src/core/display-private.h @@ -229,7 +229,6 @@ struct _MetaDisplay MetaStartupNotification *startup_notification; - MetaRectangle rect; /* Size of screen; rect.x & rect.y are always 0 */ MetaCursor current_cursor; MetaStack *stack; diff --git a/src/core/display.c b/src/core/display.c index 248de99f2..655e1cf58 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -144,7 +144,6 @@ enum IN_FULLSCREEN_CHANGED, SHOWING_DESKTOP_CHANGED, STARTUP_SEQUENCE_CHANGED, - MONITORS_CHANGED, RESTACKED, WORKAREAS_CHANGED, LAST_SIGNAL @@ -170,9 +169,6 @@ static MetaDisplay *the_display = NULL; static void on_monitors_changed_internal (MetaMonitorManager *monitor_manager, MetaDisplay *display); -static void on_monitors_changed (MetaMonitorManager *monitor_manager, - MetaDisplay *display); - static void prefs_changed_callback (MetaPreference pref, void *data); @@ -516,13 +512,6 @@ meta_display_class_init (MetaDisplayClass *klass) 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_POINTER); - display_signals[MONITORS_CHANGED] = - g_signal_new ("monitors-changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 0); - display_signals[RESTACKED] = g_signal_new ("restacked", G_TYPE_FROM_CLASS (klass), @@ -743,7 +732,6 @@ meta_display_open (void) display->focus_window = NULL; display->x11_display = NULL; - display->rect.x = display->rect.y = 0; display->current_cursor = -1; /* invalid/unset */ display->tile_preview_timeout_id = 0; display->check_fullscreen_later = 0; @@ -794,12 +782,6 @@ meta_display_open (void) monitor_manager = meta_backend_get_monitor_manager (backend); g_signal_connect (monitor_manager, "monitors-changed-internal", G_CALLBACK (on_monitors_changed_internal), display); - g_signal_connect (monitor_manager, "monitors-changed", - G_CALLBACK (on_monitors_changed), display); - - meta_monitor_manager_get_screen_size (monitor_manager, - &display->rect.width, - &display->rect.height); meta_display_set_cursor (display, META_CURSOR_DEFAULT); @@ -2763,11 +2745,20 @@ meta_display_get_size (MetaDisplay *display, int *width, int *height) { + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + int display_width, display_height; + + meta_monitor_manager_get_screen_size (monitor_manager, + &display_width, + &display_height); + if (width != NULL) - *width = display->rect.width; + *width = display_width; if (height != NULL) - *height = display->rect.height; + *height = display_height; } /** @@ -3078,10 +3069,6 @@ on_monitors_changed_internal (MetaMonitorManager *monitor_manager, MetaBackend *backend; MetaCursorRenderer *cursor_renderer; - meta_monitor_manager_get_screen_size (monitor_manager, - &display->rect.width, - &display->rect.height); - reload_logical_monitors (display); /* Fix up monitor for all windows on this display */ @@ -3100,13 +3087,6 @@ on_monitors_changed_internal (MetaMonitorManager *monitor_manager, meta_cursor_renderer_force_update (cursor_renderer); } -static void -on_monitors_changed (MetaMonitorManager *monitor_manager, - MetaDisplay *display) -{ - g_signal_emit (display, display_signals[MONITORS_CHANGED], 0); -} - void meta_display_restacked (MetaDisplay *display) { diff --git a/src/core/edge-resistance.c b/src/core/edge-resistance.c index 1983904b4..245e6ae52 100644 --- a/src/core/edge-resistance.c +++ b/src/core/edge-resistance.c @@ -1064,14 +1064,18 @@ compute_resistance_and_snapping_edges (MetaDisplay *display) { GList *new_edges; MetaEdge *new_edge; + MetaRectangle display_rect = { 0 }; MetaRectangle reduced; + meta_display_get_size (display, + &display_rect.width, &display_rect.height); + /* We don't care about snapping to any portion of the window that * is offscreen (we also don't care about parts of edges covered * by other windows or DOCKS, but that's handled below). */ meta_rectangle_intersect (&cur_rect, - &display->rect, + &display_rect, &reduced); new_edges = NULL; diff --git a/src/core/window.c b/src/core/window.c index 3526f3cc6..0a5772e64 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -5618,13 +5618,17 @@ meta_window_recalc_features (MetaWindow *window) if (!window->has_resize_func) { window->has_maximize_func = FALSE; + MetaRectangle display_rect = { 0 }; + + meta_display_get_size (window->display, &display_rect.width, + &display_rect.height); /* don't allow fullscreen if we can't resize, unless the size * is entire screen size (kind of broken, because we * actually fullscreen to monitor size not screen size) */ - if (window->size_hints.min_width == window->display->rect.width && - window->size_hints.min_height == window->display->rect.height) + if (window->size_hints.min_width == display_rect.width && + window->size_hints.min_height == display_rect.height) ; /* leave fullscreen available */ else window->has_fullscreen_func = FALSE; @@ -6511,9 +6515,14 @@ meta_window_get_work_area_all_monitors (MetaWindow *window, MetaRectangle *area) { GList *tmp; + MetaRectangle display_rect = { 0 }; + + meta_display_get_size (window->display, + &display_rect.width, + &display_rect.height); /* Initialize to the whole display */ - *area = window->display->rect; + *area = display_rect; tmp = meta_window_get_workspaces (window); while (tmp != NULL) @@ -6731,10 +6740,14 @@ warp_grab_pointer (MetaWindow *window, int *x, int *y) { - MetaRectangle rect; - MetaDisplay *display; + MetaRectangle rect; + MetaRectangle display_rect = { 0 }; + MetaDisplay *display; display = window->display; + meta_display_get_size (display, + &display_rect.width, + &display_rect.height); /* We may not have done begin_grab_op yet, i.e. may not be in a grab */ @@ -6759,8 +6772,8 @@ warp_grab_pointer (MetaWindow *window, *y += rect.y; /* Avoid weird bouncing at the screen edge; see bug 154706 */ - *x = CLAMP (*x, 0, window->display->rect.width-1); - *y = CLAMP (*y, 0, window->display->rect.height-1); + *x = CLAMP (*x, 0, display_rect.width - 1); + *y = CLAMP (*y, 0, display_rect.height - 1); meta_error_trap_push (display->x11_display); diff --git a/src/core/workspace.c b/src/core/workspace.c index 3de8c7b4e..8479fe13b 100644 --- a/src/core/workspace.c +++ b/src/core/workspace.c @@ -794,6 +794,7 @@ ensure_work_areas_validated (MetaWorkspace *workspace) GList *windows; GList *tmp; GList *logical_monitors, *l; + MetaRectangle display_rect = { 0 }; MetaRectangle work_area; if (!workspace->work_areas_invalid) @@ -804,6 +805,10 @@ ensure_work_areas_validated (MetaWorkspace *workspace) g_assert (workspace->screen_edges == NULL); g_assert (workspace->monitor_edges == NULL); + meta_display_get_size (workspace->display, + &display_rect.width, + &display_rect.height); + /* STEP 1: Get the list of struts */ workspace->all_struts = copy_strut_list (workspace->builtin_struts); @@ -846,13 +851,13 @@ ensure_work_areas_validated (MetaWorkspace *workspace) workspace->screen_region = meta_rectangle_get_minimal_spanning_set_for_region ( - &workspace->display->rect, + &display_rect, workspace->all_struts); /* STEP 3: Get the work areas (region-to-maximize-to) for the screen and * monitors. */ - work_area = workspace->display->rect; /* start with the screen */ + work_area = display_rect; /* start with the screen */ if (workspace->screen_region == NULL) work_area = meta_rect (0, 0, -1, -1); else @@ -869,7 +874,7 @@ ensure_work_areas_validated (MetaWorkspace *workspace) work_area.width, MIN_SANE_AREA); if (work_area.width < 1) { - work_area.x = (workspace->display->rect.width - MIN_SANE_AREA)/2; + work_area.x = (display_rect.width - MIN_SANE_AREA)/2; work_area.width = MIN_SANE_AREA; } else @@ -886,7 +891,7 @@ ensure_work_areas_validated (MetaWorkspace *workspace) work_area.height, MIN_SANE_AREA); if (work_area.height < 1) { - work_area.y = (workspace->display->rect.height - MIN_SANE_AREA)/2; + work_area.y = (display_rect.height - MIN_SANE_AREA)/2; work_area.height = MIN_SANE_AREA; } else @@ -953,7 +958,7 @@ ensure_work_areas_validated (MetaWorkspace *workspace) g_assert (workspace->screen_edges == NULL); g_assert (workspace->monitor_edges == NULL); workspace->screen_edges = - meta_rectangle_find_onscreen_edges (&workspace->display->rect, + meta_rectangle_find_onscreen_edges (&display_rect, workspace->all_struts); tmp = NULL; for (l = logical_monitors; l; l = l->next) @@ -1005,8 +1010,11 @@ meta_workspace_set_builtin_struts (MetaWorkspace *workspace, MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); MetaDisplay *display = workspace->display; + MetaRectangle display_rect = { 0 }; GSList *l; + meta_display_get_size (display, &display_rect.width, &display_rect.height); + for (l = struts; l; l = l->next) { MetaStrut *strut = l->data; @@ -1033,7 +1041,7 @@ meta_workspace_set_builtin_struts (MetaWorkspace *workspace, META_DISPLAY_DOWN)) continue; - strut->rect.height = display->rect.height - strut->rect.y; + strut->rect.height = display_rect.height - strut->rect.y; break; case META_SIDE_LEFT: if (meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager, @@ -1050,7 +1058,7 @@ meta_workspace_set_builtin_struts (MetaWorkspace *workspace, META_DISPLAY_RIGHT)) continue; - strut->rect.width = display->rect.width - strut->rect.x; + strut->rect.width = display_rect.width - strut->rect.x; break; } } diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index 5827ad884..21218e9a8 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -84,8 +84,8 @@ static const char *net_wm_name = "Mutter"; static char *get_screen_name (Display *xdisplay, int number); -static void on_monitors_changed (MetaDisplay *display, - MetaX11Display *x11_display); +static void on_monitors_changed_internal (MetaMonitorManager *monitor_manager, + MetaX11Display *x11_display); static void update_cursor_theme (MetaX11Display *x11_display); static void unset_wm_check_hint (MetaX11Display *x11_display); @@ -507,12 +507,15 @@ static void set_desktop_geometry_hint (MetaX11Display *x11_display) { unsigned long data[2]; + int monitor_width, monitor_height; if (x11_display->display->closing > 0) return; - data[0] = x11_display->display->rect.width; - data[1] = x11_display->display->rect.height; + meta_display_get_size (x11_display->display, &monitor_width, &monitor_height); + + data[0] = monitor_width; + data[1] = monitor_height; meta_verbose ("Setting _NET_DESKTOP_GEOMETRY to %lu, %lu\n", data[0], data[1]); @@ -993,6 +996,9 @@ meta_x11_display_new (MetaDisplay *display, GError **error) GdkDisplay *gdk_display; const char *gdk_gl_env = NULL; const char *xdisplay_name; + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); xdisplay_name = g_getenv ("DISPLAY"); if (!xdisplay_name) @@ -1158,9 +1164,9 @@ meta_x11_display_new (MetaDisplay *display, GError **error) x11_display->group_prop_hooks = NULL; meta_x11_display_init_group_prop_hooks (x11_display); - g_signal_connect_object (display, - "monitors-changed", - G_CALLBACK (on_monitors_changed), + g_signal_connect_object (monitor_manager, + "monitors-changed-internal", + G_CALLBACK (on_monitors_changed_internal), x11_display, 0); @@ -1554,6 +1560,11 @@ create_guard_window (MetaX11Display *x11_display) XSetWindowAttributes attributes; Window guard_window; gulong create_serial; + int display_width, display_height; + + meta_display_get_size (x11_display->display, + &display_width, + &display_height); attributes.event_mask = NoEventMask; attributes.override_redirect = True; @@ -1566,8 +1577,8 @@ create_guard_window (MetaX11Display *x11_display) x11_display->xroot, 0, /* x */ 0, /* y */ - x11_display->display->rect.width, - x11_display->display->rect.height, + display_width, + display_height, 0, /* border width */ 0, /* depth */ InputOnly, /* class */ @@ -1618,9 +1629,15 @@ meta_x11_display_create_guard_window (MetaX11Display *x11_display) } static void -on_monitors_changed (MetaDisplay *display, - MetaX11Display *x11_display) +on_monitors_changed_internal (MetaMonitorManager *monitor_manager, + MetaX11Display *x11_display) { + int display_width, display_height; + + meta_monitor_manager_get_screen_size (monitor_manager, + &display_width, + &display_height); + set_desktop_geometry_hint (x11_display); /* Resize the guard window to fill the screen again. */ @@ -1630,8 +1647,8 @@ on_monitors_changed (MetaDisplay *display, changes.x = 0; changes.y = 0; - changes.width = display->rect.width; - changes.height = display->rect.height; + changes.width = display_width; + changes.height = display_height; XConfigureWindow (x11_display->xdisplay, x11_display->guard_window, diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index 631bb2501..216d8c70b 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -1343,9 +1343,10 @@ meta_window_x11_update_struts (MetaWindow *window) strut_begin = struts[4+(i*2)]; strut_end = struts[4+(i*2)+1]; - temp = g_new (MetaStrut, 1); + temp = g_new0 (MetaStrut, 1); temp->side = 1 << i; /* See MetaSide def. Matches nicely, eh? */ - temp->rect = window->display->rect; + meta_display_get_size (window->display, + &temp->rect.width, &temp->rect.height); switch (temp->side) { case META_SIDE_RIGHT: @@ -1406,9 +1407,10 @@ meta_window_x11_update_struts (MetaWindow *window) if (thickness == 0) continue; - temp = g_new (MetaStrut, 1); + temp = g_new0 (MetaStrut, 1); temp->side = 1 << i; - temp->rect = window->display->rect; + meta_display_get_size (window->display, + &temp->rect.width, &temp->rect.height); switch (temp->side) { case META_SIDE_RIGHT: