Commit 14098dc0 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Made --no-interface not calling gtk_init() (and thus not contacting the X

2001-11-17  Michael Natterer  <mitch@gimp.org>

	Made --no-interface not calling gtk_init() (and thus not
	contacting the X server) any more. (Fixes #58961).

	* app/core/gimp.[ch]: added two new function pointers
	"gui_main_loop_func" and "gui_main_loop_quit_func" and an own
	stack of GMainLoops which is used if they are not set.

	* app/gui/gui.[ch]: added main loop functions here and set them as
	pointers in the Gimp instance. Separated gui_libs_init() from
	gui_themes_init() so it can be used as replacement for gtk_init()
	and be called before command line parsing.

	* app/main.c: check for "--no-interface" before initializing
	anything. Added a "--g-fatal-warnings" option (cut'n'paste from
	gtkmain.c). Added a check for "--" (end of options).

	* app/app_procs.c: call the new gimp_main_loop() functions,
	call gui_themes_init().

	* app/devices.[ch]: reduce usage of "the_gimp" by passing "Gimp"
	pointers to some functions.

	* app/plug_in.c: some ugly checks for the_gimp->no_interface which
	will go away once this file is core/ui chopped. Call
	gimp_main_loop() stuff instead of gtk_main().

	* app/core/gimptoolinfo.c: allow passing a NUL GdkPixbuf pointer.
parent b042c682
2001-11-17 Michael Natterer <mitch@gimp.org>
Made --no-interface not calling gtk_init() (and thus not
contacting the X server) any more. (Fixes #58961).
* app/core/gimp.[ch]: added two new function pointers
"gui_main_loop_func" and "gui_main_loop_quit_func" and an own
stack of GMainLoops which is used if they are not set.
* app/gui/gui.[ch]: added main loop functions here and set them as
pointers in the Gimp instance. Separated gui_libs_init() from
gui_themes_init() so it can be used as replacement for gtk_init()
and be called before command line parsing.
* app/main.c: check for "--no-interface" before initializing
anything. Added a "--g-fatal-warnings" option (cut'n'paste from
gtkmain.c). Added a check for "--" (end of options).
* app/app_procs.c: call the new gimp_main_loop() functions,
call gui_themes_init().
* app/devices.[ch]: reduce usage of "the_gimp" by passing "Gimp"
pointers to some functions.
* app/plug_in.c: some ugly checks for the_gimp->no_interface which
will go away once this file is core/ui chopped. Call
gimp_main_loop() stuff instead of gtk_main().
* app/core/gimptoolinfo.c: allow passing a NUL GdkPixbuf pointer.
2001-11-17 Wang Jian <lark@linux.net.cn>
* configure.in(ALL_LINGUAS): Added zh_CN for Simplified Chinese.
......@@ -47,7 +77,7 @@
2001-11-16 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpcolorbutton.[ch]: added Black and White to popup
menu. Take widget->allocation into account when calculation popup
menu. Take widget->allocation into account when calculating popup
position since GtkButton is a NO_WINDOW widget now.
2001-11-16 Sven Neumann <sven@gimp.org>
......
......@@ -195,6 +195,7 @@ static void plug_in_init_shm (void);
static gchar * plug_in_search_in_path (gchar *search_path,
gchar *filename);
PlugIn *current_plug_in = NULL;
GSList *proc_defs = NULL;
......@@ -416,8 +417,11 @@ plug_in_init (Gimp *gimp,
/* add the plug-in procs to the procedure database */
plug_in_add_to_db ();
/* make the menu */
plug_in_make_menu ();
if (! gimp->no_interface)
{
/* make the menu */
plug_in_make_menu ();
}
/* run the available extensions */
if (be_verbose)
......@@ -1232,7 +1236,8 @@ plug_in_close (PlugIn *plug_in,
if (plug_in->recurse)
{
gtk_main_quit ();
gimp_main_loop_quit (the_gimp);
plug_in->recurse = FALSE;
}
......@@ -1357,11 +1362,14 @@ plug_in_run (ProcRecord *proc_rec,
*/
if ((proc_rec->proc_type == GIMP_EXTENSION) &&
(proc_rec->num_args == 0))
gtk_main ();
{
gimp_main_loop (the_gimp);
}
if (plug_in->recurse)
{
gtk_main ();
gimp_main_loop (the_gimp);
return_vals = plug_in_get_current_return_vals (proc_rec);
}
}
......@@ -1386,7 +1394,9 @@ plug_in_repeat (gboolean with_interface)
if (last_plug_in)
{
gdisplay = gimp_context_get_display (gimp_get_user_context (the_gimp));
if (!gdisplay) return;
if (! gdisplay)
return;
/* construct the procedures arguments */
args = g_new (Argument, 3);
......@@ -1558,7 +1568,7 @@ plug_in_handle_message (WireMessage *msg)
break;
case GP_TEMP_PROC_RETURN:
plug_in_handle_proc_return (msg->data);
gtk_main_quit ();
gimp_main_loop_quit (the_gimp);
break;
case GP_PROC_INSTALL:
plug_in_handle_proc_install (msg->data);
......@@ -1567,7 +1577,7 @@ plug_in_handle_message (WireMessage *msg)
plug_in_handle_proc_uninstall (msg->data);
break;
case GP_EXTENSION_ACK:
gtk_main_quit ();
gimp_main_loop_quit (the_gimp);
break;
}
}
......@@ -2091,31 +2101,34 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
proc->exec_method.temporary.plug_in = (void *) current_plug_in;
procedural_db_register (the_gimp, proc);
/* If there is a menu path specified, create a menu entry */
if (proc_install->menu_path)
{
menu_entry = g_new (PlugInMenuEntry, 1);
menu_entry->proc_def = proc_def;
/* Below we use a hack to allow translations of Script-Fu paths.
* Would be nice if we could solve this properly, but I haven't
* found a way yet ... (Sven)
*/
if (plug_in_def && plug_in_def->locale_domain)
menu_entry->domain = plug_in_def->locale_domain;
else if (strncmp (proc_def->db_info.name, "script_fu", 9) == 0)
menu_entry->domain = "gimp-script-fu";
else
menu_entry->domain = std_plugins_domain;
if (plug_in_def)
menu_entry->help_path = plug_in_def->help_path;
else
menu_entry->help_path = NULL;
/* plug_in_make_menu_entry frees the menu_entry for us */
plug_in_make_menu_entry (NULL, menu_entry, NULL);
}
if (! the_gimp->no_interface)
{
/* If there is a menu path specified, create a menu entry */
if (proc_install->menu_path)
{
menu_entry = g_new (PlugInMenuEntry, 1);
menu_entry->proc_def = proc_def;
/* Below we use a hack to allow translations of Script-Fu paths.
* Would be nice if we could solve this properly, but I haven't
* found a way yet ... (Sven)
*/
if (plug_in_def && plug_in_def->locale_domain)
menu_entry->domain = plug_in_def->locale_domain;
else if (strncmp (proc_def->db_info.name, "script_fu", 9) == 0)
menu_entry->domain = "gimp-script-fu";
else
menu_entry->domain = std_plugins_domain;
if (plug_in_def)
menu_entry->help_path = plug_in_def->help_path;
else
menu_entry->help_path = NULL;
/* plug_in_make_menu_entry frees the menu_entry for us */
plug_in_make_menu_entry (NULL, menu_entry, NULL);
}
}
break;
}
}
......@@ -2635,9 +2648,9 @@ plug_in_make_menu (void)
#endif
#ifdef ENABLE_NLS
menu_entries = g_tree_new ((GCompareFunc)strcoll);
menu_entries = g_tree_new ((GCompareFunc) strcoll);
#else
menu_entries = g_tree_new ((GCompareFunc)strcmp);
menu_entries = g_tree_new ((GCompareFunc) strcmp);
#endif
tmp = plug_in_defs;
......@@ -2701,7 +2714,7 @@ plug_in_make_menu (void)
}
g_tree_traverse (menu_entries,
(GTraverseFunc)plug_in_make_menu_entry, G_IN_ORDER, NULL);
(GTraverseFunc) plug_in_make_menu_entry, G_IN_ORDER, NULL);
g_tree_destroy (menu_entries);
g_slist_free (domains);
......@@ -2884,9 +2897,12 @@ plug_in_proc_def_dead (void *freed_proc_def)
static void
plug_in_proc_def_remove (PlugInProcDef *proc_def)
{
/* Destroy the menu item */
if (proc_def->menu_path)
menus_destroy (proc_def->menu_path);
if (! the_gimp->no_interface)
{
/* Destroy the menu item */
if (proc_def->menu_path)
menus_destroy (proc_def->menu_path);
}
/* Unregister the procedural database entry */
procedural_db_unregister (the_gimp, proc_def->db_info.name);
......
......@@ -130,7 +130,7 @@ app_init (gint gimp_argc,
if (! no_interface)
{
gui_libs_init (the_gimp, &gimp_argc, &gimp_argv);
gui_themes_init (the_gimp);
get_standard_colormaps ();
......@@ -146,14 +146,17 @@ app_init (gint gimp_argc,
*/
gimp_initialize (the_gimp, app_init_update_status);
tool_manager_init (the_gimp);
/* Now we are ready to draw the splash-screen-image
* to the start-up window
*/
if (! no_interface && ! no_splash && ! no_splash_image)
if (! no_interface)
{
splash_logo_load ();
tool_manager_init (the_gimp);
/* Now we are ready to draw the splash-screen-image
* to the start-up window
*/
if (! no_splash && ! no_splash_image)
{
splash_logo_load ();
}
}
/* Load all data files
......@@ -162,10 +165,6 @@ app_init (gint gimp_argc,
if (! no_interface)
{
#ifdef DISPLAY_FILTERS
color_display_init ();
#endif /* DISPLAY_FILTERS */
gui_init (the_gimp);
}
......@@ -206,7 +205,7 @@ app_init (gint gimp_argc,
gui_post_init (the_gimp);
}
gtk_main ();
gimp_main_loop (the_gimp);
}
void
......@@ -245,10 +244,10 @@ app_exit_finish (void)
plug_in_kill ();
tool_manager_exit (the_gimp);
if (! no_interface)
{
tool_manager_exit (the_gimp);
gui_exit (the_gimp);
}
......@@ -259,8 +258,8 @@ app_exit_finish (void)
base_exit ();
/* There used to be gtk_main_quit() here, but there's a chance
* that gtk_main() was never called before we reach this point. --Sven
/* There used to be foo_main_quit() here, but there's a chance
* that foo_main() was never called before we reach this point. --Sven
*/
gtk_exit (0);
exit (0);
}
......@@ -117,16 +117,20 @@ gimp_init (Gimp *gimp)
{
gimp_core_config_init (gimp);
gimp->be_verbose = FALSE;
gimp->no_data = FALSE;
gimp->no_interface = FALSE;
gimp->be_verbose = FALSE;
gimp->no_data = FALSE;
gimp->no_interface = FALSE;
gimp->create_display_func = NULL;
gimp->gui_set_busy_func = NULL;
gimp->gui_unset_busy_func = NULL;
gimp->main_loops = NULL;
gimp->busy = 0;
gimp->busy_idle_id = 0;
gimp->gui_main_loop_func = NULL;
gimp->gui_main_loop_quit_func = NULL;
gimp->gui_create_display_func = NULL;
gimp->gui_set_busy_func = NULL;
gimp->gui_unset_busy_func = NULL;
gimp->busy = 0;
gimp->busy_idle_id = 0;
gimp_units_init (gimp);
......@@ -474,6 +478,50 @@ gimp_shutdown (Gimp *gimp)
gimp_unitrc_save (gimp);
}
void
gimp_main_loop (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (gimp->gui_main_loop_func)
{
gimp->gui_main_loop_func (gimp);
}
else
{
GMainLoop *loop;
loop = g_main_loop_new (NULL, TRUE);
gimp->main_loops = g_list_prepend (gimp->main_loops, loop);
g_main_loop_run (loop);
gimp->main_loops = g_list_remove (gimp->main_loops, loop);
g_main_loop_unref (loop);
}
}
void
gimp_main_loop_quit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (gimp->gui_main_loop_func)
{
gimp->gui_main_loop_quit_func (gimp);
}
else
{
GMainLoop *loop;
loop = (GMainLoop *) gimp->main_loops->data;
g_main_loop_quit (loop);
}
}
void
gimp_set_busy (Gimp *gimp)
{
......@@ -572,9 +620,9 @@ gimp_create_display (Gimp *gimp,
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
if (gimp->create_display_func)
if (gimp->gui_create_display_func)
{
return gimp->create_display_func (gimage, scale);
return gimp->gui_create_display_func (gimage, scale);
}
return NULL;
......
......@@ -24,6 +24,7 @@
#include "gimpimage-new.h"
typedef void (* GimpMainLoopFunc) (Gimp *gimp);
typedef GimpObject * (* GimpCreateDisplayFunc) (GimpImage *gimage,
guint scale);
typedef void (* GimpSetBusyFunc) (Gimp *gimp);
......@@ -49,7 +50,11 @@ struct _Gimp
gboolean no_data;
gboolean no_interface;
GimpCreateDisplayFunc create_display_func;
GList *main_loops;
GimpMainLoopFunc gui_main_loop_func;
GimpMainLoopFunc gui_main_loop_quit_func;
GimpCreateDisplayFunc gui_create_display_func;
GimpSetBusyFunc gui_set_busy_func;
GimpUnsetBusyFunc gui_unset_busy_func;
......@@ -133,6 +138,9 @@ void gimp_restore (Gimp *gimp,
gboolean no_data);
void gimp_shutdown (Gimp *gimp);
void gimp_main_loop (Gimp *gimp);
void gimp_main_loop_quit (Gimp *gimp);
void gimp_set_busy (Gimp *gimp);
void gimp_set_busy_until_idle (Gimp *gimp);
void gimp_unset_busy (Gimp *gimp);
......
......@@ -256,7 +256,7 @@ gimp_tool_info_new (Gimp *gimp,
g_return_val_if_fail (help != NULL, NULL);
g_return_val_if_fail (menu_path != NULL, NULL);
g_return_val_if_fail (stock_id != NULL, NULL);
g_return_val_if_fail (GDK_IS_PIXBUF (stock_pixbuf), NULL);
g_return_val_if_fail (! stock_pixbuf || GDK_IS_PIXBUF (stock_pixbuf), NULL);
tool_info = g_object_new (GIMP_TYPE_TOOL_INFO,
"name", identifier,
......@@ -287,7 +287,8 @@ gimp_tool_info_new (Gimp *gimp,
tool_info->stock_id = stock_id;
tool_info->stock_pixbuf = stock_pixbuf;
g_object_ref (G_OBJECT (stock_pixbuf));
if (stock_pixbuf)
g_object_ref (G_OBJECT (stock_pixbuf));
return tool_info;
}
......
......@@ -238,12 +238,14 @@ input_dialog_able_callback (GtkWidget *widget,
}
void
devices_init (void)
devices_init (Gimp *gimp)
{
GdkDevice *device;
DeviceInfo *device_info;
GList *list;
g_return_if_fail (GIMP_IS_GIMP (gimp));
current_device = gdk_device_get_core_pointer ();
/* create device info structures for present devices */
......@@ -265,12 +267,12 @@ devices_init (void)
device_info->num_keys = device->num_keys;
device_info->keys = NULL;
device_info->context = gimp_create_context (the_gimp,
device_info->context = gimp_create_context (gimp,
device_info->name, NULL);
gimp_context_define_properties (device_info->context,
DEVICE_CONTEXT_MASK,
FALSE);
gimp_context_copy_properties (gimp_get_user_context (the_gimp),
gimp_context_copy_properties (gimp_get_user_context (gimp),
device_info->context,
DEVICE_CONTEXT_MASK);
device_status_context_connect (device_info->context,
......@@ -281,12 +283,14 @@ devices_init (void)
}
void
devices_restore (void)
devices_restore (Gimp *gimp)
{
DeviceInfo *device_info;
GimpContext *context;
gchar *filename;
g_return_if_fail (GIMP_IS_GIMP (gimp));
/* Augment with information from rc file */
filename = gimp_personal_rc_file ("devicerc");
gimprc_parse_file (filename);
......@@ -297,7 +301,7 @@ devices_restore (void)
suppress_update = TRUE;
context = gimp_get_user_context (the_gimp);
context = gimp_get_user_context (gimp);
gimp_context_copy_properties (device_info->context, context,
DEVICE_CONTEXT_MASK);
......
......@@ -34,10 +34,10 @@ typedef enum
} DeviceValues;
/* Initialize the input devices */
void devices_init (void);
void devices_init (Gimp *gimp);
/* Restores device settings from rc file */
void devices_restore (void);
void devices_restore (Gimp *gimp);
/* Create device info dialog */
GtkWidget * input_dialog_create (void);
......
......@@ -238,12 +238,14 @@ input_dialog_able_callback (GtkWidget *widget,
}
void
devices_init (void)
devices_init (Gimp *gimp)
{
GdkDevice *device;
DeviceInfo *device_info;
GList *list;
g_return_if_fail (GIMP_IS_GIMP (gimp));
current_device = gdk_device_get_core_pointer ();
/* create device info structures for present devices */
......@@ -265,12 +267,12 @@ devices_init (void)
device_info->num_keys = device->num_keys;
device_info->keys = NULL;
device_info->context = gimp_create_context (the_gimp,
device_info->context = gimp_create_context (gimp,
device_info->name, NULL);
gimp_context_define_properties (device_info->context,
DEVICE_CONTEXT_MASK,
FALSE);
gimp_context_copy_properties (gimp_get_user_context (the_gimp),
gimp_context_copy_properties (gimp_get_user_context (gimp),
device_info->context,
DEVICE_CONTEXT_MASK);
device_status_context_connect (device_info->context,
......@@ -281,12 +283,14 @@ devices_init (void)
}
void
devices_restore (void)
devices_restore (Gimp *gimp)
{
DeviceInfo *device_info;
GimpContext *context;
gchar *filename;
g_return_if_fail (GIMP_IS_GIMP (gimp));
/* Augment with information from rc file */
filename = gimp_personal_rc_file ("devicerc");
gimprc_parse_file (filename);
......@@ -297,7 +301,7 @@ devices_restore (void)
suppress_update = TRUE;
context = gimp_get_user_context (the_gimp);
context = gimp_get_user_context (gimp);
gimp_context_copy_properties (device_info->context, context,
DEVICE_CONTEXT_MASK);
......
......@@ -18,6 +18,7 @@
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
......@@ -66,6 +67,8 @@
/* local function prototypes */
static void gui_main (Gimp *gimp);
static void gui_main_quit (Gimp *gimp);
static void gui_set_busy (Gimp *gimp);
static void gui_unset_busy (Gimp *gimp);
static GimpObject * gui_display_new (GimpImage *gimage,
......@@ -117,16 +120,31 @@ gui_themes_dir_foreach_func (const gchar *filename,
}
void
gui_libs_init (Gimp *gimp,
gint *argc,
gui_libs_init (gint *argc,
gchar ***argv)
{
#ifdef HAVE_PUTENV
gchar *display_env;
#endif
g_return_if_fail (argc != NULL);
g_return_if_fail (argv != NULL);
gtk_init (argc, argv);
#ifdef HAVE_PUTENV
display_env = g_strconcat ("DISPLAY=", gdk_get_display (), NULL);
putenv (display_env);
#endif
}
void
gui_themes_init (Gimp *gimp)
{
gchar *theme_dir;
gchar *gtkrc;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (argc != NULL);
g_return_if_fail (argv != NULL);
gimp_stock_init ();
......@@ -183,9 +201,11 @@ gui_init (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp->create_display_func = gui_display_new;
gimp->gui_set_busy_func = gui_set_busy;
gimp->gui_unset_busy_func = gui_unset_busy;
gimp->gui_main_loop_func = gui_main;
gimp->gui_main_loop_quit_func = gui_main_quit;
gimp->gui_create_display_func = gui_display_new;
gimp->gui_set_busy_func = gui_set_busy;
gimp->gui_unset_busy_func = gui_unset_busy;
image_disconnect_handler_id =
gimp_container_add_handler (gimp->images, "disconnect",
......@@ -217,12 +237,16 @@ gui_init (Gimp *gimp)
menus_init (gimp);
#ifdef DISPLAY_FILTERS
color_display_init ();
#endif /* DISPLAY_FILTERS */
gximage_init ();
render_setup (gimprc.transparency_type, gimprc.transparency_size);
dialogs_init (gimp);
devices_init ();
devices_init (gimp);
session_init (gimp);
}
......@@ -241,7 +265,7 @@ gui_restore (Gimp *gimp,
color_select_init ();
devices_restore ();
devices_restore (gimp);
if (gimprc.always_restore_session || restore_session)
session_restore (gimp);
......@@ -358,6 +382,18 @@ gui_really_quit_dialog (GCallback quit_func)
/* private functions */
static void
gui_main (Gimp *gimp)
{
gtk_main ();
}
static void
gui_main_quit (Gimp *gimp)
{
gtk_main_quit ();
}
gboolean double_speed = FALSE;
static GimpObject *
......
......@@ -20,10 +20,11 @@
#define __GUI_H__
void gui_libs_init (Gimp *gimp,
gint *argc,
void gui_libs_init (gint *argc,
gchar ***argv);
void gui_themes_init (Gimp *gimp);
void gui_init (Gimp *gimp);
void gui_restore (Gimp *gimp,
gboolean restore_session);
......
......@@ -238,12 +238,14 @@ input_dialog_able_callback (GtkWidget *widget,
}
void
devices_init (void)
devices_init (Gimp *gimp)
{
GdkDevice *device;
DeviceInfo *device_info;
GList *list;
g_return_if_fail (GIMP_IS_GIMP (gimp));
current_device = gdk_device_get_core_pointer ();
/* create device info structures for present devices */
......@@ -265,12 +267,12 @@ devices_init (void)
device_info->num_keys = device->num_keys;
device_info->keys = NULL;
device_info->context = gimp_create_context (the_gimp,
device_info->context = gimp_create_context (gimp,
device_info->name, NULL);
gimp_context_define_properties (device_info->context,
DEVICE_CONTEXT_MASK,
FALSE);
gimp_context_copy_properties (gimp_get_user_context (the_gimp),
gimp_context_copy_properties (gimp_get_user_context (gimp),
device_info->context,
DEVICE_CONTEXT_MASK);
device_status_context_connect (device_info->context,
......@@ -281,12 +283,14 @@ devices_init (void)
}
void
devices_restore (void)
devices_restore (Gimp *gimp)
{
DeviceInfo *device_info;
GimpContext *context;
gchar *filename;
g_return_if_fail (GIMP_IS_GIMP (gimp));
/* Augment with information from rc file */
filename = gimp_personal_rc_file ("devicerc");
gimprc_parse_file (filename);
......@@ -297,7 +301,7 @@ devices_restore (void)
suppress_update = TRUE;
context = gimp_get_user_context (the_gimp);
context = gimp_get_user_context (gimp);
gimp_context_copy_properties (device_info->context, context,
DEVICE_CONTEXT_MASK);
......
......@@ -195,6 +195,7 @@ static void plug_in_init_shm (void);
static gchar * plug_in_search_in_path (gchar *search_path,
gchar *filename);
PlugIn *current_plug_in = NULL;
GSList *proc_defs = NULL;
......@@ -416,8 +417,11 @@ plug_in_init (Gimp *gimp,
/* add the plug-in procs to the procedure database */
plug_in_add_to_db ();
/* make the menu */
plug_in_make_menu ();
if (! gimp->no_interface)
{