diff options
author | Gustavo Noronha Silva <gns@gnome.org> | 2012-12-09 22:25:37 +0800 |
---|---|---|
committer | Gustavo Noronha Silva <gns@gnome.org> | 2012-12-11 05:15:54 +0800 |
commit | c968c68cabc319896ad4d2096940c9a34d4c13cd (patch) | |
tree | d9cde42306f750303d3d35ee701fe58c5040f878 /src | |
parent | 3573116d0473da1ca51d1766d412a97185addb9d (diff) | |
download | gsoc2013-epiphany-c968c68cabc319896ad4d2096940c9a34d4c13cd.tar.gz gsoc2013-epiphany-c968c68cabc319896ad4d2096940c9a34d4c13cd.tar.zst gsoc2013-epiphany-c968c68cabc319896ad4d2096940c9a34d4c13cd.zip |
Append new tab on the window with most tabs in the current workspace
This change uses a different heuristic to decide on what the best window to add
a new tab is from the last window which has been interacted with, which might
even be in a different workspace, to the window with the most tabs in the
current workspace. If no window exists on the current workspace one will be
created.
Partial fix for https://bugzilla.gnome.org/show_bug.cgi?id=685976
Diffstat (limited to 'src')
-rw-r--r-- | src/ephy-session.c | 2 | ||||
-rw-r--r-- | src/ephy-shell.c | 38 | ||||
-rw-r--r-- | src/ephy-shell.h | 2 | ||||
-rw-r--r-- | src/ephy-window.c | 39 | ||||
-rw-r--r-- | src/ephy-window.h | 2 |
5 files changed, 82 insertions, 1 deletions
diff --git a/src/ephy-session.c b/src/ephy-session.c index d761d9d33..3a0f197a3 100644 --- a/src/ephy-session.c +++ b/src/ephy-session.c @@ -261,7 +261,7 @@ session_command_open_uris (EphySession *session, g_object_ref (shell); - window = EPHY_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (shell))); + window = ephy_shell_get_main_window (shell); new_windows_in_tabs = g_settings_get_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_NEW_WINDOWS_IN_TABS); diff --git a/src/ephy-shell.c b/src/ephy-shell.c index eb9789166..9800038cb 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -1061,6 +1061,44 @@ ephy_shell_get_n_windows (EphyShell *shell) return g_list_length (shell->priv->windows); } +EphyWindow* +ephy_shell_get_main_window (EphyShell *shell) +{ + EphyWindow *window = NULL; + GList *windows; + GList *iter; + + g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL); + + /* Select the window with most tabs in the current workspace as the window to + * use for opening a new tab on, if that turns out to be the case. + */ + windows = ephy_shell_get_windows (shell); + + for (iter = windows; iter != NULL; iter = iter->next) { + EphyWindow *candidate = EPHY_WINDOW (iter->data); + GtkWidget *cur_notebook; + GtkWidget *cand_notebook; + + if (!ephy_window_is_on_current_workspace (candidate)) + continue; + + if (!window) { + window = candidate; + continue; + } + + cur_notebook = ephy_window_get_notebook (window); + cand_notebook = ephy_window_get_notebook (candidate); + if (gtk_notebook_get_n_pages (cand_notebook) > gtk_notebook_get_n_pages (cur_notebook)) + window = candidate; + } + + g_list_free (windows); + + return window; +} + gboolean ephy_shell_close_all_windows (EphyShell *shell) { diff --git a/src/ephy-shell.h b/src/ephy-shell.h index 3cf8b1844..057d7cbe5 100644 --- a/src/ephy-shell.h +++ b/src/ephy-shell.h @@ -176,6 +176,8 @@ GList *ephy_shell_get_windows (EphyShell *shell); guint ephy_shell_get_n_windows (EphyShell *shell); +EphyWindow *ephy_shell_get_main_window (EphyShell *shell); + gboolean ephy_shell_close_all_windows (EphyShell *shell); G_END_DECLS diff --git a/src/ephy-window.c b/src/ephy-window.c index 64c7be8ee..d1c0170d1 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -61,10 +61,15 @@ #include "window-commands.h" #include <gdk/gdkkeysyms.h> +#include <gdk/gdkx.h> #include <gio/gio.h> #include <glib/gi18n.h> #include <gtk/gtk.h> #include <libsoup/soup.h> + +#define WNCK_I_KNOW_THIS_IS_UNSTABLE +#include <libwnck/libwnck.h> + #ifdef HAVE_WEBKIT2 #include <webkit2/webkit2.h> #else @@ -4390,6 +4395,40 @@ ephy_window_get_location_controller (EphyWindow *window) } /** + * ephy_window_is_on_current_workspace: + * @window: an #EphyWindow + * + * Returns whether @window is on the current workspace + * + * Returns: %TRUE if the window is on the current workspace, %FALSE otherwise + **/ +gboolean +ephy_window_is_on_current_workspace (EphyWindow *window) +{ + GdkWindow *gdk_window = NULL; + WnckWorkspace *workspace = NULL; + WnckWindow *wnck_window = NULL; + + if (!gtk_widget_get_realized (GTK_WIDGET (window))) + return TRUE; + + workspace = wnck_screen_get_active_workspace (wnck_screen_get_default ()); + + /* From WNCK docs: + * "May return NULL sometimes, if libwnck is in a weird state due to + * the asynchronous nature of the interaction with the window manager." + * In such a case we cannot really check, so assume we are. + */ + if (!workspace) + return TRUE; + + gdk_window = gtk_widget_get_window (GTK_WIDGET (window)); + wnck_window = wnck_window_get (GDK_WINDOW_XID (gdk_window)); + + return wnck_window_is_on_workspace (wnck_window, workspace); +} + +/** * ephy_window_close: * @window: an #EphyWindow * diff --git a/src/ephy-window.h b/src/ephy-window.h index 8ce845de2..e2841111a 100644 --- a/src/ephy-window.h +++ b/src/ephy-window.h @@ -76,6 +76,8 @@ const char *ephy_window_get_location (EphyWindow *window); gboolean ephy_window_close (EphyWindow *window); +gboolean ephy_window_is_on_current_workspace (EphyWindow *window); + G_END_DECLS #endif |