[mutter/wip/xwayland-on-demand: 27/32] Use MetaMonitorManager insted of MetaDisplay where possible



commit 1838ec08a25b32b9daaba98647d2297d934efa26
Author: Armin Krezović <krezovic armin gmail com>
Date:   Sun Aug 27 20:44:38 2017 +0200

    Use MetaMonitorManager insted of MetaDisplay where possible
    
    This drops display's monitors-changed signal and makes all
    the code rely on MetaMonitorManager.

 src/compositor/meta-background.c |   25 +++++++----------------
 src/compositor/plugins/default.c |   12 +++++++---
 src/core/display-private.h       |    1 -
 src/core/display.c               |   39 ++++++++++++++-----------------------
 src/core/edge-resistance.c       |    5 +++-
 src/core/window.c                |   22 +++++++++++++++-----
 src/core/workspace.c             |   22 +++++++++++++-------
 src/x11/meta-x11-display.c       |   39 +++++++++++++++++++++++++++----------
 src/x11/window-x11.c             |    4 +-
 9 files changed, 95 insertions(+), 74 deletions(-)
---
diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c
index 838b4a4..60a9831 100644
--- a/src/compositor/meta-background.c
+++ b/src/compositor/meta-background.c
@@ -21,6 +21,7 @@
 #include <meta/util.h>
 #include <meta/meta-background.h>
 #include <meta/meta-background-image.h>
+#include <meta/meta-monitor-manager.h>
 #include "meta-background-private.h"
 #include "cogl-utils.h"
 
@@ -129,8 +130,7 @@ free_wallpaper_texture (MetaBackground *self)
 }
 
 static void
-on_monitors_changed (MetaDisplay    *display,
-                     MetaBackground *self)
+on_monitors_changed (MetaBackground *self)
 {
   MetaBackgroundPrivate *priv = self->priv;
 
@@ -143,7 +143,7 @@ on_monitors_changed (MetaDisplay    *display,
     {
       int i;
 
-      priv->n_monitors = meta_display_get_n_monitors (display);
+      priv->n_monitors = meta_display_get_n_monitors (priv->display);
       priv->monitors = g_new0 (MetaBackgroundMonitor, priv->n_monitors);
 
       for (i = 0; i < priv->n_monitors; i++)
@@ -157,22 +157,9 @@ set_display (MetaBackground *self,
 {
   MetaBackgroundPrivate *priv = self->priv;
 
-  if (priv->display != NULL)
-    {
-      g_signal_handlers_disconnect_by_func (priv->display,
-                                            (gpointer)on_monitors_changed,
-                                            self);
-    }
-
   priv->display = display;
 
-  if (priv->display != NULL)
-    {
-      g_signal_connect (priv->display, "monitors-changed",
-                        G_CALLBACK (on_monitors_changed), self);
-    }
-
-  on_monitors_changed (priv->display, self);
+  on_monitors_changed (self);
 }
 
 static void
@@ -323,11 +310,15 @@ 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 ccf500a..12adbf2 100644
--- a/src/compositor/plugins/default.c
+++ b/src/compositor/plugins/default.c
@@ -26,6 +26,7 @@
 #include <meta/window.h>
 #include <meta/meta-background-group.h>
 #include <meta/meta-background-actor.h>
+#include <meta/meta-monitor-manager.h>
 #include <meta/util.h>
 #include <glib/gi18n-lib.h>
 
@@ -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 652ce81..26970ad 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 1f761ff..127d657 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
@@ -513,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),
@@ -725,7 +717,9 @@ meta_display_open (void)
   int i;
   guint32 timestamp;
   Window old_active_xwindow = None;
-  MetaMonitorManager *manager;
+  MetaBackend *backend = meta_get_backend ();
+  MetaMonitorManager *monitor_manager
+    = meta_backend_get_monitor_manager (backend);
 
   g_assert (the_display == NULL);
   display = the_display = g_object_new (META_TYPE_DISPLAY, NULL);
@@ -739,7 +733,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;
@@ -787,14 +780,9 @@ meta_display_open (void)
                                       g_int64_equal);
   display->wayland_windows = g_hash_table_new (NULL, NULL);
 
-  manager = meta_monitor_manager_get ();
-  g_signal_connect (manager, "monitors-changed",
+  g_signal_connect (monitor_manager, "monitors-changed",
                     G_CALLBACK (on_monitors_changed), display);
 
-  meta_monitor_manager_get_screen_size (manager,
-                                        &display->rect.width,
-                                        &display->rect.height);
-
   meta_display_set_cursor (display, META_CURSOR_DEFAULT);
 
   display->stack = meta_stack_new (display);
@@ -2754,11 +2742,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;
 }
 
 /**
@@ -3069,10 +3066,6 @@ on_monitors_changed (MetaMonitorManager *manager,
   MetaBackend *backend;
   MetaCursorRenderer *cursor_renderer;
 
-  meta_monitor_manager_get_screen_size (manager,
-                                        &display->rect.width,
-                                        &display->rect.height);
-
   reload_logical_monitors (display);
 
   /* Fix up monitor for all windows on this display */
@@ -3089,8 +3082,6 @@ on_monitors_changed (MetaMonitorManager *manager,
   backend = meta_get_backend ();
   cursor_renderer = meta_backend_get_cursor_renderer (backend);
   meta_cursor_renderer_force_update (cursor_renderer);
-
-  g_signal_emit (display, display_signals[MONITORS_CHANGED], 0);
 }
 
 void
diff --git a/src/core/edge-resistance.c b/src/core/edge-resistance.c
index 40031e5..786cf9f 100644
--- a/src/core/edge-resistance.c
+++ b/src/core/edge-resistance.c
@@ -1020,14 +1020,17 @@ compute_resistance_and_snapping_edges (MetaDisplay *display)
         {
           GList *new_edges;
           MetaEdge *new_edge;
+          MetaRectangle display_rect;
           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 4b50ce0..274ce39 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -5311,13 +5311,17 @@ meta_window_recalc_features (MetaWindow *window)
   if (!window->has_resize_func)
     {
       window->has_maximize_func = FALSE;
+      MetaRectangle display_rect;
+
+      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;
@@ -6209,9 +6213,13 @@ meta_window_get_work_area_all_monitors (MetaWindow    *window,
                                         MetaRectangle *area)
 {
   GList *tmp;
+  MetaRectangle display_rect;
+
+  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)
@@ -6426,10 +6434,12 @@ warp_grab_pointer (MetaWindow          *window,
                    int                 *x,
                    int                 *y)
 {
-  MetaRectangle  rect;
+  MetaRectangle  display_rect, rect;
   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
    */
@@ -6454,8 +6464,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 2984a2f..116862d 100644
--- a/src/core/workspace.c
+++ b/src/core/workspace.c
@@ -793,7 +793,7 @@ ensure_work_areas_validated (MetaWorkspace *workspace)
   GList *windows;
   GList *tmp;
   GList *logical_monitors, *l;
-  MetaRectangle work_area;
+  MetaRectangle display_rect, work_area;
 
   if (!workspace->work_areas_invalid)
     return;
@@ -803,6 +803,9 @@ 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);
@@ -845,13 +848,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
@@ -868,7 +871,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
@@ -885,7 +888,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
@@ -952,7 +955,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)
@@ -1004,8 +1007,11 @@ meta_workspace_set_builtin_struts (MetaWorkspace *workspace,
   MetaMonitorManager *monitor_manager =
     meta_backend_get_monitor_manager (backend);
   MetaDisplay *display = workspace->display;
+  MetaRectangle display_rect;
   GSList *l;
 
+  meta_display_get_size (display, &display_rect.width, &display_rect.height);
+
   for (l = struts; l; l = l->next)
     {
       MetaStrut *strut = l->data;
@@ -1032,7 +1038,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,
@@ -1049,7 +1055,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 2840398..795f486 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 (MetaMonitorManager *monitor_manager,
+                                 MetaX11Display     *x11_display);
 
 static void update_cursor_theme (MetaX11Display *x11_display);
 static void unset_wm_check_hint (MetaX11Display *x11_display);
@@ -501,12 +501,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]);
 
@@ -987,6 +990,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)
@@ -1152,7 +1158,7 @@ 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,
+  g_signal_connect_object (monitor_manager,
                            "monitors-changed",
                            G_CALLBACK (on_monitors_changed),
                            x11_display,
@@ -1549,6 +1555,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;
@@ -1561,8 +1572,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 */
@@ -1613,9 +1624,15 @@ meta_x11_display_create_guard_window (MetaX11Display *x11_display)
 }
 
 static void
-on_monitors_changed (MetaDisplay    *display,
-                     MetaX11Display *x11_display)
+on_monitors_changed (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. */
@@ -1625,8 +1642,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 f210d73..343ce2e 100644
--- a/src/x11/window-x11.c
+++ b/src/x11/window-x11.c
@@ -1317,7 +1317,7 @@ meta_window_x11_update_struts (MetaWindow *window)
 
               temp = g_new (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:
@@ -1380,7 +1380,7 @@ meta_window_x11_update_struts (MetaWindow *window)
 
               temp = g_new (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:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]