Blame SOURCES/0001-monitor-manager-xrandr-Force-an-update-when-resuming.patch

e3f29c
From ed7cad0561b79e68ddd91f0e12042087199676ea Mon Sep 17 00:00:00 2001
db633a
From: Rui Matos <tiagomatos@gmail.com>
db633a
Date: Sun, 25 Oct 2015 16:14:58 +0100
e3f29c
Subject: [PATCH 3/8] monitor-manager-xrandr: Force an update when resuming
e3f29c
 from suspend
db633a
db633a
The stack below us isn't as reliable as we'd like and in some cases
db633a
doesn't generate RRScreenChangeNotify events when e.g. resuming a
db633a
laptop on a dock, meaning that we'd miss newly attached outputs.
db633a
---
e3f29c
 src/backends/x11/meta-monitor-manager-xrandr.c | 188 ++++++++++++++++++-------
e3f29c
 1 file changed, 137 insertions(+), 51 deletions(-)
db633a
db633a
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
e3f29c
index 8d1bdfb69..d451fcccc 100644
db633a
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
db633a
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
e3f29c
@@ -61,6 +61,11 @@ struct _MetaMonitorManagerXrandr
db633a
   XRRScreenResources *resources;
db633a
   int rr_event_base;
db633a
   int rr_error_base;
db633a
+
db633a
+  guint logind_watch_id;
db633a
+  guint logind_signal_sub_id;
db633a
+
db633a
+  gboolean need_hardware_poll;
db633a
   gboolean has_randr15;
db633a
 
e3f29c
   xcb_timestamp_t last_xrandr_set_timestamp;
e3f29c
@@ -787,8 +792,15 @@ meta_monitor_manager_xrandr_read_current (MetaMonitorManager *manager)
db633a
   manager->screen_width = WidthOfScreen (screen);
db633a
   manager->screen_height = HeightOfScreen (screen);
db633a
 
db633a
-  resources = XRRGetScreenResourcesCurrent (manager_xrandr->xdisplay,
db633a
-					    DefaultRootWindow (manager_xrandr->xdisplay));
db633a
+  if (manager_xrandr->need_hardware_poll)
db633a
+    {
db633a
+      resources = XRRGetScreenResources (manager_xrandr->xdisplay,
db633a
+                                         DefaultRootWindow (manager_xrandr->xdisplay));
db633a
+      manager_xrandr->need_hardware_poll = FALSE;
db633a
+    }
db633a
+  else
db633a
+    resources = XRRGetScreenResourcesCurrent (manager_xrandr->xdisplay,
db633a
+                                              DefaultRootWindow (manager_xrandr->xdisplay));
db633a
   if (!resources)
db633a
     return;
db633a
 
e3f29c
@@ -1910,6 +1922,115 @@ meta_monitor_manager_xrandr_get_default_layout_mode (MetaMonitorManager *manager
e3f29c
   return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
db633a
 }
db633a
 
db633a
+static gboolean
db633a
+is_xvnc (MetaMonitorManager *manager)
db633a
+{
db633a
+  unsigned int i;
db633a
+
db633a
+  for (i = 0; i < manager->n_outputs; ++i)
db633a
+    if (g_str_has_prefix (manager->outputs[i].name, "VNC-"))
db633a
+      return TRUE;
db633a
+
db633a
+  return FALSE;
db633a
+}
db633a
+
db633a
+static void
db633a
+meta_monitor_manager_xrandr_update (MetaMonitorManagerXrandr *manager_xrandr)
db633a
+{
db633a
+  MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
e3f29c
+  gboolean is_hotplug;
e3f29c
+  gboolean is_our_configuration;
db633a
+  unsigned int timestamp;
db633a
+
e3f29c
+  meta_monitor_manager_read_current_state (manager);
db633a
+
db633a
+  timestamp = manager_xrandr->resources->timestamp;
db633a
+  if (is_xvnc (manager))
db633a
+    timestamp += 100;
db633a
+
e3f29c
+  is_hotplug = (timestamp < manager_xrandr->resources->configTimestamp);
e3f29c
+  is_our_configuration = (manager_xrandr->resources->timestamp ==
e3f29c
+                          manager_xrandr->last_xrandr_set_timestamp);
e3f29c
+  if (is_hotplug)
db633a
+    {
db633a
+      meta_monitor_manager_on_hotplug (manager);
db633a
+    }
db633a
+  else
db633a
+    {
e3f29c
+      MetaMonitorsConfig *config;
e3f29c
+
e3f29c
+      if (is_our_configuration)
e3f29c
+        {
e3f29c
+          MetaMonitorConfigManager *config_manager =
e3f29c
+            meta_monitor_manager_get_config_manager (manager);
e3f29c
+
e3f29c
+          config = meta_monitor_config_manager_get_current (config_manager);
e3f29c
+        }
e3f29c
+      else
e3f29c
+        {
e3f29c
+          config = NULL;
e3f29c
+        }
e3f29c
+
e3f29c
+      meta_monitor_manager_rebuild_derived (manager, config);
db633a
+    }
db633a
+}
db633a
+
db633a
+static void
db633a
+logind_signal_handler (GDBusConnection *connection,
db633a
+                       const gchar     *sender_name,
db633a
+                       const gchar     *object_path,
db633a
+                       const gchar     *interface_name,
db633a
+                       const gchar     *signal_name,
db633a
+                       GVariant        *parameters,
db633a
+                       gpointer         user_data)
db633a
+{
db633a
+  MetaMonitorManagerXrandr *manager_xrandr = user_data;
db633a
+  gboolean suspending;
db633a
+
db633a
+  if (!g_str_equal (signal_name, "PrepareForSleep"))
db633a
+    return;
db633a
+
db633a
+  g_variant_get (parameters, "(b)", &suspending);
db633a
+  if (!suspending)
db633a
+    {
db633a
+      manager_xrandr->need_hardware_poll = TRUE;
db633a
+      meta_monitor_manager_xrandr_update (manager_xrandr);
db633a
+    }
db633a
+}
db633a
+
db633a
+static void
db633a
+logind_appeared (GDBusConnection *connection,
db633a
+                 const gchar     *name,
db633a
+                 const gchar     *name_owner,
db633a
+                 gpointer         user_data)
db633a
+{
db633a
+  MetaMonitorManagerXrandr *manager_xrandr = user_data;
db633a
+
db633a
+  manager_xrandr->logind_signal_sub_id = g_dbus_connection_signal_subscribe (connection,
db633a
+                                                                             "org.freedesktop.login1",
db633a
+                                                                             "org.freedesktop.login1.Manager",
db633a
+                                                                             "PrepareForSleep",
db633a
+                                                                             "/org/freedesktop/login1",
db633a
+                                                                             NULL,
db633a
+                                                                             G_DBUS_SIGNAL_FLAGS_NONE,
db633a
+                                                                             logind_signal_handler,
db633a
+                                                                             manager_xrandr,
db633a
+                                                                             NULL);
db633a
+}
db633a
+
db633a
+static void
db633a
+logind_vanished (GDBusConnection *connection,
db633a
+                 const gchar     *name,
db633a
+                 gpointer         user_data)
db633a
+{
db633a
+  MetaMonitorManagerXrandr *manager_xrandr = user_data;
db633a
+
db633a
+  if (connection && manager_xrandr->logind_signal_sub_id > 0)
db633a
+    g_dbus_connection_signal_unsubscribe (connection, manager_xrandr->logind_signal_sub_id);
db633a
+
db633a
+  manager_xrandr->logind_signal_sub_id = 0;
db633a
+}
db633a
+
db633a
 static void
db633a
 meta_monitor_manager_xrandr_init (MetaMonitorManagerXrandr *manager_xrandr)
db633a
 {
e3f29c
@@ -1948,6 +2069,15 @@ meta_monitor_manager_xrandr_init (MetaMonitorManagerXrandr *manager_xrandr)
db633a
       meta_monitor_manager_xrandr_init_monitors (manager_xrandr);
db633a
 #endif
db633a
     }
db633a
+
db633a
+  manager_xrandr->logind_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
db633a
+                                                      "org.freedesktop.login1",
db633a
+                                                      G_BUS_NAME_WATCHER_FLAGS_NONE,
db633a
+                                                      logind_appeared,
db633a
+                                                      logind_vanished,
db633a
+                                                      manager_xrandr,
db633a
+                                                      NULL);
db633a
+  manager_xrandr->need_hardware_poll = TRUE;
db633a
 }
db633a
 
db633a
 static void
e3f29c
@@ -1962,6 +2092,10 @@ meta_monitor_manager_xrandr_finalize (GObject *object)
e3f29c
   g_hash_table_destroy (manager_xrandr->tiled_monitor_atoms);
e3f29c
   g_free (manager_xrandr->supported_scales);
db633a
 
db633a
+  if (manager_xrandr->logind_watch_id > 0)
db633a
+    g_bus_unwatch_name (manager_xrandr->logind_watch_id);
db633a
+  manager_xrandr->logind_watch_id = 0;
db633a
+
db633a
   G_OBJECT_CLASS (meta_monitor_manager_xrandr_parent_class)->finalize (object);
db633a
 }
db633a
 
e3f29c
@@ -1996,64 +2130,16 @@ meta_monitor_manager_xrandr_class_init (MetaMonitorManagerXrandrClass *klass)
e3f29c
     g_quark_from_static_string ("-meta-monitor-xrandr-data");
db633a
 }
db633a
 
db633a
-static gboolean
db633a
-is_xvnc (MetaMonitorManager *manager)
db633a
-{
db633a
-  unsigned int i;
db633a
-
db633a
-  for (i = 0; i < manager->n_outputs; ++i)
db633a
-    if (g_str_has_prefix (manager->outputs[i].name, "VNC-"))
db633a
-      return TRUE;
db633a
-
db633a
-  return FALSE;
db633a
-}
db633a
-
db633a
 gboolean
db633a
 meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xrandr,
db633a
 					   XEvent                   *event)
db633a
 {
db633a
-  MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
e3f29c
-  gboolean is_hotplug;
e3f29c
-  gboolean is_our_configuration;
db633a
-  unsigned int timestamp;
db633a
-
db633a
   if ((event->type - manager_xrandr->rr_event_base) != RRScreenChangeNotify)
db633a
     return FALSE;
db633a
 
db633a
   XRRUpdateConfiguration (event);
db633a
 
e3f29c
-  meta_monitor_manager_read_current_state (manager);
e3f29c
-
db633a
-
db633a
-  timestamp = manager_xrandr->resources->timestamp;
db633a
-  if (is_xvnc (manager))
db633a
-    timestamp += 100;
db633a
-
e3f29c
-  is_hotplug = (timestamp < manager_xrandr->resources->configTimestamp);
e3f29c
-  is_our_configuration = (manager_xrandr->resources->timestamp ==
e3f29c
-                          manager_xrandr->last_xrandr_set_timestamp);
e3f29c
-  if (is_hotplug)
db633a
-    {
db633a
-      meta_monitor_manager_on_hotplug (manager);
db633a
-    }
db633a
-  else
db633a
-    {
e3f29c
-      MetaMonitorsConfig *config;
e3f29c
-
e3f29c
-      if (is_our_configuration)
e3f29c
-        {
e3f29c
-          MetaMonitorConfigManager *config_manager =
e3f29c
-            meta_monitor_manager_get_config_manager (manager);
e3f29c
-
e3f29c
-          config = meta_monitor_config_manager_get_current (config_manager);
e3f29c
-        }
e3f29c
-      else
e3f29c
-        {
e3f29c
-          config = NULL;
e3f29c
-        }
e3f29c
-
e3f29c
-      meta_monitor_manager_xrandr_rebuild_derived (manager, config);
db633a
-    }
db633a
+  meta_monitor_manager_xrandr_update (manager_xrandr);
db633a
 
db633a
   return TRUE;
db633a
 }
db633a
-- 
e3f29c
2.14.2
db633a