[geary/wip/737258-unity] Dynamically detect when running under Unity: Bug #737258



commit ef850fffc1f614ee415c32a42a4b22503edc9a6f
Author: Jim Nelson <jim yorba org>
Date:   Fri Nov 14 13:44:13 2014 -0800

    Dynamically detect when running under Unity: Bug #737258

 configure                                     |    6 ------
 src/CMakeLists.txt                            |   10 ----------
 src/client/application/geary-application.vala |    7 +++++++
 src/client/components/main-window.vala        |   14 +++++++-------
 src/client/components/pill-toolbar.vala       |    5 ++---
 src/client/composer/composer-window.vala      |   23 +++++++++++------------
 6 files changed, 27 insertions(+), 38 deletions(-)
---
diff --git a/configure b/configure
index e8c45b2..a2b5057 100755
--- a/configure
+++ b/configure
@@ -24,8 +24,6 @@ configure_help() {
        
          --disable-fatal-warnings
                                Disable Vala fatal warnings when compiling.
-         --enable-unity
-                               Enable Unity interface changes.
          --enable-ref-tracking
                                Enable reference tracking which is dumped to stdout when the program exits.
          --disable-schemas-compile
@@ -96,10 +94,6 @@ do
                             CMDLINE="${CMDLINE} -DREF_TRACKING=ON"
                             ;;
         
-        --enable-unity)
-                            CMDLINE="${CMDLINE} -DENABLE_UNITY=ON"
-                            ;;
-        
         --disable-schemas-compile)
                             CMDLINE="${CMDLINE} -DGSETTINGS_COMPILE=OFF"
                             CMDLINE="${CMDLINE} -DGSETTINGS_COMPILE_IN_PLACE=OFF"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 79633ab..13d1f2b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -583,16 +583,6 @@ else ()
     message(STATUS "Reference tracking: OFF")
 endif ()
 
-if (ENABLE_UNITY)
-    message(STATUS "Unity interface changes: ON")
-    set(EXTRA_VALA_OPTIONS
-        ${EXTRA_VALA_OPTIONS}
-        --define=ENABLE_UNITY
-    )
-else ()
-    message(STATUS "Unity interface changes: OFF")
-endif ()
-
 if (DISABLE_POODLE)
     message(STATUS "POODLE SSLv3 fix: OFF")
     set(EXTRA_VALA_OPTIONS
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index e093d5a..f533254 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -80,6 +80,11 @@ public class GearyApplication : Gtk.Application {
     
     public Configuration config { get; private set; }
     
+    /**
+     * Indicates application is running under Ubuntu's Unity shell.
+     */
+    public bool is_running_unity { get; private set; }
+    
     private static GearyApplication _instance = null;
     
     private string bin;
@@ -92,6 +97,8 @@ public class GearyApplication : Gtk.Application {
         Object(application_id: APP_ID);
         
         _instance = this;
+        
+        is_running_unity = Geary.String.stri_equal(Environment.get_variable("XDG_CURRENT_DESKTOP"), "Unity");
     }
     
     // Application.run() calls this as an entry point.
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index f8ea60f..ee80bc8 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -78,10 +78,10 @@ public class MainWindow : Gtk.ApplicationWindow {
         
         // Toolbar.
         main_toolbar = new MainToolbar();
-#if !ENABLE_UNITY
-        main_toolbar.show_close_button = true;
-        set_titlebar(main_toolbar);
-#endif
+        if (!GearyApplication.instance.is_running_unity) {
+            main_toolbar.show_close_button = true;
+            set_titlebar(main_toolbar);
+        }
         
         set_styling();
         create_layout();
@@ -218,9 +218,9 @@ public class MainWindow : Gtk.ApplicationWindow {
         folder_paned.pack1(status_bar_box, false, false);
         folder_paned.pack2(conversations_paned, true, false);
         
-#if ENABLE_UNITY
-        main_layout.pack_start(main_toolbar, false, true, 0);
-#endif
+        if (GearyApplication.instance.is_running_unity)
+            main_layout.pack_start(main_toolbar, false, true, 0);
+        
         main_layout.pack_end(folder_paned, true, true, 0);
         
         add(main_layout);
diff --git a/src/client/components/pill-toolbar.vala b/src/client/components/pill-toolbar.vala
index b4ea51d..5e9f5d4 100644
--- a/src/client/components/pill-toolbar.vala
+++ b/src/client/components/pill-toolbar.vala
@@ -56,10 +56,9 @@ public interface PillBar : Gtk.Container {
         }
         
         // Unity buttons are a bit tight
-#if ENABLE_UNITY
-        if (b.image != null)
+        if (GearyApplication.instance.is_running_unity && b.image != null)
             b.image.margin = b.image.margin + 4;
-#endif
+        
         b.always_show_image = true;
         
         if (!show_label)
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index 8e7e57f..8d1af40 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -16,21 +16,20 @@ public class ComposerWindow : Gtk.Window, ComposerContainer {
         
         add(composer);
         composer.subject_entry.changed.connect(() => {
-#if ENABLE_UNITY
-            title
-#else
-            composer.header.title
-#endif
-                = Geary.String.is_empty(composer.subject_entry.text.strip()) ? DEFAULT_TITLE :
-                composer.subject_entry.text.strip();
+            string new_title = Geary.String.is_empty_or_whitespace(composer.subject_entry.text)
+                ? DEFAULT_TITLE : composer.subject_entry.text.strip();
+            if (GearyApplication.instance.is_running_unity)
+                title = new_title;
+            else
+                composer.header.title = new_title;
         });
         composer.subject_entry.changed();
         
-#if !ENABLE_UNITY
-        composer.header.show_close_button = true;
-        composer.header.parent.remove(composer.header);
-        set_titlebar(composer.header);
-#endif
+        if (!GearyApplication.instance.is_running_unity) {
+            composer.header.show_close_button = true;
+            composer.header.parent.remove(composer.header);
+            set_titlebar(composer.header);
+        }
         
         add_accel_group(composer.ui.get_accel_group());
         show();


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