[epiphany] Extend ephy-tab:// support for windows



commit ad1643e353a85961b9d7139d5874b1f95f420c39
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Sun Feb 2 19:02:31 2020 +0100

    Extend ephy-tab:// support for windows
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/117

 src/ephy-location-controller.c |  23 +++++++++-
 src/ephy-suggestion-model.c    | 100 +++++++++++++++++++++--------------------
 2 files changed, 72 insertions(+), 51 deletions(-)
---
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index 62e82582d..96bfe906c 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -151,12 +151,31 @@ entry_activate_cb (GtkEntry               *entry,
     GtkWidget *tab;
     EphyWebView *webview;
     gint current = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
-    guint64 page = g_ascii_strtoull (content + strlen ("ephy-tab://"), NULL, 0);
+    g_auto (GStrv) split = g_strsplit (content + strlen ("ephy-tab://"), "@", -1);
+
+    g_assert (g_strv_length (split) == 2);
 
     tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), current);
-    gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page);
     webview = ephy_embed_get_web_view (EPHY_EMBED (tab));
 
+    if (atoi (split[1]) != 0) {
+      GApplication *application;
+      EphyEmbedShell *shell;
+      EphyWindow *window;
+      GList *windows;
+
+      shell = ephy_embed_shell_get_default ();
+      application = G_APPLICATION (shell);
+      windows = gtk_application_get_windows (GTK_APPLICATION (application));
+
+      window = g_list_nth_data (windows, atoi (split[1]));
+      notebook = ephy_window_get_notebook (window);
+
+      gtk_window_present (GTK_WINDOW (window));
+    }
+
+    gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), atoi (split[0]));
+
     if (ephy_web_view_is_overview (webview))
       g_signal_emit_by_name (GTK_NOTEBOOK (notebook), "tab-close-request", tab);
 
diff --git a/src/ephy-suggestion-model.c b/src/ephy-suggestion-model.c
index 97965a01a..47cf85e15 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -399,65 +399,67 @@ add_tabs (EphySuggestionModel *self,
   EphyEmbedShell *shell;
   EphyWindow *window;
   GtkWidget *notebook;
+  GList *windows;
   gint n_pages;
   gint current;
   guint added = 0;
 
   shell = ephy_embed_shell_get_default ();
   application = G_APPLICATION (shell);
-  window = EPHY_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (application)));
+  windows = gtk_application_get_windows (GTK_APPLICATION (application));
   self->num_custom_entries = 0;
 
-  if (!window)
-    return 0;
+  for (guint win_idx = 0; win_idx < g_list_length (windows); win_idx++) {
+    window = EPHY_WINDOW (g_list_nth_data (windows, win_idx));
 
-  notebook = ephy_window_get_notebook (window);
-  n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
-  current = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+    notebook = ephy_window_get_notebook (window);
+    n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
+    current = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
 
-  for (int i = 0; i < n_pages; i++) {
-    EphyEmbed *embed;
-    EphyWebView *webview;
-    EphySuggestion *suggestion;
-    g_autofree gchar *escaped_title = NULL;
-    g_autofree gchar *markup = NULL;
-    const gchar *display_address;
-    const gchar *url;
-    g_autofree gchar *address = NULL;
-    const gchar *title;
-    g_autofree gchar *title_casefold = NULL;
-    g_autofree gchar *display_address_casefold = NULL;
-    g_autofree gchar *query_casefold = NULL;
-
-    if (i == current)
-      continue;
-
-    embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i));
-    webview = ephy_embed_get_web_view (embed);
-    display_address = ephy_web_view_get_display_address (webview);
-    url = ephy_web_view_get_address (webview);
-    address = g_strdup_printf ("ephy-tab://%d", i);
-    title = webkit_web_view_get_title (WEBKIT_WEB_VIEW (webview));
-
-    display_address_casefold = g_utf8_casefold (display_address, -1);
-    query_casefold = g_utf8_casefold (query, -1);
-    if (!title)
-      title = "";
-
-    title_casefold = g_utf8_casefold (title, -1);
-
-    if ((title_casefold && strstr (title_casefold, query_casefold)) || strstr (display_address_casefold, 
query_casefold)) {
-      char *escaped_address = g_markup_escape_text (display_address, -1);
-
-      escaped_title = g_markup_escape_text (title, -1);
-      markup = dzl_fuzzy_highlight (escaped_title, query, FALSE);
-      suggestion = ephy_suggestion_new_with_custom_subtitle (markup, title, escaped_address, address);
-      load_favicon (self, suggestion, display_address);
-      ephy_suggestion_set_secondary_icon (suggestion, "go-jump-symbolic");
-
-      g_sequence_append (self->urls, g_strdup (url));
-      g_sequence_append (self->items, suggestion);
-      added++;
+    for (int i = 0; i < n_pages; i++) {
+      EphyEmbed *embed;
+      EphyWebView *webview;
+      EphySuggestion *suggestion;
+      g_autofree gchar *escaped_title = NULL;
+      g_autofree gchar *markup = NULL;
+      const gchar *display_address;
+      const gchar *url;
+      g_autofree gchar *address = NULL;
+      const gchar *title;
+      g_autofree gchar *title_casefold = NULL;
+      g_autofree gchar *display_address_casefold = NULL;
+      g_autofree gchar *query_casefold = NULL;
+
+      if (win_idx == 0 && i == current)
+        continue;
+
+      embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i));
+      webview = ephy_embed_get_web_view (embed);
+      display_address = ephy_web_view_get_display_address (webview);
+      url = ephy_web_view_get_address (webview);
+      address = g_strdup_printf ("ephy-tab://%d@%d", i, win_idx);
+      title = webkit_web_view_get_title (WEBKIT_WEB_VIEW (webview));
+
+      display_address_casefold = g_utf8_casefold (display_address, -1);
+      query_casefold = g_utf8_casefold (query, -1);
+      if (!title)
+        title = "";
+
+      title_casefold = g_utf8_casefold (title, -1);
+
+      if ((title_casefold && strstr (title_casefold, query_casefold)) || strstr (display_address_casefold, 
query_casefold)) {
+        char *escaped_address = g_markup_escape_text (display_address, -1);
+
+        escaped_title = g_markup_escape_text (title, -1);
+        markup = dzl_fuzzy_highlight (escaped_title, query, FALSE);
+        suggestion = ephy_suggestion_new_with_custom_subtitle (markup, title, escaped_address, address);
+        load_favicon (self, suggestion, display_address);
+        ephy_suggestion_set_secondary_icon (suggestion, "go-jump-symbolic");
+
+        g_sequence_append (self->urls, g_strdup (url));
+        g_sequence_append (self->items, suggestion);
+        added++;
+      }
     }
   }
 


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