diff --git a/ChangeLog b/ChangeLog index 8758799d95..3f6205dd3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,36 @@ +2007-01-26 Tor Lillqvist + + Make the handling of console output make more sense Win32. Should + mostly fix #400927. + + * app/app_procs.c (app_exit): Drop the Win32 "This console window + will close in ten seconds" message from here. + (app_run): Drop the call to FreeConsole() from here. GIMP is built + as a GUI executable on Windows, and in case we do open a fresh + console window in main() (see below), we shouldn't then + immediately close it here. + + * app/errors.c (errors_init): Drop printing the "You can mimize + this window, but don't close it" message on Win32 from here. + + * app/main.c (gimp_open_console_window): New Win32-only + function. If either stdout or stderr are unconnected, open a new + console window and connect stdout and/or stderr to it as + needed. Set the console title to "GIMP output. You can minimize + this window, but don't close it." Register an atexit function that + waits for the user to close the console window. + (wait_console_window): New Win32-only function. Registered as an + atexit function when GIMP has opened a new console window. Prompts + the user to type any character to close the window. + (main, gimp_show_version): Always call gimp_open_console_window() + in the unstable version. As the "This is a development version of + GIMP. Debug messages may appear here" message says, one point of + the unstable version is that debug messages should be visible, so + I think it makes sense to always see them in an unstable + version. In stable versions, call gimp_open_console_window() only + if options that cause output that the user wants to see were + given, like --help and --version. + 2007-01-25 Tor Lillqvist * app/plug-in/gimpplugin.c (gimp_plug_in_open): On Win32 prevent diff --git a/app/app_procs.c b/app/app_procs.c index eca4651ab1..f56f0e5ed2 100644 --- a/app/app_procs.c +++ b/app/app_procs.c @@ -59,11 +59,6 @@ #include "gimp-intl.h" -#ifdef G_OS_WIN32 -#include -#endif - - /* local prototypes */ static void app_init_update_none (const gchar *text1, @@ -115,23 +110,6 @@ app_abort (gboolean no_interface, void app_exit (gint status) { -#ifdef G_OS_WIN32 - /* Give them time to read the message if it was printed in a - * separate console window. I would really love to have - * some way of asking for confirmation to close the console - * window. - */ - HANDLE console; - DWORD mode; - - console = GetStdHandle (STD_OUTPUT_HANDLE); - if (GetConsoleMode (console, &mode) != 0) - { - g_print (_("(This console window will close in ten seconds)\n")); - Sleep(10000); - } -#endif - exit (status); } @@ -198,16 +176,6 @@ app_run (const gchar *full_prog_name, gimp_user_install_free (install); } -#if defined G_OS_WIN32 && !defined GIMP_CONSOLE_COMPILATION - /* Common windoze apps don't have a console at all. So does Gimp - * - if appropiate. This allows to compile as console application - * with all it's benefits (like inheriting the console) but hide - * it, if the user doesn't want it. - */ - if (!no_interface && !be_verbose && !console_messages) - FreeConsole (); -#endif - gimp_load_config (gimp, alternate_system_gimprc, alternate_gimprc); config = GIMP_BASE_CONFIG (gimp->config); diff --git a/app/errors.c b/app/errors.c index 0acc2cdf96..63489f07e8 100644 --- a/app/errors.c +++ b/app/errors.c @@ -108,10 +108,6 @@ errors_init (Gimp *gimp, #ifdef GIMP_UNSTABLE g_printerr ("This is a development version of GIMP. " "Debug messages may appear here.\n\n"); - -#ifdef G_OS_WIN32 - g_printerr ("You can minimize this window, but don't close it.\n\n"); -#endif #endif /* GIMP_UNSTABLE */ the_errors_gimp = gimp; diff --git a/app/main.c b/app/main.c index 05e4760302..31e8349fbe 100644 --- a/app/main.c +++ b/app/main.c @@ -65,6 +65,7 @@ #ifdef G_OS_WIN32 #include +#include #endif #include "gimp-intl.h" @@ -98,6 +99,11 @@ static void gimp_init_signal_handlers (void); static void gimp_sigfatal_handler (gint sig_num) G_GNUC_NORETURN; #endif +#if defined (G_OS_WIN32) && !defined (GIMP_CONSOLE_COMPILATION) +static void gimp_open_console_window (void); +#else +#define gimp_open_console_window() /* as nothing */ +#endif static const gchar *system_gimprc = NULL; static const gchar *user_gimprc = NULL; @@ -271,6 +277,10 @@ main (int argc, g_thread_init (NULL); #endif +#ifdef GIMP_UNSTABLE + gimp_open_console_window (); +#endif + gimp_init_malloc (); gimp_env_init (FALSE); @@ -297,8 +307,17 @@ main (int argc, } else if ((strcmp (arg, "--version") == 0) || (strcmp (arg, "-v") == 0)) { + gimp_open_console_window (); gimp_show_version_and_exit (); } +#if defined (G_OS_WIN32) && !defined (GIMP_CONSOLE_COMPILATION) + else if ((strcmp (arg, "--help") == 0) || + (strcmp (arg, "-?") == 0) || + (strncmp (arg, "--help-", 7) == 0)) + { + gimp_open_console_window (); + } +#endif } #ifdef GIMP_CONSOLE_COMPILATION @@ -316,6 +335,7 @@ main (int argc, { if (error) { + gimp_open_console_window (); g_print ("%s\n", error->message); g_error_free (error); } @@ -330,6 +350,9 @@ main (int argc, app_exit (EXIT_FAILURE); } + if (no_interface || be_verbose || console_messages || batch_commands != NULL) + gimp_open_console_window (); + if (no_interface) new_instance = TRUE; @@ -417,7 +440,7 @@ main (int argc, #ifdef G_OS_WIN32 -/* In case we build this as a windowed application */ +/* In case we build this as a windowed application. Well, we do. */ #ifdef __GNUC__ # ifndef _stdcall @@ -434,6 +457,38 @@ WinMain (struct HINSTANCE__ *hInstance, return main (__argc, __argv); } +#ifndef GIMP_CONSOLE_COMPILATION + +static void +wait_console_window (void) +{ + FILE *console = fopen ("CONOUT$", "w"); + + SetConsoleTitle (_("GIMP output. Type any character to close this window.")); + fprintf (console, _("(Type any character to close this window)\n")); + fflush (console); + _getch (); +} + +static void +gimp_open_console_window (void) +{ + if (((HANDLE) _get_osfhandle (fileno (stdout)) == INVALID_HANDLE_VALUE || + (HANDLE) _get_osfhandle (fileno (stderr)) == INVALID_HANDLE_VALUE) && AllocConsole ()) + { + if ((HANDLE) _get_osfhandle (fileno (stdout)) == INVALID_HANDLE_VALUE) + freopen ("CONOUT$", "w", stdout); + + if ((HANDLE) _get_osfhandle (fileno (stderr)) == INVALID_HANDLE_VALUE) + freopen ("CONOUT$", "w", stderr); + + SetConsoleTitle (_("GIMP output. You can minimize this window, but don't close it.")); + + atexit (wait_console_window); + } +} +#endif + #endif /* G_OS_WIN32 */ @@ -497,6 +552,8 @@ gimp_option_dump_gimprc (const gchar *option_name, { GimpConfigDumpFormat format = GIMP_CONFIG_DUMP_NONE; + gimp_open_console_window (); + if (strcmp (option_name, "--dump-gimprc") == 0) format = GIMP_CONFIG_DUMP_GIMPRC; if (strcmp (option_name, "--dump-gimprc-system") == 0) @@ -526,6 +583,7 @@ gimp_option_dump_gimprc (const gchar *option_name, static void gimp_show_version (void) { + gimp_open_console_window (); g_print (_("%s version %s"), GIMP_NAME, GIMP_VERSION); g_print ("\n"); }