mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-05 02:11:08 +00:00
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
This commit is contained in:
parent
99ebb1cad2
commit
146f3a988d
@ -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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
GtkApplicationImplQuartz *quartz;
|
||||
}
|
||||
|
||||
static pascal OSErr
|
||||
quit_requested (const AppleEvent *aevt,
|
||||
AppleEvent *reply,
|
||||
long refcon)
|
||||
{
|
||||
GtkApplicationImplQuartz *quartz = GSIZE_TO_POINTER ((gsize)refcon);
|
||||
- (id)initWithImpl:(GtkApplicationImplQuartz*)impl;
|
||||
- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender;
|
||||
@end
|
||||
|
||||
/* Don't emit the "quit" signal immediately, since we're
|
||||
* called from a weird point in the guts of gdkeventloop-quartz.c
|
||||
@implementation GtkApplicationQuartzDelegate
|
||||
-(id)initWithImpl:(GtkApplicationImplQuartz*)impl
|
||||
{
|
||||
[super init];
|
||||
quartz = impl;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user