[epiphany] window: Make triggering the narrow mode less aggressive



commit 9c6cff8018828606ad086302dd39ac8ffb48898c
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Nov 23 10:51:27 2018 +0100

    window: Make triggering the narrow mode less aggressive
    
    Trigger the narrow mode below widths of 600pt rather than 720pt to make
    that mode less present on the desktop. Also tries to trigger the narrow
    mode on landscape mobile phones by triggering it for maximized or
    fullscreened windows that are either on short screens or themselves
    short, short being defined as less than 400pt high.

 src/ephy-window.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 51 insertions(+), 9 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 57cda1a79..56dc46af0 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -476,6 +476,49 @@ sync_tab_security (EphyWebView *view,
   ephy_title_widget_set_security_level (title_widget, security_level);
 }
 
+static void
+update_adaptive_mode (EphyWindow *window)
+{
+  EphyHeaderBar *header_bar = EPHY_HEADER_BAR (ephy_window_get_header_bar (window));
+  EphyActionBar *action_bar = EPHY_ACTION_BAR (window->action_bar);
+  gboolean is_narrow, is_mobile_landscape;
+  EphyAdaptiveMode adaptive_mode;
+  gint width, height;
+  GdkDisplay *display;
+  GdkWindow *surface;
+  GdkMonitor *monitor = NULL;
+  GdkRectangle geometry = {};
+
+  gtk_window_get_size (GTK_WINDOW (window),
+                       &width,
+                       &height);
+
+  /* Get the monitor to guess whether we are on a mobile or not. If not found,
+   * fallback to the window size.
+   */
+  display = gtk_widget_get_display (GTK_WIDGET (window));
+  surface = gtk_widget_get_window (GTK_WIDGET (window));
+  if (display != NULL && surface != NULL)
+    monitor = gdk_display_get_monitor_at_window (display, surface);
+  if (monitor != NULL)
+    gdk_monitor_get_geometry (monitor, &geometry);
+  else
+    geometry.height = height;
+
+  /* window->is_maximized doesn't work here for some reason, so we use
+   * gtk_window_is_maximized() instead.
+   */
+  is_narrow = width <= 600;
+  is_mobile_landscape = geometry.height <= 400 &&
+                        (gtk_window_is_maximized (GTK_WINDOW (window)) ||
+                         window->is_fullscreen);
+  adaptive_mode = is_narrow || is_mobile_landscape ?
+    EPHY_ADAPTIVE_MODE_NARROW :
+    EPHY_ADAPTIVE_MODE_NORMAL;
+  ephy_header_bar_set_adaptive_mode (header_bar, adaptive_mode);
+  ephy_action_bar_set_adaptive_mode (action_bar, adaptive_mode);
+}
+
 static void
 ephy_window_fullscreen (EphyWindow *window)
 {
@@ -488,6 +531,7 @@ ephy_window_fullscreen (EphyWindow *window)
   sync_tab_load_status (ephy_embed_get_web_view (embed), WEBKIT_LOAD_STARTED, 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);
 }
@@ -497,6 +541,7 @@ ephy_window_unfullscreen (EphyWindow *window)
 {
   window->is_fullscreen = FALSE;
 
+  update_adaptive_mode (window);
   sync_chromes_visibility (window);
   ephy_embed_leaving_fullscreen (window->active_embed);
 }
@@ -2881,9 +2926,6 @@ ephy_window_configure_event (GtkWidget *widget,
                              GdkEventConfigure *event)
 {
   EphyWindow *window = EPHY_WINDOW (widget);
-  EphyHeaderBar *header_bar = EPHY_HEADER_BAR (ephy_window_get_header_bar (window));
-  EphyActionBar *action_bar = EPHY_ACTION_BAR (window->action_bar);
-  EphyAdaptiveMode adaptive_mode;
   gboolean result;
   gint width, height;
 
@@ -2893,12 +2935,6 @@ ephy_window_configure_event (GtkWidget *widget,
                        &width,
                        &height);
 
-  adaptive_mode = width <= 720 ?
-    EPHY_ADAPTIVE_MODE_NARROW :
-    EPHY_ADAPTIVE_MODE_NORMAL;
-  ephy_header_bar_set_adaptive_mode (header_bar, adaptive_mode);
-  ephy_action_bar_set_adaptive_mode (action_bar, adaptive_mode);
-
   if (!window->is_maximized && !window->is_fullscreen) {
     gtk_window_get_position (GTK_WINDOW (widget),
                              &window->current_x,
@@ -2907,6 +2943,8 @@ ephy_window_configure_event (GtkWidget *widget,
     window->current_height = height;
   }
 
+  update_adaptive_mode (window);
+
   return result;
 }
 
@@ -2944,6 +2982,8 @@ ephy_window_state_event (GtkWidget           *widget,
     window->is_maximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED;
   }
 
+  update_adaptive_mode (window);
+
   return result;
 }
 
@@ -3009,6 +3049,8 @@ ephy_window_show (GtkWidget *widget)
     }
   }
 
+  update_adaptive_mode (window);
+
   GTK_WIDGET_CLASS (ephy_window_parent_class)->show (widget);
 }
 


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