GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
display-available.c
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2012-2026 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <stdlib.h>
31
32#if defined (OCTAVE_USE_WINDOWS_API)
33# include <windows.h>
34#elif defined (HAVE_FRAMEWORK_CARBON)
35# include <Carbon/Carbon.h>
36#else
37# if defined (HAVE_X_WINDOWS)
38# include <X11/Xlib.h>
39# endif
40# if defined (HAVE_WAYLAND_CLIENT)
41# include <wayland-client.h>
42# endif
43#endif
44
45#include "display-available.h"
46
47const char *
48display_available (int *dpy_avail)
49{
50 *dpy_avail = 0;
51
52 const char *err_msg = "";
53
54#if defined (OCTAVE_USE_WINDOWS_API)
55
56 HDC hdc = GetDC (0);
57
58 if (hdc)
59 *dpy_avail = 1;
60 else
61 err_msg = "no graphical display found";
62
63#elif defined (HAVE_FRAMEWORK_CARBON)
64
65 CGDirectDisplayID display = CGMainDisplayID ();
66
67 if (display)
68 *dpy_avail = 1;
69 else
70 err_msg = "no graphical display found";
71
72#elif defined (HAVE_X_WINDOWS) || defined (HAVE_WAYLAND_CLIENT)
73
74#if defined (HAVE_X_WINDOWS)
75 const char *display_name = getenv ("DISPLAY");
76
77 if (display_name && *display_name)
78 {
79 Display *display = XOpenDisplay (display_name);
80
81 if (display)
82 {
83 Screen *screen = DefaultScreenOfDisplay (display);
84
85 if (! screen)
86 err_msg = "X11 display has no default screen";
87
88 XCloseDisplay (display);
89
90 *dpy_avail = 1;
91 }
92# if ! defined (HAVE_WAYLAND_CLIENT)
93 else
94 err_msg = "unable to open X11 DISPLAY";
95# endif
96 }
97# if ! defined (HAVE_WAYLAND_CLIENT)
98 else
99 err_msg = "X11 DISPLAY environment variable not set";
100# endif
101#endif
102
103#if defined (HAVE_WAYLAND_CLIENT)
104 if (*dpy_avail == 0)
105 {
106 struct wl_display *display = wl_display_connect (NULL);
107 if (display)
108 {
109 wl_display_disconnect (display);
110
111 *dpy_avail = 1;
112 }
113 else
114# if defined (HAVE_X_WINDOWS)
115 err_msg = "No working Wayland or X11 display is connected or X11 DISPLAY environment variable not set";
116# else
117 err_msg = "No working Wayland display is connected";
118# endif
119 }
120#endif
121
122#else
123
124 err_msg = "no graphical display found";
125
126#endif
127
128 return err_msg;
129}
const char * display_available(int *dpy_avail)