diff options
author | Ryan Lortie <desrt@desrt.ca> | 2013-12-16 10:59:49 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2014-01-07 23:08:45 -0500 |
commit | 146f3a988d6c88fe9661e9ae299af6df72a5181a (patch) | |
tree | 41c7f0808ab3e07ef5589ca60dc4e380e68747cf | |
parent | 99ebb1cad2d8f4eec293bca02f73a450fac18577 (diff) | |
download | gtk+-146f3a988d6c88fe9661e9ae299af6df72a5181a.tar.gz |
gtkapplication-quartz: clean up inhibit code
When testing with bloatpad, the existing inhibit code seems not to be
working at all. Replace it with a cleaner and simpler version that
works.
https://bugzilla.gnome.org/show_bug.cgi?id=720551
-rw-r--r-- | gtk/gtkapplication-quartz.c | 84 |
1 files changed, 31 insertions, 53 deletions
diff --git a/gtk/gtkapplication-quartz.c b/gtk/gtkapplication-quartz.c index c1412091a4..9d9f89707a 100644 --- a/gtk/gtkapplication-quartz.c +++ b/gtk/gtkapplication-quartz.c @@ -22,8 +22,6 @@ #include "gtkapplicationprivate.h" #include "gtkmodelmenu-quartz.h" -#include "gtkmessagedialog.h" -#include <glib/gi18n-lib.h> #import <Cocoa/Cocoa.h> typedef struct @@ -51,66 +49,39 @@ typedef struct GSList *inhibitors; gint quit_inhibit; guint next_cookie; + NSObject *delegate; } GtkApplicationImplQuartz; G_DEFINE_TYPE (GtkApplicationImplQuartz, gtk_application_impl_quartz, GTK_TYPE_APPLICATION_IMPL) -/* OS X implementation copied from EggSMClient, but simplified since - * it doesn't need to interact with the user. - */ - -static gboolean -idle_will_quit (gpointer user_data) +@interface GtkApplicationQuartzDelegate : NSObject { - GtkApplicationImplQuartz *quartz = user_data; + GtkApplicationImplQuartz *quartz; +} - if (quartz->quit_inhibit == 0) - g_application_quit (G_APPLICATION (quartz->impl.application)); - else - { - GtkApplicationQuartzInhibitor *inhibitor; - GSList *iter; - GtkWidget *dialog; - - for (iter = quartz->inhibitors; iter; iter = iter->next) - { - inhibitor = iter->data; - if (inhibitor->flags & GTK_APPLICATION_INHIBIT_LOGOUT) - break; - } - g_assert (inhibitor != NULL); - - dialog = gtk_message_dialog_new (inhibitor->window, - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _("%s cannot quit at this time:\n\n%s"), - g_get_application_name (), - inhibitor->reason); - g_signal_connect_swapped (dialog, - "response", - G_CALLBACK (gtk_widget_destroy), - dialog); - gtk_widget_show_all (dialog); - } +- (id)initWithImpl:(GtkApplicationImplQuartz*)impl; +- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender; +@end - return G_SOURCE_REMOVE; +@implementation GtkApplicationQuartzDelegate +-(id)initWithImpl:(GtkApplicationImplQuartz*)impl +{ + [super init]; + quartz = impl; + return self; } -static pascal OSErr -quit_requested (const AppleEvent *aevt, - AppleEvent *reply, - long refcon) +-(NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender { - GtkApplicationImplQuartz *quartz = GSIZE_TO_POINTER ((gsize)refcon); - - /* Don't emit the "quit" signal immediately, since we're - * called from a weird point in the guts of gdkeventloop-quartz.c + /* We have no way to give our message other than to pop up a dialog + * ourselves, which we should not do since the OS will already show + * one when we return NSTerminateNow. + * + * Just let the OS show the generic message... */ - g_idle_add_full (G_PRIORITY_DEFAULT, idle_will_quit, quartz, NULL); - - return quartz->quit_inhibit == 0 ? noErr : userCanceledErr; + return quartz->quit_inhibit == 0 ? NSTerminateNow : NSTerminateCancel; } +@end static void gtk_application_impl_quartz_menu_changed (GtkApplicationImplQuartz *quartz) @@ -133,9 +104,10 @@ gtk_application_impl_quartz_startup (GtkApplicationImpl *impl, GtkApplicationImplQuartz *quartz = (GtkApplicationImplQuartz *) impl; if (register_session) - AEInstallEventHandler (kCoreEventClass, kAEQuitApplication, - NewAEEventHandlerUPP (quit_requested), - (long)GPOINTER_TO_SIZE (quartz), false); + { + quartz->delegate = [[GtkApplicationQuartzDelegate alloc] initWithImpl:quartz]; + [NSApp setDelegate: quartz->delegate]; + } gtk_application_impl_quartz_menu_changed (quartz); @@ -149,6 +121,12 @@ gtk_application_impl_quartz_shutdown (GtkApplicationImpl *impl) gtk_quartz_clear_main_menu (); + if (quartz->delegate) + { + [quartz->delegate release]; + quartz->delegate = NULL; + } + g_slist_free_full (quartz->inhibitors, (GDestroyNotify) gtk_application_quartz_inhibitor_free); quartz->inhibitors = NULL; } |