From 51c8b6fcc07085c509f02c8b6a9f87de6aab637d Mon Sep 17 00:00:00 2001 From: Alexander Kojevnikov Date: Tue, 19 Apr 2011 21:09:24 +0800 Subject: [PATCH] osx: Move the main menu to where it belongs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fix rigth click → Quit (issue 24) and the ⌘ Q shortcut (issue 44). --- src/spek-platform.c | 16 +++++++++++++++- src/spek-platform.h | 5 ++++- src/spek-window.vala | 2 ++ vapi/spek-platform.vapi | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/spek-platform.c b/src/spek-platform.c index 5b2b1fb..c875a91 100644 --- a/src/spek-platform.c +++ b/src/spek-platform.c @@ -34,7 +34,7 @@ void spek_platform_init () { #ifdef G_OS_DARWIN - GtkOSXApplication *app = g_object_new (GTK_TYPE_OSX_APPLICATION, NULL); + g_object_new (GTK_TYPE_OSX_APPLICATION, NULL); #endif } @@ -65,6 +65,20 @@ void spek_platform_fix_args (gchar **argv, gint argc) { #endif } +void spek_platform_fix_ui (GtkUIManager *ui) +{ +#ifdef G_OS_DARWIN + GtkOSXApplication *app = NULL; + GtkWidget *menubar = NULL; + + app = g_object_new (GTK_TYPE_OSX_APPLICATION, NULL); + menubar = gtk_ui_manager_get_widget (ui, "/MenuBar"); + gtk_widget_hide (menubar); + gtk_osxapplication_set_menu_bar (app, GTK_MENU_SHELL (menubar)); + gtk_osxapplication_ready (app); +#endif +} + void spek_platform_show_uri (const gchar *uri) { #ifdef G_OS_WIN32 /* gtk_show_uri doesn't work on Windows... */ diff --git a/src/spek-platform.h b/src/spek-platform.h index 3662995..f17f531 100644 --- a/src/spek-platform.h +++ b/src/spek-platform.h @@ -19,7 +19,7 @@ #ifndef __SPEK_PLATFORM_H__ #define __SPEK_PLATFORM_H__ -#include +#include /* Platform-specific initialisation */ void spek_platform_init (); @@ -27,6 +27,9 @@ void spek_platform_init (); /* Convert from UTF-16 to UTF-8 when running on Windows */ void spek_platform_fix_args (gchar **argv, gint argc); +/* OSX has its own approach to menu bars */ +void spek_platform_fix_ui (GtkUIManager *ui); + /* Open a link in the browser */ void spek_platform_show_uri (const gchar *uri); diff --git a/src/spek-window.vala b/src/spek-window.vala index edb41a6..57fa555 100644 --- a/src/spek-window.vala +++ b/src/spek-window.vala @@ -123,6 +123,8 @@ namespace Spek { toolbar.show_all (); spectrogram.show_all (); vbox.show (); + + Platform.fix_ui (ui); show (); // Set up Drag and Drop diff --git a/vapi/spek-platform.vapi b/vapi/spek-platform.vapi index 1146051..f8ab17c 100644 --- a/vapi/spek-platform.vapi +++ b/vapi/spek-platform.vapi @@ -2,6 +2,7 @@ namespace Spek.Platform { public static void init (); public static void fix_args (string[] args); + public static void fix_ui (Gtk.UIManager ui); public static void show_uri (string uri); public static string read_line (string uri); public static double get_font_scale ();