GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
display-available.c
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2012-2015 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 "display-available.h"
38 
39 const char *
40 display_available (int *dpy_avail)
41 {
42  *dpy_avail = 0;
43 
44  const char *err_msg = "";
45 
46 #if defined (OCTAVE_USE_WINDOWS_API)
47 
48  HDC hdc = GetDC (0);
49 
50  if (hdc)
51  *dpy_avail = 1;
52  else
53  err_msg = "no graphical display found";
54 
55 #elif defined (HAVE_FRAMEWORK_CARBON)
56 
57  CGDirectDisplayID display = CGMainDisplayID ();
58 
59  if (display)
60  *dpy_avail = 1;
61  else
62  err_msg = "no graphical display found";
63 
64 #elif defined (HAVE_X_WINDOWS)
65 
66  const char *display_name = getenv ("DISPLAY");
67 
68  if (display_name && *display_name)
69  {
70  Display *display = XOpenDisplay (display_name);
71 
72  if (display)
73  {
74  Screen *screen = DefaultScreenOfDisplay (display);
75 
76  if (! screen)
77  err_msg = "X11 display has no default screen";
78 
79  XCloseDisplay (display);
80 
81  *dpy_avail = 1;
82  }
83  else
84  err_msg = "unable to open X11 DISPLAY";
85  }
86  else
87  err_msg = "X11 DISPLAY environment variable not set";
88 
89 #else
90 
91  err_msg = "no graphical display found";
92 
93 #endif
94 
95  return err_msg;
96 }
An image of characters with associated attributes.
Definition: Screen.h:75
const char * display_available(int *dpy_avail)