diff --git a/ChangeLog b/ChangeLog index 70a6f77cfc..72de4a8bca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-01-20 Sven Neumann + + * tools/gimp-remote.c: added new command-line options --existing + and --query. The former allows to get the old behaviour back and + the latter might be useful one day. + + * docs/gimp-remote-1.3.1.in: document the new options. + 2004-01-20 Michael Natterer * app/widgets/gimphelp-ids.h: added help IDs for the libgimp diff --git a/docs/gimp-remote-1.3.1.in b/docs/gimp-remote-1.3.1.in index 1654e0a1c1..4e5c05488b 100644 --- a/docs/gimp-remote-1.3.1.in +++ b/docs/gimp-remote-1.3.1.in @@ -4,7 +4,7 @@ gimp-remote - tells a running GIMP to open a (local or remote) image file. .SH SYNOPSIS .B gimp-remote [\-h] [\-\-help] [-v] [\-\-version] [\-\-display \fIdisplay\fP] -\fIfilename\fP ... +[\-e] [\-\-existing] [-q] [\-\-query] \fIfilename\fP ... .SH DESCRIPTION .PP @@ -18,7 +18,8 @@ or URL can be specified on the commandline. .PP If no GIMP window is found, \fIgimp-remote\fP will start a new GIMP instance and ask it to load the specified images. If no filename or -URL is given, \fIgimp-remote\fP will always start a new GIMP. +URL is given, \fIgimp-remote\fP will start a new GIMP. This behaviour +can be altered using the command-line options described below. .SH OPTIONS @@ -33,6 +34,13 @@ Output the version info. .TP 8 .B \-\-display \fIdisplay\fP Use the designated X display. +.TP 8 +.B \-e, \-\-existing +If no running GIMP instance is found, don't start a new one but exit. +.TP 8 +.B \-q, \-\-query +Check if GIMP is running and exit. A status code of 0 indicates that +a GIMP toolbox window has been found on this display. .SH EXAMPLES .TP diff --git a/docs/gimp-remote.1.in b/docs/gimp-remote.1.in index 1654e0a1c1..4e5c05488b 100644 --- a/docs/gimp-remote.1.in +++ b/docs/gimp-remote.1.in @@ -4,7 +4,7 @@ gimp-remote - tells a running GIMP to open a (local or remote) image file. .SH SYNOPSIS .B gimp-remote [\-h] [\-\-help] [-v] [\-\-version] [\-\-display \fIdisplay\fP] -\fIfilename\fP ... +[\-e] [\-\-existing] [-q] [\-\-query] \fIfilename\fP ... .SH DESCRIPTION .PP @@ -18,7 +18,8 @@ or URL can be specified on the commandline. .PP If no GIMP window is found, \fIgimp-remote\fP will start a new GIMP instance and ask it to load the specified images. If no filename or -URL is given, \fIgimp-remote\fP will always start a new GIMP. +URL is given, \fIgimp-remote\fP will start a new GIMP. This behaviour +can be altered using the command-line options described below. .SH OPTIONS @@ -33,6 +34,13 @@ Output the version info. .TP 8 .B \-\-display \fIdisplay\fP Use the designated X display. +.TP 8 +.B \-e, \-\-existing +If no running GIMP instance is found, don't start a new one but exit. +.TP 8 +.B \-q, \-\-query +Check if GIMP is running and exit. A status code of 0 indicates that +a GIMP toolbox window has been found on this display. .SH EXAMPLES .TP diff --git a/tools/gimp-remote.c b/tools/gimp-remote.c index d92a923fde..9d24fefe2a 100644 --- a/tools/gimp-remote.c +++ b/tools/gimp-remote.c @@ -52,6 +52,9 @@ #define GIMP_BINARY "gimp-1.3" +static gboolean existing = FALSE; +static gboolean query = FALSE; + static GdkWindow * gimp_remote_find_window (GdkDisplay *display, @@ -158,18 +161,20 @@ usage (const gchar *name) g_print ("Tells a running Gimp to open a (local or remote) image file.\n\n" "Usage: %s [options] [FILE|URI]...\n\n", name); g_print ("Valid options are:\n" - " --display Use the designated X display.\n" - " -h --help Output this help.\n" - " -v --version Output version info.\n" - "\n"); + " -h, --help Output this help.\n" + " -v, --version Output version info.\n" + " --display Use the designated X display.\n" + " -e, --existing Use a running GIMP only, never start a new one.\n" + " -q, --query Query if a GIMP is running, then quit.\n" + "\n"); g_print ("Example: %s http://www.gimp.org/icons/frontpage-small.gif\n" " or: %s localfile.png\n\n", name, name); } static void -start_new_gimp (GdkScreen *screen, - gchar *argv0, - GString *file_list) +start_new_gimp (GdkScreen *screen, + const gchar *argv0, + GString *file_list) { gchar *display_name; gchar **argv; @@ -246,6 +251,7 @@ start_new_gimp (GdkScreen *screen, /* if execv and execvp return, there was an arror */ g_printerr ("Couldn't start %s for the following reason: %s\n", GIMP_BINARY, g_strerror (errno)); + exit (EXIT_FAILURE); } @@ -267,8 +273,15 @@ parse_option (const gchar *progname, usage (progname); exit (EXIT_SUCCESS); } - else if (strcmp (arg, "-n") == 0 || - strcmp (arg, "--new") == 0) + else if (strcmp (arg, "-e") == 0 || strcmp (arg, "--existing") == 0) + { + existing = TRUE; + } + else if (strcmp (arg, "-q") == 0 || strcmp (arg, "--query") == 0) + { + query = TRUE; + } + else if (strcmp (arg, "-n") == 0 || strcmp (arg, "--new") == 0) { /* accepted for backward compatibility; this is now the default */ } @@ -353,13 +366,18 @@ main (gint argc, screen = gdk_screen_get_default (); /* if called without any filenames, always start a new GIMP */ - if (file_list->len == 0) + if (file_list->len == 0 && !query && !existing) { start_new_gimp (screen, argv[0], file_list); } gimp_window = gimp_remote_find_window (display, screen); + if (query) + { + exit (gimp_window ? EXIT_SUCCESS : EXIT_FAILURE); + } + if (gimp_window) { GdkDragContext *context; @@ -423,6 +441,9 @@ main (gint argc, } else { + if (existing) + exit (EXIT_FAILURE); + start_new_gimp (screen, argv[0], file_list); }