# HG changeset patch # User John W. Eaton # Date 1250142960 -7200 # Node ID aff7a8e7d8b9139188494ae9a0c152b1df98c02a # Parent 6ab2598a4ac23f168932d780f468606051800d74 new option, --no-window-system diff -r 6ab2598a4ac2 -r aff7a8e7d8b9 src/ChangeLog --- a/src/ChangeLog Mon Aug 10 11:14:46 2009 +0200 +++ b/src/ChangeLog Thu Aug 13 07:56:00 2009 +0200 @@ -1,3 +1,14 @@ +2009-06-11 John W. Eaton + + * display.h (display_info::no_window_system): New static function. + (display_info::display_info, display_info::init, + display_info::instance_ok): New argument, QUERY. + (display_info::init): Skip query if QUERY is false. + + * octave.cc (long_opts, octave_main): Handle --no-window-system option. + (NO_WINDOW_SYSTEM_OPTION): New defined value. + (usage_string, verbose_usage): Mention --no-window-system option. + 2009-08-09 John W. Eaton * parse.y (Fevalin): Also return output from CATCH expression. diff -r 6ab2598a4ac2 -r aff7a8e7d8b9 src/display.cc --- a/src/display.cc Mon Aug 10 11:14:46 2009 +0200 +++ b/src/display.cc Thu Aug 13 07:56:00 2009 +0200 @@ -40,102 +40,105 @@ display_info *display_info::instance = 0; void -display_info::init (void) +display_info::init (bool query) { + if (query) + { #if defined (OCTAVE_USE_WINDOWS_API) - HDC hdc = GetDC (0); + HDC hdc = GetDC (0); - if (hdc) - { - dp = GetDeviceCaps (hdc, BITSPIXEL); + if (hdc) + { + dp = GetDeviceCaps (hdc, BITSPIXEL); - ht = GetDeviceCaps (hdc, VERTRES); - wd = GetDeviceCaps (hdc, HORZRES); + ht = GetDeviceCaps (hdc, VERTRES); + wd = GetDeviceCaps (hdc, HORZRES); - double ht_mm = GetDeviceCaps (hdc, VERTSIZE); - double wd_mm = GetDeviceCaps (hdc, HORZSIZE); + double ht_mm = GetDeviceCaps (hdc, VERTSIZE); + double wd_mm = GetDeviceCaps (hdc, HORZSIZE); - rx = wd * 25.4 / wd_mm; - ry = ht * 25.4 / ht_mm; - } - else - warning ("no graphical display found"); + rx = wd * 25.4 / wd_mm; + ry = ht * 25.4 / ht_mm; + } + else + warning ("no graphical display found"); #elif defined (HAVE_FRAMEWORK_CARBON) - CGDirectDisplayID display = CGMainDisplayID (); - - if (display) - { - dp = CGDisplayBitsPerPixel (display); - - ht = CGDisplayPixelsHigh (display); - wd = CGDisplayPixelsWide (display); - - CGSize sz_mm = CGDisplayScreenSize (display); - - // On modern Mac systems (>= 10.5) CGSize is a struct keeping 2 - // CGFloat values, but the CGFloat typedef is not present on - // older systems, so use double instead. - double ht_mm = sz_mm.height; - double wd_mm = sz_mm.width; - - rx = wd * 25.4 / wd_mm; - ry = ht * 25.4 / ht_mm; - } - else - warning ("no graphical display found"); - -#elif defined (HAVE_X_WINDOWS) - - const char *display_name = getenv ("DISPLAY"); - - if (display_name && *display_name) - { - Display *display = XOpenDisplay (display_name); + CGDirectDisplayID display = CGMainDisplayID (); if (display) { - Screen *screen = DefaultScreenOfDisplay (display); + dp = CGDisplayBitsPerPixel (display); + + ht = CGDisplayPixelsHigh (display); + wd = CGDisplayPixelsWide (display); + + CGSize sz_mm = CGDisplayScreenSize (display); - if (screen) - { - dp = DefaultDepthOfScreen (screen); + // On modern Mac systems (>= 10.5) CGSize is a struct keeping 2 + // CGFloat values, but the CGFloat typedef is not present on + // older systems, so use double instead. + double ht_mm = sz_mm.height; + double wd_mm = sz_mm.width; + + rx = wd * 25.4 / wd_mm; + ry = ht * 25.4 / ht_mm; + } + else + warning ("no graphical display found"); + +#elif defined (HAVE_X_WINDOWS) + + const char *display_name = getenv ("DISPLAY"); - ht = HeightOfScreen (screen); - wd = WidthOfScreen (screen); + if (display_name && *display_name) + { + Display *display = XOpenDisplay (display_name); - int screen_number = XScreenNumberOfScreen (screen); + if (display) + { + Screen *screen = DefaultScreenOfDisplay (display); + + if (screen) + { + dp = DefaultDepthOfScreen (screen); - double ht_mm = DisplayHeightMM (display, screen_number); - double wd_mm = DisplayWidthMM (display, screen_number); + ht = HeightOfScreen (screen); + wd = WidthOfScreen (screen); + + int screen_number = XScreenNumberOfScreen (screen); - rx = wd * 25.4 / wd_mm; - ry = ht * 25.4 / ht_mm; + double ht_mm = DisplayHeightMM (display, screen_number); + double wd_mm = DisplayWidthMM (display, screen_number); + + rx = wd * 25.4 / wd_mm; + ry = ht * 25.4 / ht_mm; + } + else + warning ("X11 display has no default screen"); } else - warning ("X11 display has no default screen"); + warning ("unable to open X11 DISPLAY"); } else - warning ("unable to open X11 DISPLAY"); - } - else - warning ("X11 DISPLAY environment variable not set"); + warning ("X11 DISPLAY environment variable not set"); #else - warning ("no graphical display found"); + warning ("no graphical display found"); #endif + } } bool -display_info::instance_ok (void) +display_info::instance_ok (bool query) { bool retval = true; if (! instance) - instance = new display_info (); + instance = new display_info (query); if (! instance) { diff -r 6ab2598a4ac2 -r aff7a8e7d8b9 src/display.h --- a/src/display.h Mon Aug 10 11:14:46 2009 +0200 +++ b/src/display.h Thu Aug 13 07:56:00 2009 +0200 @@ -29,10 +29,10 @@ { protected: - display_info (void) + display_info (bool query = true) : ht (1), wd (1), dp (0), rx (72), ry (72) { - init (); + init (query); } public: @@ -62,6 +62,13 @@ return instance_ok () ? instance->do_y_dpi () : 0; } + // To disable querying the window system for defaults, this function + // must be called before any other display_info function. + static void no_window_system (void) + { + instance_ok (false); + } + private: static display_info *instance; @@ -82,9 +89,9 @@ double do_x_dpi (void) const { return rx; } double do_y_dpi (void) const { return ry; } - void init (void); + void init (bool query = true); - static bool instance_ok (void); + static bool instance_ok (bool query = true); }; #endif diff -r 6ab2598a4ac2 -r aff7a8e7d8b9 src/octave.cc --- a/src/octave.cc Mon Aug 10 11:14:46 2009 +0200 +++ b/src/octave.cc Thu Aug 13 07:56:00 2009 +0200 @@ -54,6 +54,7 @@ #include #include "Cell.h" #include "defun.h" +#include "display.h" #include "error.h" #include "file-io.h" #include "input.h" @@ -127,7 +128,7 @@ "octave [-?HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\ [--exec-path path] [--help] [--image-path path] [--info-file file]\n\ [--info-program prog] [--interactive] [--line-editing] [--no-history] [--no-init-file]\n\ - [--no-line-editing] [--no-site-file] [--no-init-path] [-p path]\n\ + [--no-line-editing] [--no-site-file] [--no-init-path] [--no-window-system] [-p path]\n\ [--path path] [--silent] [--traditional] [--verbose] [--version] [file]"; // This is here so that it's more likely that the usage message and @@ -156,6 +157,7 @@ #define PERSIST_OPTION 11 #define TRADITIONAL_OPTION 12 #define LINE_EDITING_OPTION 13 +#define NO_WINDOW_SYSTEM_OPTION 14 long_options long_opts[] = { { "debug", prog_args::no_arg, 0, 'd' }, @@ -175,6 +177,7 @@ { "no-line-editing", prog_args::no_arg, 0, NO_LINE_EDITING_OPTION }, { "no-site-file", prog_args::no_arg, 0, NO_SITE_FILE_OPTION }, { "no-init-path", prog_args::no_arg, 0, NO_INIT_PATH_OPTION }, + { "no-window-system", prog_args::no_arg, 0, NO_WINDOW_SYSTEM_OPTION }, { "norc", prog_args::no_arg, 0, 'f' }, { "path", prog_args::required_arg, 0, 'p' }, { "persist", prog_args::no_arg, 0, PERSIST_OPTION }, @@ -506,6 +509,7 @@ --no-init-path Don't initialize function search path.\n\ --no-line-editing Don't use readline for command-line editing.\n\ --no-site-file Don't read the site-wide octaverc file.\n\ + --no-window-system Disable window system, including graphics.\n\ --norc, -f Don't read any initialization files.\n\ --path PATH, -p PATH Add PATH to head of function search path.\n\ --persist Go interactive after --eval or reading from FILE.\n\ @@ -749,6 +753,10 @@ set_initial_path = false; break; + case NO_WINDOW_SYSTEM_OPTION: + display_info::no_window_system (); + break; + case TRADITIONAL_OPTION: traditional = true; break;