kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone

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

88c283
From 849902beff553de41dd3940b17672ef98f687be5 Mon Sep 17 00:00:00 2001
776610
From: Rui Matos <tiagomatos@gmail.com>
776610
Date: Mon, 4 Jun 2018 16:35:04 -0400
776610
Subject: [PATCH] monitor-manager-xrandr: Force an update when resuming from
776610
 suspend
776610
776610
The stack below us isn't as reliable as we'd like and in some cases
776610
doesn't generate RRScreenChangeNotify events when e.g. resuming a
776610
laptop on a dock, meaning that we'd miss newly attached outputs.
776610
---
776610
 src/backends/meta-gpu.c                       |  7 ++
88c283
 src/backends/meta-gpu.h                       |  4 +
776610
 src/backends/x11/meta-gpu-xrandr.c            | 26 ++++-
776610
 .../x11/meta-monitor-manager-xrandr.c         | 96 +++++++++++++++++--
88c283
 4 files changed, 123 insertions(+), 10 deletions(-)
776610
776610
diff --git a/src/backends/meta-gpu.c b/src/backends/meta-gpu.c
776610
index 3577391e5..946f72387 100644
776610
--- a/src/backends/meta-gpu.c
776610
+++ b/src/backends/meta-gpu.c
776610
@@ -64,6 +64,13 @@ meta_gpu_has_hotplug_mode_update (MetaGpu *gpu)
776610
   return FALSE;
776610
 }
776610
 
776610
+void
776610
+meta_gpu_poll_hardware (MetaGpu *gpu)
776610
+{
776610
+  if (META_GPU_GET_CLASS (gpu)->poll_hardware)
776610
+    META_GPU_GET_CLASS (gpu)->poll_hardware (gpu);
776610
+}
776610
+
776610
 gboolean
776610
 meta_gpu_read_current (MetaGpu  *gpu,
776610
                        GError  **error)
776610
diff --git a/src/backends/meta-gpu.h b/src/backends/meta-gpu.h
88c283
index 701acdc97..a2fd061f7 100644
776610
--- a/src/backends/meta-gpu.h
776610
+++ b/src/backends/meta-gpu.h
88c283
@@ -36,8 +36,12 @@ struct _MetaGpuClass
776610
 
776610
   gboolean (* read_current) (MetaGpu  *gpu,
776610
                              GError  **error);
776610
+  void     (* poll_hardware) (MetaGpu *gpu);
776610
 };
776610
 
88c283
+META_EXPORT_TEST
776610
+void meta_gpu_poll_hardware (MetaGpu *gpu);
88c283
+
88c283
 META_EXPORT_TEST
776610
 gboolean meta_gpu_read_current (MetaGpu  *gpu,
776610
                                 GError  **error);
776610
diff --git a/src/backends/x11/meta-gpu-xrandr.c b/src/backends/x11/meta-gpu-xrandr.c
88c283
index 3e8a7318d..90b33d486 100644
776610
--- a/src/backends/x11/meta-gpu-xrandr.c
776610
+++ b/src/backends/x11/meta-gpu-xrandr.c
776610
@@ -44,6 +44,8 @@ struct _MetaGpuXrandr
776610
 
776610
   int max_screen_width;
776610
   int max_screen_height;
776610
+
776610
+  gboolean need_hardware_poll;
776610
 };
776610
 
776610
 G_DEFINE_TYPE (MetaGpuXrandr, meta_gpu_xrandr, META_TYPE_GPU)
776610
@@ -81,6 +83,14 @@ get_xmode_name (XRRModeInfo *xmode)
776610
   return g_strdup_printf ("%dx%d", width, height);
776610
 }
776610
 
776610
+static void
776610
+meta_gpu_xrandr_poll_hardware (MetaGpu *gpu)
776610
+{
776610
+  MetaGpuXrandr *gpu_xrandr = META_GPU_XRANDR (gpu);
776610
+
776610
+  gpu_xrandr->need_hardware_poll = TRUE;
776610
+}
776610
+
776610
 static gboolean
776610
 meta_gpu_xrandr_read_current (MetaGpu  *gpu,
776610
                               GError  **error)
88c283
@@ -116,8 +126,18 @@ meta_gpu_xrandr_read_current (MetaGpu  *gpu,
776610
   monitor_manager->screen_width = WidthOfScreen (screen);
776610
   monitor_manager->screen_height = HeightOfScreen (screen);
776610
 
776610
-  resources = XRRGetScreenResourcesCurrent (xdisplay,
776610
-                                            DefaultRootWindow (xdisplay));
776610
+  if (gpu_xrandr->need_hardware_poll)
776610
+    {
776610
+      resources = XRRGetScreenResources (xdisplay,
776610
+                                         DefaultRootWindow (xdisplay));
776610
+      gpu_xrandr->need_hardware_poll = FALSE;
776610
+    }
776610
+  else
776610
+    {
776610
+      resources = XRRGetScreenResourcesCurrent (xdisplay,
776610
+                                                DefaultRootWindow (xdisplay));
776610
+    }
776610
+
776610
   if (!resources)
776610
     {
776610
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
88c283
@@ -250,6 +270,7 @@ meta_gpu_xrandr_finalize (GObject *object)
776610
 static void
776610
 meta_gpu_xrandr_init (MetaGpuXrandr *gpu_xrandr)
776610
 {
776610
+  gpu_xrandr->need_hardware_poll = TRUE;
776610
 }
776610
 
776610
 static void
88c283
@@ -261,4 +282,5 @@ meta_gpu_xrandr_class_init (MetaGpuXrandrClass *klass)
776610
   object_class->finalize = meta_gpu_xrandr_finalize;
776610
 
776610
   gpu_class->read_current = meta_gpu_xrandr_read_current;
776610
+  gpu_class->poll_hardware = meta_gpu_xrandr_poll_hardware;
776610
 }
776610
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
88c283
index 448e51fae..d60f00325 100644
776610
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
776610
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
88c283
@@ -71,6 +71,10 @@ struct _MetaMonitorManagerXrandr
776610
   Display *xdisplay;
776610
   int rr_event_base;
776610
   int rr_error_base;
776610
+
776610
+  guint logind_watch_id;
776610
+  guint logind_signal_sub_id;
776610
+
776610
   gboolean has_randr15;
776610
 
776610
   /*
88c283
@@ -102,6 +106,8 @@ typedef struct _MetaMonitorXrandrData
88c283
 
776610
 GQuark quark_meta_monitor_xrandr_data;
776610
 
776610
+static void meta_monitor_manager_xrandr_update (MetaMonitorManagerXrandr *manager_xrandr);
776610
+
776610
 Display *
776610
 meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *manager_xrandr)
776610
 {
88c283
@@ -1016,6 +1022,62 @@ meta_monitor_manager_xrandr_get_default_layout_mode (MetaMonitorManager *manager
776610
   return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
776610
 }
776610
 
776610
+static void
776610
+logind_signal_handler (GDBusConnection *connection,
776610
+                       const gchar     *sender_name,
776610
+                       const gchar     *object_path,
776610
+                       const gchar     *interface_name,
776610
+                       const gchar     *signal_name,
776610
+                       GVariant        *parameters,
776610
+                       gpointer         user_data)
776610
+{
776610
+  MetaMonitorManagerXrandr *manager_xrandr = user_data;
776610
+  gboolean suspending;
776610
+
776610
+  if (!g_str_equal (signal_name, "PrepareForSleep"))
776610
+    return;
776610
+
776610
+  g_variant_get (parameters, "(b)", &suspending);
776610
+  if (!suspending)
776610
+    {
776610
+      meta_gpu_poll_hardware (manager_xrandr->gpu);
776610
+      meta_monitor_manager_xrandr_update (manager_xrandr);
776610
+    }
776610
+}
776610
+
776610
+static void
776610
+logind_appeared (GDBusConnection *connection,
776610
+                 const gchar     *name,
776610
+                 const gchar     *name_owner,
776610
+                 gpointer         user_data)
776610
+{
776610
+  MetaMonitorManagerXrandr *manager_xrandr = user_data;
776610
+
776610
+  manager_xrandr->logind_signal_sub_id = g_dbus_connection_signal_subscribe (connection,
776610
+                                                                             "org.freedesktop.login1",
776610
+                                                                             "org.freedesktop.login1.Manager",
776610
+                                                                             "PrepareForSleep",
776610
+                                                                             "/org/freedesktop/login1",
776610
+                                                                             NULL,
776610
+                                                                             G_DBUS_SIGNAL_FLAGS_NONE,
776610
+                                                                             logind_signal_handler,
776610
+                                                                             manager_xrandr,
776610
+                                                                             NULL);
776610
+}
776610
+
776610
+static void
776610
+logind_vanished (GDBusConnection *connection,
776610
+                 const gchar     *name,
776610
+                 gpointer         user_data)
776610
+{
776610
+  MetaMonitorManagerXrandr *manager_xrandr = user_data;
776610
+
776610
+  if (connection && manager_xrandr->logind_signal_sub_id > 0)
776610
+    g_dbus_connection_signal_unsubscribe (connection, manager_xrandr->logind_signal_sub_id);
776610
+
776610
+  manager_xrandr->logind_signal_sub_id = 0;
776610
+}
776610
+
776610
 static void
776610
 meta_monitor_manager_xrandr_constructed (GObject *object)
776610
 {
88c283
@@ -1072,12 +1134,23 @@ meta_monitor_manager_xrandr_finalize (GObject *object)
776610
   g_hash_table_destroy (manager_xrandr->tiled_monitor_atoms);
776610
   g_free (manager_xrandr->supported_scales);
776610
 
776610
+  if (manager_xrandr->logind_watch_id > 0)
776610
+    g_bus_unwatch_name (manager_xrandr->logind_watch_id);
776610
+  manager_xrandr->logind_watch_id = 0;
776610
+
776610
   G_OBJECT_CLASS (meta_monitor_manager_xrandr_parent_class)->finalize (object);
776610
 }
776610
 
776610
 static void
776610
 meta_monitor_manager_xrandr_init (MetaMonitorManagerXrandr *manager_xrandr)
776610
 {
776610
+  manager_xrandr->logind_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
776610
+                                                      "org.freedesktop.login1",
776610
+                                                      G_BUS_NAME_WATCHER_FLAGS_NONE,
776610
+                                                      logind_appeared,
776610
+                                                      logind_vanished,
776610
+                                                      manager_xrandr,
776610
+                                                      NULL);
776610
 }
776610
 
776610
 static void
88c283
@@ -1123,9 +1196,8 @@ is_xvnc (MetaMonitorManager *manager)
776610
   return FALSE;
776610
 }
776610
 
776610
-gboolean
776610
-meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xrandr,
776610
-					   XEvent                   *event)
776610
+static void
776610
+meta_monitor_manager_xrandr_update (MetaMonitorManagerXrandr *manager_xrandr)
776610
 {
776610
   MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
776610
   MetaGpuXrandr *gpu_xrandr;
88c283
@@ -1134,11 +1206,6 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xra
776610
   gboolean is_our_configuration;
776610
   unsigned int timestamp;
776610
 
776610
-  if ((event->type - manager_xrandr->rr_event_base) != RRScreenChangeNotify)
776610
-    return FALSE;
776610
-
776610
-  XRRUpdateConfiguration (event);
776610
-
776610
   meta_monitor_manager_read_current_state (manager);
776610
 
776610
   gpu_xrandr = META_GPU_XRANDR (manager_xrandr->gpu);
88c283
@@ -1173,6 +1240,19 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xra
776610
 
776610
       meta_monitor_manager_xrandr_rebuild_derived (manager, config);
776610
     }
776610
+}
776610
+
776610
+gboolean
776610
+meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xrandr,
776610
+					   XEvent                   *event)
776610
+{
776610
+
776610
+  if ((event->type - manager_xrandr->rr_event_base) != RRScreenChangeNotify)
776610
+    return FALSE;
776610
+
776610
+  XRRUpdateConfiguration (event);
776610
+
776610
+  meta_monitor_manager_xrandr_update (manager_xrandr);
776610
 
776610
   return TRUE;
776610
 }
776610
-- 
88c283
2.21.0
776610