[gnome-builder/wip/chergert/layout] layout: avoid some CSS invalidations when possible
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/layout] layout: avoid some CSS invalidations when possible
- Date: Thu, 6 Jul 2017 02:15:35 +0000 (UTC)
commit 820fe80725478e6e7afcd5c41df1a9177126bc7f
Author: Christian Hergert <chergert redhat com>
Date: Wed Jul 5 19:13:16 2017 -0700
layout: avoid some CSS invalidations when possible
We still need to come up with some more tricks to avoid the
invalidations when transitioning layout views between stacks.
However, this is clearly better than what we have now and at
least fixes the "stable situation" where the colors don't
change on either stack.
libide/layout/ide-layout-stack-header.c | 70 ++++++++++++++++++++++---------
1 files changed, 50 insertions(+), 20 deletions(-)
---
diff --git a/libide/layout/ide-layout-stack-header.c b/libide/layout/ide-layout-stack-header.c
index eb9c15e..b9b3ed7 100644
--- a/libide/layout/ide-layout-stack-header.c
+++ b/libide/layout/ide-layout-stack-header.c
@@ -20,8 +20,10 @@
#include <glib/gi18n.h>
-#include "ide-layout-private.h"
-#include "ide-layout-stack-header.h"
+#include "ide-macros.h"
+
+#include "layout/ide-layout-private.h"
+#include "layout/ide-layout-stack-header.h"
struct _IdeLayoutStackHeader
{
@@ -33,6 +35,8 @@ struct _IdeLayoutStackHeader
GdkRGBA background_rgba;
GdkRGBA foreground_rgba;
+ guint update_css_handler;
+
guint background_rgba_set : 1;
guint foreground_rgba_set : 1;
@@ -271,7 +275,7 @@ ide_layout_stack_header_view_row_activated (GtkListBox *list_box,
IDE_LAYOUT_VIEW (view));
}
-static void
+static gboolean
ide_layout_stack_header_update_css (IdeLayoutStackHeader *self)
{
g_autoptr(GString) str = NULL;
@@ -323,44 +327,68 @@ ide_layout_stack_header_update_css (IdeLayoutStackHeader *self)
}
if (!gtk_css_provider_load_from_data (self->background_css, str->str, str->len, &error))
- g_warning ("Failed to load CSS: '%s': %s",
- str->str, error->message);
+ g_warning ("Failed to load CSS: '%s': %s", str->str, error->message);
+
+ self->update_css_handler = 0;
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+ide_layout_stack_header_queue_update_css (IdeLayoutStackHeader *self)
+{
+ g_assert (IDE_IS_LAYOUT_STACK_HEADER (self));
- gtk_widget_queue_resize (GTK_WIDGET (self));
+ ide_clear_source (&self->update_css_handler);
+
+ /* So low priority we don't really care */
+ self->update_css_handler = gdk_threads_add_timeout_full (G_PRIORITY_HIGH,
+ 0,
+ (GSourceFunc) ide_layout_stack_header_update_css,
+ g_object_ref (self),
+ g_object_unref);
}
void
_ide_layout_stack_header_set_background_rgba (IdeLayoutStackHeader *self,
const GdkRGBA *background_rgba)
{
+ GdkRGBA old;
+ gboolean old_set;
+
g_assert (IDE_IS_LAYOUT_STACK_HEADER (self));
- self->background_rgba_set = FALSE;
+ old_set = self->background_rgba_set;
+ old = self->background_rgba;
- if (background_rgba)
- {
- self->background_rgba = *background_rgba;
- self->background_rgba_set = TRUE;
- }
+ if (background_rgba != NULL)
+ self->background_rgba = *background_rgba;
+
+ self->background_rgba_set = !!background_rgba;
- ide_layout_stack_header_update_css (self);
+ if (self->background_rgba_set != old_set || !gdk_rgba_equal (&self->background_rgba, &old))
+ ide_layout_stack_header_queue_update_css (self);
}
void
_ide_layout_stack_header_set_foreground_rgba (IdeLayoutStackHeader *self,
const GdkRGBA *foreground_rgba)
{
+ GdkRGBA old;
+ gboolean old_set;
+
g_assert (IDE_IS_LAYOUT_STACK_HEADER (self));
- self->foreground_rgba_set = FALSE;
+ old_set = self->foreground_rgba_set;
+ old = self->foreground_rgba;
- if (foreground_rgba)
- {
- self->foreground_rgba = *foreground_rgba;
- self->foreground_rgba_set = TRUE;
- }
+ if (foreground_rgba != NULL)
+ self->foreground_rgba = *foreground_rgba;
- ide_layout_stack_header_update_css (self);
+ self->foreground_rgba_set = !!foreground_rgba;
+
+ if (self->background_rgba_set != old_set || !gdk_rgba_equal (&self->foreground_rgba, &old))
+ ide_layout_stack_header_queue_update_css (self);
}
static void
@@ -370,6 +398,8 @@ ide_layout_stack_header_destroy (GtkWidget *widget)
g_assert (IDE_IS_LAYOUT_STACK_HEADER (self));
+ ide_clear_source (&self->update_css_handler);
+
if (self->background_css != NULL)
{
gtk_style_context_remove_provider_for_screen (gdk_screen_get_default (),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]