int main (int argc, char *argv[]) { const gchar *dir; GeditCommandLine *command_line; gboolean ret; gboolean service = FALSE; #ifdef G_OS_UNIX GeditDBus *dbus; GeditDBusResult dbusret; #endif #ifdef OS_OSX GPollFunc orig_poll_func; GPollFunc gdk_poll_func; #endif #ifndef ENABLE_GVFS_METADATA const gchar *cache_dir; gchar *metadata_filename; #endif /* Setup debugging */ gedit_debug_init (); gedit_debug_message (DEBUG_APP, "Startup"); /* Setup locale/gettext */ setlocale (LC_ALL, ""); gedit_dirs_init (); dir = gedit_dirs_get_gedit_locale_dir (); bindtextdomain (GETTEXT_PACKAGE, dir); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #ifndef ENABLE_GVFS_METADATA /* Setup metadata-manager */ cache_dir = gedit_dirs_get_user_cache_dir (); metadata_filename = g_build_filename (cache_dir, METADATA_FILE, NULL); gedit_metadata_manager_init (metadata_filename); g_free (metadata_filename); #endif #ifdef OS_OSX orig_poll_func = g_main_context_get_poll_func (NULL); #endif /* Parse command line arguments */ command_line = gedit_command_line_get_default (); ret = gedit_command_line_parse (command_line, &argc, &argv); if (!ret) { g_object_unref (command_line); return 1; } #ifdef G_OS_UNIX #ifdef OS_OSX /* Note: this is a bit of a hack. What happens here is that we are going to * store the poll function installed by gdk (happens in post-parse of options) * and replace it with the original main loop poll handler. We do this because * the gedit dbus stuff is going to run some main loops to run async gdbus calls. * The problem is that for OS X, the gdk poll func in the main context (which * will be run due to the fact that the main loops in our dbus code iterate the * main context) is going to process events from NSApp, INCLUDING apple events * such as OpenFiles. Since we are not setup yet, we are going to miss these * events. By swapping out the gdk poll func, and swapping it back in later, * we prevent this from happening. Note that we only do this when building * on OS X to prevent any possible future problems for other platforms. * This is a dirty hack, but it works for now. */ gdk_poll_func = g_main_context_get_poll_func (NULL); g_main_context_set_poll_func (NULL, orig_poll_func); #endif /* Run over dbus */ dbus = gedit_dbus_new (); dbusret = gedit_dbus_run (dbus); #ifdef OS_OSX g_main_context_set_poll_func (NULL, gdk_poll_func); #endif switch (dbusret) { case GEDIT_DBUS_RESULT_SUCCESS: case GEDIT_DBUS_RESULT_FAILED: /* fallthrough */ g_object_unref (command_line); g_object_unref (dbus); return dbusret == GEDIT_DBUS_RESULT_SUCCESS ? 0 : 1; break; case GEDIT_DBUS_RESULT_PROCEED_SERVICE: service = TRUE; break; case GEDIT_DBUS_RESULT_PROCEED: break; } #endif gedit_main (service); #ifdef G_OS_UNIX g_object_unref (dbus); #endif g_object_unref (command_line); return 0; }
int main (int argc, char *argv[]) { GType type; GeditApp *app; gint status; const gchar *dir; #ifdef OS_OSX type = GEDIT_TYPE_APP_OSX; #else #ifdef G_OS_WIN32 if (!gedit_w32_load_private_dll ()) { return 1; } type = GEDIT_TYPE_APP_WIN32; #else type = GEDIT_TYPE_APP_X11; #endif #endif /* NOTE: we should not make any calls to the gedit api before the * private library is loaded */ gedit_dirs_init (); /* Setup locale/gettext */ setlocale (LC_ALL, ""); dir = gedit_dirs_get_gedit_locale_dir (); bindtextdomain (GETTEXT_PACKAGE, dir); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); app = g_object_new (type, "application-id", "org.gnome.gedit", "flags", G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN, NULL); /* https://honk.sigxcpu.org/con/GTK__and_the_application_id.html */ g_set_prgname("org.gnome.gedit"); status = g_application_run (G_APPLICATION (app), argc, argv); /* Break reference cycles caused by the PeasExtensionSet * for GeditAppActivatable which holds a ref on the GeditApp */ g_object_run_dispose (G_OBJECT (app)); g_object_add_weak_pointer (G_OBJECT (app), (gpointer *) &app); g_object_unref (app); if (app != NULL) { gedit_debug_message (DEBUG_APP, "Leaking with %i refs", G_OBJECT (app)->ref_count); } #ifdef G_OS_WIN32 gedit_w32_unload_private_dll (); #endif return status; }