[gnome-flashback] desktop-background: redraw background in idle



commit 6be4bd68bf87c9ca4b71438eb9f4ece189e64052
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Aug 29 14:45:01 2019 +0300

    desktop-background: redraw background in idle
    
    Root window size is updated after size-changed signal meaning that
    we will get old root window size in signal handler.
    
    GTK is calling _gdk_x11_screen_size_changed when configuring root
    window but when that happens screen size has already been updated
    and size-changed signal will not be emitted.
    
    Redraw background in idle to make sure that we do that only once
    and GTK has finished processing x11 events.
    
    https://gitlab.gnome.org/GNOME/gnome-flashback/issues/23

 .../libdesktop-background/gf-desktop-background.c  | 34 ++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/gnome-flashback/libdesktop-background/gf-desktop-background.c 
b/gnome-flashback/libdesktop-background/gf-desktop-background.c
index b3c4781..4fccbc1 100644
--- a/gnome-flashback/libdesktop-background/gf-desktop-background.c
+++ b/gnome-flashback/libdesktop-background/gf-desktop-background.c
@@ -30,6 +30,8 @@ struct _GfDesktopBackground
   gulong            size_changed_id;
   gulong            change_event_id;
 
+  guint             redraw_idle_id;
+
   GnomeBG          *bg;
   GnomeBGCrossfade *fade;
 
@@ -112,18 +114,40 @@ transitioned_cb (GnomeBG             *bg,
   draw_background (background, FALSE);
 }
 
+static gboolean
+redraw_cb (gpointer user_data)
+{
+  GfDesktopBackground *background;
+
+  background = GF_DESKTOP_BACKGROUND (user_data);
+
+  draw_background (background, FALSE);
+
+  background->redraw_idle_id = 0;
+  return G_SOURCE_REMOVE;
+}
+
+static void
+queue_redraw (GfDesktopBackground *background)
+{
+  if (background->redraw_idle_id != 0)
+    return;
+
+  background->redraw_idle_id = g_idle_add (redraw_cb, background);
+}
+
 static void
 monitors_changed_cb (GdkScreen           *screen,
                      GfDesktopBackground *background)
 {
-  draw_background (background, FALSE);
+  queue_redraw (background);
 }
 
 static void
 size_changed_cb (GdkScreen           *screen,
                  GfDesktopBackground *background)
 {
-  draw_background (background, FALSE);
+  queue_redraw (background);
 }
 
 static void
@@ -153,6 +177,12 @@ gf_desktop_background_dispose (GObject *object)
       background->change_event_id = 0;
     }
 
+  if (background->redraw_idle_id != 0)
+    {
+      g_source_remove (background->redraw_idle_id);
+      background->redraw_idle_id = 0;
+    }
+
   g_clear_object (&background->bg);
   g_clear_object (&background->fade);
   g_clear_object (&background->settings);


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