From: Daniel Carl Date: Tue, 11 Jul 2017 21:18:42 +0000 (+0200) Subject: Split client creation into pieces. X-Git-Url: https://git.owens.tech/rss.xml/rss.xml/git?a=commitdiff_plain;h=8381352bc0a75be0e5a717efbcf4622d1e6a3518;p=vimb.git Split client creation into pieces. Setup the gui elements only when the webview is ready to be show like suggested by the webkit developers. --- diff --git a/src/main.c b/src/main.c index c35f54b..c00e80a 100644 --- a/src/main.c +++ b/src/main.c @@ -45,7 +45,9 @@ #include "util.h" static void client_destroy(Client *c); -static Client *client_new(WebKitWebView *webview, gboolean); +static Client *client_new(WebKitWebView *webview); +static void client_show(WebKitWebView *webview, Client *c); +static GtkWidget *create_window(Client *c); static gboolean input_clear(Client *c); static void input_print(Client *c, MessageType type, gboolean hide, const char *message); @@ -380,7 +382,7 @@ gboolean vb_load_uri(Client *c, const Arg *arg) } else if (arg->i == TARGET_NEW) { spawn_new_instance(uri); } else { /* TARGET_RELATED */ - Client *newclient = client_new(c->webview, FALSE); + Client *newclient = client_new(c->webview); /* Load the uri into the new client. */ webkit_web_view_load_uri(newclient->webview, uri); set_title(c, uri); @@ -660,47 +662,36 @@ static void client_destroy(Client *c) * @webview: Related webview or NULL if a client with an independent * webview shoudl be created. */ -static Client *client_new(WebKitWebView *webview, gboolean show) +static Client *client_new(WebKitWebView *webview) { Client *c; - char *xid; - GtkWidget *box; /* create the client */ - c = g_slice_new0(Client); + /* Prepend the new client to the queue of clients. */ + c = g_slice_new0(Client); + c->next = vb.clients; + vb.clients = c; + c->state.progress = 100; - if (vb.embed) { - c->window = gtk_plug_new(vb.embed); - xid = g_strdup_printf("%d", (int)vb.embed); - } else { - GtkRequisition req; - c->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_role(GTK_WINDOW(c->window), PROJECT_UCFIRST); - /* We have to call gtk_widget_get_preferred_size before - * gtk_widget_size_allocate otherwise a warning is thrown when the - * widget is realized. */ - gtk_widget_get_preferred_size(GTK_WIDGET(c->window), &req, NULL); - gtk_widget_realize(GTK_WIDGET(c->window)); - gtk_window_set_default_size(GTK_WINDOW(c->window), WIN_WIDTH, WIN_HEIGHT); + completion_init(c); + map_init(c); + handler_init(c); - xid = g_strdup_printf("%d", - (int)GDK_WINDOW_XID(gtk_widget_get_window(GTK_WIDGET(c->window)))); - } + /* webview */ + c->webview = webview_new(c, webview); + c->page_id = webkit_web_view_get_page_id(c->webview); + c->inspector = webkit_web_view_get_inspector(c->webview); - /* set the x window id to env */ - g_setenv("VIMB_XID", xid, TRUE); - g_free(xid); + return c; +} - completion_init(c); - map_init(c); +static void client_show(WebKitWebView *webview, Client *c) +{ + GtkWidget *box; + char *xid; - g_object_connect( - G_OBJECT(c->window), - "signal::destroy", G_CALLBACK(on_window_destroy), c, - "signal::delete-event", G_CALLBACK(on_window_delete_event), c, - "signal::key-press-event", G_CALLBACK(on_map_keypress), c, - NULL); + c->window = create_window(c); /* statusbar */ c->statusbar.box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)); @@ -718,10 +709,6 @@ static Client *client_new(WebKitWebView *webview, gboolean show) gtk_box_pack_start(c->statusbar.box, c->statusbar.cmd, FALSE, FALSE, 0); gtk_box_pack_start(c->statusbar.box, c->statusbar.right, FALSE, FALSE, 2); - /* webview */ - c->webview = webview_new(c, webview); - c->page_id = webkit_web_view_get_page_id(c->webview); - /* inputbox */ c->input = gtk_text_view_new(); gtk_widget_set_name(c->input, "input"); @@ -745,29 +732,52 @@ static Client *client_new(WebKitWebView *webview, gboolean show) GTK_STYLE_PROVIDER(vb.style_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - /* initialize the settings */ + /* TODO separate initialization o setting from applying the values or + * allow to se the default values for different scopes. For now we can + * init the settings not in client_new because we need the access to some + * widget for some settings. */ setting_init(c); - /* initialize the url handlers */ - handler_init(c); + gtk_widget_show_all(c->window); + if (vb.embed) { + xid = g_strdup_printf("%d", (int)vb.embed); + } else { + xid = g_strdup_printf("%d", (int)GDK_WINDOW_XID(gtk_widget_get_window(c->window))); + } + + /* set the x window id to env */ + g_setenv("VIMB_XID", xid, TRUE); + g_free(xid); /* start client in normal mode */ vb_enter(c, 'n'); c->state.enable_register = TRUE; - if (show) { - gtk_widget_show_all(c->window); - } - /* read the config file */ ex_run_file(c, vb.files[FILES_CONFIG]); +} - /* Prepend the new client to the queue of clients. */ - c->next = vb.clients; - vb.clients = c; +static GtkWidget *create_window(Client *c) +{ + GtkWidget *window; - return c; + if (vb.embed) { + window = gtk_plug_new(vb.embed); + } else { + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_role(GTK_WINDOW(window), PROJECT_UCFIRST); + gtk_window_set_default_size(GTK_WINDOW(window), WIN_WIDTH, WIN_HEIGHT); + } + + g_object_connect( + G_OBJECT(window), + "signal::destroy", G_CALLBACK(on_window_destroy), c, + "signal::delete-event", G_CALLBACK(on_window_delete_event), c, + "signal::key-press-event", G_CALLBACK(on_map_keypress), c, + NULL); + + return window; } /** @@ -1113,7 +1123,7 @@ static void on_webview_close(WebKitWebView *webview, Client *c) static WebKitWebView *on_webview_create(WebKitWebView *webview, WebKitNavigationAction *navact, Client *c) { - Client *new = client_new(webview, FALSE); + Client *new = client_new(webview); return new->webview; } @@ -1333,7 +1343,7 @@ static void on_webview_notify_uri(WebKitWebView *webview, GParamSpec *pspec, Cli */ static void on_webview_ready_to_show(WebKitWebView *webview, Client *c) { - gtk_widget_show_all(GTK_WIDGET(c->window)); + client_show(webview, c); } /** @@ -1777,7 +1787,7 @@ int main(int argc, char* argv[]) printf("Commit: %s\n", COMMIT); printf("WebKit compile: %d.%d.%d\n", WEBKIT_MAJOR_VERSION, - WEBKIT_MINOR_VERSION, + WEBKIT_MINOR_VERSION, WEBKIT_MICRO_VERSION); printf("WebKit run: %d.%d.%d\n", webkit_get_major_version(), @@ -1819,7 +1829,8 @@ int main(int argc, char* argv[]) vb.embed = strtol(winid, NULL, 0); } - c = client_new(NULL, TRUE); + c = client_new(NULL); + client_show(NULL, c); if (argc <= 1) { vb_load_uri(c, &(Arg){TARGET_CURRENT, NULL}); } else if (!strcmp(argv[argc - 1], "-")) { diff --git a/src/main.h b/src/main.h index ac565d4..7eb1141 100644 --- a/src/main.h +++ b/src/main.h @@ -216,6 +216,7 @@ struct Client { /* WebKitWebContext *webctx; */ /* not used atm, use webkit_web_context_get_default() instead */ GtkWidget *window, *input; WebKitWebView *webview; + WebKitWebInspector *inspector; guint64 page_id; /* page id of the webview */ GtkTextBuffer *buffer; GDBusProxy *dbusproxy; diff --git a/src/normal.c b/src/normal.c index 0dc06ee..7161fe1 100644 --- a/src/normal.c +++ b/src/normal.c @@ -691,18 +691,16 @@ static VbResult normal_search_selection(Client *c, const NormalCmdInfo *info) static VbResult normal_view_inspector(Client *c, const NormalCmdInfo *info) { - WebKitWebInspector *inspector; WebKitSettings *settings; - settings = webkit_web_view_get_settings(c->webview); - inspector = webkit_web_view_get_inspector(c->webview); + settings = webkit_web_view_get_settings(c->webview); /* Try to get the inspected uri to identify if the inspector is shown at * the time or not. */ - if (webkit_web_inspector_is_attached(inspector)) { - webkit_web_inspector_close(inspector); + if (webkit_web_inspector_is_attached(c->inspector)) { + webkit_web_inspector_close(c->inspector); } else if (webkit_settings_get_enable_developer_extras(settings)) { - webkit_web_inspector_show(inspector); + webkit_web_inspector_show(c->inspector); } else { /* Inform the user on attempt to enable webinspector when the * developer extra are not enabled. */