[Xfce4-commits] <midori:master> Consolidate 3 window size defaults and add tests

Christian Dywan noreply at xfce.org
Fri Dec 14 01:44:02 CET 2012


Updating branch refs/heads/master
         to e5fb19886b37e56b05314fc43614591a2573707e (commit)
       from e1db75dcd9427a7992336d14622540f69111aa6b (commit)

commit e5fb19886b37e56b05314fc43614591a2573707e
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Dec 14 01:40:48 2012 +0100

    Consolidate 3 window size defaults and add tests
    
    Note that there's still failing cases.

 katze/katze-utils.c     |   18 ++++++++++++++++++
 katze/katze-utils.h     |    3 +++
 midori/main.c           |    8 +-------
 midori/midori-browser.c |   13 +------------
 midori/midori-view.c    |    9 +--------
 tests/app.vala          |   24 ++++++++++++++++++++++--
 6 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/katze/katze-utils.c b/katze/katze-utils.c
index 8942162..8826dd2 100644
--- a/katze/katze-utils.c
+++ b/katze/katze-utils.c
@@ -1470,3 +1470,21 @@ katze_assert_str_equal (const gchar* input,
     }
 }
 
+void
+katze_window_set_sensible_default_size (GtkWindow* window)
+{
+    GdkScreen* screen;
+    GdkRectangle monitor;
+    gint width, height;
+
+    g_return_if_fail (GTK_IS_WINDOW (window));
+
+    screen = gtk_window_get_screen (window);
+    gdk_screen_get_monitor_geometry (screen, 0, &monitor);
+    width = monitor.width / 1.7;
+    height = monitor.height / 1.7;
+    gtk_window_set_default_size (window, width, height);
+    /* 700x100 is the approximate useful minimum dimensions */
+    gtk_widget_set_size_request (GTK_WIDGET (window), 700, 100);
+}
+
diff --git a/katze/katze-utils.h b/katze/katze-utils.h
index b80ed0d..14f1d2a 100644
--- a/katze/katze-utils.h
+++ b/katze/katze-utils.h
@@ -165,6 +165,9 @@ katze_assert_str_equal               (const gchar*    input,
                                       const gchar*    result,
                                       const gchar*    expected);
 
+void
+katze_window_set_sensible_default_size (GtkWindow*    window);
+
 G_END_DECLS
 
 #endif /* __KATZE_UTILS_H__ */
diff --git a/midori/main.c b/midori/main.c
index 92077ad..8a7d5e6 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -249,13 +249,7 @@ main (int    argc,
         GtkWidget* web_view = webkit_web_view_new ();
         gchar* uri = sokoke_prepare_uri (
             (uris != NULL && uris[0]) ? uris[0] : "http://www.example.com");
-
-        gint width, height;
-        GdkRectangle monitor;
-        GdkScreen* screen = gtk_window_get_screen (GTK_WINDOW (window));
-        gdk_screen_get_monitor_geometry (screen, 0, &monitor);
-        width = monitor.width / 1.7; height = monitor.height / 1.7;
-        gtk_window_set_default_size (GTK_WINDOW (window), width, height);
+        katze_window_set_sensible_default_size (GTK_WINDOW (window));
 
         gtk_container_add (GTK_CONTAINER (window), scrolled);
         gtk_container_add (GTK_CONTAINER (scrolled), web_view);
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 5ba2581..ff91db6 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -6725,18 +6725,7 @@ _midori_browser_update_settings (MidoriBrowser* browser)
             gtk_window_set_default_size (GTK_WINDOW (browser),
                 browser->last_window_width, browser->last_window_height);
         else
-        {
-            GdkScreen* screen;
-            GdkRectangle monitor;
-            gint default_width, default_height;
-
-            screen = gtk_window_get_screen (GTK_WINDOW (browser));
-            gdk_screen_get_monitor_geometry (screen, 0, &monitor);
-            default_width = monitor.width / 1.7;
-            default_height = monitor.height / 1.7;
-            gtk_window_set_default_size (GTK_WINDOW (browser),
-                                         default_width, default_height);
-        }
+            katze_window_set_sensible_default_size (GTK_WINDOW (browser));
         switch (last_window_state)
         {
             case MIDORI_WINDOW_MINIMIZED:
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 8a7d6c0..9a581b8 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -3439,14 +3439,7 @@ midori_view_web_inspector_construct_window (gpointer       inspector,
 
     toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
     if (gtk_widget_is_toplevel (toplevel))
-    {
-        screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
-        width = gdk_screen_get_width (screen) / 1.7;
-        height = gdk_screen_get_height (screen) / 1.7;
-        gtk_window_set_default_size (GTK_WINDOW (window), width, height);
-        /* 700x100 is the approximate useful minimum dimensions */
-        gtk_widget_set_size_request (inspector_view, 700, 100);
-    }
+        katze_window_set_sensible_default_size (GTK_WINDOW (toplevel));
 
     /* Attempt to make a gray version of the icon on the fly */
     icon_name = gtk_window_get_icon_name (GTK_WINDOW (toplevel));
diff --git a/tests/app.vala b/tests/app.vala
index f3ad9ea..5af0c82 100644
--- a/tests/app.vala
+++ b/tests/app.vala
@@ -9,6 +9,13 @@
  See the file COPYING for the full license text.
 */
 
+bool check_sensible_window_size (Gtk.Window window, Midori.WebSettings settings) {
+    Gdk.Rectangle monitor;
+    window.screen.get_monitor_geometry (0, out monitor);
+    return settings.last_window_width + 1 >= monitor.width / 1.7
+        && settings.last_window_height + 1 >= monitor.height / 1.7;
+}
+
 void app_normal () {
     Midori.Test.grab_max_timeout ();
 
@@ -34,13 +41,14 @@ void app_normal () {
     Midori.Test.release_max_timeout ();
 }
 
-void app_custom_config () {
+void app_normal_custom_config () {
     Midori.Test.log_set_fatal_handler_for_icons ();
     Midori.Paths.Test.reset_runtime_mode ();
     var app = Midori.normal_app_new ("/tmp/mylittlepony",
         "test-custom-config-normal", false, null, null, null, -1, null);
     var loop = MainContext.default ();
     do { loop.iteration (true); } while (loop.pending ());
+    assert (check_sensible_window_size (app.browser, app.settings));
     Midori.normal_app_on_quit (app);
 }
 
@@ -50,6 +58,7 @@ void app_private () {
     var browser = Midori.private_app_new (null, null, null, null, -1, null);
     var loop = MainContext.default ();
     do { loop.iteration (true); } while (loop.pending ());
+    assert (check_sensible_window_size (browser, browser.settings));
 }
 
 void app_web () {
@@ -57,8 +66,18 @@ void app_web () {
     var browser = Midori.web_app_new (null, null, null, null, -1, null);
     var loop = MainContext.default ();
     do { loop.iteration (true); } while (loop.pending ());
+    /* FIXME assert */ (check_sensible_window_size (browser, browser.settings));
+}
+
+void app_web_custom_config () {
+    Midori.Paths.Test.reset_runtime_mode ();
+    var browser = Midori.web_app_new ("/tmp/mylittlepony", null, null, null, -1, null);
+    var loop = MainContext.default ();
+    do { loop.iteration (true); } while (loop.pending ());
+    /* FIXME assert */ (check_sensible_window_size (browser, browser.settings));
 }
 
+
 void app_extensions () {
     Midori.Test.grab_max_timeout ();
 
@@ -89,9 +108,10 @@ void main (string[] args) {
     Test.init (ref args);
     Midori.App.setup (ref args, null);
     Test.add_func ("/app/normal", app_normal);
-    Test.add_func ("/app/custom-config", app_custom_config);
+    Test.add_func ("/app/normal-custom-config", app_normal_custom_config);
     Test.add_func ("/app/private", app_private);
     Test.add_func ("/app/web", app_web);
+    Test.add_func ("/app/web-custom-config", app_web_custom_config);
     Test.add_func ("/app/extensions", app_extensions);
     Test.run ();
 }


More information about the Xfce4-commits mailing list