[Xfce4-commits] <midori:master> Implement and optimize for portrait mode support for Fremantle

Christian Dywan noreply at xfce.org
Sun Nov 29 14:12:01 CET 2009


Updating branch refs/heads/master
         to 1d68dc9fb7a6f89f325e9c26d60f7ac4e8b7c0ad (commit)
       from 11de65af920275d97c39e1f00eb768545c145395 (commit)

commit 1d68dc9fb7a6f89f325e9c26d60f7ac4e8b7c0ad
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Nov 27 23:42:07 2009 +0100

    Implement and optimize for portrait mode support for Fremantle
    
    Listen to accelerometer movement.
    Hide tool items in portrait mode.
    Omit Homepage and View Source from app menu.
    Include Compact Add, View Source and Fullscreen in context menu.
    Hide buttons in portrait mode in preferences.

 katze/katze-preferences.c |   30 ++++++++++++++--
 midori/midori-app.c       |   11 ++++++
 midori/midori-browser.c   |   83 ++++++++++++++++++++++++++++++++++++++++----
 midori/midori-view.c      |   14 ++++++--
 4 files changed, 123 insertions(+), 15 deletions(-)

diff --git a/katze/katze-preferences.c b/katze/katze-preferences.c
index f42f77d..91006cb 100644
--- a/katze/katze-preferences.c
+++ b/katze/katze-preferences.c
@@ -66,6 +66,19 @@ katze_preferences_response_cb (KatzePreferences* preferences,
         gtk_widget_destroy (GTK_WIDGET (preferences));
 }
 
+#ifdef HAVE_HILDON_2_2
+static void
+katze_preferences_size_request_cb (KatzePreferences* preferences,
+                                   GtkRequisition*   requisition)
+{
+    GdkScreen* screen = gtk_widget_get_screen (GTK_WIDGET (preferences));
+    if (gdk_screen_get_height (screen) > gdk_screen_get_width (screen))
+        gtk_widget_hide (gtk_dialog_get_action_area (GTK_DIALOG (preferences)));
+    else
+        gtk_widget_show (gtk_dialog_get_action_area (GTK_DIALOG (preferences)));
+}
+#endif
+
 static void
 katze_preferences_init (KatzePreferences* preferences)
 {
@@ -94,9 +107,17 @@ katze_preferences_init (KatzePreferences* preferences)
         #endif
         NULL);
     #endif
+
     g_object_connect (preferences,
         "signal::response", katze_preferences_response_cb, NULL,
         NULL);
+
+    #ifdef HAVE_HILDON_2_2
+    katze_preferences_size_request_cb (preferences, NULL);
+    g_object_connect (preferences,
+        "signal::size-request", katze_preferences_size_request_cb, NULL,
+        NULL);
+    #endif
 }
 
 static void
@@ -168,7 +189,8 @@ katze_preferences_prepare (KatzePreferences* preferences)
     priv->sizegroup = NULL;
     priv->sizegroup2 = NULL;
 
-    g_signal_connect (priv->scrolled, "destroy", G_CALLBACK (gtk_widget_destroyed), &priv->scrolled);
+    g_signal_connect (priv->scrolled, "destroy",
+                      G_CALLBACK (gtk_widget_destroyed), &priv->scrolled);
     #else
     priv->notebook = gtk_notebook_new ();
     gtk_container_set_border_width (GTK_CONTAINER (priv->notebook), 6);
@@ -195,7 +217,8 @@ katze_preferences_prepare (KatzePreferences* preferences)
     priv->box = NULL;
     priv->hbox = NULL;
 
-    g_signal_connect (priv->notebook, "destroy", G_CALLBACK (gtk_widget_destroyed), &priv->notebook);
+    g_signal_connect (priv->notebook, "destroy",
+                      G_CALLBACK (gtk_widget_destroyed), &priv->notebook);
     #endif
 
     #if HAVE_OSX
@@ -206,8 +229,7 @@ katze_preferences_prepare (KatzePreferences* preferences)
     gtk_button_set_image (GTK_BUTTON (button), icon);
     g_signal_connect (button, "clicked",
         G_CALLBACK (katze_preferences_help_clicked_cb), preferences);
-    gtk_box_pack_end (GTK_BOX (hbox),
-        button, FALSE, FALSE, 4);
+    gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 4);
     gtk_box_pack_end (GTK_BOX (GTK_DIALOG (preferences)->action_area),
         hbox, FALSE, FALSE, 0);
     #endif
diff --git a/midori/midori-app.c b/midori/midori-app.c
index 434e346..cb756e1 100644
--- a/midori/midori-app.c
+++ b/midori/midori-app.c
@@ -22,6 +22,11 @@
 
 #if HAVE_HILDON
     #include <libosso.h>
+    #ifdef HAVE_HILDON_2_2
+        #include <dbus/dbus.h>
+        #include <mce/mode-names.h>
+        #include <mce/dbus-names.h>
+    #endif
     typedef osso_context_t* MidoriAppInstance;
     #define MidoriAppInstanceNull NULL
 #elif HAVE_UNIQUE
@@ -642,6 +647,12 @@ midori_app_create_instance (MidoriApp*   app,
         osso_deinitialize (instance);
         return NULL;
     }
+
+    #ifdef HAVE_HILDON_2_2
+    if (OSSO_OK == osso_rpc_run_system (instance, MCE_SERVICE, MCE_REQUEST_PATH,
+        MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ, NULL, DBUS_TYPE_INVALID))
+        /* Accelerometer enabled */;
+    #endif
     #else
     GdkDisplay* display;
     gchar* display_name;
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 588ca57..25d064a 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -38,6 +38,16 @@
     #include <unistd.h>
 #endif
 
+#ifdef HAVE_HILDON_2_2
+    #include <dbus/dbus.h>
+    #include <mce/mode-names.h>
+    #include <mce/dbus-names.h>
+    #define MCE_SIGNAL_MATCH "type='signal'," \
+        "sender='"    MCE_SERVICE     "',"    \
+        "path='"      MCE_SIGNAL_PATH "',"    \
+        "interface='" MCE_SIGNAL_IF   "'"
+#endif
+
 struct _MidoriBrowser
 {
     #if HAVE_HILDON
@@ -3029,8 +3039,6 @@ _action_compact_menu_populate_popup (GtkAction*     action,
       { "Open" },
       #if HAVE_HILDON
       { "Find" },
-      { "Homepage" },
-      { "SourceView" },
       #else
       { "Print" },
       { "About" },
@@ -3057,12 +3065,7 @@ _action_compact_menu_populate_popup (GtkAction*     action,
 
     for (i = 0; i < G_N_ELEMENTS (actions); i++)
     {
-        #if HAVE_HILDON
-        #if HILDON_CHECK_VERSION (2, 2, 0)
-        #define HAVE_APP_MENU 1
-        #endif
-        #endif
-        #ifdef HAVE_APP_MENU
+        #ifdef HAVE_HILDON_2_2
         GtkAction* _action;
         gchar* label;
         GtkWidget* button;
@@ -5474,6 +5477,58 @@ midori_browser_ui_manager_disconnect_proxy_cb (GtkUIManager*  ui_manager,
     }
 }
 
+#ifdef HAVE_HILDON_2_2
+static void
+midori_browser_set_portrait_mode (MidoriBrowser* browser,
+                                  gboolean       portrait)
+{
+    if (portrait)
+        hildon_gtk_window_set_portrait_flags (GTK_WINDOW (browser),
+                                              HILDON_PORTRAIT_MODE_REQUEST);
+    else
+        hildon_gtk_window_set_portrait_flags (GTK_WINDOW (browser),
+                                              ~HILDON_PORTRAIT_MODE_REQUEST);
+    _action_set_visible (browser, "Bookmarks", !portrait);
+    _action_set_visible (browser, "CompactAdd", !portrait);
+    _action_set_visible (browser, "Back", !portrait);
+    _action_set_visible (browser, "SourceView", !portrait);
+    _action_set_visible (browser, "Fullscreen", !portrait);
+}
+
+static DBusHandlerResult
+midori_browser_mce_filter_cb (DBusConnection* connection,
+                              DBusMessage*    message,
+                              gpointer        data)
+{
+    if (dbus_message_is_signal (message, MCE_SIGNAL_IF, MCE_DEVICE_ORIENTATION_SIG))
+    {
+        DBusError error;
+        char *rotation, *stand, *face;
+        int x, y, z;
+
+        dbus_error_init (&error);
+        if (dbus_message_get_args (message,
+                                   &error,
+                                   DBUS_TYPE_STRING, &rotation,
+                                   DBUS_TYPE_STRING, &stand,
+                                   DBUS_TYPE_STRING, &face,
+                                   DBUS_TYPE_INT32,  &x,
+                                   DBUS_TYPE_INT32,  &y,
+                                   DBUS_TYPE_INT32,  &z, DBUS_TYPE_INVALID))
+        {
+            gboolean portrait = !strcmp (rotation, MCE_ORIENTATION_PORTRAIT);
+            midori_browser_set_portrait_mode (MIDORI_BROWSER (data), portrait);
+        }
+        else
+        {
+            g_warning ("%s: %s\n", error.name, error.message);
+            dbus_error_free (&error);
+        }
+    }
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+#endif
+
 static void
 midori_browser_init (MidoriBrowser* browser)
 {
@@ -5792,6 +5847,18 @@ midori_browser_init (MidoriBrowser* browser)
     gtk_box_pack_start (GTK_BOX (vbox), browser->navigationbar, FALSE, FALSE, 0);
     #endif
 
+    #ifdef HAVE_HILDON_2_2
+    DBusConnection* system_bus = dbus_bus_get (DBUS_BUS_SYSTEM, NULL);
+    if (system_bus)
+    {
+        dbus_bus_add_match (system_bus, MCE_SIGNAL_MATCH, NULL);
+        dbus_connection_add_filter (system_bus,
+            midori_browser_mce_filter_cb, browser, NULL);
+        hildon_gtk_window_set_portrait_flags (GTK_WINDOW (browser),
+                                              HILDON_PORTRAIT_MODE_SUPPORT);
+    }
+    #endif
+
     /* Bookmarkbar */
     browser->bookmarkbar = gtk_toolbar_new ();
     gtk_widget_set_name (browser->bookmarkbar, "MidoriBookmarkbar");
diff --git a/midori/midori-view.c b/midori/midori-view.c
index e41d19f..d4a89e3 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -1977,12 +1977,14 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
             gtk_menu_shell_append (menu_shell, menuitem);
         }
 
+        #if !HAVE_HILDON
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "ZoomIn"));
         gtk_menu_shell_append (menu_shell, menuitem);
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "ZoomOut"));
         gtk_menu_shell_append (menu_shell, menuitem);
+        #endif
 
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "Encoding"));
@@ -2012,7 +2014,15 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
             }
         }
 
-        #if !HAVE_HILDON
+        #if HAVE_HILDON
+        gtk_menu_shell_append (menu_shell, gtk_separator_menu_item_new ());
+        menuitem = sokoke_action_create_popup_menu_item (
+                gtk_action_group_get_action (actions, "CompactAdd"));
+        gtk_menu_shell_append (menu_shell, menuitem);
+        menuitem = sokoke_action_create_popup_menu_item (
+                gtk_action_group_get_action (actions, "Fullscreen"));
+        gtk_menu_shell_append (menu_shell, menuitem);
+        #else
         gtk_menu_shell_append (menu_shell, gtk_separator_menu_item_new ());
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "BookmarkAdd"));
@@ -2033,7 +2043,6 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "SaveAs"));
         gtk_menu_shell_append (menu_shell, menuitem);
-        #if !HAVE_HILDON
         /* Currently views that don't support source, don't support
            saving either. If that changes, we need to think of something. */
         if (!midori_view_can_view_source (view))
@@ -2041,7 +2050,6 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "SourceView"));
         gtk_menu_shell_append (menu_shell, menuitem);
-        #endif
     }
 
     gtk_widget_show_all (menu);



More information about the Xfce4-commits mailing list