From 2d5a6a36d81a25798f50f6e03395d90c94b4fac2 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Thu, 16 Jun 2016 22:46:51 +0200
Subject: [PATCH] Prepare the style provider only once.

Added names for the main styled gui elements for easier styling via css.
---
 src/completion.c |  5 ++---
 src/main.c       | 11 +++++++----
 src/main.h       |  1 +
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/completion.c b/src/completion.c
index 714ddcf..8bda61f 100644
--- a/src/completion.c
+++ b/src/completion.c
@@ -98,11 +98,10 @@ gboolean completion_create(Client *c, GtkTreeModel *model,
     comp->win  = gtk_scrolled_window_new(NULL, NULL);
     comp->tree = gtk_tree_view_new();
 
-    GtkCssProvider* provider = gtk_css_provider_get_default();
-    gtk_css_provider_load_from_data(provider, GUI_STYLE, -1, NULL);
     gtk_style_context_add_provider(gtk_widget_get_style_context(comp->tree),
-            GTK_STYLE_PROVIDER(provider),
+            GTK_STYLE_PROVIDER(vb.style_provider),
             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+    gtk_widget_set_name(GTK_WIDGET(comp->tree), "completion");
 
     gtk_box_pack_end(GTK_BOX(gtk_widget_get_parent(GTK_WIDGET(c->statusbar.box))), comp->win, FALSE, FALSE, 0);
     gtk_container_add(GTK_CONTAINER(comp->win), comp->tree);
diff --git a/src/main.c b/src/main.c
index a91cde3..982ec7c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -559,13 +559,11 @@ static Client *client_new(WebKitWebView *webview)
     gtk_box_pack_end(GTK_BOX(box), GTK_WIDGET(c->input), FALSE, FALSE, 0);
 
     /* Set the default style for statusbar and inputbox. */
-    GtkCssProvider* provider = gtk_css_provider_get_default();
-    gtk_css_provider_load_from_data(provider, GUI_STYLE, -1, NULL);
     gtk_style_context_add_provider(gtk_widget_get_style_context(GTK_WIDGET(c->statusbar.box)),
-            GTK_STYLE_PROVIDER(provider),
+            GTK_STYLE_PROVIDER(vb.style_provider),
             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
     gtk_style_context_add_provider(gtk_widget_get_style_context(c->input),
-            GTK_STYLE_PROVIDER(provider),
+            GTK_STYLE_PROVIDER(vb.style_provider),
             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
 
     /* set the x window id to env */
@@ -1075,6 +1073,7 @@ static void vimb_setup(void)
      * the documentation. */
     ctx = webkit_web_context_get_default();
     webkit_web_context_set_process_model(ctx, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
+    webkit_web_context_set_web_process_count_limit(ctx, 1);
     webkit_web_context_set_cache_model(ctx, WEBKIT_CACHE_MODEL_WEB_BROWSER);
 
     g_signal_connect(ctx, "initialize-web-extensions", G_CALLBACK(on_webctx_init_web_extension), NULL);
@@ -1096,6 +1095,10 @@ static void vimb_setup(void)
     vb_mode_add('c', ex_enter, ex_leave, ex_keypress, ex_input_changed);
     vb_mode_add('i', input_enter, input_leave, input_keypress, NULL);
     vb_mode_add('p', pass_enter, pass_leave, pass_keypress, NULL);
+
+    /* Prepare the style provider to be used for the clients and completion. */
+    vb.style_provider = gtk_css_provider_get_default();
+    gtk_css_provider_load_from_data(vb.style_provider, GUI_STYLE, -1, NULL);
 }
 
 /**
diff --git a/src/main.h b/src/main.h
index 2db4696..b4af03e 100644
--- a/src/main.h
+++ b/src/main.h
@@ -255,6 +255,7 @@ struct Vimb {
     struct {
         guint   history_max;
     } config;
+    GtkCssProvider *style_provider;
 };
 
 
-- 
2.20.1