Mercurial > octave
diff libinterp/corefcn/display.cc @ 20947:ecb95c6384f2
backout changeset e74e617060cf
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 19 Dec 2015 07:54:00 -0600 |
parents | 6eff66fb8a02 |
children | 850e3d2533d4 |
line wrap: on
line diff
--- a/libinterp/corefcn/display.cc Fri Dec 18 22:39:36 2015 -0500 +++ b/libinterp/corefcn/display.cc Sat Dec 19 07:54:00 2015 -0600 @@ -20,141 +20,33 @@ */ -#include "display.h" +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif -#if defined (OCTAVE_USE_WINDOWS_API) -#include <windows.h> -#elif defined (HAVE_FRAMEWORK_CARBON) -#include <Carbon/Carbon.h> -#elif defined (HAVE_X_WINDOWS) -#include <X11/Xlib.h> -#endif +#include "singleton-cleanup.h" + +#include "cdisplay.h" +#include "display.h" +#include "error.h" display_info *display_info::instance = 0; void display_info::init (bool query) { - if (!query) - return; - -#if defined (OCTAVE_USE_WINDOWS_API) - - HDC hdc = GetDC (0); - - if (hdc) + if (query) { - dp = GetDeviceCaps (hdc, BITSPIXEL); - - ht = GetDeviceCaps (hdc, VERTRES); - wd = GetDeviceCaps (hdc, HORZRES); - - double ht_mm = GetDeviceCaps (hdc, VERTSIZE); - double wd_mm = GetDeviceCaps (hdc, HORZSIZE); - - rx = wd * 25.4 / wd_mm; - ry = ht * 25.4 / ht_mm; - - dpy_avail = true; - } - else - err_msg = "no graphical display found"; - -#elif defined (HAVE_FRAMEWORK_CARBON) - - CGDirectDisplayID display = CGMainDisplayID (); - - if (display) - { -#if defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL) - - dp = CGDisplayBitsPerPixel (display); - -#else - - // FIXME: This will only work for MacOS > 10.5. For earlier - // versions this code is not needed (use CGDisplayBitsPerPixel - // instead). - - CGDisplayModeRef mode = CGDisplayCopyDisplayMode (display); - CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding (mode); - - if (CFStringCompare (pixelEncoding, CFSTR (IO32BitDirectPixels), 0) == 0) - dp = 32; - else if (CFStringCompare (pixelEncoding, - CFSTR (IO16BitDirectPixels), 0) == 0) - dp = 16; - else - dp = 8; - -#endif - - ht = CGDisplayPixelsHigh (display); - wd = CGDisplayPixelsWide (display); - - CGSize sz_mm = CGDisplayScreenSize (display); + int avail = 0; - // For MacOS >= 10.6, 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; - - dpy_avail = true; - } - else - err_msg = "no graphical display found"; - -#elif defined (HAVE_X_WINDOWS) - - const char *display_name = std::getenv ("DISPLAY"); - - if (display_name && *display_name) - { - Display *display = XOpenDisplay (display_name); - - if (display) - { - Screen *screen = DefaultScreenOfDisplay (display); - - if (screen) - { - dp = DefaultDepthOfScreen (screen); + const char *msg = octave_get_display_info (&ht, &wd, &dp, &rx, &ry, + &avail); - ht = HeightOfScreen (screen); - wd = WidthOfScreen (screen); - - int screen_number = XScreenNumberOfScreen (screen); - - 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 - err_msg = "X11 display has no default screen"; + dpy_avail = avail; - XCloseDisplay (display); - - dpy_avail = true; - } - else - err_msg = "unable to open X11 DISPLAY"; + if (msg) + err_msg = msg; } - else - err_msg = "X11 DISPLAY environment variable not set"; - -#else - - err_msg = "no graphical display found"; - -#endif - } bool