[gitg] Use native controls on OS X



commit 871ac85e1bdef037a72e95f805e2e11120417720
Author: Jesse van den Kieboom <jkieboom esri com>
Date:   Sun Nov 8 15:14:26 2015 +0100

    Use native controls on OS X

 configure.ac                     |   22 ++++
 gitg/Makefile.am                 |    1 +
 gitg/gitg-window.vala            |   45 ++++++---
 gitg/resources/ui/gitg-window.ui |  199 ++++++++++++++++++++------------------
 libgitg/Makefile.am              |    9 ++
 libgitg/gitg-platform-support.c  |   20 ++++
 libgitg/gitg-platform-support.h  |    9 ++
 vapi/gitg-platform-support.vapi  |    9 ++
 8 files changed, 204 insertions(+), 110 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0487fd3..3419ee8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,6 +110,28 @@ PKG_CHECK_MODULES(LIBGITG, [
        libsecret-1
 ])
 
+gdk_targets=`$PKG_CONFIG --variable=targets gdk-3.0`
+
+for target in $gdk_targets;
+do
+       case "$target" in
+               quartz)
+                       gdk_windowing_quartz=yes
+                       ;;
+               win32)
+                       gdk_windowing_win32=yes
+                       ;;
+               x11)
+                       gdk_windowing_x11=yes
+       esac
+done
+
+AM_CONDITIONAL(GDK_WINDOWING_X11, test "$gdk_windowing_x11" = "yes")
+AM_CONDITIONAL(GDK_WINDOWING_QUARTZ, test "$gdk_windowing_quartz" = "yes")
+AM_CONDITIONAL(GDK_WINDOWING_WIN32, test "$gdk_windowing_win32" = "yes")
+
+AC_PROG_OBJC
+
 AC_MSG_CHECKING([for libgit2-glib threading support])
 
 cflags_save="${CFLAGS}"
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index 8f1f8bc..33dfe0b 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -26,6 +26,7 @@ gitg_gitg_VALAFLAGS =                                         \
        --pkg gd-1.0                                            \
        --pkg gtksourceview-3.0                                 \
        --pkg GtkSpell-3.0                                      \
+       --pkg gitg-platform-support                             \
        --girdir "$(top_builddir)/libgd"                        \
        --girdir "$(top_builddir)"                              \
        --vapidir "$(top_srcdir)/vapi"                          \
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index a10337c..6d0ddb3 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -58,6 +58,9 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
        private Gtk.Grid d_grid_main;
 
        [GtkChild]
+       private Gtk.Grid d_grid_top;
+
+       [GtkChild]
        private Gtk.ToggleButton d_select_button;
        [GtkChild]
        private Gtk.Button d_select_cancel_button;
@@ -188,6 +191,12 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
 
        construct
        {
+               if (Gitg.PlatformSupport.use_native_window_controls())
+               {
+                       set_titlebar(null);
+                       d_grid_top.attach(d_header_bar, 0, 0, 1, 1);
+               }
+
                add_action_entries(win_entries, this);
 
                d_notifications = new Notifications(d_overlay);
@@ -365,26 +374,26 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
 
        private void update_title()
        {
+               string windowtitle = "gitg";
+               string title;
+               string? subtitle = null;
+
                if (d_repository != null)
                {
-                       // set title
                        File? workdir = d_repository.get_workdir();
-                       string name;
 
                        if (workdir != null)
                        {
                                var parent_path = Utils.replace_home_dir_with_tilde(workdir.get_parent());
 
-                               name = @"$(d_repository.name) ($parent_path)";
-                               title = @"$name - gitg";
+                               title = @"$(d_repository.name) ($parent_path)";
+                               windowtitle = @"$name - gitg";
                        }
                        else
                        {
-                               name = d_repository.name;
+                               title = d_repository.name;
                        }
 
-                       d_header_bar.set_title(name);
-
                        string? head_name = null;
 
                        try
@@ -396,19 +405,25 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
 
                        if (head_name != null)
                        {
-                               d_header_bar.set_subtitle(Markup.escape_text(head_name));
-                       }
-                       else
-                       {
-                               d_header_bar.set_subtitle(null);
+                               subtitle = Markup.escape_text(head_name);
                        }
                }
                else
                {
-                       title = "gitg";
+                       title = _("Projects");
+               }
+
+               if (Gitg.PlatformSupport.use_native_window_controls())
+               {
+                       d_header_bar.set_title(subtitle);
+                       this.title = title;
+               }
+               else
+               {
+                       d_header_bar.set_title(title);
+                       d_header_bar.set_subtitle(subtitle);
 
-                       d_header_bar.set_title(_("Projects"));
-                       d_header_bar.set_subtitle(null);
+                       this.title = windowtitle;
                }
        }
 
diff --git a/gitg/resources/ui/gitg-window.ui b/gitg/resources/ui/gitg-window.ui
index 98e8ac0..b6955e9 100644
--- a/gitg/resources/ui/gitg-window.ui
+++ b/gitg/resources/ui/gitg-window.ui
@@ -14,10 +14,7 @@
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="vexpand">False</property>
-        <property name="show_close_button">True</property>
-        <style>
-          <class name="titlebar"/>
-        </style>
+        <property name="show_close_button">False</property>
         <child>
           <object class="GtkButton" id="d_dash_button">
             <property name="visible">False</property>
@@ -130,130 +127,142 @@
       </object>
     </child>
     <child>
-      <object class="GtkOverlay" id="d_overlay">
+      <object class="GtkGrid" id="d_grid_top">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <child>
-          <object class="GtkGrid" id="d_grid_main">
+          <object class="GtkOverlay" id="d_overlay">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <child>
-              <object class="GtkBox" id="d_infobar_placeholder">
+              <object class="GtkGrid" id="d_grid_main">
                 <property name="visible">True</property>
-                <property name="orientation">horizontal</property>
+                <property name="can_focus">False</property>
                 <child>
-                  <object class="GtkInfoBar" id="d_infobar">
-                    <property name="visible">False</property>
-                    <child internal-child="content_area">
-                      <object class="GtkBox" id="infobar_content_area">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="border_width">8</property>
-                        <property name="orientation">vertical</property>
-                        <property name="spacing">16</property>
-                        <child>
-                          <object class="GtkLabel" id="d_infobar_primary_label">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="selectable">True</property>
-                            <property name="use-markup">True</property>
-                            <property name="halign">GTK_ALIGN_START</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">True</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="d_infobar_secondary_label">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="selectable">True</property>
-                            <property name="use-markup">True</property>
-                            <property name="halign">GTK_ALIGN_START</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">True</property>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                        <child internal-child="action_area">
-                          <object class="GtkButtonBox" id="infobar_action_area">
+                  <object class="GtkBox" id="d_infobar_placeholder">
+                    <property name="visible">True</property>
+                    <property name="orientation">horizontal</property>
+                    <child>
+                      <object class="GtkInfoBar" id="d_infobar">
+                        <property name="visible">False</property>
+                        <child internal-child="content_area">
+                          <object class="GtkBox" id="infobar_content_area">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="border_width">5</property>
+                            <property name="border_width">8</property>
                             <property name="orientation">vertical</property>
-                            <property name="spacing">6</property>
-                            <property name="layout_style">end</property>
+                            <property name="spacing">16</property>
+                            <child>
+                              <object class="GtkLabel" id="d_infobar_primary_label">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="selectable">True</property>
+                                <property name="use-markup">True</property>
+                                <property name="halign">GTK_ALIGN_START</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
                             <child>
-                              <object class="GtkButton" id="d_infobar_close_button">
+                              <object class="GtkLabel" id="d_infobar_secondary_label">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="selectable">True</property>
+                                <property name="use-markup">True</property>
+                                <property name="halign">GTK_ALIGN_START</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                            <child internal-child="action_area">
+                              <object class="GtkButtonBox" id="infobar_action_area">
                                 <property name="visible">True</property>
-                                <property name="label" translatable="yes">Close</property>
+                                <property name="can_focus">False</property>
+                                <property name="border_width">5</property>
+                                <property name="orientation">vertical</property>
+                                <property name="spacing">6</property>
+                                <property name="layout_style">end</property>
+                                <child>
+                                  <object class="GtkButton" id="d_infobar_close_button">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Close</property>
+                                  </object>
+                                </child>
                               </object>
                             </child>
                           </object>
                         </child>
+                        <action-widgets>
+                          <action-widget response="-6">d_infobar_close_button</action-widget>
+                        </action-widgets>
                       </object>
                     </child>
-                    <action-widgets>
-                      <action-widget response="-6">d_infobar_close_button</action-widget>
-                    </action-widgets>
-                  </object>
-                </child>
-              </object>
-            </child>
-            <child>
-              <object class="GtkSearchBar" id="d_search_bar">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="show-close-button">False</property>
-                <child>
-                  <object class="GdTaggedEntry" id="d_search_entry">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="invisible_char">●</property>
-                    <property name="invisible_char_set">True</property>
-                    <property name="width-request">500</property>
-                    <signal name="changed" handler="search_entry_changed" swapped="no"/>
                   </object>
                 </child>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">1</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkStack" id="d_main_stack">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="hexpand">True</property>
-                <property name="vexpand">True</property>
                 <child>
-                  <object class="GitgDashView" id="d_dash_view">
+                  <object class="GtkSearchBar" id="d_search_bar">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="show-close-button">False</property>
+                    <child>
+                      <object class="GdTaggedEntry" id="d_search_entry">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="invisible_char">●</property>
+                        <property name="invisible_char_set">True</property>
+                        <property name="width-request">500</property>
+                        <signal name="changed" handler="search_entry_changed" swapped="no"/>
+                      </object>
+                    </child>
                   </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
                 </child>
                 <child>
-                  <object class="GtkStack" id="d_stack_activities">
+                  <object class="GtkStack" id="d_main_stack">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
+                    <property name="hexpand">True</property>
+                    <property name="vexpand">True</property>
+                    <child>
+                      <object class="GitgDashView" id="d_dash_view">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkStack" id="d_stack_activities">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                      </object>
+                    </child>
                   </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">2</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
                 </child>
               </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">2</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
             </child>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>            
+          </packing>
         </child>
       </object>
     </child>
diff --git a/libgitg/Makefile.am b/libgitg/Makefile.am
index 15ff118..2266674 100644
--- a/libgitg/Makefile.am
+++ b/libgitg/Makefile.am
@@ -21,6 +21,11 @@ libgitg_libgitg_1_0_la_LDFLAGS =     \
 libgitg_libgitg_1_0_la_LIBADD =        \
        $(LIBGITG_LIBS)
 
+if GDK_WINDOWING_QUARTZ
+libgitg_libgitg_1_0_la_LIBADD += -lobjc
+libgitg_libgitg_1_0_la_CFLAGS += -xobjective-c
+endif
+
 libgitg_libgitg_1_0_la_VALAFLAGS =     \
        --pkg ggit-1.0                  \
        --pkg gtk+-3.0                  \
@@ -31,6 +36,7 @@ libgitg_libgitg_1_0_la_VALAFLAGS =    \
        --pkg gdesktop-enums-3.0        \
        --pkg libsoup-2.4               \
        --pkg gtksourceview-3.0         \
+       --pkg gitg-platform-support     \
        $(GITG_VALAFLAGS)               \
        --vapidir $(top_srcdir)/vapi    \
        --includedir libgitg            \
@@ -82,11 +88,14 @@ libgitg_libgitg_1_0_la_VALASOURCES =                        \
 
 libgitg_libgitg_1_0_la_SOURCES =               \
        $(libgitg_libgitg_1_0_la_VALASOURCES)   \
+       libgitg/gitg-platform-support.c         \
        libgitg/gitg-resources.c
 
 libgitg_libgitg_1_0_la_headerdir = $(prefix)/include/libgitg-1.0/libgitg
 libgitg_libgitg_1_0_la_header_HEADERS = libgitg/libgitg.h
 
+noinst_HEADERS += libgitg/gitg-platform-support.h
+
 libgitg_libgitg_1_0_la_vapidir = $(prefix)/share/vala/vapi
 libgitg_libgitg_1_0_la_vapi_DATA = libgitg/libgitg-1.0.vapi
 
diff --git a/libgitg/gitg-platform-support.c b/libgitg/gitg-platform-support.c
new file mode 100644
index 0000000..bd043d2
--- /dev/null
+++ b/libgitg/gitg-platform-support.c
@@ -0,0 +1,20 @@
+#include "gitg-platform-support.h"
+
+#ifdef GDK_WINDOWING_QUARTZ
+#include <gdk/gdkquartz.h>
+#endif
+
+gboolean
+gitg_platform_support_use_native_window_controls (GdkDisplay *display)
+{
+#ifdef GDK_WINDOWING_QUARTZ
+       if (display == NULL)
+       {
+               display = gdk_display_get_default ();
+       }
+
+       return GDK_IS_QUARTZ_DISPLAY (display);
+#else
+       return FALSE;
+#endif
+}
diff --git a/libgitg/gitg-platform-support.h b/libgitg/gitg-platform-support.h
new file mode 100644
index 0000000..a58c814
--- /dev/null
+++ b/libgitg/gitg-platform-support.h
@@ -0,0 +1,9 @@
+#ifndef __GITG_PLATFORM_SUPPORT_H__
+#define __GITG_PLATFORM_SUPPORT_H__
+
+#include <gdk/gdk.h>
+
+gboolean gitg_platform_support_use_native_window_controls (GdkDisplay *display);
+
+#endif /* __GITG_PLATFORM_SUPPORT_H__ */
+
diff --git a/vapi/gitg-platform-support.vapi b/vapi/gitg-platform-support.vapi
new file mode 100644
index 0000000..c0485d2
--- /dev/null
+++ b/vapi/gitg-platform-support.vapi
@@ -0,0 +1,9 @@
+[CCode(cheader_filename = "libgitg/gitg-platform-support.h")]
+namespace Gitg
+{
+       [CCode(cprefix = "GitgPlatformSupport", lower_case_cprefix = "gitg_platform_support_")]
+       public class PlatformSupport
+       {
+               public static bool use_native_window_controls(Gdk.Display? display = null);
+       }
+}


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