comparison libinterp/corefcn/cdisplay.c @ 18932:edc4791fbcb2

avoid some old-style cast warnings * cdisplay.h, cdisplay.c: New files. Compile C code and headers with C compiler. * corefcn/module.mk: Include them in the appropriate lists. * display.cc (display_info::init): Call new octave_get_display_info function.
author John W. Eaton <jwe@octave.org>
date Thu, 17 Jul 2014 11:19:21 -0400
parents
children
comparison
equal deleted inserted replaced
18931:dbb207d10d7c 18932:edc4791fbcb2
1 /*
2
3 Copyright (C) 2009-2014 John W. Eaton
4
5 This file is part of Octave.
6
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdlib.h>
28
29 #if defined (OCTAVE_USE_WINDOWS_API)
30 #include <windows.h>
31 #elif defined (HAVE_FRAMEWORK_CARBON)
32 #include <Carbon/Carbon.h>
33 #elif defined (HAVE_X_WINDOWS)
34 #include <X11/Xlib.h>
35 #endif
36
37 #include "cdisplay.h"
38
39 const char *
40 octave_get_display_info (int *ht, int *wd, int *dp, double *rx, double *ry,
41 int *dpy_avail)
42 {
43 const char *msg = 0;
44
45 *dpy_avail = 0;
46
47 #if defined (OCTAVE_USE_WINDOWS_API)
48
49 HDC hdc = GetDC (0);
50
51 if (hdc)
52 {
53 *dp = GetDeviceCaps (hdc, BITSPIXEL);
54
55 *ht = GetDeviceCaps (hdc, VERTRES);
56 *wd = GetDeviceCaps (hdc, HORZRES);
57
58 double ht_mm = GetDeviceCaps (hdc, VERTSIZE);
59 double wd_mm = GetDeviceCaps (hdc, HORZSIZE);
60
61 *rx = *wd * 25.4 / wd_mm;
62 *ry = *ht * 25.4 / ht_mm;
63
64 *dpy_avail = 1;
65 }
66 else
67 msg = "no graphical display found";
68
69 #elif defined (HAVE_FRAMEWORK_CARBON)
70
71 CGDirectDisplayID display = CGMainDisplayID ();
72
73 if (display)
74 {
75 #if defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL)
76
77 *dp = CGDisplayBitsPerPixel (display);
78
79 #else
80
81 /* FIXME: This will only work for MacOS > 10.5. For earlier versions
82 this code is not needed (use CGDisplayBitsPerPixel instead). */
83
84 CGDisplayModeRef mode = CGDisplayCopyDisplayMode (display);
85 CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding (mode);
86
87 if (CFStringCompare (pixelEncoding, CFSTR (IO32BitDirectPixels), 0) == 0)
88 *dp = 32;
89 else if (CFStringCompare (pixelEncoding,
90 CFSTR (IO16BitDirectPixels), 0) == 0)
91 *dp = 16;
92 else
93 *dp = 8;
94
95 #endif
96
97 *ht = CGDisplayPixelsHigh (display);
98 *wd = CGDisplayPixelsWide (display);
99
100 CGSize sz_mm = CGDisplayScreenSize (display);
101
102 /* For MacOS >= 10.6, CGSize is a struct keeping 2 CGFloat
103 values, but the CGFloat typedef is not present on older
104 systems, so use double instead. */
105
106 double ht_mm = sz_mm.height;
107 double wd_mm = sz_mm.width;
108
109 *rx = *wd * 25.4 / wd_mm;
110 *ry = *ht * 25.4 / ht_mm;
111
112 *dpy_avail = 1;
113 }
114 else
115 msg = "no graphical display found";
116
117 #elif defined (HAVE_X_WINDOWS)
118
119 const char *display_name = getenv ("DISPLAY");
120
121 if (display_name && *display_name)
122 {
123 Display *display = XOpenDisplay (display_name);
124
125 if (display)
126 {
127 Screen *screen = DefaultScreenOfDisplay (display);
128
129 if (screen)
130 {
131 *dp = DefaultDepthOfScreen (screen);
132
133 *ht = HeightOfScreen (screen);
134 *wd = WidthOfScreen (screen);
135
136 int screen_number = XScreenNumberOfScreen (screen);
137
138 double ht_mm = DisplayHeightMM (display, screen_number);
139 double wd_mm = DisplayWidthMM (display, screen_number);
140
141 *rx = *wd * 25.4 / wd_mm;
142 *ry = *ht * 25.4 / ht_mm;
143 }
144 else
145 msg = "X11 display has no default screen";
146
147 XCloseDisplay (display);
148
149 *dpy_avail = 1;
150 }
151 else
152 msg = "unable to open X11 DISPLAY";
153 }
154 else
155 msg = "X11 DISPLAY environment variable not set";
156
157 #else
158
159 msg = "no graphical display found";
160
161 #endif
162
163 return msg;
164 }