Mercurial > hg > octave-nkf
changeset 9335:f2d354df53ee
new option, --no-window-system
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Jun 2009 14:20:36 -0400 |
parents | 4f96a7770492 |
children | 98c6b3aa0b7b |
files | src/ChangeLog src/display.cc src/display.h src/octave.cc |
diffstat | 4 files changed, 97 insertions(+), 68 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2009-06-11 John W. Eaton <jwe@octave.org> + + * 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-06-11 Jaroslav Hajek <highegg@gmail.com> * ov-class.cc (octave_class::subsref): Set up proper nargout for call to subsref
--- a/src/display.cc +++ b/src/display.cc @@ -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) {
--- a/src/display.h +++ b/src/display.h @@ -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
--- a/src/octave.cc +++ b/src/octave.cc @@ -54,6 +54,7 @@ #include <defaults.h> #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 }, @@ -512,6 +515,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\ @@ -755,6 +759,10 @@ set_initial_path = false; break; + case NO_WINDOW_SYSTEM_OPTION: + display_info::no_window_system (); + break; + case TRADITIONAL_OPTION: traditional = true; break;