[Users] [PATCH 3/8] osx: add OSX integration with native GTK library

Igor Mammedov imammedo at redhat.com
Tue Jan 20 22:14:37 CET 2015


Add integration with native OS X menu and native
fullscreen mode for main window.

Signed-off-by: Igor Mammedov <imammedo at redhat.com>
---
 configure.ac        |  8 ++++++++
 src/Makefile.am     | 15 ++++++++++++---
 src/cm_osx.c        | 21 +++++++++++++++++++++
 src/cm_osx.h        | 13 +++++++++++++
 src/compose.c       |  1 +
 src/gtk/Makefile.am |  4 +++-
 src/main.c          |  3 +++
 src/mainwindow.c    |  3 +++
 8 files changed, 64 insertions(+), 4 deletions(-)
 create mode 100644 src/cm_osx.c
 create mode 100644 src/cm_osx.h

diff --git a/configure.ac b/configure.ac
index 86d5de5..703b3a3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1858,6 +1858,14 @@ else
 	AC_MSG_RESULT(no)
 fi
 
+_gdk_tgt=`$PKG_CONFIG --variable=target gdk-2.0`
+AM_CONDITIONAL([GDK_TARGET_QUARTZ], [test x$_gdk_tgt = xquartz])
+if test "x$_gdk_tgt" = xquartz; then
+	PKG_CHECK_MODULES(GTK_MAC, gtk-mac-integration-gtk2)
+	AC_SUBST(GTK_MAC_LIBS)
+	AC_SUBST(GTK_MAC_CFLAGS)
+fi
+
 dnl And finally the automake conditionals.
 
 AM_CONDITIONAL(BUILD_ACPI_NOTIFIER_PLUGIN,	test x"$enable_acpi_notifier_plugin" != xno)
diff --git a/src/Makefile.am b/src/Makefile.am
index cfb89a5..4404879 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -122,6 +122,12 @@ abook_headers = \
 	pine.h \
 	vcard.h
 
+if GDK_TARGET_QUARTZ
+osx_integration_source = cm_osx.c
+osx_integration_CPPFLAGS = @GTK_MAC_CFLAGS@ -xobjective-c
+osx_integration_LDFLAGS = @GTK_MAC_LIBS@ -lobjc
+endif
+
 claws_mail_SOURCES = \
 	account.c \
 	action.c \
@@ -232,7 +238,8 @@ claws_mail_SOURCES = \
 	unmime.c \
 	uri_opener.c \
 	wizard.c \
-	$(abook_source)
+	$(abook_source) \
+	$(osx_integration_source)
 
 claws_mailincludedir = $(pkgincludedir)
 claws_mailinclude_HEADERS = \
@@ -569,7 +576,8 @@ claws_mail_LDADD = \
 	$(STARTUP_NOTIFICATION_LIBS) \
 	$(LIBETPAN_LIBS) \
 	$(DBUS_LIBS) \
-	$(CONTACTS_LIBS)
+	$(CONTACTS_LIBS) \
+	$(osx_integration_LDFLAGS)
 
 pixmapdir=$(datadir)/icons/hicolor/48x48/apps
 
@@ -590,7 +598,8 @@ AM_CPPFLAGS = \
 	$(DBUS_CFLAGS) \
 	$(NETWORKMANAGER_SUPPORT_CFLAGS) \
 	$(VALGRIND_CFLAGS) \
-	$(CONTACTS_CFLAGS)
+	$(CONTACTS_CFLAGS) \
+	$(osx_integration_CPPFLAGS)
 
 #no-unused-function is there because of bison stuff
 #no-deprecated-declarations because of gpgme_data_rewind, which we have
diff --git a/src/cm_osx.c b/src/cm_osx.c
new file mode 100644
index 0000000..6e9804e
--- /dev/null
+++ b/src/cm_osx.c
@@ -0,0 +1,21 @@
+#include <gdk/gdkquartz.h>
+#include "gtkosxapplication.h"
+#include "cm_osx.h"
+
+void claws_mail_osx_init(GtkWidget *window)
+{
+	GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
+	NSWindow *native = gdk_quartz_window_get_nswindow (GTK_WIDGET (window)->window);
+
+	[native setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
+
+	gtkosx_application_ready(theApp);
+}
+
+void claws_mail_osx_set_menu(GtkWidget *menu)
+{
+	GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
+
+	gtk_widget_hide (menu);
+	gtkosx_application_set_menu_bar(theApp, GTK_MENU_SHELL(menu));
+}
diff --git a/src/cm_osx.h b/src/cm_osx.h
new file mode 100644
index 0000000..c763eba
--- /dev/null
+++ b/src/cm_osx.h
@@ -0,0 +1,13 @@
+#ifndef CM_OSX_H
+
+#include <gtk/gtk.h>
+
+#ifdef MAC_INTEGRATION
+void claws_mail_osx_init(GtkWidget *window);
+void claws_mail_osx_set_menu(GtkWidget *menu);
+#else
+static inline void claws_mail_osx_init(GtkWidget *window) {}
+static inline void claws_mail_osx_set_menu(GtkWidget *menu) {}
+#endif
+
+#endif
diff --git a/src/compose.c b/src/compose.c
index d4156ca..b9857f5 100644
--- a/src/compose.c
+++ b/src/compose.c
@@ -8052,6 +8052,7 @@ static Compose *compose_create(PrefsAccount *account,
 		gtk_widget_show(window);
 	}
 	
+	claws_mail_osx_set_menu(gtk_ui_manager_get_widget(compose->ui_manager, "/Menu"));
 	return compose;
 }
 
diff --git a/src/gtk/Makefile.am b/src/gtk/Makefile.am
index da36309..5937556 100644
--- a/src/gtk/Makefile.am
+++ b/src/gtk/Makefile.am
@@ -16,6 +16,8 @@ gtk2_sources = \
 	gtkcmoptionmenu.c
 endif
 
+GTK_CFLAGS += @GTK_MAC_CFLAGS@
+
 libclawsgtk_la_SOURCES = \
 	about.c \
 	colorlabel.c \
@@ -88,7 +90,7 @@ AM_CPPFLAGS = \
 	$(GTK_CFLAGS) \
 	$(ENCHANT_CFLAGS) \
 	-DPLUGINDIR=\"$(PLUGINDIR)\" \
-	-DDOCDIR=\"$(DOCDIR)\" 
+	-DDOCDIR=\"$(DOCDIR)\"
 
 libclawsgtk_la_LIBADD = \
 	../common/libclawscommon.la \
diff --git a/src/main.c b/src/main.c
index 813bb47..405d147 100644
--- a/src/main.c
+++ b/src/main.c
@@ -142,6 +142,7 @@
 #include "crash.h"
 
 #include "timing.h"
+#include "cm_osx.h"
 
 #ifdef HAVE_NETWORKMANAGER_SUPPORT
 /* Went offline due to NetworkManager */
@@ -1556,6 +1557,8 @@ int main(int argc, char *argv[])
 
 	END_TIMING();
 
+	claws_mail_osx_init(mainwin->window);
+
 	gtk_main();
 
 #ifdef HAVE_NETWORKMANAGER_SUPPORT
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 377d1b9..3be7221 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -93,6 +93,7 @@
 #ifdef G_OS_WIN32
 #include "w32lib.h"
 #endif
+#include "cm_osx.h"
 
 #define AC_LABEL_WIDTH	240
 
@@ -2218,6 +2219,8 @@ MainWindow *main_window_create()
 	if (prefs_common.mainwin_menubar)
 		cm_toggle_menu_set_active_full(mainwin->ui_manager,"Menu/View/ShowHide/MenuBar", TRUE);
 	
+	claws_mail_osx_set_menu(gtk_ui_manager_get_widget(mainwin->ui_manager, "/Menu"));
+
 	return mainwin;
 }
 
-- 
1.9.3 (Apple Git-50)




More information about the Users mailing list