From 92f8f0d934086b3c133f72322dd92b3f641b575d Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 2 Jan 2012 00:07:41 +0000 Subject: [PATCH] Add gtk mac integration - Move the menu bar to the top of the screen --- configure.ac | 5 +++++ src/Makefile.am | 5 +++++ src/main.c | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/configure.ac b/configure.ac index b2bddd8..dab9baa 100644 --- a/configure.ac +++ b/configure.ac @@ -32,6 +32,11 @@ AM_CONDITIONAL([SYS_WIN], test "$SYS" = "WIN") AM_CONDITIONAL([SYS_MAC], test "$SYS" = "MAC") AM_CONDITIONAL([SYS_X11], test "$SYS" = "X11") +# Check for Mac OX +if test "$SYS" = "MAC"; then + PKG_CHECK_MODULES(MAC, gtk-mac-integration) +fi + # Check for relative build AC_ARG_ENABLE(relative, [AS_HELP_STRING([--enable-relative], [enable runtime search paths @<:@default=no@:>@])], diff --git a/src/Makefile.am b/src/Makefile.am index fb3d4f6..ec7fb21 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,6 +34,11 @@ aweather_dbg_CPPFLAGS = $(aweather_CPPFLAGS) aweather_dbg_LDADD = $(aweather_LDADD) endif +if SYS_MAC +aweather_CPPFLAGS += $(MAC_CFLAGS) +aweather_LDADD += $(MAC_LIBS) +endif + .rc.o: ../data/icons/48x48/aweather.ico $(RC) -o $@ $< diff --git a/src/main.c b/src/main.c index 55d0ad9..a8bc426 100644 --- a/src/main.c +++ b/src/main.c @@ -21,6 +21,10 @@ #include #include +#ifdef MAC_INTEGRATION +#include +#endif + #include #include "aweather-gui.h" @@ -87,6 +91,19 @@ static void set_toggle_action(AWeatherGui *gui, const char *action, gboolean ena gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(object), enabled); } +static void setup_mac(AWeatherGui *gui) +{ +#ifdef MAC_INTEGRATION + GtkWidget *menu = aweather_gui_get_widget(gui, "main_menu"); + GtkOSXApplication *app = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL); + gtk_widget_hide(menu); + gtk_osxapplication_set_menu_bar(app, GTK_MENU_SHELL(menu)); + gtk_osxapplication_set_use_quartz_accelerators(app, TRUE); + gtk_osxapplication_ready(app); + //gtk_osxapplication_sync_menubar(app) +#endif +} + /******** * Main * ********/ @@ -173,6 +190,7 @@ int main(int argc, char *argv[]) /* Done with init, show gui */ gtk_widget_show_all(GTK_WIDGET(gui)); set_toggle_action(gui, "fullscreen", fullscreen); // Resest widget hiding + setup_mac(gui); // done after show_all gtk_main(); gdk_threads_leave(); gdk_display_close(gdk_display_get_default()); -- 2.41.0