annotate src/display-available.c @ 28020:eb46a9f47164 stable release-5-2-0

Avoid color changes in MS Windows GUI terminal (bug #57658). * scripts/miscellaneous/mkoctfile.m: Add the gcc compiler flag "-fdiagnostics-color=never" in case of MS Windows and the GUI is running. For the MS Windows CLI version the output looks very nice. Update year.
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Tue, 28 Jan 2020 10:57:35 +0900
parents 00f796120a6d
children b442ec6dda5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
3 Copyright (C) 2012-2019 John W. Eaton
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
10 (at your option) any later version.
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
15 GNU General Public License for more details.
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
19 <https://www.gnu.org/licenses/>.
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
23 #if defined (HAVE_CONFIG_H)
22003
2d3972b802ff use consistent style for including config.h in source files
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
24 # include "config.h"
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include <stdlib.h>
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #if defined (OCTAVE_USE_WINDOWS_API)
22003
2d3972b802ff use consistent style for including config.h in source files
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
30 # include <windows.h>
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #elif defined (HAVE_FRAMEWORK_CARBON)
22003
2d3972b802ff use consistent style for including config.h in source files
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
32 # include <Carbon/Carbon.h>
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #elif defined (HAVE_X_WINDOWS)
22003
2d3972b802ff use consistent style for including config.h in source files
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
34 # include <X11/Xlib.h>
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #endif
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #include "display-available.h"
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 const char *
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 display_available (int *dpy_avail)
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 {
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 *dpy_avail = 0;
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 const char *err_msg = "";
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #if defined (OCTAVE_USE_WINDOWS_API)
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 HDC hdc = GetDC (0);
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 if (hdc)
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 *dpy_avail = 1;
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 else
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 err_msg = "no graphical display found";
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 #elif defined (HAVE_FRAMEWORK_CARBON)
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 CGDirectDisplayID display = CGMainDisplayID ();
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 if (display)
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 *dpy_avail = 1;
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 else
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 err_msg = "no graphical display found";
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 #elif defined (HAVE_X_WINDOWS)
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 const char *display_name = getenv ("DISPLAY");
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 if (display_name && *display_name)
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 {
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 Display *display = XOpenDisplay (display_name);
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 if (display)
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 {
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 Screen *screen = DefaultScreenOfDisplay (display);
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 if (! screen)
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 err_msg = "X11 display has no default screen";
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 XCloseDisplay (display);
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 *dpy_avail = 1;
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 }
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 else
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 err_msg = "unable to open X11 DISPLAY";
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 }
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 else
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 err_msg = "X11 DISPLAY environment variable not set";
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 #else
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 err_msg = "no graphical display found";
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 #endif
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 return err_msg;
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 }