[epiphany/wip/exalm/tabs] window: Use HdyApplicationWindow




commit 1ad3af22967368d0520d3d6c4be4080c62f6125a
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Sep 8 21:02:14 2020 +0500

    window: Use HdyApplicationWindow

 src/ephy-window.c | 95 +++++++++++++++++++++++++++----------------------------
 src/ephy-window.h |  4 +--
 2 files changed, 49 insertions(+), 50 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 78a682243..67f42f354 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -141,10 +141,13 @@ const struct {
 #define SETTINGS_CONNECTION_DATA_KEY    "EphyWindowSettings"
 
 struct _EphyWindow {
-  DzlApplicationWindow parent_instance;
+  HdyApplicationWindow parent_instance;
 
-  GtkWidget *header_bar;
   GtkWidget *main_deck;
+  HdyFullscreenBox *fullscreen_box;
+  GtkWidget *window_handle;
+  GtkBox *titlebar_box;
+  GtkWidget *header_bar;
   EphyPagesView *pages_view;
   EphyBookmarksManager *bookmarks_manager;
   GHashTable *action_labels;
@@ -190,7 +193,8 @@ enum {
   PROP_0,
   PROP_ACTIVE_CHILD,
   PROP_CHROME,
-  PROP_SINGLE_TAB_MODE
+  PROP_SINGLE_TAB_MODE,
+  PROP_FULLSCREEN
 };
 
 /* Make sure not to overlap with those in ephy-lockdown.c */
@@ -416,7 +420,7 @@ ephy_window_link_iface_init (EphyLinkInterface *iface)
   iface->open_link = ephy_window_open_link;
 }
 
-G_DEFINE_TYPE_WITH_CODE (EphyWindow, ephy_window, DZL_TYPE_APPLICATION_WINDOW,
+G_DEFINE_TYPE_WITH_CODE (EphyWindow, ephy_window, HDY_TYPE_APPLICATION_WINDOW,
                          G_IMPLEMENT_INTERFACE (EPHY_TYPE_LINK,
                                                 ephy_window_link_iface_init)
                          G_IMPLEMENT_INTERFACE (EPHY_TYPE_EMBED_CONTAINER,
@@ -433,7 +437,7 @@ sync_chromes_visibility (EphyWindow *window)
   show_tabsbar = (window->chrome & EPHY_WINDOW_CHROME_TABSBAR);
 
   gtk_widget_set_visible (GTK_WIDGET (window->tab_bar),
-                          show_tabsbar && !(window->is_popup || window->is_fullscreen));
+                          show_tabsbar && !(window->is_popup));
 }
 
 static void
@@ -555,6 +559,7 @@ ephy_window_fullscreen (EphyWindow *window)
   EphyEmbed *embed;
 
   window->is_fullscreen = TRUE;
+  g_object_notify (G_OBJECT (window), "fullscreen");
 
   /* sync status */
   embed = window->active_embed;
@@ -562,7 +567,6 @@ ephy_window_fullscreen (EphyWindow *window)
   sync_tab_security (ephy_embed_get_web_view (embed), NULL, window);
 
   update_adaptive_mode (window);
-  sync_chromes_visibility (window);
   ephy_embed_entering_fullscreen (embed);
 }
 
@@ -570,9 +574,9 @@ static void
 ephy_window_unfullscreen (EphyWindow *window)
 {
   window->is_fullscreen = FALSE;
+  g_object_notify (G_OBJECT (window), "fullscreen");
 
   update_adaptive_mode (window);
-  sync_chromes_visibility (window);
   ephy_embed_leaving_fullscreen (window->active_embed);
 }
 
@@ -2594,15 +2598,6 @@ tab_accels_update (EphyWindow *window)
   g_strfreev (actions);
 }
 
-static void
-accel_cb_tabs_next (GtkWidget *widget,
-                    gpointer   user_data)
-{
-  EphyWindow *window = EPHY_WINDOW (user_data);
-
-  ephy_tab_view_next (ephy_window_get_tab_view (window));
-}
-
 #define TAB_ACCELS_N 10
 
 static void
@@ -2611,7 +2606,6 @@ setup_tab_accels (EphyWindow *window)
   GActionGroup *action_group;
   GApplication *app;
   guint i;
-  DzlShortcutController *controller = dzl_shortcut_controller_find (GTK_WIDGET (window));
 
   action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "tab");
   app = g_application_get_default ();
@@ -2641,26 +2635,6 @@ setup_tab_accels (EphyWindow *window)
     g_free (action_name);
     g_free (action_name_with_tab);
   }
-
-  /* We have to setup the Ctrl + Tab shortcut in the window's ShortcutController
-   * because otherwise libdazzle would handle this shortcut by changing
-   * the focused widget instead of switching between the browser tabs
-   */
-  dzl_shortcut_controller_add_command_callback (controller,
-                                                "org.gnome.Epiphany.next-tab-pages",
-                                                "<Primary>Tab",
-                                                DZL_SHORTCUT_PHASE_DISPATCH,
-                                                accel_cb_tabs_next,
-                                                window,
-                                                NULL);
-
-  dzl_shortcut_controller_add_command_callback (controller,
-                                                "org.gnome.Epiphany.prev-tab-pages",
-                                                "<Primary>ISO_Left_Tab",
-                                                DZL_SHORTCUT_PHASE_DISPATCH,
-                                                accel_cb_tabs_next,
-                                                window,
-                                                NULL);
 }
 
 static void
@@ -3241,6 +3215,9 @@ ephy_window_get_property (GObject    *object,
     case PROP_SINGLE_TAB_MODE:
       g_value_set_boolean (value, window->is_popup);
       break;
+    case PROP_FULLSCREEN:
+      g_value_set_boolean (value, window->is_fullscreen);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -3254,10 +3231,6 @@ ephy_window_state_event (GtkWidget           *widget,
   EphyWindow *window = EPHY_WINDOW (widget);
   gboolean result = GDK_EVENT_PROPAGATE;
 
-  if (GTK_WIDGET_CLASS (ephy_window_parent_class)->window_state_event) {
-    result = GTK_WIDGET_CLASS (ephy_window_parent_class)->window_state_event (widget, event);
-  }
-
   if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
     GActionGroup *action_group;
     GAction *action;
@@ -3271,8 +3244,8 @@ ephy_window_state_event (GtkWidget           *widget,
       ephy_window_unfullscreen (window);
     }
 
-    if (window->show_fullscreen_header_bar)
-      dzl_application_window_set_fullscreen (DZL_APPLICATION_WINDOW (window), fullscreen);
+    hdy_fullscreen_box_set_fullscreen (window->fullscreen_box, fullscreen && 
window->show_fullscreen_header_bar);
+    gtk_widget_set_visible (GTK_WIDGET (window->titlebar_box), !fullscreen || 
window->show_fullscreen_header_bar);
 
     window->show_fullscreen_header_bar = FALSE;
 
@@ -3287,6 +3260,10 @@ ephy_window_state_event (GtkWidget           *widget,
 
   update_adaptive_mode (window);
 
+  if (GTK_WIDGET_CLASS (ephy_window_parent_class)->window_state_event) {
+    result = GTK_WIDGET_CLASS (ephy_window_parent_class)->window_state_event (widget, event);
+  }
+
   return result;
 }
 
@@ -3464,11 +3441,16 @@ setup_header_bar (EphyWindow *window)
   GtkWidget *header_bar;
   EphyTitleWidget *title_widget;
 
+  window->window_handle = hdy_window_handle_new ();
   header_bar = ephy_header_bar_new (window);
 
-  dzl_application_window_set_titlebar (DZL_APPLICATION_WINDOW (window), header_bar);
+  gtk_container_add (GTK_CONTAINER (window->window_handle), header_bar);
+
+  gtk_widget_show (window->window_handle);
   gtk_widget_show (header_bar);
 
+  gtk_style_context_add_class (gtk_widget_get_style_context (header_bar), "titlebar");
+
   title_widget = ephy_header_bar_get_title_widget (EPHY_HEADER_BAR (header_bar));
   g_signal_connect (title_widget, "lock-clicked",
                     G_CALLBACK (title_widget_lock_clicked_cb), window);
@@ -3744,6 +3726,7 @@ ephy_window_constructed (GObject *object)
   window->tab_bar = hdy_tab_bar_new ();
   window->tab_bar_revealer = GTK_REVEALER (gtk_revealer_new ());
   window->main_deck = hdy_deck_new ();
+  window->fullscreen_box = hdy_fullscreen_box_new ();
   window->pages_view = ephy_pages_view_new ();
 
   gtk_revealer_set_transition_type (window->tab_bar_revealer, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
@@ -3764,6 +3747,7 @@ ephy_window_constructed (GObject *object)
   window->location_controller = setup_location_controller (window, EPHY_HEADER_BAR (window->header_bar));
   window->action_bar = setup_action_bar (window);
   box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
+  window->titlebar_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
 
   if (g_settings_get_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_ASK_FOR_DEFAULT) &&
       !is_browser_default () &&
@@ -3771,20 +3755,26 @@ ephy_window_constructed (GObject *object)
     add_default_browser_question (box);
 
   gtk_container_add (GTK_CONTAINER (window->tab_bar_revealer), GTK_WIDGET (window->tab_bar));
-  gtk_box_pack_start (box, GTK_WIDGET (window->tab_bar_revealer), FALSE, TRUE, 0);
+  gtk_box_pack_start (window->titlebar_box, GTK_WIDGET (window->window_handle), FALSE, TRUE, 0);
+  gtk_box_pack_start (window->titlebar_box, GTK_WIDGET (window->tab_bar_revealer), FALSE, TRUE, 0);
   gtk_box_pack_start (box, GTK_WIDGET (window->tab_view), TRUE, TRUE, 0);
   gtk_box_pack_start (box, GTK_WIDGET (window->action_bar), FALSE, TRUE, 0);
-  gtk_container_add (GTK_CONTAINER (window->main_deck), GTK_WIDGET (box));
+  gtk_container_add (GTK_CONTAINER (window->fullscreen_box), GTK_WIDGET (box));
+  hdy_fullscreen_box_set_titlebar (window->fullscreen_box, GTK_WIDGET (window->titlebar_box));
+
+  gtk_container_add (GTK_CONTAINER (window->main_deck), GTK_WIDGET (window->fullscreen_box));
   gtk_container_add (GTK_CONTAINER (window->main_deck), GTK_WIDGET (window->pages_view));
   gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (window->main_deck));
-  gtk_widget_show_all (GTK_WIDGET (window->pages_view));
   gtk_widget_show (GTK_WIDGET (window->main_deck));
+  gtk_widget_show (GTK_WIDGET (window->pages_view));
+  gtk_widget_show (GTK_WIDGET (window->fullscreen_box));
+  gtk_widget_show (GTK_WIDGET (window->titlebar_box));
   gtk_widget_show (GTK_WIDGET (box));
   gtk_widget_show (GTK_WIDGET (window->tab_view));
   gtk_widget_show (GTK_WIDGET (window->tab_bar));
   gtk_widget_show (GTK_WIDGET (window->tab_bar_revealer));
 
-  hdy_deck_set_visible_child (HDY_DECK (window->main_deck), GTK_WIDGET (box));
+  hdy_deck_set_visible_child (HDY_DECK (window->main_deck), GTK_WIDGET (window->fullscreen_box));
   hdy_deck_set_can_swipe_back (HDY_DECK (window->main_deck), TRUE);
 
   /* other notifiers */
@@ -3902,6 +3892,15 @@ ephy_window_class_init (EphyWindowClass *klass)
                                                        G_PARAM_READWRITE |
                                                        G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (object_class,
+                                   PROP_FULLSCREEN,
+                                   g_param_spec_boolean ("fullscreen",
+                                                         NULL,
+                                                         NULL,
+                                                         FALSE,
+                                                         G_PARAM_READABLE |
+                                                         G_PARAM_STATIC_STRINGS));
+
   manager = ephy_embed_shell_get_downloads_manager (EPHY_EMBED_SHELL (ephy_shell_get_default ()));
   g_signal_connect (manager, "download-completed", G_CALLBACK (download_completed_cb), NULL);
 }
diff --git a/src/ephy-window.h b/src/ephy-window.h
index 893dfed69..caa8d9d78 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -27,13 +27,13 @@
 #include "ephy-tab-view.h"
 #include "ephy-web-view.h"
 
-#include <gtk/gtk.h>
+#include <handy.h>
 
 G_BEGIN_DECLS
 
 #define EPHY_TYPE_WINDOW (ephy_window_get_type ())
 
-G_DECLARE_FINAL_TYPE (EphyWindow, ephy_window, EPHY, WINDOW, DzlApplicationWindow)
+G_DECLARE_FINAL_TYPE (EphyWindow, ephy_window, EPHY, WINDOW, HdyApplicationWindow)
 
 typedef enum
 {


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